imbajin commented on code in PR #3027:
URL: https://github.com/apache/hugegraph/pull/3027#discussion_r3246541875
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java:
##########
@@ -162,7 +163,9 @@ public Id selfNodeId() {
if (this.globalNodeInfo == null) {
return null;
}
- return this.globalNodeInfo.nodeId();
+ // Scope server id to graph to avoid cross-graph collision
+ return IdGenerator.of(this.graph.spaceGraphName() + "/" +
+ this.globalNodeInfo.nodeId().asString());
}
Review Comment:
‼️ **Critical:`initServerInfo()` 中读写路径 ID 不一致(阻塞性问题)**
此处修改后 `selfNodeId()` 返回命名空间化的 ID(如 `DEFAULT-hugegraph/server-1`),但调用方
`initServerInfo()` 的存在性检查仍使用原始裸 ID,两条路径的 key 不同:
```java
// initServerInfo()(本 PR 未修改这部分)
Id serverId = nodeInfo.nodeId(); // ❌ 裸 ID:"server-1"
HugeServerInfo existed = this.serverInfo(serverId); // ❌ 用 "server-1" 查询
// ...
this.globalNodeInfo = nodeInfo; // line 140,赋值后
selfNodeId() 才变
this.saveServerInfo(this.selfNodeId(), ...); // ✅ 保存
"DEFAULT-hugegraph/server-1"
```
**后果:**
- lines 109–122 的 alive 检查(防止同名节点重复启动的保护)永远查不到已命名空间化的旧记录,保护逻辑被静默跳过
- 重启时旧的命名空间记录不会被正确识别,会直接写入新记录,旧记录成为孤儿数据积累在 backend 中
**建议修法:** 在 `initServerInfo()` 入口先设置 `globalNodeInfo`,再统一用 `selfNodeId()`
做后续查询,保持读写 key 一致:
```java
public synchronized void initServerInfo(GlobalMasterInfo nodeInfo) {
E.checkArgument(nodeInfo != null, "The global node info can't be null");
this.globalNodeInfo = nodeInfo; // 先赋值,selfNodeId() 立即返回命名空间 ID
Id serverId = this.selfNodeId(); // ✅ 与 save / remove 路径使用同一个 key
HugeServerInfo existed = this.serverInfo(serverId);
if (existed != null && existed.alive()) {
// ... 存活检查 & 等待逻辑不变 ...
}
E.checkArgument(existed == null || !existed.alive(),
"The server with name '%s' already in cluster",
serverId);
// master 唯一性检查不变 ...
this.saveServerInfo(serverId, this.selfNodeRole());
}
```
这样读取和写入始终使用同一个 ID,alive 检查和 master 唯一性保护才能真正生效。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]