RemoveNode removes a node from the hash ring
(nodeID string)
| 38 | |
| 39 | // RemoveNode removes a node from the hash ring |
| 40 | func (h *HashRing) RemoveNode(nodeID string) { |
| 41 | h.lock.Lock() |
| 42 | defer h.lock.Unlock() |
| 43 | var index int |
| 44 | var hash uint32 |
| 45 | for i, node := range h.nodes { |
| 46 | if node.ID == nodeID { |
| 47 | hash = h.hash(node.ID) |
| 48 | index = i |
| 49 | break |
| 50 | } |
| 51 | } |
| 52 | h.nodes = append(h.nodes[:index], h.nodes[index+1:]...) |
| 53 | for i, hsh := range h.hashes { |
| 54 | if hsh == hash { |
| 55 | h.hashes = append(h.hashes[:i], h.hashes[i+1:]...) |
| 56 | break |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // GetNode returns the node responsible for the given key |
| 62 | func (h *HashRing) GetNode(key string) Node { |