incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

getVertex(顶点id值)

Open Li-YanMing opened this issue 7 years ago • 17 comments

Expected behavior 期望表现

创建了一个图库,有20万数据(A列+B列 关系列)需要写入。 按照官方给的Batch 例子方法,循环获取数据创建顶点和边,每500个顶点写入一次,再写入边。

Actual behavior 实际表现

执行了几万条后报错。 Exception in thread "main" class javax.ws.rs.NotFoundException: VERTEX with id '"顶点id值"' does not exist at com.baidu.hugegraph.exception.ServerException.fromResponse(ServerException.java:44) at com.baidu.hugegraph.client.RestClient.checkStatus(RestClient.java:63) at com.baidu.hugegraph.rest.RestClient.get(RestClient.java:177) at com.baidu.hugegraph.api.graph.VertexAPI.get(VertexAPI.java:83) at com.baidu.hugegraph.driver.GraphManager.getVertex(GraphManager.java:69)

我拿报错的顶点id值 在hugegraph-studio中查询也可以查询到。

另外,有没有根据id查询顶点的其他方法,可以不报错,即时不存在也给个返回值。

Steps to reproduce the problem 复现步骤

反复执行,总会有顶点id报不存在(不是同一个点),并且顶点已经插入图库了。

Specifications of environment 环境信息

  • hugegraph version: V0.7.4
  • operating system: centos6.5
  • hugegraph backend: mysql5.5.47

Li-YanMing avatar Dec 25 '18 02:12 Li-YanMing

@mingzichongfu 插入程序流程是什么样的?是否顶点插入完毕后再插入边的呢?有使用多线程吗? 如果是穿插着插入顶点和边的话,可设置参数checkVertex=false忽略顶点的检查。 addEdges(List edges, boolean checkVertex)

javeme avatar Dec 25 '18 04:12 javeme

@mingzichongfu 插入程序流程是什么样的?是否顶点插入完毕后再插入边的呢?有使用多线程吗? 如果是穿插着插入顶点和边的话,可设置参数checkVertex=false忽略顶点的检查。 addEdges(List edges, boolean checkVertex)

没有使用多线程。 addEdges(List edges, boolean checkVertex)设置false也试过, 也是同样报错。

Li-YanMing avatar Dec 25 '18 04:12 Li-YanMing

@mingzichongfu 请问程序中是有调用VertexAPI.get()接口吗?是否方便贴一下插入代码?

javeme avatar Dec 25 '18 05:12 javeme

@mingzichongfu 请问程序中是有调用VertexAPI.get()接口吗?是否方便贴一下插入代码?

            List<Vertex> vertexList =  new LinkedList<>();
            List<Edge> edgeList = new LinkedList<>();
            List<EdgeBean> edgebeans=new LinkedList<EdgeBean>();
            int num=0;
            while (rs.next()) {
                String sfzh =rs.getString("gmsfz");
                String hzsfzh =rs.getString("hzsfz");
                String gx =rs.getString("gx");
                String gmxm =rs.getString("gmxm");
                //后续操作
                //HugeGraphService.getInstance().makeEdgeLable(gx, "person", "person");
                GraphManager graph=HugeGraphService.getInstance().getGraph();
                Vertex vertex1=HugeGraphService.getInstance().createVertex("person", sfzh, gmxm);
                Vertex vertex2=HugeGraphService.getInstance().createVertex("person", hzsfzh,"");
                vertexList.add(vertex1);
                vertexList.add(vertex2);
                if(!"".equals(gx)&&!"null".equals(gx)&&null!=gx){
	                EdgeBean bean=new EdgeBean();
	                bean.setRelationName(gx);
	                bean.setSourceKey(sfzh);
	                bean.setTargetKey(hzsfzh);
	                edgebeans.add(bean);
                }

                if(vertexList.size()>=500){
                	vertexList =graph.addVertices(vertexList);
                	vertexList.forEach(vertex -> System.out.println(vertex.id()));
                	num++;
                	System.out.println("第"+num+"次提交顶点");
                    //创建边
                	for(EdgeBean eb:edgebeans){
                		Vertex _source=graph.getVertex("2:"+eb.getSourceKey());
                		Vertex _target=graph.getVertex("2:"+eb.getTargetKey());
                		//System.out.println("eb.getRelationName()="+eb.getRelationName());
                		Edge edge = HugeGraphService.getInstance().createEdge(eb.getRelationName(), _source, _target);
                        edgeList.add(edge);
                	}
                	graph.addEdges(edgeList,false);
                	System.out.println("提交边");
                	
                	
                	
                	vertexList= new LinkedList<>();
                	edgebeans=new LinkedList<EdgeBean>();
                	edgeList = new LinkedList<>();
                	
                }
                
            }

