Janusgraph 0.3.0 Tinkerpop 3.3.3 java - 使用 GryoMessageSerializerV3d0 添加 Edge 后出现序列化错误

Janusgraph 0.3.0 Tinkerpop 3.3.3 java - serialization error after adding Edge using GryoMessageSerializerV3d0

在 Java 中添加边后出现以下错误:

16:40:44.267 [gremlin-driver-loop-1] WARN org.apache.tinkerpop.gremlin.driver.MessageSerializer - Response [PooledUnsafeDirectByteBuf(ridx: 98, widx: 98, cap: 98)] could not be deserialized by org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV3d0. org.apache.tinkerpop.shaded.kryo.KryoException: Encountered unregistered class ID: 65536 Serialization trace: id (org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge) at org.apache.tinkerpop.gremlin.structure.io.gryo.AbstractGryoClassResolver.readClass(AbstractGryoClassResolver.java:148)

Janusgraph版本为0.3.0,Tinkerpop版本为3.3.3,Janusgraph序列化配置如下:

> serializers: - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [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.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} # Older serialization versions for backwards compatibility: - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: {ioRegistries: [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.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }} - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}

以下错误几乎同时记录在服务器上并且似乎是相关的:

> 105869 2018-11-08 06:10:44,659 [gremlin-server-worker-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception. java.io.IOException: Connection reset by peer at sun.nio.ch.FileDispatcherImpl.read0(Native Method)

据我所知,我已经根据匹配的序列化程序版本排好了队,但显然一定遗漏了一些东西。非常感谢任何帮助!

代码可以在这里看到: https://gist.github.com/ptclarke/45472fa5c268a6e8441e4c35615194aa

我想你需要在客户端注册 JanusGraphIoRegistry:

GryoMapper.Builder builder = GryoMapper.build().
                                        addRegistry(JanusGraphIoRegistry.getInstance());

GryoMessageSerializerV3d0 serializer = new GryoMessageSerializerV3d0(builder);
Cluster cluster = Cluster.build().
                          addContactPoint(host).
                          port(port).
                          serializer(serializer).
                          create();

作为对您的代码的一些额外建议。考虑避免像这样的大量小更新:

public void updateVertex(Vertex v, Map<Object, Object> propertyMap) {
    for(Entry<Object, Object> e : propertyMap.entrySet()) {
        g.V(v).property(e.getKey(), e.getValue()).next();
    }
}

改为:

public void updateVertex(Vertex v, Map<Object, Object> propertyMap) {
    GraphTraversal<Vertex,Vertex> t = g.V(v);
    for(Entry<Object, Object> e : propertyMap.entrySet()) {
        t = t.property(e.getKey(), e.getValue());
    }
    t.iterate();
}

您还可以简化 "add edge" 代码:

public Edge addEdge(String label, Vertex from, Vertex to) {         
    return g.V(from).addE(label).to(to).next(); 
}