Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.page.PageInfo;
import org.apache.hugegraph.backend.query.Condition;
import org.apache.hugegraph.backend.query.ConditionQuery;
Expand Down Expand Up @@ -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());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‼️ Critical:initServerInfo() 中读写路径 ID 不一致(阻塞性问题)

此处修改后 selfNodeId() 返回命名空间化的 ID(如 DEFAULT-hugegraph/server-1),但调用方 initServerInfo() 的存在性检查仍使用原始裸 ID,两条路径的 key 不同:

// 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 一致:

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 唯一性保护才能真正生效。


public NodeRole selfNodeRole() {
Expand Down
Loading