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

时间:2018-11-08 06:52:05

标签: janusgraph

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

  
    

16:40:44.267 [gremlin-driver-loop-1]警告org.apache.tinkerpop.gremlin.driver.MessageSerializer-响应[PooledUnsafeDirectByteBuf(ridx:98,widx:98,cap:98)]由org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV3d0反序列化。     org.apache.tinkerpop.shaded.kryo.KryoException:遇到未注册的类ID:65536     序列化跟踪:     id(org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge)         在org.apache.tinkerpop.gremlin.structure.io.gryo.AbstractGryoClassResolver.readClass(AbstractGryoClassResolver.java:148)

  

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

  

>   序列化器:     -{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]}}     #较旧的序列化版本,用于向后兼容:     -{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]警告io.netty.channel.DefaultChannelPipeline-触发了exceptionCaught()事件,该事件到达管道的末尾。这通常意味着管道中的最后一个处理程序未处理异常。   java.io.IOException:对等重置连接       在sun.nio.ch.FileDispatcherImpl.read0(本机方法)

据我所知,我的鸭子排列在匹配的序列化器版本上,但显然一定错过了一些东西。任何帮助,不胜感激!

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

1 个答案:

答案 0 :(得分:4)

我认为您需要在客户端注册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();
}

您还可以简化“添加优势”代码:

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