1

Lets say I have a cassandra cluster with the following scheme:

(76-100) Node1 - Node2 (0-25)
                 |      |
(51-75)  Node4 - Node3 (26-50)

Each node is primarily responsible for a range of partition keys: For example, for a total range of 0-100, I have indicated what range the node is responsible above.

Now, lets say Node 1 is coordinator handing requests. A read request corresponding to partition key 28 reaches Node 1.

How does Node 1 know that Node 2 is primary node for partition key 28. Does each node have a mapping of node IDs to the partition key they are responsible for. For instance,

{Node1:76-100, Node2: 0-25, Node3: 26-50, Node4: 51-75}

is this mapping present as global configuration in all the nodes since any node can act as coordinator when requests are forwarded in round-robin fashion?

Thanks

Community
  • 1
  • 1
brain storm
  • 30,124
  • 69
  • 225
  • 393

1 Answers1

2

The mapping is not present as a global configuration. Rather each node maintains its own copy of the state of the other nodes in the cluster. Typically the cluster will use the gossip protocol to frequently exchange information about the other nodes in the cluster with a few nearby nodes. In this way the mapping information will rapidly propagate to all the nodes in the cluster, even if there are thousands of nodes.

It is necessary for every node to know how to map partition keys to token values, and to know which node is responsible for that token. This is so that every node can act as a coordinator to handle any request by sending it to the exact nodes that are handling that key.

Taken a step further, if you use for example the current java driver, you can have the client use a token aware routing policy. This works by the client driver also getting a copy of the information about how to map keys to nodes. Then when you issue a request, it will be sent directly to a node that is handling that key. This gives a nice performance boost.

Generally you do not need to worry about how the keys are mapped, since if you use vnodes and the Murmur3Partitioner, the cluster will take care of creating the mapping of keys to balance the load across the cluster as nodes are added and removed.

Jim Meyer
  • 9,275
  • 1
  • 24
  • 49