go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

consistenthash: map[uint64][]interface{}

Open hitzhangjie opened this issue 3 years ago • 2 comments
trafficstars

When hash conflicts happened, the added item will be put into the []interface{}.

Supposing we have two different processes, which are watching the etcd events. While the two processes may add the services instances in different order:

p1: add n1, n2, n3 into the []interface{} p2: may add n3, n1, n2 into the []interface{}

If so, when we pick one from the []interface{}, p1 may choose index1 'n2', while p2 also choose index1 but it's 'n1'.

hitzhangjie avatar Aug 04 '22 07:08 hitzhangjie

When using this library, the service may should pay attention to the order of instances (n1, n2, n3 or n3, n2, n1) returned by the service registry?

hitzhangjie avatar Aug 04 '22 07:08 hitzhangjie

I don't think you need to pay attention. Balancing is random if not for consistent reason. If for consistent, you'll use keys, the order is not important.

kevwan avatar Aug 18 '22 00:08 kevwan

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 18 '23 01:08 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Mar 19 '24 01:03 github-actions[bot]