bitflicker64 commented on code in PR #3210:
URL: https://github.com/apache/hugegraph/pull/3210#discussion_r4033548511


##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java:
##########
@@ -482,6 +495,82 @@ private HugeGraph createSysGraphIfNeed() {
         return graph;
     }
 
+    private void waitForActiveStores() {
+        int timeout = this.conf.get(ServerOptions.PD_STORES_WAIT_TIMEOUT);
+        if (timeout <= 0) {
+            return;
+        }
+        PDConfig pdConfig = PDConfig.of(this.pdPeers);
+        pdConfig.setAuthority(PdMetaDriver.PDAuthConfig.service(),
+                              PdMetaDriver.PDAuthConfig.token());
+        // same short-lived client as limitStorage(); PDClient has no close()
+        PDClient pdClient = PDClient.create(pdConfig);
+        try {
+            Metapb.PDConfig pd = pdClient.getPDConfig();
+            int required = pd.getMinStoreCount() > 0 ? pd.getMinStoreCount() :

Review Comment:
   ⚠️ Important. With the `PDConfig` PD serves, `min_store_count` is always 0 
(`ConfigService` only sets partition and shard count), so `required` is 
`shard_count` on every cluster, and this runs on every start, not just the 
first boot.
   
   That turns a normal restart into a failure: 3 stores, `default-shard-count: 
3`, one store down for maintenance. Each raft group still has 2 of 3 replicas, 
PD's `checkStoreStatus()` reports `Cluster_OK` (it compares against 
`pd.initial-store-count` and a per-group majority), and before this PR the 
server opened its graphs. Now `getActiveStores()` returns 2, the loop waits 300 
s and throws. The count is also not what PD enforces on first boot: 
`allocShards()` checks `pd.initial-store-count` and caps shards at 
`min(shard_count, stores)`, so a cluster with fewer stores than `shard_count` 
never starts, and one with `initial-store-count` above `shard_count` still hits 
the original retry ceiling.
   
   Requested change: gate the wait on PD's own readiness instead of a derived 
count, for example poll `pdClient.getClusterStats()` until the state is 
`Cluster_OK` (which already encodes `initial-store-count` and the majority 
check), or at least skip the wait once shard groups exist. Add a test for the 
restart-with-a-store-down case.



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