org.apache.cassandra.service
Class StorageService

java.lang.Object
  extended by org.apache.cassandra.service.StorageService
All Implemented Interfaces:
IEndPointStateChangeSubscriber, StorageServiceMBean

public final class StorageService
extends java.lang.Object
implements IEndPointStateChangeSubscriber, StorageServiceMBean


Field Summary
static java.lang.String binaryVerbHandler_
           
static java.lang.String bootstrapTokenVerbHandler_
           
static java.lang.String dataFileVerbHandler_
           
static char Delimiter
           
static java.lang.String LEFT_NORMALLY
           
static java.lang.String MOVE_STATE
           
static java.lang.String mutationVerbHandler_
           
static java.lang.String rangeSliceVerbHandler_
           
static java.lang.String rangeVerbHandler_
           
static java.lang.String readRepairVerbHandler_
           
static java.lang.String readVerbHandler_
           
static java.lang.String REMOVE_TOKEN
           
static java.lang.String STATE_BOOTSTRAPPING
           
static java.lang.String STATE_LEAVING
           
static java.lang.String STATE_LEFT
           
static java.lang.String STATE_NORMAL
           
static java.lang.String streamFinishedVerbHandler_
           
static java.lang.String streamInitiateDoneVerbHandler_
           
static java.lang.String streamInitiateVerbHandler_
           
static java.lang.String streamRequestVerbHandler_
           
 
Constructor Summary
StorageService()
           
 
Method Summary
 void addBootstrapSource(java.net.InetAddress s, java.lang.String table)
           
static void calculatePendingRanges(TokenMetadata tm, AbstractReplicationStrategy strategy)
           
 void clearSnapshot()
          Remove all the existing snapshots.
 java.util.Map<Range,java.util.List<java.net.InetAddress>> constructRangeToEndPointMap(java.util.List<Range> ranges)
          Construct the range to endpoint mapping based on the true view of the world.
 void decommission()
          transfer this node's data to other machines and remove it from service.
 void deliverHints(java.net.InetAddress endpoint)
          Deliver hints to the specified node when it has crashed and come back up/ marked as alive after a network partition
 void doConsistencyCheck(Row row, java.util.List<java.net.InetAddress> endpoints, ReadCommand command)
          This method performs the requisite operations to make sure that the N replicas are in sync.
 java.net.InetAddress findSuitableEndPoint(java.lang.String key)
          This function finds the closest live endpoint that contains a given key.
 void forceTableCleanup()
          Trigger a cleanup of keys on all tables.
 void forceTableCompaction()
          Forces major compaction (all sstable files compacted)
 void forceTableFlush(java.lang.String tableName, java.lang.String... columnFamilies)
          Flush all memtables for a table and column families.
 void forceTableRepair(java.lang.String tableName, java.lang.String... columnFamilies)
          Trigger proactive repair for a table and column families.
 java.util.List<Range> getAllRanges(java.util.List<Token> sortedTokens)
          Get all ranges that span the ring given a set of tokens.
 int getCurrentGenerationNumber()
          Return the generation value for this node.
 IEndPointSnitch getEndPointSnitch()
           
 java.util.Map<java.net.InetAddress,java.net.InetAddress> getHintedEndpointMap(java.lang.String key, java.util.List<java.net.InetAddress> naturalEndpoints)
          This method returns the N endpoints that are responsible for storing the specified key i.e for replication.
 java.util.List<java.net.InetAddress> getLiveNaturalEndpoints(java.lang.String key)
          This method attempts to return N endpoints that are responsible for storing the specified key i.e for replication.
 java.util.List<java.net.InetAddress> getLiveNaturalEndpoints(Token token)
           
 java.util.Set<java.lang.String> getLiveNodes()
          Retrieve the list of live nodes in the cluster, where "liveness" is determined by the failure detector of the node being queried.
 double getLoad()
          raw load value
 java.util.Map<java.lang.String,java.lang.String> getLoadMap()
          Human-readable load value.
 java.lang.String getLoadString()
          Human-readable load value
 Range getLocalPrimaryRange()
           
 java.util.Collection<Range> getLocalRanges()
           
 Token getLocalToken()
           
 java.util.List<java.net.InetAddress> getNaturalEndpoints(java.lang.String key)
          This method returns the N endpoints that are responsible for storing the specified key i.e for replication.
 java.util.List<java.net.InetAddress> getNaturalEndpoints(Token token)
          This method returns the N endpoints that are responsible for storing the specified key i.e for replication.
