apache / incubator-hugegraph

A graph database that supports more than 100+ billion data, high performance and scalability (Include OLTP Engine & REST-API & Backends)
https://hugegraph.apache.org
Apache License 2.0
2.58k stars 512 forks source link

[Question] 通过官方tinkpop的gremlin-go客户端连接GremlinServer,序列化问题如何解决 #2442

Closed ycycyccc closed 4 months ago

ycycyccc commented 5 months ago

Problem Type (问题类型)

None

Before submit

Environment (环境信息)

Your Question (问题描述)

SDK:https://github.com/apache/tinkerpop/gremlin-go/v3 v3.6.1

gremlingo.NewDriverRemoteConnection 初始化 执行 result, err := g.V("aaa").ToList() 报错

`2024/02/02 16:09:50 %!(EXTRA string=gremlinServerWSProtocol.responseHandler(), string=%!(EXTRA gremlingo.responseStatus={87 Error during serialization: Serializer for type org.apache.hugegraph.backend.id.IdGenerator$StringId not found map[exceptions:[org.apache.tinkerpop.gremlin.driver.ser.SerializationException java.io.IOException] stackTrace:org.apache.tinkerpop.gremlin.driver.ser.SerializationException: java.io.IOException: Serializer for type org.apache.hugegraph.backend.id.IdGenerator$StringId not found
        at org.apache.tinkerpop.gremlin.driver.ser.binary.ResponseMessageSerializer.writeValue(ResponseMessageSerializer.java:86)
        at org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1.serializeResponseAsBinary(GraphBinaryMessageSerializerV1.java:150)
        at org.apache.tinkerpop.gremlin.server.op.AbstractOpProcessor.makeFrame(AbstractOpProcessor.java:291)
        at org.apache.tinkerpop.gremlin.server.op.AbstractOpProcessor.handleIterator(AbstractOpProcessor.java:167)
        at org.apache.tinkerpop.gremlin.server.op.AbstractEvalOpProcessor.lambda$evalOpInternal$5(AbstractEvalOpProcessor.java:263)
        at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:283)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.hugegraph.auth.HugeGraphAuthProxy$ContextTask.run(HugeGraphAuthProxy.java:1860)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.io.IOException: Serializer for type org.apache.hugegraph.backend.id.IdGenerator$StringId not found
        at org.apache.tinkerpop.gremlin.structure.io.binary.TypeSerializerRegistry.validateInstance(TypeSerializerRegistry.java:409)
        at org.apache.tinkerpop.gremlin.structure.io.binary.TypeSerializerRegistry.getSerializer(TypeSerializerRegistry.java:378)
        at org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryWriter.write(GraphBinaryWriter.java:90)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.VertexSerializer.writeValue(VertexSerializer.java:51)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.VertexSerializer.writeValue(VertexSerializer.java:33)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.SimpleTypeSerializer.writeValue(SimpleTypeSerializer.java:91)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.SimpleTypeSerializer.write(SimpleTypeSerializer.java:73)
        at org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryWriter.write(GraphBinaryWriter.java:112)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.CollectionSerializer.writeValue(CollectionSerializer.java:52)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.ListSerializer.writeValue(ListSerializer.java:44)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.ListSerializer.writeValue(ListSerializer.java:29)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.SimpleTypeSerializer.writeValue(SimpleTypeSerializer.java:91)
        at org.apache.tinkerpop.gremlin.structure.io.binary.types.SimpleTypeSerializer.write(SimpleTypeSerializer.java:73)
        at org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryWriter.write(GraphBinaryWriter.java:112)
        at org.apache.tinkerpop.gremlin.driver.ser.binary.ResponseMessageSerializer.writeValue(ResponseMessageSerializer.java:84)
        ... 12 more
]}, uint16=87))

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

dosubot[bot] commented 5 months ago

🤖

你好,@ycycyccc!很高兴再次见到你。🌀

您遇到的序列化问题可能是由于客户端和服务器之间的序列化/反序列化格式不匹配导致的。

在提供的上下文中,服务器配置为使用四种类型的序列化器:GraphBinaryMessageSerializerV1GraphSONMessageSerializerV1d0GraphSONMessageSerializerV2d0GraphSONMessageSerializerV3d0。所有这些序列化器都配置为serializeResultToString: falseioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry]

要解决序列化问题,您需要确保gremlin-go客户端使用与服务器相同的序列化/反序列化格式。如果服务器使用GraphBinaryMessageSerializerV1,那么客户端也应使用GraphBinaryMessageSerializerV1。同样,如果服务器使用GraphSONMessageSerializerV1d0GraphSONMessageSerializerV2d0GraphSONMessageSerializerV3d0,那么客户端也应使用相应的GraphSONMessageSerializer

以下是如何在gremlin-go客户端中设置序列化器的示例:

import (
    "github.com/apache/tinkerpop/gremlin-go"
)

func main() {
    dialer := gremlin.NewDialer("ws://localhost:8183/gremlin", 
        gremlin.WithAuth("username", "password"), // if required
        gremlin.WithSerializer( /* the matching serializer */ ),
    )
    client := gremlin.NewClient(dialer)
    // ...
}

/* the matching serializer */替换为与服务器使用的序列化器匹配的序列化器。例如,如果服务器使用GraphSONMessageSerializerV3d0,您可以使用gremlin.NewGraphSONv3Serializer()

请注意,gremlin-go客户端也应能够处理在org.apache.hugegraph.io.HugeGraphIoRegistry中注册的自定义类型。如果客户端无法处理这些类型,您可能需要在客户端中为这些类型实现自定义序列化/反序列化。

参考资料:

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

imbajin commented 5 months ago

@ycycyccc 2 points may help:

  1. use gremlin-client v3.5.1 instead(keep consistent with our server)
  2. we do have a hugegraph-go-client in huegegrpah-toolchain repo(refer https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-client-go/README.md) , u don't need to use tinkerpop-gremlin-go directly instead~

hugegraph-go-client discussions: https://github.com/apache/incubator-hugegraph/discussions/2384

github-actions[bot] commented 4 months ago

Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label