解決gremlin-dirver訪問tinkerpop服務器提示序列化錯誤
問題描述
程序集成了gremlin-driver,訪問遠程tinkerpop服務器,在執行創建節點操作時,返回如下錯誤棧:
2017-08-17 15:25:27.519 ERROR 13548 --- [n-driver-loop-3] o.a.t.g.d.Handler$GremlinResponseHandler : Could not process the response io.netty.handler.codec.DecoderException: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: org.apache.tinkerpop.shaded.kryo.KryoException: Encountered unregistered class ID: 65536 Serialization trace: id (org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at org.apache.tinkerpop.gremlin.driver.handler.WebSocketClientHandler.channelRead0(WebSocketClientHandler.java:91) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:572) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:513) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:427) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:399) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: org.apache.tinkerpop.shaded.kryo.KryoException: Encountered unregistered class ID: 65536
分析
從錯誤提示中可以猜到是kryo序列化出了問題,在處理vertex時出現了未注冊類。這是考慮序列化的原理,kryo將結果從JanusGraph中序列化到Tinkerpop,再通過網絡發送到應用,出現未注冊類的情況肯定是應用端反序列化時無法找到對應類。因此考慮如何將類注冊到kryo中去。
解決:
注冊類:org.janusgraph.graphdb.relations.RelationIdentifier到配置文件中去。
hosts: [192.168.66.xxx] port: 8182 serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: false, custom: [org.janusgraph.graphdb.relations.RelationIdentifier] }}
