com.netflix.astyanax.connectionpool.impl
Class TokenPartitionedTopology<CL>

java.lang.Object
  extended by com.netflix.astyanax.connectionpool.impl.TokenPartitionedTopology<CL>
Type Parameters:
CL -
All Implemented Interfaces:
Topology<CL>

public class TokenPartitionedTopology<CL>
extends java.lang.Object
implements Topology<CL>

Partition hosts by start token. Each token may map to a list of partitions. The class maintains 3 different data structures to represent HostConnectionPools for a set of hosts in a partitioned ring.

  1. sortedRing - the list of all pools for all hosts sorted in order specified by the token ranges for the cluster
  2. tokenToPartitionMap - map of token range to host connection pools for that range
  3. allPools - all pools for all known hosts in case no tokens can be found by calls such as ring describe etc
Prominent features of this class

Maintaining the set of pools for all hosts in a token ring See the setPools(Collection) method for details on how the various data structures are updated from a list of HostConnectionPools Note that when host connection pools are set on this class, each host associated with the host conneciton pool can serve multiple partitions, hence this class builds a reverse index from token range -> list < HostConnectionPool> using this update.

Lookup all HostConnectionPools for a given row keyor token See the getPartition(ByteBuffer) method for details on how the various data structures are consulted for retrieving the comprehensive list of host connection pools for a row key.
Note that if the token range token is provided directly, then we can directly consult the tokenPartitionMap. But if we receive a row key, then that is converted to an integer which is then used to do a bin search over the list of all sorted tokens in the token ring.

See Also:
HostConnectionPoolPartition} for details of token ranges partition based connection pools maintained for each host.

Constructor Summary
TokenPartitionedTopology(Partitioner partitioner, LatencyScoreStrategy strategy)
           
 
Method Summary
 void addPool(HostConnectionPool<CL> pool)
          Add a pool without knowing its token.
 TokenHostConnectionPoolPartition<CL> getAllPools()
          Return a partition that represents all hosts in the ring
 TokenHostConnectionPoolPartition<CL> getPartition(java.nio.ByteBuffer rowkey)
          Get the partition best suited to handle a row key
 TokenHostConnectionPoolPartition<CL> getPartition(java.lang.String token)
          Return the partition for a specific token
 int getPartitionCount()
           
 java.util.List<java.lang.String> getPartitionNames()
           
 java.util.Map<java.lang.String,TokenHostConnectionPoolPartition<CL>> getPartitions()
           
protected  TokenHostConnectionPoolPartition<CL> makePartition(java.math.BigInteger partition)
           
 void refresh()
          Refresh the internal state and apply the latency score strategy
 void removePool(HostConnectionPool<CL> pool)
          Remove this pool from all partitions
 void resumePool(HostConnectionPool<CL> pool)
          Resume a host that was previously down
 boolean setPools(java.util.Collection<HostConnectionPool<CL>> ring)
          Refresh the internal topology structure
 void suspendPool(HostConnectionPool<CL> pool)
          Suspend a host that is down
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TokenPartitionedTopology

public TokenPartitionedTopology(Partitioner partitioner,
                                LatencyScoreStrategy strategy)
Method Detail

makePartition

protected TokenHostConnectionPoolPartition<CL> makePartition(java.math.BigInteger partition)

setPools

public boolean setPools(java.util.Collection<HostConnectionPool<CL>> ring)
Description copied from interface: Topology
Refresh the internal topology structure

Specified by:
setPools in interface Topology<CL>
Returns:
True if anything changed in the internal state

resumePool

public void resumePool(HostConnectionPool<CL> pool)
Description copied from interface: Topology
Resume a host that was previously down

Specified by:
resumePool in interface Topology<CL>

suspendPool

public void suspendPool(HostConnectionPool<CL> pool)
Description copied from interface: Topology
Suspend a host that is down

Specified by:
suspendPool in interface Topology<CL>

refresh

public void refresh()
Description copied from interface: Topology
Refresh the internal state and apply the latency score strategy

Specified by:
refresh in interface Topology<CL>

getPartition

public TokenHostConnectionPoolPartition<CL> getPartition(java.lang.String token)
Description copied from interface: Topology
Return the partition for a specific token

Specified by:
getPartition in interface Topology<CL>

getPartition

public TokenHostConnectionPoolPartition<CL> getPartition(java.nio.ByteBuffer rowkey)
Description copied from interface: Topology
Get the partition best suited to handle a row key

Specified by:
getPartition in interface Topology<CL>

getAllPools

public TokenHostConnectionPoolPartition<CL> getAllPools()
Description copied from interface: Topology
Return a partition that represents all hosts in the ring

Specified by:
getAllPools in interface Topology<CL>

getPartitionCount

public int getPartitionCount()
Specified by:
getPartitionCount in interface Topology<CL>
Returns:
Get total number of tokens in the topology

removePool

public void removePool(HostConnectionPool<CL> pool)
Description copied from interface: Topology
Remove this pool from all partitions

Specified by:
removePool in interface Topology<CL>

addPool

public void addPool(HostConnectionPool<CL> pool)
Description copied from interface: Topology
Add a pool without knowing its token. This pool will be added to the all pools partition only

Specified by:
addPool in interface Topology<CL>

getPartitionNames

public java.util.List<java.lang.String> getPartitionNames()
Specified by:
getPartitionNames in interface Topology<CL>
Returns:
Return a list of all unqiue ids or first token for partitions in the topology

getPartitions

public java.util.Map<java.lang.String,TokenHostConnectionPoolPartition<CL>> getPartitions()
Specified by:
getPartitions in interface Topology<CL>
Returns:
Return a mapping of partition ids to partition details

toString

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