VGalaxies commented on code in PR #2676:
URL: https://github.com/apache/hugegraph/pull/2676#discussion_r3371421505


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java:
##########
@@ -228,6 +238,32 @@ protected boolean graphIsReady() {
         return !this.closed && this.graph.started() && 
this.graph.initialized();
     }
 
+    protected synchronized void updateIsSingleNode(){
+        Collection<HugeServerInfo> servers=this.allServerInfos();
+        boolean hasWorkerNode = false;
+        long now = DateUtil.now().getTime();
+        int computerNodeCount=0;
+
+        // Iterate servers to find suitable one
+        for (HugeServerInfo server : servers) {
+            if (!server.alive()) {
+                continue;
+            }
+            if (server.role().master()) {
+                continue;
+            }else if (server.role().computer()){
+                computerNodeCount++;
+            }
+            hasWorkerNode = true;
+        }
+
+        boolean singleNode = !hasWorkerNode||computerNodeCount==1;

Review Comment:
   High 
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java:260
 - One computer node marks every cluster as single-node
      Evidence: `singleNode = !hasWorkerNode || computerNodeCount == 1` becomes 
true for any live cluster with exactly one `COMPUTER`, even when live `WORKER` 
nodes also exist. Then `selfIsMasterOrSingleComputer()` allows that computer 
node to run `scheduleTasksOnMaster()` via `TaskManager.java:450-451`.
      Impact: A normal master/worker cluster with one computer node can now 
have a non-master computer scheduling tasks concurrently with the real master, 
and `onlySingleNode()` also makes the assigned master execute worker tasks 
locally instead of returning in non-elected mode.
      Requested fix: Keep `onlySingleNode` as the original “no live non-master 
workers” meaning, and add a separate standalone-computer predicate that is true 
only when the current node is `COMPUTER` and the live server set contains no 
master/worker and exactly that one computer.



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java:
##########
@@ -172,8 +172,18 @@ public NodeRole selfNodeRole() {
         return this.globalNodeInfo.nodeRole();
     }
 
-    public boolean selfIsMaster() {
-        return this.selfNodeRole() != null && this.selfNodeRole().master();
+    public boolean selfIsMasterOrSingleComputer() {
+        boolean isMaster=this.selfNodeRole() != null && 
this.selfNodeRole().master();
+        boolean isSingleComputer=isStandAloneComputer();

Review Comment:
   Medium 
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java:177
 - Standalone computer cannot schedule immediately after startup
      Evidence: `onlySingleNode` is initialized false and `initServerInfo()` 
does not recompute it; `selfIsMasterOrSingleComputer()` depends on that flag 
through `isStandAloneComputer()`. The first recompute is 
`TaskManager.java:442`, but the scheduler starts after `10 * SCHEDULE_PERIOD` 
at `TaskManager.java:103-106`.
      Impact: A single `COMPUTER` server still rejects task scheduling as 
“non-master” during startup until the delayed background scheduler runs, making 
the feature timing-dependent.
      Requested fix: Initialize/recompute standalone-computer state 
synchronously during `initServerInfo()`, or make the master check derive 
standalone-computer status from current live server info before rejecting 
scheduling.



-- 
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]

Reply via email to