static IPartitioner getPartitioner()
           
 java.net.InetAddress getPrimary(java.lang.String key)
          This method returns the endpoint that is responsible for storing the specified key.
 java.net.InetAddress getPrimary(Token token)
           
 Range getPrimaryRangeForEndPoint(java.net.InetAddress ep)
          Get the primary range for the specified endpoint.
 java.util.Map<Range,java.util.List<java.lang.String>> getRangeToEndPointMap()
          Retrieve a map of range to end points that describe the ring topology of a Cassandra cluster.
 AbstractReplicationStrategy getReplicationStrategy()
           
static AbstractReplicationStrategy getReplicationStrategy(TokenMetadata tokenMetadata, IPartitioner partitioner)
           
 java.util.List<java.lang.String> getSplits(int splits)
           
 java.net.InetAddress getSuccessor(java.net.InetAddress ep)
           
 java.lang.String getToken()
          Fetch a string representation of the token.
 TokenMetadata getTokenMetadata()
           
 java.util.Set<java.lang.String> getUnreachableNodes()
          Retrieve the list of unreachable nodes in the cluster, as determined by this node's failure detector.
 java.lang.Iterable<ColumnFamilyStore> getValidColumnFamilies(java.lang.String tableName, java.lang.String... columnFamilies)
           
 WriteResponseHandler getWriteResponseHandler(int blockFor, int consistency_level)
           
 void initClient()
           
 void initServer()
           
static StorageService instance()
           
 boolean isBootstrapMode()
           
 boolean isClientMode()
           
 boolean isPrimary(java.lang.String key)
          This method determines whether the local endpoint is the primary for the given key.
 void loadBalance()
          This node will unload its data onto its neighbors, and bootstrap to share the range of the most-loaded node in the ring.
 void move(java.lang.String newToken)
           
 void onAlive(java.net.InetAddress endpoint, EndPointState state)
           
 void onChange(java.net.InetAddress endpoint, java.lang.String apStateName, ApplicationState apState)
           
 void onDead(java.net.InetAddress endpoint, EndPointState state)
           
 void onJoin(java.net.InetAddress endpoint, EndPointState epState)
          Use to inform interested parties about the change in the state for specified endpoint
 void removeBootstrapSource(java.net.InetAddress s, java.lang.String table)
           
 void removeToken(java.lang.String tokenString)
          removeToken removes token (and all data associated with enpoint that had it) from the ring
 void setLog4jLevel(java.lang.String classQualifier, java.lang.String rawLevel)
          set the logging level at runtime
 void setToken(Token token)
          This method updates the local token on disk
 void stopClient()
           
 void takeAllSnapshot(java.lang.String tag)
          Takes a snapshot for every table.
 void takeSnapshot(java.lang.String tableName, java.lang.String tag)
          Takes the snapshot for a given table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOVE_STATE

public static final java.lang.String MOVE_STATE
See Also:
Constant Field Values

Delimiter

public static final char Delimiter
See Also:
Constant Field Values

STATE_BOOTSTRAPPING

public static final java.lang.String STATE_BOOTSTRAPPING
See Also:
Constant Field Values

STATE_NORMAL

public static final java.lang.String STATE_NORMAL
See Also:
Constant Field Values

STATE_LEAVING

public static final java.lang.String STATE_LEAVING
See Also:
Constant Field Values

STATE_LEFT

public static final java.lang.String STATE_LEFT
See Also:
Constant Field Values

REMOVE_TOKEN

public static final java.lang.String REMOVE_TOKEN
See Also:
Constant Field Values

LEFT_NORMALLY

public static final java.lang.String LEFT_NORMALLY
See Also:
Constant Field Values

mutationVerbHandler_

public static final java.lang.String mutationVerbHandler_
See Also:
Constant Field Values

binaryVerbHandler_

public static final java.lang.String binaryVerbHandler_
See Also:
Constant Field Values

readRepairVerbHandler_

public static final java.lang.String readRepairVerbHandler_
See Also:
Constant Field Values

readVerbHandler_

public static final java.lang.String readVerbHandler_
See Also:
Constant Field Values

streamInitiateVerbHandler_

public static final java.lang.String streamInitiateVerbHandler_
See Also:
Constant Field Values

streamInitiateDoneVerbHandler_

