This is the payoff the whole project has been building toward. Add a node to the ring and only the keys in its slice of the ring move to it - everyone else stays exactly put. Today you prove it by capturing which keys move when a node joins.
Show that adding a node reassigns only the keys in the arc it now covers.
Now compare this to lesson four’s disaster. When delta joins at 31777, it drops into
the arc between alpha (28075) and beta (58567) and takes over just the piece of that
arc from 28075 up to 31777. The only key living there is orange at 29675, so orange
moves from beta to delta and nothing else changes. One key moved, versus eight
under modulo hashing.
This is the defining property of consistent hashing: adding a node only steals keys from
its immediate clockwise neighbor, the keys in the new node’s arc. Every key outside that
arc is untouched because its first-node-clockwise answer did not change. The MovedKeys
helper - a plain before-and-after diff of the assignment - is worth keeping; you will use
it to measure removals next and to check the capstone. In a real cache this means adding
a server invalidates a sliver of entries, not the entire cache.
// Diff the assignment before and after a ring change.func MovedKeys(before, after map[string]string) []string {var moved []stringfor k, was := range before {if after[k] != was {moved = append(moved, k)}}return moved // sort before asserting}