mochengqian opened a new issue, #969:
URL: https://github.com/apache/dubbo-go-pixiu/issues/969

   ## Background
   
   Follow-up from the #950 audit 
(https://github.com/apache/dubbo-go-pixiu/issues/950#issuecomment-4642984375).
   
   Two functions implement **byte-for-byte the same** endpoint-ID 
collision-suffix algorithm in two packages:
   
   - `nextStableEndpointID` — `pkg/server/cluster_manager.go` (used by 
`assembleClusterEndpoints` on the static/dynamic config path, and by 
`resolveSetEndpointSlotByHash`)
   - `uniqueSnapshotEndpointID` — `pkg/cluster/cluster.go` (used by 
`newEndpointSnapshot` on snapshot rebuild)
   
   Both do the same thing: resolve a base ID (operator-supplied `endpoint.ID` 
if set, else `model.GenerateEndpointID(clusterName, endpoint)`), return it if 
free, otherwise append `-2`, `-3`, ... until unique within the per-cluster 
dedup set.
   
   ## Problem
   
   They are kept in sync only by convention. Endpoint ID is the runtime 
health/cooldown key, so if a future change touches one and not the other (e.g. 
changes the suffix separator, or the collision base), config assembly and 
snapshot rebuild would silently assign **different** IDs to the same endpoint — 
splitting health/cooldown state for that endpoint across a snapshot rebuild.
   
   There is no test pinning the two implementations to each other; each is only 
tested in isolation.
   
   ## Proposal
   
   Lift the algorithm into a single shared helper, most naturally in 
`pkg/model` next to `GenerateEndpointID` (which both call), e.g.:
   
   ```go
   // pkg/model
   func StableUniqueEndpointID(clusterName string, endpoint *Endpoint, taken 
map[string]struct{}) string
   ```
   
   Then `nextStableEndpointID` and `uniqueSnapshotEndpointID` become thin 
call-throughs (or are removed). This guarantees assembly and snapshot rebuild 
can never drift.
   
   ## Acceptance criteria
   
   - One implementation of the `-2/-3` suffix algorithm; both call sites use it.
   - Existing dedup tests in `pkg/server` and `pkg/cluster` still pass 
unchanged.
   - A test asserts assembly and snapshot rebuild produce identical IDs for a 
duplicate-ID cluster (locks the two paths together).
   
   ## Out of scope
   
   - Changing the dedup *semantics* (suffix-vs-replace, hard-fail on 
duplicates) — that is #949's discussion, not this refactor.
   
   ## Difficulty
   
   Low. Pure consolidation, no behavior change.


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