public static final java.lang.String streamInitiateDoneVerbHandler_
See Also:
Constant Field Values

streamFinishedVerbHandler_

public static final java.lang.String streamFinishedVerbHandler_
See Also:
Constant Field Values

dataFileVerbHandler_

public static final java.lang.String dataFileVerbHandler_
See Also:
Constant Field Values

streamRequestVerbHandler_

public static final java.lang.String streamRequestVerbHandler_
See Also:
Constant Field Values

rangeVerbHandler_

public static final java.lang.String rangeVerbHandler_
See Also:
Constant Field Values

rangeSliceVerbHandler_

public static final java.lang.String rangeSliceVerbHandler_
See Also:
Constant Field Values

bootstrapTokenVerbHandler_

public static final java.lang.String bootstrapTokenVerbHandler_
See Also:
Constant Field Values
Constructor Detail

StorageService

public StorageService()
Method Detail

getPartitioner

public static IPartitioner getPartitioner()

getLocalRanges

public java.util.Collection<Range> getLocalRanges()

getLocalPrimaryRange

public Range getLocalPrimaryRange()

instance

public static StorageService instance()

addBootstrapSource

public void addBootstrapSource(java.net.InetAddress s,
                               java.lang.String table)

removeBootstrapSource

public void removeBootstrapSource(java.net.InetAddress s,
                                  java.lang.String table)

setToken

public void setToken(Token token)
This method updates the local token on disk


getReplicationStrategy

public static AbstractReplicationStrategy getReplicationStrategy(TokenMetadata tokenMetadata,
                                                                 IPartitioner partitioner)

stopClient

public void stopClient()

initClient

public void initClient()
                throws java.io.IOException
Throws:
java.io.IOException

initServer

public void initServer()
                throws java.io.IOException
Throws:
java.io.IOException

isBootstrapMode

public boolean isBootstrapMode()

getTokenMetadata

public TokenMetadata getTokenMetadata()

getEndPointSnitch

public IEndPointSnitch getEndPointSnitch()

doConsistencyCheck

public void doConsistencyCheck(Row row,
                               java.util.List<java.net.InetAddress> endpoints,
                               ReadCommand command)
This method performs the requisite operations to make sure that the N replicas are in sync. We do this in the background when we do not care much about consistency.


getRangeToEndPointMap

public java.util.Map<Range,java.util.List<java.lang.String>> getRangeToEndPointMap()
Description copied from interface: StorageServiceMBean
Retrieve a map of range to end points that describe the ring topology of a Cassandra cluster.

Specified by:
getRangeToEndPointMap in interface StorageServiceMBean
Returns:
mapping of ranges to end points

constructRangeToEndPointMap

public java.util.Map<Range,java.util.List<java.net.InetAddress>> constructRangeToEndPointMap(java.util.List<Range> ranges)
Construct the range to endpoint mapping based on the true view of the world.

Parameters:
ranges -
Returns:
mapping of ranges to the replicas responsible for them.

onChange

public void onChange(java.net.InetAddress endpoint,
                     java.lang.String apStateName,
                     ApplicationState apState)
Specified by:
onChange in interface IEndPointStateChangeSubscriber

calculatePendingRanges

public static void calculatePendingRanges(TokenMetadata tm,
                                          AbstractReplicationStrategy strategy)

onJoin

public void onJoin(java.net.InetAddress endpoint,
                   EndPointState epState)
Description copied from interface: IEndPointStateChangeSubscriber
Use to inform interested parties about the change in the state for specified endpoint

Specified by:
onJoin in interface IEndPointStateChangeSubscriber
Parameters:
endpoint - endpoint for which the state change occurred.
epState - state that actually changed for the above endpoint.

onAlive

public void onAlive(java.net.InetAddress endpoint,
                    EndPointState state)
Specified by:
onAlive in interface IEndPointStateChangeSubscriber

onDead

public void onDead(java.net.InetAddress endpoint,
                   EndPointState state)
Specified by:
onDead in interface IEndPointStateChangeSubscriber

getLoad

public double getLoad()
raw load value


getLoadString

public java.lang.String getLoadString()
Description copied from interface: StorageServiceMBean
Human-readable load value

Specified by:
getLoadString in interface StorageServiceMBean

getLoadMap

public java.util.Map<java.lang.String,java.lang.String> getLoadMap()
Description copied from interface: StorageServiceMBean
Human-readable load value. Keys are IP addresses.

