This is an automated email from the ASF dual-hosted git repository.
imbajin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hugegraph.git
The following commit(s) were added to refs/heads/master by this push:
new 66e5339e3 fix(server): different graph name share the same backend
(#3027)
66e5339e3 is described below
commit 66e5339e3a2e5d96e4d1e36e6ef0281ec3454625
Author: Soyaazz <[email protected]>
AuthorDate: Sun May 17 11:54:28 2026 +0800
fix(server): different graph name share the same backend (#3027)
## Main Changes
Change `ServerInfoManager.selfNodeId()` which returns "server-1" previously
to "{graphname}/server-1"
## Upgrade impact
This change namespaces the server id by graph name, so old unfinished tasks
in the non-PD local scheduler may still reference the previous bare server id,
for example `server-1`.
Those historical tasks can remain visible, but they may not be restored or
cancelled by the new namespaced server id after upgrade. The impact is limited
to unfinished local-scheduler tasks that already existed before upgrading;
newly scheduled tasks use the new namespaced id. To avoid this compatibility
edge case, finish or cancel pending local tasks before upgrading.
---
.../apache/hugegraph/task/ServerInfoManager.java | 11 ++--
.../org/apache/hugegraph/unit/UnitTestSuite.java | 2 +
.../hugegraph/unit/core/ServerInfoManagerTest.java | 76 ++++++++++++++++++++++
3 files changed, 85 insertions(+), 4 deletions(-)
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java
index bcef86901..1560ec0b8 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java
@@ -29,6 +29,7 @@ import org.apache.hugegraph.HugeException;
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;
@@ -104,7 +105,9 @@ public class ServerInfoManager {
public synchronized void initServerInfo(GlobalMasterInfo nodeInfo) {
E.checkArgument(nodeInfo != null, "The global node info can't be
null");
- Id serverId = nodeInfo.nodeId();
+ this.globalNodeInfo = nodeInfo;
+
+ Id serverId = this.selfNodeId();
HugeServerInfo existed = this.serverInfo(serverId);
if (existed != null && existed.alive()) {
final long now = DateUtil.now().getTime();
@@ -137,8 +140,6 @@ public class ServerInfoManager {
} while (page != null);
}
- this.globalNodeInfo = nodeInfo;
-
// TODO: save ServerInfo to AuthServer
this.saveServerInfo(this.selfNodeId(), this.selfNodeRole());
}
@@ -162,7 +163,9 @@ public class ServerInfoManager {
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());
}
public NodeRole selfNodeRole() {
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
index ce249a967..f9542ecac 100644
---
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
@@ -45,6 +45,7 @@ import org.apache.hugegraph.unit.core.RolePermissionTest;
import org.apache.hugegraph.unit.core.RowLockTest;
import org.apache.hugegraph.unit.core.SecurityManagerTest;
import org.apache.hugegraph.unit.core.SerialEnumTest;
+import org.apache.hugegraph.unit.core.ServerInfoManagerTest;
import org.apache.hugegraph.unit.core.SystemSchemaStoreTest;
import org.apache.hugegraph.unit.core.TraversalUtilTest;
import org.apache.hugegraph.unit.id.EdgeIdTest;
@@ -125,6 +126,7 @@ import org.junit.runners.Suite;
TraversalUtilTest.class,
PageStateTest.class,
SystemSchemaStoreTest.class,
+ ServerInfoManagerTest.class,
RoleElectionStateMachineTest.class,
HugeGraphAuthProxyTest.class,
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/ServerInfoManagerTest.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/ServerInfoManagerTest.java
new file mode 100644
index 000000000..85815bbc1
--- /dev/null
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/ServerInfoManagerTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.unit.core;
+
+import java.util.concurrent.ExecutorService;
+
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.masterelection.GlobalMasterInfo;
+import org.apache.hugegraph.task.ServerInfoManager;
+import org.apache.hugegraph.testutil.Assert;
+import org.apache.hugegraph.testutil.Whitebox;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class ServerInfoManagerTest {
+
+ private ServerInfoManager sysGraphManager;
+ private ServerInfoManager hugegraphManager;
+
+ @Before
+ public void setup() {
+ HugeGraphParams sysGraphParams = Mockito.mock(HugeGraphParams.class);
+ Mockito.when(sysGraphParams.spaceGraphName())
+ .thenReturn("DEFAULT-~sys_graph");
+
+ HugeGraphParams hugegraphParams = Mockito.mock(HugeGraphParams.class);
+ Mockito.when(hugegraphParams.spaceGraphName())
+ .thenReturn("DEFAULT-hugegraph");
+
+ ExecutorService executor = Mockito.mock(ExecutorService.class);
+
+ this.sysGraphManager = new ServerInfoManager(sysGraphParams, executor);
+ this.hugegraphManager = new ServerInfoManager(hugegraphParams,
executor);
+ }
+
+ @Test
+ public void testSelfNodeIdScopedByGraphWithSameNodeId() {
+ GlobalMasterInfo nodeInfo = GlobalMasterInfo.master("server-1");
+
+ Whitebox.setInternalState(this.sysGraphManager,
+ "globalNodeInfo", nodeInfo);
+ Whitebox.setInternalState(this.hugegraphManager,
+ "globalNodeInfo", nodeInfo);
+
+ Id sysGraphNodeId = this.sysGraphManager.selfNodeId();
+ Id hugegraphNodeId = this.hugegraphManager.selfNodeId();
+
+ Assert.assertEquals("DEFAULT-~sys_graph/server-1",
+ sysGraphNodeId.asString());
+ Assert.assertEquals("DEFAULT-hugegraph/server-1",
+ hugegraphNodeId.asString());
+ Assert.assertFalse(sysGraphNodeId.equals(hugegraphNodeId));
+ }
+
+ @Test
+ public void testSelfNodeIdReturnsNullWhenNotInitialized() {
+ Assert.assertNull(this.sysGraphManager.selfNodeId());
+ }
+}