0
votes

I went through Is there a way to see token ranges for each node in cassandra which uses vnodes?. In this implementation we get all hosts and get token ranges in those individual hosts to get all token range across all nodes.

But, in my case, I am using below code:

public static synchronized List<Object[]> getTokenRangesAcrossNodes(
      final String node, final Integer port, final String userName, final String password) {

    if (cluster == null) {
      connect(node, port, userName, password);
    }
    Metadata metadata = cluster.getMetadata();
    return unwrapTokenRanges(new ArrayList<>(metadata.getTokenRanges()));
  }

In above connect() function node has all the comma seperated cassandra host string and I use Cluster.builder().addContactPoints() to create session.

My question is:

  1. Does metadata.getTokenRanges() gives all token ranges across all hosts? or do I need to get all hosts and get token ranges for each host?
  2. Does fetching token range across all nodes is different from the token range for a given keyspace?

Cassandra version: 3.*

1

1 Answers

0
votes

Each host exposes its primary tokens by getTokens().

Metadata.getTokenRanges() returns the token ranges that define data distribution in the ring.

You have also the option to use Metadata.getTokenRanges(String keyspace, Host host) which returns the token ranges that are replicated on a given host for a certain keyspace.

Check the following links:

And this example might prove helpful.