Specified by:
getLoadMap in interface StorageServiceMBean

deliverHints

public final void deliverHints(java.net.InetAddress endpoint)
Deliver hints to the specified node when it has crashed and come back up/ marked as alive after a network partition


getLocalToken

public Token getLocalToken()

getToken

public java.lang.String getToken()
Description copied from interface: StorageServiceMBean
Fetch a string representation of the token.

Specified by:
getToken in interface StorageServiceMBean
Returns:
a string token

getLiveNodes

public java.util.Set<java.lang.String> getLiveNodes()
Description copied from interface: StorageServiceMBean
Retrieve the list of live nodes in the cluster, where "liveness" is determined by the failure detector of the node being queried.

Specified by:
getLiveNodes in interface StorageServiceMBean
Returns:
set of IP addresses, as Strings

getUnreachableNodes

public java.util.Set<java.lang.String> getUnreachableNodes()
Description copied from interface: StorageServiceMBean
Retrieve the list of unreachable nodes in the cluster, as determined by this node's failure detector.

Specified by:
getUnreachableNodes in interface StorageServiceMBean
Returns:
set of IP addresses, as Strings

getCurrentGenerationNumber

public int getCurrentGenerationNumber()
Description copied from interface: StorageServiceMBean
Return the generation value for this node.

Specified by:
getCurrentGenerationNumber in interface StorageServiceMBean
Returns:
generation number

forceTableCleanup

public void forceTableCleanup()
                       throws java.io.IOException
Description copied from interface: StorageServiceMBean
Trigger a cleanup of keys on all tables.

Specified by:
forceTableCleanup in interface StorageServiceMBean
Throws:
java.io.IOException

forceTableCompaction

public void forceTableCompaction()
                          throws java.io.IOException
Description copied from interface: StorageServiceMBean
Forces major compaction (all sstable files compacted)

Specified by:
forceTableCompaction in interface StorageServiceMBean
Throws:
java.io.IOException

takeSnapshot

public void takeSnapshot(java.lang.String tableName,
                         java.lang.String tag)
                  throws java.io.IOException
Takes the snapshot for a given table.

Specified by:
takeSnapshot in interface StorageServiceMBean
Parameters:
tableName - the name of the table.
tag - the tag given to the snapshot (null is permissible)
Throws:
java.io.IOException

takeAllSnapshot

public void takeAllSnapshot(java.lang.String tag)
                     throws java.io.IOException
Takes a snapshot for every table.

Specified by:
takeAllSnapshot in interface StorageServiceMBean
Parameters:
tag - the tag given to the snapshot (null is permissible)
Throws:
java.io.IOException

clearSnapshot

public void clearSnapshot()
                   throws java.io.IOException
Remove all the existing snapshots.

Specified by:
clearSnapshot in interface StorageServiceMBean
Throws:
java.io.IOException

getValidColumnFamilies

public java.lang.Iterable<ColumnFamilyStore> getValidColumnFamilies(java.lang.String tableName,
                                                                    java.lang.String... columnFamilies)
                                                             throws java.io.IOException
Throws:
java.io.IOException

forceTableFlush

public void forceTableFlush(java.lang.String tableName,
                            java.lang.String... columnFamilies)
                     throws java.io.IOException
Flush all memtables for a table and column families.

Specified by:
forceTableFlush in interface StorageServiceMBean
Parameters:
tableName -
columnFamilies -
Throws:
java.io.IOException

forceTableRepair

public void forceTableRepair(java.lang.String tableName,
                             java.lang.String... columnFamilies)
                      throws java.io.IOException
Trigger proactive repair for a table and column families.

Specified by:
forceTableRepair in interface StorageServiceMBean
Parameters:
tableName -
columnFamilies -
Throws:
java.io.IOException

getSuccessor

public java.net.InetAddress getSuccessor(java.net.InetAddress ep)

getPrimaryRangeForEndPoint

public Range getPrimaryRangeForEndPoint(java.net.InetAddress ep)
Get the primary range for the specified endpoint.

Parameters:
ep - endpoint we are interested in.
Returns:
range for the specified endpoint.

getAllRanges

public java.util.List<Range> getAllRanges(java.util.List<Token> sortedTokens)
Get all ranges that span the ring given a set of tokens. All ranges are in sorted order of ranges.

Returns:
ranges in sorted order

getPrimary

