JanusGraph中是否存在更高效的顶点删除方式?
关于JanusGraph批量删除顶点的问题
是否可以像OrientDB那样直接在JanusGraph中执行drop()操作删除所有顶点?
一、可行但耗时的方案:g.V().drop().iterate()
使用g.V().drop().iterate()遍历并删除70005个基础顶点耗时约2分钟。需要注意的是,JanusGraph的JanusGraph接口继承自自身的Transaction接口,而非Tinkerpop-Gremlin的Transaction接口,它实际继承自Tinkerpop-Gremlin的Graph接口。
执行日志
2023-05-10 10:21:19,726 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]) 2023-05-10 10:21:19,803 [INFO] [c.d.o.d.i.c.DefaultMavenCoordinates.main] :: DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.15.0 2023-05-10 10:21:20,226 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision 2023-05-10 10:21:20,474 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/127.0.0.1:9042, hostId=null, hashCode=4bb4c89e)=null; please provide the correct local DC, or check your contact points 2023-05-10 10:21:20,688 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] :: Generated unique-instance-id=c0a8563c288-rmt-lap-win201 2023-05-10 10:21:20,703 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]) 2023-05-10 10:21:20,728 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision 2023-05-10 10:21:20,760 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/127.0.0.1:9042, hostId=null, hashCode=1ec16fcd)=null; please provide the correct local DC, or check your contact points 2023-05-10 10:21:20,775 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] :: Initiated fixed thread pool of size 40 2023-05-10 10:21:20,876 [INFO] [o.j.g.d.StandardJanusGraph.main] :: Gremlin script evaluation is disabled 2023-05-10 10:21:20,901 [INFO] [o.j.d.l.k.KCVSLog.main] :: Loaded unidentified ReadMarker start time 2023-05-10T15:21:20.901765Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@f1d0004 2023-05-10 10:21:20,955 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes 2023-05-10 10:21:22,284 [INFO] [Main.main] :: g.V().count().next(): 70005 2023-05-10 10:21:22,287 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes 2023-05-10 10:23:09,867 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes 2023-05-10 10:23:10,914 [INFO] [Main.main] :: g.V().count().next(): 0
对应Java代码
JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open(); GraphTraversalSource g = janusGraph.traversal(); logger.info("g.V().count().next(): " + g.V().count().next()); g.V().drop().iterate(); logger.info("g.V().count().next(): " + g.V().count().next());
二、模仿OrientDB/Neo4j的无iterate()方案失败
在OrientDB和Neo4j中,只需执行g.V().drop() + orientGraph.commit()即可立即完成删除操作:
OrientDB示例代码
OrientGraph orientGraph = OrientGraph.open(configuration); GraphTraversalSource g = orientGraph.traversal(); g.V().drop(); orientGraph.commit();
但在JanusGraph中尝试g.V().drop() + g.tx().commit()却无法生效,删除前后顶点数均为70003:
失败执行日志
Connected to the target VM, address: '127.0.0.1:55234', transport: 'socket' 2023-05-10 08:05:21,875 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]) 2023-05-10 08:05:21,961 [INFO] [c.d.o.d.i.c.DefaultMavenCoordinates.main] :: DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.15.0 2023-05-10 08:05:26,093 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision 2023-05-10 08:05:28,441 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:9042, hostId=null, hashCode=3954ab39)=null; please provide the correct local DC, or check your contact points 2023-05-10 08:05:28,713 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] :: Generated unique-instance-id=c0a8563c24184-rmt-lap-win201 2023-05-10 08:05:28,731 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]) 2023-05-10 08:05:28,758 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision 2023-05-10 08:05:30,236 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/127.0.0.1:9042, hostId=null, hashCode=31297484)=null; please provide the correct local DC, or check your contact points 2023-05-10 08:05:30,249 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] :: Initiated fixed thread pool of size 40 2023-05-10 08:05:30,350 [INFO] [o.j.g.d.StandardJanusGraph.main] :: Gremlin script evaluation is disabled 2023-05-10 08:05:30,374 [INFO] [o.j.d.l.k.KCVSLog.main] :: Loaded unidentified ReadMarker start time 2023-05-10T13:05:30.374192Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@378f002a 2023-05-10 08:05:30,437 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes 2023-05-10 08:05:31,861 [INFO] [Main.main] :: g.V().count().next(): 70003 2023-05-10 08:05:31,866 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes 2023-05-10 08:05:33,045 [INFO] [Main.main] :: g.V().count().next(): 70003 2023-05-10 08:05:34,523 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes 2023-05-10 08:05:34,530 [INFO] [Main.main] :: vp[empty] 2023-05-10 08:05:34,531 [INFO] [Main.main] :: vp[empty] 2023-05-10 08:05:34,534 [INFO] [Main.main] :: vp[empty] ... 2023-05-10 08:05:34,530 [INFO] [Main.main] :: vp[empty] Disconnected from the target VM, address: '127.0.0.1:55234', transport: 'socket' Process finished with exit code 0
对应Java代码
JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open(); GraphTraversalSource g = janusGraph.traversal(); logger.info("g.V().count().next(): " + g.V().count().next()); // g.V().drop().iterate(); g.V().drop(); g.tx().commit(); logger.info("g.V().count().next(): " + g.V().count().next());
内容的提问来源于stack exchange,提问作者Zach
相关产品推荐
相关产品推荐

