Search code examples
cassandradistributed-database

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!


Solution

  • 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).