incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Question] 6 server(1 master + 5 worker) 集群搭建后,如何使用HugeGraph-Java-Client去连接server,我当前连接方式是否有问题?

Open Tommu10ve opened this issue 6 months ago • 4 comments

Problem Type (问题类型)

None

Before submit

  • [x] 我已经确认现有的 IssuesFAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: 1.5.0 (Apache Release Version)
  • Backend: RocksDB 6 nodes SSD

Your Question (问题描述)

192.168.12.56 nginx 代理 6台server 服务

http {
    upstream backend {
        # 定义后端服务器列表(6台服务器)
        server 192.168.12.40:8080;
        server 192.168.12.41:8080;
        server 192.168.12.42:8080;
        server 192.168.12.43:8080;
        server 192.168.12.44:8080;
        server 192.168.12.45:8080;

        # 可选:负载均衡策略(默认是轮询)
        # least_conn;  # 最少连接
        # ip_hash;     # 基于客户端 IP 的哈希(会话保持)
    }

    server {
        listen 8080;  # Nginx 监听的端口(通常是 80 或 443)

        location / {
            proxy_pass http://backend;  # 反向代理到后端服务器
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

HugeGraph-Java-Client 端配置

        <dependency>
            <groupId>org.apache.hugegraph</groupId>
            <artifactId>hugegraph-client</artifactId>
            <version>1.5.0</version>
        </dependency>
   HugeClient hugeClient = HugeClient.builder("http://192.168.12.56:8080",
                                                   "hugegraph")
                                          .build();

HugeGraph-Java-Client HugeClient.builder中 如何链接集群版本的图数据库?

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


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


Tommu10ve avatar Jun 19 '25 08:06 Tommu10ve

通过上面方式执行后: 原来单机部署好的server功能运行正常代码,在集群环境下会以下异常:

Image

Tommu10ve avatar Jun 19 '25 08:06 Tommu10ve

HugeGraph-Java-Client 本身不感知集群,只是把请求发送到你配置的 REST 接口(比如 Nginx 代理地址),所以你的 client 连接方式没问题,不需要特殊配置。出现 “invalid vertex ID” 这类异常,通常不是 client 配置问题,而是后端集群或代理层(如 Nginx)导致的。例如:

  • Nginx 没有配置会话保持(如 ip_hash),导致同一个会话的请求被分发到不同节点,节点间数据未同步或缓存不一致时就会报错。
  • 集群各节点 hugegraph.properties 配置不一致,尤其是 raft.group_peers、data/wal 路径、端口等,或者节点未全部初始化、网络不通。
  • 旧参数如 raft.mode 已废弃,1.5.0 只需配置 raft.group_peers,且必须写在每个节点的 graphs/hugegraph.properties 文件里,不能写在 rest-server.properties 里。参考 参考2

建议排查:

  1. 检查 Nginx 是否开启了 ip_hash 或其他会话保持策略,避免同一会话请求被分发到不同节点。
  2. 确认所有节点的 hugegraph.properties 配置完全一致,raft.group_peers 包含所有节点,端口、路径无冲突,节点已全部初始化且网络互通。
  3. 检查 vertex/edge id 是否有格式或编码问题,尤其是 URL 编码。参考
  4. 如果是新集群,建议先用 curl 直接请求 Nginx 代理地址,确认 REST API 能正常增删查改。

如还有具体报错堆栈或日志,可以补充下详细内容,便于进一步定位。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar Jun 19 '25 08:06 dosubot[bot]

@dosu-bot 如果没有nginx代理,HugeGraph-Java-Client怎么连接到集群server

Tommu10ve avatar Jun 19 '25 09:06 Tommu10ve

HugeGraph-Java-Client 不能自动感知集群,也不支持多节点切换或高可用。没有 Nginx 代理时,你只能在 HugeClient.builder 里填写某一个节点的 REST API 地址(比如 master 节点的 http://ip:port),所有请求都会发到这个节点。如果该节点不可用,client 也无法自动切换到其他节点。

所以,直接连接集群时,写法如下:

HugeClient hugeClient = HugeClient.builder("http://某个节点IP:端口", "hugegraph").build();

注意事项:

  • 你只能指定一个节点的 REST 地址,不能写多个。
  • 集群所有节点的 graphs/hugegraph.properties 配置必须完全一致(尤其是 raft.group_peers),端口不能冲突,网络互通,data/wal 路径可区分。
  • 高可用、负载均衡、自动故障切换只能靠 Nginx 或类似的反向代理实现,Java client 本身不支持这些功能。参考 参考2

如果直接连节点,建议选 leader 节点(可通过 REST API 查询当前 leader),否则写入操作可能会被重定向或失败。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar Jun 19 '25 09:06 dosubot[bot]

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

github-actions[bot] avatar Jul 04 '25 21:07 github-actions[bot]