在Java应用程序中使用Gremlin从远程JanusGraph服务器检索边缘列表时出现序列化错误(错误消息和配置如下)。
这是引发错误的遍历:
List<Edge> eList = g.E().toList();
仅获取一条边线也会引发错误:
Edge edge= g.E().next();
尽管如此,当检索一个顶点或一系列顶点时,它仍然可以完美地工作:
List<Vertex> vList = g.V().toList();
这是我的remote-objects.yaml文件:
hosts: [localhost]
port: 8182
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0,
config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
这是获取远程遍历的代码:
PropertiesConfiguration conf = new PropertiesConfiguration(remote-objects.yaml);
cluster = Cluster.open(conf.getString("gremlin.remote.driver.clusterFile"));
client = cluster.connect();
g = AnonymousTraversalSource.traversal().withRemote(propFileName);
这是我的服务器配置中的序列化器:
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0, org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0, org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
# Older serialization versions for backwards compatibility:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0, org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: {ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0, org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0, org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0, org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0, org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
这是错误消息:
java.util.concurrent.CompletionException: io.netty.handler.codec.DecoderException: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: org.apache.tinkerpop.shaded.kryo.KryoException: java.lang.NegativeArraySizeException
Serialization trace:
id (org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge)
at java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:375)
CompletableFuture.java:375
at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1934)
CompletableFuture.java:1934
at org.apache.tinkerpop.gremlin.driver.ResultSet.one(ResultSet.java:119)
ResultSet.java:119
at org.apache.tinkerpop.gremlin.driver.ResultSet$1.hasNext(ResultSet.java:171)
ResultSet.java:171
at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:178)
ResultSet.java:178
at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:165)
ResultSet.java:165
at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal$TraverserIterator.next(DriverRemoteTraversal.java:140)
DriverRemoteTraversal.java:140
at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal$TraverserIterator.next(DriverRemoteTraversal.java:125)
DriverRemoteTraversal.java:125
at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal.nextTraverser(DriverRemoteTraversal.java:106)
DriverRemoteTraversal.java:106
at org.apache.tinkerpop.gremlin.process.remote.traversal.step.map.RemoteStep.processNextStart(RemoteStep.java:80)
RemoteStep.java:80
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:128)
AbstractStep.java:128
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:38)
AbstractStep.java:38
at org.apache.tinkerpop.gremlin.process.traversal.Traversal.fill(Traversal.java:179)
Traversal.java:179
at org.apache.tinkerpop.gremlin.process.traversal.Traversal.toList(Traversal.java:117)
Traversal.java:117
at com.ibm.graph.App.main(App.java:25)
App.java:25
Caused by: io.netty.handler.codec.DecoderException: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: org.apache.tinkerpop.shaded.kryo.KryoException: java.lang.NegativeArraySizeException
答案 0 :(得分:3)
我相信您的问题是驱动程序和服务器之间的序列化程序配置不匹配。对于驾驶员,您可以这样做:
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0,
config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
但是对于您拥有的服务器:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0,
config: { ioRegistries [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0,
org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
您已在驱动程序侧省略了TinkerIoRegistryV3d0
。对于ioRegistries
,添加注册表的顺序很重要。因此,如果先在服务器上添加JanusGraphIoRegistry
,然后在驱动程序上意外省略了TinkerIoRegistryV3d0
,则可能会很幸运,因为序列化程序注册标识符将与JansuGraph对齐。
无论如何,将TinkerIoRegistryV3d0
添加到驱动程序配置中,或者将其从服务器配置中删除,一切正常。附带说明一下,如果您要通过网络序列化TinkerGraph实例(例如,使用TinkerIoRegistryV3d0
步骤),通常只需要subgraph()
。