public java.net.InetAddress getPrimary(java.lang.String key)
This method returns the endpoint that is responsible for storing the specified key.

Parameters:
key - - key for which we need to find the endpoint
Returns:
value - the endpoint responsible for this key

getPrimary

public java.net.InetAddress getPrimary(Token token)

isPrimary

public boolean isPrimary(java.lang.String key)
This method determines whether the local endpoint is the primary for the given key.

Parameters:
key -
Returns:
true if the local endpoint is the primary replica.

getNaturalEndpoints

public java.util.List<java.net.InetAddress> getNaturalEndpoints(java.lang.String key)
This method returns the N endpoints that are responsible for storing the specified key i.e for replication.

Parameters:
key - - key for which we need to find the endpoint return value - the endpoint responsible for this key

getNaturalEndpoints

public java.util.List<java.net.InetAddress> getNaturalEndpoints(Token token)
This method returns the N endpoints that are responsible for storing the specified key i.e for replication.

Parameters:
token - - token for which we need to find the endpoint return value - the endpoint responsible for this token

getLiveNaturalEndpoints

public java.util.List<java.net.InetAddress> getLiveNaturalEndpoints(java.lang.String key)
This method attempts to return N endpoints that are responsible for storing the specified key i.e for replication.

Parameters:
key - - key for which we need to find the endpoint return value - the endpoint responsible for this key

getLiveNaturalEndpoints

public java.util.List<java.net.InetAddress> getLiveNaturalEndpoints(Token token)

getHintedEndpointMap

public java.util.Map<java.net.InetAddress,java.net.InetAddress> getHintedEndpointMap(java.lang.String key,
                                                                                     java.util.List<java.net.InetAddress> naturalEndpoints)
This method returns the N endpoints that are responsible for storing the specified key i.e for replication.

Parameters:
key - - key for which we need to find the endpoint return value - the endpoint responsible for this key

findSuitableEndPoint

public java.net.InetAddress findSuitableEndPoint(java.lang.String key)
                                          throws java.io.IOException,
                                                 UnavailableException
This function finds the closest live endpoint that contains a given key.

Throws:
java.io.IOException
UnavailableException

setLog4jLevel

public void setLog4jLevel(java.lang.String classQualifier,
                          java.lang.String rawLevel)
Description copied from interface: StorageServiceMBean
set the logging level at runtime

Specified by:
setLog4jLevel in interface StorageServiceMBean

getSplits

public java.util.List<java.lang.String> getSplits(int splits)
Parameters:
splits: - number of ranges to break into. Minimum 2.
Returns:
list of Tokens (_not_ keys!) breaking up the data this node is responsible for into `splits` pieces. There will be 1 more token than splits requested. So for splits of 2, tokens T1 T2 T3 will be returned, where (T1, T2] is the first range and (T2, T3] is the second. The first token will always be the left Token of this node's primary range, and the last will always be the Right token of that range.

decommission

public void decommission()
                  throws java.lang.InterruptedException
Description copied from interface: StorageServiceMBean
transfer this node's data to other machines and remove it from service.

Specified by:
decommission in interface StorageServiceMBean
Throws:
java.lang.InterruptedException

move

public void move(java.lang.String newToken)
          throws java.io.IOException,
                 java.lang.InterruptedException
Specified by:
move in interface StorageServiceMBean
Parameters:
newToken - token to move this node to. This node will unload its data onto its neighbors, and bootstrap to the new token.
Throws:
java.io.IOException
java.lang.InterruptedException

loadBalance

public void loadBalance()
                 throws java.io.IOException,
                        java.lang.InterruptedException
Description copied from interface: StorageServiceMBean
This node will unload its data onto its neighbors, and bootstrap to share the range of the most-loaded node in the ring.

Specified by:
loadBalance in interface StorageServiceMBean
Throws:
java.io.IOException
java.lang.InterruptedException

removeToken

public void removeToken(java.lang.String tokenString)
Description copied from interface: StorageServiceMBean
removeToken removes token (and all data associated with enpoint that had it) from the ring

Specified by:
removeToken in interface StorageServiceMBean

getWriteResponseHandler

public WriteResponseHandler getWriteResponseHandler(int blockFor,
                                                    int consistency_level)

getReplicationStrategy

public AbstractReplicationStrategy getReplicationStrategy()

isClientMode

public boolean isClientMode()


Copyright © 2010 The Apache Software Foundation