这个是插入的部分代码

Li-YanMing avatar Dec 25 '18 05:12 Li-YanMing

@javeme 我第一次的写法是: 从数据库把数据查询出来,把new vertex1,new vertex2放到集合里,把new Edge(label,vetex1,vetex2)放到集合里, 先提交顶点, 再提交边,但是不成功,debug边里的source ,target都是null。 所以我把创建边的顶点关键信息先存在另一个集合里, 循环集合根据vertexid 将顶点查询出来在创建边,提交边。

Li-YanMing avatar Dec 25 '18 05:12 Li-YanMing

@mingzichongfu 多谢反馈,明白你遇到的问题了,我们会根据提供的代码进行重现和分析。 目前可以你可以通过 Map<sfzh, vertexId> map来映射一下顶点id,把graph.getVertex(sfzh)换为map.get(sfzh),map的更新在vertexList =graph.addVertices(vertexList);之后进行: vertexList.forEach(vertex -> map.put(vertex.property("sfzh"), vertex.id())

javeme avatar Dec 25 '18 07:12 javeme

@mingzichongfu 多谢反馈,明白你遇到的问题了,我们会根据提供的代码进行重现和分析。 目前可以你可以通过 Map<sfzh, vertexId> map来映射一下顶点id,把graph.getVertex(sfzh)换为map.get(sfzh),map的更新在vertexList =graph.addVertices(vertexList);之后进行: vertexList.forEach(vertex -> map.put(vertex.property("sfzh"), vertex.id())

放到map里和放到对象里 做法应该没什么分别吧。 问题关键是执行程序 插入了十几万数据后,根据顶点id获取顶点失败,拿报错提示的id去hugegraph-studio 通过 gremlin能查询到顶点。

Li-YanMing avatar Dec 25 '18 07:12 Li-YanMing

@mingzichongfu

Vertex vertex1=HugeGraphService.getInstance().createVertex("person", sfzh, gmxm);
Vertex vertex2=HugeGraphService.getInstance().createVertex("person", hzsfzh,"");

createVertex方法的实现能否给出,sfzh, gmxm这两个参数你是作为key和value处理了,还是两个各作为一个属性的value处理的。

或者能否直接给出VertexLabel的定义看看。

Linary avatar Dec 25 '18 07:12 Linary

@mingzichongfu

Vertex vertex1=HugeGraphService.getInstance().createVertex("person", sfzh, gmxm);
Vertex vertex2=HugeGraphService.getInstance().createVertex("person", hzsfzh,"");

createVertex方法的实现能否给出,sfzh, gmxm这两个参数你是作为key和value处理了,还是两个各作为一个属性的value处理的。

或者能否直接给出VertexLabel的定义看看。

public Vertex createVertex(String label,String nodeId,String name){ Vertex vertex =new Vertex(label).property( "nodeId", nodeId) .property("name", name).property("nodeType", "1"); return vertex; }

Li-YanMing avatar Dec 25 '18 07:12 Li-YanMing

@mingzichongfu 嗯,这个方法应该没问题,你用的是0.7.4版本的 hugegraph 吗?

Linary avatar Dec 25 '18 07:12 Linary

@mingzichongfu 嗯,这个方法应该没问题,你用的是0.7.4版本的 hugegraph 吗?

是的0.7.4,

Li-YanMing avatar Dec 25 '18 07:12 Li-YanMing

@mingzichongfu 多谢反馈,明白你遇到的问题了,我们会根据提供的代码进行重现和分析。 目前可以你可以通过 Map<sfzh, vertexId> map来映射一下顶点id,把graph.getVertex(sfzh)换为map.get(sfzh),map的更新在vertexList =graph.addVertices(vertexList);之后进行: vertexList.forEach(vertex -> map.put(vertex.property("sfzh"), vertex.id())

放到map里和放到对象里 做法应该没什么分别吧。 问题关键是执行程序 插入了十几万数据后,根据顶点id获取顶点失败,拿报错提示的id去hugegraph-studio 通过 gremlin能查询到顶点。

@mingzichongfu 我们分析了代码,发现报错是下面这两行导致的

Vertex _source=graph.getVertex("2:"+eb.getSourceKey());
Vertex _target=graph.getVertex("2:"+eb.getTargetKey());

这可能的确是一个BUG,我们得花点时间重现。为了不妨碍你的进度,你按照 @javeme 的那种方式实现,可以先避开这个问题。

Linary avatar Dec 25 '18 07:12 Linary

@mingzichongfu 多谢反馈,明白你遇到的问题了,我们会根据提供的代码进行重现和分析。 目前可以你可以通过 Map<sfzh, vertexId> map来映射一下顶点id,把graph.getVertex(sfzh)换为map.get(sfzh),map的更新在vertexList =graph.addVertices(vertexList);之后进行: vertexList.forEach(vertex -> map.put(vertex.property("sfzh"), vertex.id())

放到map里和放到对象里 做法应该没什么分别吧。 问题关键是执行程序 插入了十几万数据后,根据顶点id获取顶点失败,拿报错提示的id去hugegraph-studio 通过 gremlin能查询到顶点。

@mingzichongfu 我们分析了代码,发现报错是下面这两行导致的

Vertex _source=graph.getVertex("2:"+eb.getSourceKey());
Vertex _target=graph.getVertex("2:"+eb.getTargetKey());

这可能的确是一个BUG,我们得花点时间重现。为了不妨碍你的进度,你按照 @javeme 的那种方式实现,可以先避开这个问题。

好的,明白

Li-YanMing avatar Dec 25 '18 08:12 Li-YanMing

@mingzichongfu 我们尝试模拟你的数据去复现这个BUG,但是没有能复现成功。

下面是我的测试类,逻辑应该跟你的一致,我只有一处修改:将 edgeLabel 固定为"knows"(我不清楚你的String gx =rs.getString("gx") 是否每次都是同一个值)。你对比一下有没有关键性的不同,如果没有麻烦试试这个测试类在你那儿跑有没有问题。

public static void main(String[] args) {
        // If connect failed will throw a exception.
        HugeClient hugeClient = new HugeClient("http://localhost:8080",
                                               "hugegraph");

        SchemaManager schema = hugeClient.schema();

        schema.propertyKey("name").asText().ifNotExist().create();
        schema.propertyKey("age").asText().ifNotExist().create();

        schema.vertexLabel("person")
              .properties("name", "age")
              .primaryKeys("name")
              .ifNotExist()
              .create();

        schema.edgeLabel("knows")
              .link("person", "person")
              .ifNotExist()
              .create();

        
        GraphManager graph = hugeClient.graph();

        List<Vertex> vertexList = new ArrayList<>();
        List<Edge> edgeList = new ArrayList<>();
        List<EdgeBean> edgebeans = new ArrayList<>();
        
        int vertexCount = 20 * 10000;
        int num = 0;

        for (int i = 1; i <= vertexCount; i++) {
            String sfzh = "sfzh-" + i;
            String hzsfzh = "hzsfz-" + i;
            String gmxm = "gmxm-" + i;
            //后续操作
            Vertex vertex1 = createVertex("person", sfzh, gmxm);
            Vertex vertex2 = createVertex("person", hzsfzh, "");
            vertexList.add(vertex1);
            vertexList.add(vertex2);

            EdgeBean bean = new EdgeBean();
            bean.setRelationName("knows");
            bean.setSourceKey(sfzh);
            bean.setTargetKey(hzsfzh);
            edgebeans.add(bean);

            if(vertexList.size()>=500){
                vertexList =graph.addVertices(vertexList);
                vertexList.forEach(vertex -> System.out.println(vertex.id()));
                num++;
                System.out.println("第"+num+"次提交顶点");
                //创建边
                for(EdgeBean eb : edgebeans){
                    Vertex _source = graph.getVertex("2:" + eb.getSourceKey());
                    Vertex _target = graph.getVertex("2:" + eb.getTargetKey());
                    Edge edge = createEdge(eb.getRelationName(), _source, _target);
                    edgeList.add(edge);
                }
                graph.addEdges(edgeList,false);
                System.out.println("提交边");

                vertexList= new ArrayList<>();
                edgebeans=new ArrayList<>();
                edgeList = new ArrayList<>();
            }
        }
    }

    private static Vertex createVertex(String label, String name, String age) {
        return new Vertex(label).property("name", name).property("age", age);
    }

    private static Edge createEdge(String label, Vertex source, Vertex target) {
        return new Edge(label).source(source).target(target);
    }

    private static class EdgeBean {

        private String label;
        private String sourceKey;
        private String targetKey;

        public void setRelationName(String label) {
            this.label = label;
        }

        public String getRelationName() {
            return this.label;
        }

        public void setSourceKey(String sourceKey) {
            this.sourceKey = sourceKey;
        }

        public void setTargetKey(String targetKey) {
            this.targetKey = targetKey;
        }

        public String getSourceKey() {
            return this.sourceKey;
        }

        public String getTargetKey() {
            return this.targetKey;
        }
    }

Linary avatar Dec 25 '18 08:12 Linary

@mingzichongfu 我们尝试模拟你的数据去复现这个BUG,但是没有能复现成功。

下面是我的测试类,逻辑应该跟你的一致,我只有一处修改:将 edgeLabel 固定为"knows"(我不清楚你的String gx =rs.getString("gx") 是否每次都是同一个值)。你对比一下有没有关键性的不同,如果没有麻烦试试这个测试类在你那儿跑有没有问题。

public static void main(String[] args) {
        // If connect failed will throw a exception.
        HugeClient hugeClient = new HugeClient("http://localhost:8080",
                                               "hugegraph");

        SchemaManager schema = hugeClient.schema();

        schema.propertyKey("name").asText().ifNotExist().create();
        schema.propertyKey("age").asText().ifNotExist().create();

        schema.vertexLabel("person")
              .properties("name", "age")
              .primaryKeys("name")
              .ifNotExist()
              .create();

        schema.edgeLabel("knows")
              .link("person", "person")
              .ifNotExist()
              .create();

        
        GraphManager graph = hugeClient.graph();

        List<Vertex> vertexList = new ArrayList<>();
        List<Edge> edgeList = new ArrayList<>();
        List<EdgeBean> edgebeans = new ArrayList<>();
        
        int vertexCount = 20 * 10000;
        int num = 0;

        for (int i = 1; i <= vertexCount; i++) {
            String sfzh = "sfzh-" + i;
            String hzsfzh = "hzsfz-" + i;
            String gmxm = "gmxm-" + i;
            //后续操作
            Vertex vertex1 = createVertex("person", sfzh, gmxm);
            Vertex vertex2 = createVertex("person", hzsfzh, "");
            vertexList.add(vertex1);
            vertexList.add(vertex2);

            EdgeBean bean = new EdgeBean();
            bean.setRelationName("knows");
            bean.setSourceKey(sfzh);
            bean.setTargetKey(hzsfzh);
            edgebeans.add(bean);

            if(vertexList.size()>=500){
                vertexList =graph.addVertices(vertexList);
                vertexList.forEach(vertex -> System.out.println(vertex.id()));
                num++;
                System.out.println("第"+num+"次提交顶点");
                //创建边
                for(EdgeBean eb : edgebeans){
                    Vertex _source = graph.getVertex("2:" + eb.getSourceKey());
                    Vertex _target = graph.getVertex("2:" + eb.getTargetKey());
                    Edge edge = createEdge(eb.getRelationName(), _source, _target);
                    edgeList.add(edge);
                }
                graph.addEdges(edgeList,false);
                System.out.println("提交边");

                vertexList= new ArrayList<>();
                edgebeans=new ArrayList<>();
                edgeList = new ArrayList<>();
            }
        }
    }

    private static Vertex createVertex(String label, String name, String age) {
        return new Vertex(label).property("name", name).property("age", age);
    }

    private static Edge createEdge(String label, Vertex source, Vertex target) {
        return new Edge(label).source(source).target(target);
    }

    private static class EdgeBean {

        private String label;
        private String sourceKey;
        private String targetKey;

        public void setRelationName(String label) {
            this.label = label;
        }

        public String getRelationName() {
            return this.label;
        }

        public void setSourceKey(String sourceKey) {
            this.sourceKey = sourceKey;
        }

        public void setTargetKey(String targetKey) {
            this.targetKey = targetKey;
        }

        public String getSourceKey() {
            return this.sourceKey;
        }

        public String getTargetKey() {
            return this.targetKey;
        }
    }

奇怪,执行你写的这个确实没有报错。 除了一个是从数据库取数据,一个是循环生成数据,别的没什么不一样的。 我在排查我的到底哪里有问题了。 (注: 20万数据里, sfzh有重复的所以id会有重复的,但是按说 已经是先插入点后插入边了, 即使同一毫秒插入,也不会有影响吧。graph没有缓存吧? 插入点和边时间间隔很小,前一秒还没有)

Li-YanMing avatar Dec 25 '18 09:12 Li-YanMing

@mingzichongfu 我试着将 sfzh 的生成方式修改成random(10000) 的也没能复现。关于缓存,server端是有缓存的,client端没有。

Linary avatar Dec 26 '18 03:12 Linary

Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label

github-actions[bot] avatar Jan 23 '22 21:01 github-actions[bot]