MCPcopy Create free account
hub / github.com/PacktPublishing/System-Programming-Essentials-with-Go / RemoveNode

Method RemoveNode

ch13/hashring.go:40–59  ·  view source on GitHub ↗

RemoveNode removes a node from the hash ring

(nodeID string)

Source from the content-addressed store, hash-verified

38
39// RemoveNode removes a node from the hash ring
40func (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
62func (h *HashRing) GetNode(key string) Node {

Callers 1

TestHashRingRemoveNodeFunction · 0.95

Calls 1

hashMethod · 0.95

Tested by 1

TestHashRingRemoveNodeFunction · 0.76