Class ShardBoundaries


  • public class ShardBoundaries
    extends java.lang.Object
    Holds boundaries (tokens) used to map a particular token (so partition key) to a shard id. In practice, each keyspace has its associated boundaries, see Keyspace.

    Technically, if we use n shards, this is a list of n-1 tokens and each token tk gets assigned to the shard ID corresponding to the slot of the smallest token in the list that is greater to tk, or n if tk is bigger than any token in the list.

    • Field Detail

      • ringVersion

        public final long ringVersion
    • Constructor Detail

      • ShardBoundaries

        public ShardBoundaries​(Token[] boundaries,
                               long ringVersion)
      • ShardBoundaries

        public ShardBoundaries​(java.util.List<Token> boundaries,
                               long ringVersion)
    • Method Detail

      • getShardForToken

        public int getShardForToken​(Token tk)
        Computes the shard to use for the provided token.
      • getShardForKey

        public int getShardForKey​(PartitionPosition key)
        Computes the shard to use for the provided key.
      • shardCount

        public int shardCount()
        The number of shards that this boundaries support, that is how many different shard ids getShardForToken(org.apache.cassandra.dht.Token) might possibly return.
        Returns:
        the number of shards supported by theses boundaries.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object