Database Reference
In-Depth Information
Ring representation
A Cassandra cluster is called a ring . The terminology is taken from Amazon Dynamo. Cas-
sandra 1.1 and earlier versions used to have a token assigned to each node. Let's call this
value the initial token. Each node is responsible for storing all the rows with token values
(a token is basically a hash value of a row key) ranging from the previous node's initial
token (exclusive) to the node's initial token (inclusive).
This way, the first node, the one with the smallest initial token, will have a range from the
token value of the last node (the node with the largest initial token) to the first token value.
So, if you jump from node to node, you will make a circle, and this is why a Cassandra
cluster is called a ring.
Let's take an example. Assume that there is a hashing algorithm (partitioner) that generates
tokens from 0 to 127 and you have four Cassandra machines to create a cluster. To allocate
equal load, we need to assign each of the four nodes to bear an equal number of tokens. So,
the first machine will be responsible for tokens one to 32, the second will hold 33 to 64,
third 65 to 96, and fourth 97 to 127 and 0. If you mark each node with the maximum token
number that it can hold, the cluster looks like a ring, as shown in the following figure:
Token ownership and distribution in a balanced Cassandra ring
Virtual nodes
In Cassandra 1.1 and previous versions, when you create a cluster or add a node, you
manually assign its initial token. This is extra work that the database should handle intern-
ally. Apart from this, adding and removing nodes requires manual resetting token owner-
ship for some or all nodes. This is called rebalancing . Yet another problem was replacing a
node. In the event of replacing a node with a new one, the data (rows that the to-be-re-
placed node owns) is required to be copied to the new machine from a replica of the old
machine (we will see replication later in this chapter). For a large database, this could take
Search WWH ::




Custom Search