Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What node does Cassandra store data on?

Is there a command or any way at all to know what data is stored on what nodes of Cassandra?

Im pretty new to Cassandra and haven't had much luck googling this question.

Thanks!

like image 707
user3376961 Avatar asked Jan 09 '23 07:01

user3376961


2 Answers

You can get Cassandra to tell you which node(s) a particular key is on with nodetool getendpoints.

$ nodetool getendpoints mykeyspace tbl '8546200'
192.168.73.188
192.168.73.190

I don't know if that's what you're looking for or not. AFAIK there isn't a way to flat-out query the responsible nodes for all rows in a table or keyspace. But as Blake pointed out, your application doesn't really need to worry about that.

If you really wanted to find out, you could query your table using the token function on your partition key. Here's an example using Blake's schema:

SELECT token(partition_key),partition_key FROM tbl;

That would list the hashed tokens with your partition keys. Then you could run a nodetool ring to list out the token ranges for each node, and see which nodes are responsible for that range. Note that if you are using vNodes your output will be pretty big (256 lines for each, by default).

like image 70
Aaron Avatar answered Mar 02 '23 05:03

Aaron


Cassandra uses consistent hashing on the row's Partition key to determine where data is stored. Tokens are assigned to nodes and the consistent hash of the Partition key determines which node(s) will store the row.

Partition key is the first part of the PRIMARY KEY in your table definition or in nested parentheses

CREATE TABLE tbl (
partition_key INT,
clus_key TEXT,
...,
PRIMARY KEY((partition_key), clus_key);

Some reading here on the ring and consistent hashing. You're probably using vNodes so I'd read a bit here too.

At query time, you don't have to worry about which node has what. Your C* driver will select a coordinator node from the list provided that will find the rows based on your query.

If you want to see details about what a query is doing in CQLSH, try turning tracing on:

> TRACING ON;
> SELECT * FROM table; 

> Tracing session: 1f6b4440-050f-11e5-ba41-672ef88f159d
> ....
> <Details about the query>
> ....
like image 20
BeepBoop Avatar answered Mar 02 '23 06:03

BeepBoop