How token range work in single node cluster , as per below example my node has token "704134931341156592" so how this single token work as a range. if it work as range so what will be it range could you please explain ?
How token range work in single node cluster , as per below example my node has token "704134931341156592" so how this single token work as a range. if it work as range so what will be it range could you please explain ?
In a single-node cluster, the node owns the whole token range. It doesn't really matter what token is assigned to it. Since it's the only node in the cluster, it has all the data.
Instead, let me illustrate with an example 3-node cluster.
I've calculated balanced tokens for 3 nodes like this:
$ _node_count=3; python -c "print [str(((2**64 / $_node_count) * i) - 2**63) for i in range($_node_count)]"
['-9223372036854775808', '-3074457345618258603', '3074457345618258602']
I've assigned the tokens to each of the nodes in cassandra.yaml
:
10.101.33.146 - initial_token: -9223372036854775808
10.101.33.196 - initial_token: -3074457345618258603
10.101.36.82 - initial_token: 3074457345618258602
Here is the output of nodetool ring
:
nodetool ring community
Datacenter: Cassandra
==========
Address Rack Status State Load Owns Token
3074457345618258602
10.101.33.146 rack1 Up Normal 174.98 KiB 33.33% -9223372036854775808
10.101.33.196 rack1 Up Normal 164.12 KiB 33.33% -3074457345618258603
10.101.36.82 rack1 Up Normal 200.86 KiB 33.33% 3074457345618258602
And here's a visual representation of where the nodes are placed around the ring based on their token assignment:
Based on the assigned tokens, here are the token ranges owned by each node:
10.101.36.82 : -3074457345618258602 to 3074457345618258602
10.101.33.146 : 3074457345618258603 to -9223372036854775808
10.101.33.196 : -9223372036854775807 to -3074457345618258603
To show you what those ranges mean, I've created this table where name
is the partition key:
CREATE TABLE community.users (
name text PRIMARY KEY,
address text
)
In this table, I have 3 users -- Tom, Dick and Harry. Below are the token values for each partition key:
cqlsh:community> SELECT name, TOKEN(name) FROM users ;
name | system.token(name)
-------+----------------------
tom | -5186961623470975143
harry | -4632103420999695370
dick | 1627195465470592336
For tom
, token -5186961623470975143
lies between the range owned by node 10.101.33.196
. The token for harry
also lies between the range owned by node 10.101.33.196
. Finally, the token for dick
is in the range owned by node 10.101.36.82
.
To confirm this, here are the outputs of the nodetool getendpoints
:
$ nodetool getendpoints community users tom
10.101.33.196
$ nodetool getendpoints community users harry
10.101.33.196
$ nodetool getendpoints community users dick
10.101.36.82
Hopefully this all makes sense now. Cheers!
5 People are following this question.
DataStax Enterprise is powered by the best distribution of Apache Cassandra ™
© 2023 DataStax, Titan, and TitanDB are registered trademarks of DataStax, Inc. and its subsidiaries in the United States and/or other countries.
Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries.
Privacy Policy Terms of Use