MCPcopy Create free account
hub / github.com/buraksezer/consistent / Remove

Method Remove

consistent.go:266–288  ·  view source on GitHub ↗

Remove removes a member from the consistent hash circle.

(name string)

Source from the content-addressed store, hash-verified

264
265// Remove removes a member from the consistent hash circle.
266func (c *Consistent) Remove(name string) {
267 c.mu.Lock()
268 defer c.mu.Unlock()
269
270 if _, ok := c.members[name]; !ok {
271 // There is no member with that name. Quit immediately.
272 return
273 }
274
275 for i := 0; i < c.config.ReplicationFactor; i++ {
276 key := []byte(fmt.Sprintf("%s%d", name, i))
277 h := c.hasher.Sum64(key)
278 delete(c.ring, h)
279 c.delSlice(h)
280 }
281 delete(c.members, name)
282 if len(c.members) == 0 {
283 // consistent hash ring is empty now. Reset the partition table.
284 c.partitions = make(map[int]*Member)
285 return
286 }
287 c.distributePartitions()
288}
289
290// LoadDistribution exposes load distribution of members.
291func (c *Consistent) LoadDistribution() map[string]float64 {

Callers 2

TestConsistentRemoveFunction · 0.80
BenchmarkAddRemoveFunction · 0.80

Calls 3

delSliceMethod · 0.95
distributePartitionsMethod · 0.95
Sum64Method · 0.65

Tested by 2

TestConsistentRemoveFunction · 0.64
BenchmarkAddRemoveFunction · 0.64