Murmur3 partitioning in Cassandra

327 views Asked by At

I need to partition my data in the same way Cassandra is partitioning data with Murmur3Partitioner.(in my 64-bit OS)

I tried the following code:

byte[] key="jim".getBytes("UTF-8");
ByteBuffer key=ByteBuffer.wrap(key);
  Murmur3Partitioner murmur3Partitioner=new Murmur3Partitioner();
  murmur3Partitioner.getToken(key);

But it doesn't give me the exact value in the following link: http://docs.datastax.com/en/cassandra/2.0/cassandra/architecture/architectureDataDistributeHashing_c.html

Is there any other way in Cassandra to find the token generated for a key?

1

There are 1 answers

3
Aaron On

Is there any other way in Cassandra to find the token generated for a key?

Yes, you can use the token() function (FYI- firstname is my partitioning key below):

aploetz@cqlsh:stackoverflow2> SELECT firstname,token(firstname),id,lastname 
    FROM usersbyfirstname ;

 firstname | token(firstname)     | id | lastname
-----------+----------------------+----+-----------
       Zoe | -8194813905246394475 |  1 | Washburne
     Hoban | -7767187360478820688 |  3 | Washburne
     Jayne | -3415298744707363779 |  4 |      Cobb
     carol | -3169904368870211108 |  9 | lowercase
    johnny | -2876970619340914070 |  7 | lowercase
       jim |  2680261686609811218 |  6 | lowercase
       Mal |  4016264465811926804 |  2 |  Reynolds
      suzy |  4113135677556563029 |  8 | lowercase
       Jim |  7378266065874653000 |  5 |       Bob

(9 rows)

Note that case-sensitivity matters, and different tokens are generated for "Jim" and "jim".

But it doesn't give me the exact value in the following link

I suspect that the document you have linked above was written only as an example, and not with exact values.

Does the value you generated above for "jim" equal 2680261686609811218? If it does, then your code above should work.