Remove removes a member from the consistent hash circle.
(name string)
| 264 | |
| 265 | // Remove removes a member from the consistent hash circle. |
| 266 | func (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. |
| 291 | func (c *Consistent) LoadDistribution() map[string]float64 { |