mochengqian opened a new pull request, #919: URL: https://github.com/apache/dubbo-go-pixiu/pull/919
### Description Implements Issue #905 Step 3 only: tighten cluster runtime consistency. Issue #905 step progress: - [x] Add tests and benchmarks - [x] Fix current correctness issues - [ ] Tighten runtime consistency - [ ] Switch cluster lookup to O(1) - [ ] Introduce healthy endpoint snapshots - [ ] Optimize simple LB hot path - [ ] Optimize consistent-hash LB last ### Why `ClusterManager` currently keeps both `store.Config` and `clustersMap` runtime state. Before switching cluster lookup to `clustersMap` in a later PR, every write path must keep these views consistent. Without this step, `UpdateCluster`, `CompareAndSetStore`, and endpoint updates can leave stale runtime clusters, stale healthcheck lifecycle state, or consistent hash entries that no longer match current endpoints. ### Root Cause: `UpdateCluster` only replaced `store.Config` and did not rebuild/replace the runtime cluster. `CompareAndSetStore` swapped the store without ensuring the new store had runtime clusters, and without stopping replaced old runtime clusters. `SetEndpoint` updated endpoint address fields without rebuilding consistent hash, so RingHash/Maglev could still point to old hosts. Healthcheck runtime stop can happen before checker timers are initialized, causing nil timer panic during early stop. ### PR Goal: Make cluster write paths maintain a consistent lifecycle boundary between config state and runtime state. Ensure `store.Config`, `clustersMap`, runtime `Cluster.Config`, healthcheck lifecycle, consistent hash, and round-robin cursor carry-over remain coherent after successful writes. ### Success Criteria: After `AddCluster` / `UpdateCluster` / `SetEndpoint` / `DeleteEndpoint` / successful `CompareAndSetStore`, `clustersMap[name].Config` points to the current cluster config. `clustersMap` does not retain stale runtime clusters removed from config. Replaced runtime clusters are stopped. `CompareAndSetStore` version mismatch returns `false` with zero side effects. Round-robin `PrePickEndpointIndex` is atomically carried over during store refresh/update. Consistent hash reflects current endpoint hosts after endpoint address update/delete. ### Paths this PR should affect: pkg/server/cluster_manager.go pkg/server/cluster_manager_test.go pkg/cluster/healthcheck/healthcheck.go ### Revise Adding `prepareClusterConfig`: centralizes endpoint assembly and consistent hash creation. Adding `ensureRuntimeClusters`: repairs nil/missing/mismatched/stale runtime map entries before CAS swap. Changing `CompareAndSetStore`: ensures runtime clusters, carries over runtime cursor state, swaps store, then stops replaced old runtime clusters. Changing `UpdateCluster`: rebuilds current config/hash, carries over RR cursor, replaces runtime cluster, and stops the old runtime. Changing `SetEndpoint` / `DeleteEndpoint`: repairs mismatched runtime state and rebuilds consistent hash from current endpoints. Adding healthcheck nil timer guard: avoids panic when a runtime cluster is stopped before checker timers are initialized. Adding regression tests: proves CAS zero side effects, runtime replacement/stop, stale runtime cleanup, cursor carry-over, and direct consistent hash host changes. -- 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]
