Try
↑ ↓ move↵ openesc close
In this lesson · topic 5 of 7
  1. 1. Too much data, too many writes
  2. 2. Range, hash, and splitting
  3. 3. Split a hot range and compare layouts
  4. 4. When one key outruns every partition
  5. 5. Adding a node, and how requests find their partition
  6. 6. Looking up by the column you did not partition on
  7. 7. Check the partitioning rules

Topic 5

Adding a node, and how requests find their partition

6 min read

A partitioning scheme is chosen once and lived with for years. The machines under it change every month. Two questions decide whether that is painful: how much data moves when they change, and how a request finds the right machine afterwards.

Why mod N is the wrong map

Send a key to machine hash(key) mod N. With 10 machines, a key stays put after an 11th joins only if hash mod 10 equals hash mod 11. Looking at hash mod 110, that is true for 10 of the 110 residues. So about 9 percent of keys stay and 91 percent move. Nearly the whole dataset crosses the network to add one machine.

Many small partitions

Create far more partitions than machines, say 1,000 for 10 machines, which is 100 each. A key’s partition is fixed for good: hash(key) mod 1000. What changes is the table that says which machine holds each partition.

When an 11th machine joins, it takes partitions from the others until the load is level. Fair share is 1,000 / 11, about 91 partitions, which is 9 percent of the data. Only that much moves, and nothing is rehashed. The rest of the cluster keeps serving from the partitions it still has.

Choose the count with care. It sets the finest grain of balancing and the ceiling on cluster size, since you cannot have more machines than partitions. Too many partitions add per-partition overhead, in metadata, files, and replication streams.

Range-partitioned stores do it the other way: start with few and split as partitions grow, the approach from the first topics. Both schemes keep the same principle, which is to move whole partitions and never recompute where keys live.

Predict first

A cluster has 20 machines and 2,000 fixed partitions. Two machines join together. Roughly how many partitions move, if the result is perfectly level?

Finding the partition

Once the map exists, a client with a key must reach the right machine. There are three common designs:

  • Any node will do. The client contacts any node, which forwards the request if it does not own the key. Nodes share the map by gossip. This is the Dynamo and Cassandra style.
  • A routing tier. A thin proxy holds the map and forwards requests. Clients stay simple, and the proxy is another thing to run and scale.
  • A smart client. The client fetches the map and talks straight to the owner. It is the fastest path and the hardest to keep correct, because the cached map goes stale after each move and the client must handle a “not mine, try there” reply.

Where the authoritative map lives matters. A strongly consistent coordination service such as ZooKeeper or etcd is a common home, because two nodes must never both believe they own a partition. Gossip is lighter but converges slowly, so for a short while different nodes disagree.

When automatic rebalancing hurts

Moving partitions is expensive, since it reads, sends and writes a lot of data on machines that are already serving traffic. Combine automatic failure detection with automatic rebalancing and you can get a cascade. A node is slow under load, the detector declares it dead, its partitions are copied elsewhere, the extra copying slows the other nodes, and the detector declares one of them dead too.

Headroom is part of the arithmetic. When one machine of n is lost, the survivors carry u x n / (n - 1) of the old load each. For 10 machines at 70 percent, survivors reach 78 percent. At 90 percent they hit 100 percent, before the rebalancing traffic is added. Many operators keep a human in the loop for rebalancing, or at least rate-limit it, for this reason.

Sources

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms