Similarityoung commented on code in PR #973:
URL: https://github.com/apache/dubbo-go-pixiu/pull/973#discussion_r3788674018
##########
pkg/model/cluster.go:
##########
@@ -305,3 +315,39 @@ func cloneLLMMeta(meta *LLMMeta) *LLMMeta {
cloned.RetryPolicy.Config =
copyutil.CloneStringAnyMap(meta.RetryPolicy.Config)
return &cloned
}
+
+// CloneClusterConfig returns a deep copy of c suitable for handing to a new
+// runtime Cluster. The clone owns its Endpoints and HealthChecks slices.
+// ConsistentHash.Hash (a mutable runtime object) is set to nil so the runtime
+// starts with a clean hash; the config fields (ReplicaNum, MaxVnodeNum,
+// MaglevTableSize) are preserved. configID is preserved so callers can detect
+// config-object identity changes. PrePickEndpointIndex is NOT copied — runtime
+// cursor state belongs on the runtime, not in the config clone.
+func CloneClusterConfig(c *ClusterConfig) *ClusterConfig {
+ if c == nil {
+ return nil
+ }
+ clone := *c
+ clone.Endpoints = CloneEndpoints(c.Endpoints)
+ clone.HealthChecks = cloneHealthChecks(c.HealthChecks)
+ clone.ConsistentHash = ConsistentHash{
+ ReplicaNum: c.ConsistentHash.ReplicaNum,
+ MaxVnodeNum: c.ConsistentHash.MaxVnodeNum,
+ MaglevTableSize: c.ConsistentHash.MaglevTableSize,
+ Hash: nil,
+ }
Review Comment:
当 `LbStr` 没有注册工厂时,请保留 `ConsistentHash.Hash`。 `prepareOwnedClusterConfig`
明确支持为此类自定义策略注入哈希,但这里在发布运行时前始终把它替换为 nil,导致读取该哈希的已注册快照负载均衡器无法选出端点。 审查测试
`TestReviewerRuntimePreservesProgrammaticCustomHash` 在 base 通过、在当前 head 因选中端点为
nil 而失败,因此应只在哈希能够重建时清空它,否则保留调用方注入的实现。
--
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]