Package org.apache.cassandra.dht
Class RandomPartitioner
- java.lang.Object
-
- org.apache.cassandra.dht.RandomPartitioner
-
- All Implemented Interfaces:
IPartitioner
public class RandomPartitioner extends java.lang.Object implements IPartitioner
This class generates a BigIntegerToken using MD5 hash.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RandomPartitioner.BigIntegerToken
-
Field Summary
Fields Modifier and Type Field Description static RandomPartitioner
instance
static java.math.BigInteger
MAXIMUM
static int
MAXIMUM_TOKEN_SIZE
static RandomPartitioner.BigIntegerToken
MINIMUM
static PartitionerDefinedOrder
partitionOrdering
static java.math.BigInteger
ZERO
-
Constructor Summary
Constructors Constructor Description RandomPartitioner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DecoratedKey
decorateKey(java.nio.ByteBuffer key)
Transform key to object representation of the on-disk format.java.util.Map<Token,java.lang.Float>
describeOwnership(java.util.List<Token> sortedTokens)
Calculate the deltas between tokens in the ring in order to compare relative sizes.Token
getMaximumToken()
The biggest token for this partitioner, unlike getMinimumToken, this token is actually used and users wanting to include all tokens need to do getMaximumToken().maxKeyBound() Not implemented for the ordered partitionersint
getMaxTokenSize()
RandomPartitioner.BigIntegerToken
getMinimumToken()
RandomPartitioner.BigIntegerToken
getRandomToken()
RandomPartitioner.BigIntegerToken
getRandomToken(java.util.Random random)
RandomPartitioner.BigIntegerToken
getToken(java.nio.ByteBuffer key)
Token.TokenFactory
getTokenFactory()
AbstractType<?>
getTokenValidator()
Token
midpoint(Token ltoken, Token rtoken)
Calculate a Token representing the approximate "middle" of the given range.AbstractType<?>
partitionOrdering()
AbstractType<?>
partitionOrdering(AbstractType<?> partitionKeyType)
Abstract type that orders the same way as DecoratedKeys provided by this partitioner.boolean
preservesOrder()
Token
split(Token ltoken, Token rtoken, double ratioToLeft)
Calculate a Token which takeapproximate 0 <= ratioToLeft <= 1
ownership of the given range.java.util.Optional<Splitter>
splitter()
-
-
-
Field Detail
-
ZERO
public static final java.math.BigInteger ZERO
-
MINIMUM
public static final RandomPartitioner.BigIntegerToken MINIMUM
-
MAXIMUM
public static final java.math.BigInteger MAXIMUM
-
MAXIMUM_TOKEN_SIZE
public static final int MAXIMUM_TOKEN_SIZE
-
instance
public static final RandomPartitioner instance
-
partitionOrdering
public static final PartitionerDefinedOrder partitionOrdering
-
-
Method Detail
-
decorateKey
public DecoratedKey decorateKey(java.nio.ByteBuffer key)
Description copied from interface:IPartitioner
Transform key to object representation of the on-disk format.- Specified by:
decorateKey
in interfaceIPartitioner
- Parameters:
key
- the raw, client-facing key- Returns:
- decorated version of key
-
midpoint
public Token midpoint(Token ltoken, Token rtoken)
Description copied from interface:IPartitioner
Calculate a Token representing the approximate "middle" of the given range.- Specified by:
midpoint
in interfaceIPartitioner
- Returns:
- The approximate midpoint between left and right.
-
split
public Token split(Token ltoken, Token rtoken, double ratioToLeft)
Description copied from interface:IPartitioner
Calculate a Token which takeapproximate 0 <= ratioToLeft <= 1
ownership of the given range.- Specified by:
split
in interfaceIPartitioner
-
getMinimumToken
public RandomPartitioner.BigIntegerToken getMinimumToken()
- Specified by:
getMinimumToken
in interfaceIPartitioner
- Returns:
- A Token smaller than all others in the range that is being partitioned. Not legal to assign to a node or key. (But legal to use in range scans.)
-
getRandomToken
public RandomPartitioner.BigIntegerToken getRandomToken()
- Specified by:
getRandomToken
in interfaceIPartitioner
- Returns:
- a randomly generated token
-
getRandomToken
public RandomPartitioner.BigIntegerToken getRandomToken(java.util.Random random)
- Specified by:
getRandomToken
in interfaceIPartitioner
- Parameters:
random
- instance of Random to use when generating the token- Returns:
- a randomly generated token
-
getTokenFactory
public Token.TokenFactory getTokenFactory()
- Specified by:
getTokenFactory
in interfaceIPartitioner
-
preservesOrder
public boolean preservesOrder()
- Specified by:
preservesOrder
in interfaceIPartitioner
- Returns:
- True if the implementing class preserves key order in the Tokens it generates.
-
getToken
public RandomPartitioner.BigIntegerToken getToken(java.nio.ByteBuffer key)
- Specified by:
getToken
in interfaceIPartitioner
- Returns:
- a Token that can be used to route a given key (This is NOT a method to create a Token from its string representation; for that, use TokenFactory.fromString.)
-
getMaxTokenSize
public int getMaxTokenSize()
- Specified by:
getMaxTokenSize
in interfaceIPartitioner
-
describeOwnership
public java.util.Map<Token,java.lang.Float> describeOwnership(java.util.List<Token> sortedTokens)
Description copied from interface:IPartitioner
Calculate the deltas between tokens in the ring in order to compare relative sizes.- Specified by:
describeOwnership
in interfaceIPartitioner
- Parameters:
sortedTokens
- a sorted List of Tokens- Returns:
- the mapping from 'token' to 'percentage of the ring owned by that token'.
-
getMaximumToken
public Token getMaximumToken()
Description copied from interface:IPartitioner
The biggest token for this partitioner, unlike getMinimumToken, this token is actually used and users wanting to include all tokens need to do getMaximumToken().maxKeyBound() Not implemented for the ordered partitioners- Specified by:
getMaximumToken
in interfaceIPartitioner
-
getTokenValidator
public AbstractType<?> getTokenValidator()
- Specified by:
getTokenValidator
in interfaceIPartitioner
-
partitionOrdering
public AbstractType<?> partitionOrdering()
- Specified by:
partitionOrdering
in interfaceIPartitioner
-
partitionOrdering
public AbstractType<?> partitionOrdering(AbstractType<?> partitionKeyType)
Description copied from interface:IPartitioner
Abstract type that orders the same way as DecoratedKeys provided by this partitioner. Used by secondary indices.- Specified by:
partitionOrdering
in interfaceIPartitioner
- Parameters:
partitionKeyType
- partition key type for PartitionerDefinedOrder
-
splitter
public java.util.Optional<Splitter> splitter()
- Specified by:
splitter
in interfaceIPartitioner
-
-