PLANNED MAINTENANCE

Hello, DataStax Community!

We want to make you aware of a few operational updates which will be carried out on the site. We are working hard to streamline the login process to integrate with other DataStax resources. As such, you will soon be prompted to update your password. Please note that your username will remain the same.

As we work to improve your user experience, please be aware that login to the DataStax Community will be unavailable for a few hours on:

  • Wednesday, July 15 16:00 PDT | 19:00 EDT | 20:00 BRT
  • Thursday, July 16 00:00 BST | 01:00 CEST | 04:30 IST | 07:00 CST | 09:00 AEST

For more info, check out the FAQ page. Thank you for being a valued member of our community.


question

pranali.khanna101994_189965 avatar image
pranali.khanna101994_189965 asked ·

How does replication work?

As per Doc, https://docs.datastax.com/en/archived/cassandra/2.1/cassandra/architecture/architectureDataDistributeHashing_c.html

Each Node in cassandra is responsible for range of hash value of partition key (Consistent hashing).

By default casssandra uses MurMur3 partitioner.

So on each node in cassandra there will be multiple partition keys availaible. For same partition key there will be only one record on one node,other copies will be available on other nodes based on replication factor .

How replication works when we say data is retrieved and stored as per partition key and partition key hashes to a value which depicts the node on which it needs to store ?

Also , can we have same partition key available on 2 nodes ? how is replication taking place as every record before writing , the location where to write is based on partition key .

So when RF=3 let's sat this record gets replicated on other 2 nodes what if they do not have that same partition key available? I mean how replication takes place in lieu of partition key and when we query the data which node responds among the 3 nodes ?

cassandrareplication
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered ·

Here is an old blog, but it is still a good source of information on this topic:

https://www.datastax.com/blog/2016/02/most-important-thing-know-cassandra-data-modeling-primary-key

quoted from this blog:

When data is inserted into the cluster, the first step is to apply a hash function to the partition key. The output is used to determine what node (and replicas) will get the data. The algorithm used by Apache Cassandra utilizes Murmur3 which will take an arbitrary input and create a consistent token value. That token value will be inside the range of tokens owned by single node. In simpler terms, a partition key will always belong to one node and that partition’s data will always be found on that node.

So, the partition key belongs to only one node.


The replication (and which nodes will have a replica of the partition) is then defined by the replication strategy (see the doc linked below). For example, with SimpleStrategy, replicas are placed on the next nodes clockwise in the ring, so the partition key, the replication strategy and the ring structure identify which nodes have the replicas.

https://docs.datastax.com/en/cassandra-oss/3.x/cassandra/architecture/archDataDistributeReplication.html

9 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Hi, Thanks for the answer . I have one doubt that if the same record is replicated on 2 or more replicas via replication factor that means partition key along with that record is also replicated there. so efficieny is ensured ? How cassandra ensured that partition key

belongs to one node when we have same data across different nodes ?

0 Likes 0 · ·
bettina.swynnerton avatar image bettina.swynnerton ♦♦ pranali.khanna101994_189965 ·

Yes, you are of course right, the partition will be on several nodes if it is replicated to several nodes.

But the partition key resolves to a unique token value, and that token belongs to only one node. This is where we will definitely have one replica for the partition. The other replicas are then determined based on the replication strategy and the ring structure, and the unique token for that partition key.

What do you mean by "is efficiency ensured"?

0 Likes 0 · ·

By efficiency I meant for example: there is a table called Monthly Weather Forecast and partition key is City. If we want to retrieve data for say 'Delhi' it must lie on one single node right ?


so when we say RF=3 we say this record with Partition key as Delhi is stored on other 2 nodes as well. So if a partition key and data exists on multiple nodes that is Partionkey 'Delhi' will reside on other node also. How we ensure efficency?

0 Likes 0 · ·
Show more comments