Add safely adds a new member to the consistent hash circle. It ensures thread safety and redistributes partitions after adding the member.
(member Member)
| 283 | // Add safely adds a new member to the consistent hash circle. |
| 284 | // It ensures thread safety and redistributes partitions after adding the member. |
| 285 | func (c *Consistent) Add(member Member) { |
| 286 | // Acquire a write lock to ensure thread safety. |
| 287 | c.mu.Lock() |
| 288 | defer c.mu.Unlock() |
| 289 | |
| 290 | // Check if the member already exists in the ring. If it does, exit early. |
| 291 | if _, exists := c.members[member.String()]; exists { |
| 292 | return |
| 293 | } |
| 294 | |
| 295 | // Add the member to the ring and redistribute partitions. |
| 296 | c.addMemberToRing(member) |
| 297 | c.distributePartitions() |
| 298 | } |
| 299 | |
| 300 | // removeFromSortedSet removes a hash value from the sorted set of hashes. |
| 301 | func (c *Consistent) removeFromSortedSet(hashValue uint64) { |
no test coverage detected