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


Nested Class Summary
static class StorageService.BootstrapInitiateDoneVerbHandler
           
 
Field Summary
static java.lang.String binaryVerbHandler_
           
static java.lang.String bootStrapInitiateDoneVerbHandler_
           
static java.lang.String bootStrapInitiateVerbHandler_
           
static java.lang.String bootStrapTerminateVerbHandler_
           
static java.lang.String bsMetadataVerbHandler_
           
static java.lang.String dataFileVerbHandler_
           
static java.lang.String mbrshipCleanerVerbHandler_
           
static java.lang.String mutationStage_
           
static java.lang.String mutationVerbHandler_
           
static java.lang.String rangeVerbHandler_
           
static java.lang.String readRepairVerbHandler_
           
static java.lang.String readStage_
           
static java.lang.String readVerbHandler_
           
static java.lang.String tokenVerbHandler_
           
 
Constructor Summary
StorageService(boolean isBootstrapMode)
           
 
Method Summary
 void addBootstrapSource(EndPoint s)
           
 void clearSnapshot()
          Remove all the existing snapshots.
 java.util.Map<EndPoint,java.util.List<Range>> constructEndPointToRangesMap()
          Construct a mapping from endpoint to ranges that endpoint is responsible for.
 java.util.Map<Range,java.util.List<EndPoint>> constructRangeToEndPointMap(Range[] ranges)
          Construct the range to endpoint mapping based on the true view of the world.
 java.util.Map<Range,java.util.List<EndPoint>> constructRangeToEndPointMap(Range[] ranges, java.util.Map<Token,EndPoint> tokenToEndPointMap)
          Construct the range to endpoint mapping based on the view as dictated by the mapping of token to endpoints passed in.
 void deliverHints(EndPoint endpoint)
          Deliver hints to the specified node when it has crashed and come back up/ marked as alive after a network partition
 void doBootstrap(EndPoint endpoint, Token token)
          Starts the bootstrap operations for the specified endpoint.
 void doConsistencyCheck(Row row, java.util.List<EndPoint> endpoints, ReadCommand command)
           
 EndPoint findSuitableEndPoint(java.lang.String key)
          This function finds the most suitable endpoint given a key.
 void forceHandoff(java.util.List<java.lang.String> dataDirectories, java.lang.String host)
          Stream the files in the bootstrap directory over to the node being bootstrapped.
 void forceTableCleanup()
           
 void forceTableCompaction()
          Trigger the immediate compaction of all tables.
 void forceTableFlush(java.lang.String tableName, java.lang.String... columnFamilies)
          Flush all memtables for a table and column families.
 Range[] getAllRanges()
          Get all ranges that span the ring as per current snapshot of the token distribution.
 Range[] getAllRanges(java.util.Set<Token> tokens)
          Get all ranges that span the ring given a set of tokens.
 int getCurrentGenerationNumber()
           
 IEndPointSnitch getEndPointSnitch()
           
 java.util.Map<EndPoint,EndPoint> getHintedStorageEndpointMap(java.lang.String key)
          This method returns the N endpoints that are responsible for storing the specified key i.e for replication.
 java.lang.String getLiveNodes()
           
 java.util.List<EndPoint> getLiveReadStorageEndPoints(java.lang.String key)
          This method attempts to return N endpoints that are responsible for storing the specified key i.e for replication.
 java.lang.String getLoadInfo()
          Get the count of primary keys from the sampler.
 java.lang.String getLoadInfo(EndPoint ep)
          Get the primary count info for this endpoint.
static EndPoint getLocalControlEndPoint()
           
static EndPoint getLocalStorageEndPoint()
           
static IPartitioner getPartitioner()
           
 EndPoint getPrimary(java.lang.String key)
          This method returns the endpoint that is responsible for storing the specified key.
 Range getPrimaryRangeForEndPoint(EndPoint ep)
          Get the primary range for the specified endpoint.
 java.util.Map<Range,java.util.List<EndPoint>> getRangeToEndPointMap()
           
 EndPoint[] getReadStorageEndPoints(java.lang.String key)
          This method returns the N endpoints that are responsible for storing the specified key i.e for replication.
 EndPoint getSuccessor(EndPoint ep)
           
 java.lang.String getToken()
           
 java.lang.String getToken(EndPoint ep)
           
 TokenMetadata getTokenMetadata()
           
 java.lang.String getUnreachableNodes()
           
static StorageService instance()
           
 boolean isBootstrapMode()
           
 boolean isInSameDataCenter(EndPoint endpoint)
           
 boolean isPrimary(java.lang.String key)
          This method determines whether the local endpoint is the primary for the given key.
 void loadAll(java.lang.String nodes)
          This method will cause the local node initiate the bootstrap process for all the nodes specified in the string parameter passed in.
 void onChange(EndPoint endpoint, EndPointState epState)
          Called when there is a change in application state.
 void relocate(java.lang.String[] keys)
           
 boolean removeBootstrapSource(EndPoint s)
           
 void removeTokenState(EndPoint endpoint)
           
 void setLog4jLevel(java.lang.String classQualifier, java.lang.String rawLevel)
          set the logging level at runtime
 void start()
           
 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.
 void updateToken(Token token)
           
 void updateTokenMetadata(Token token, EndPoint endpoint, boolean bs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mutationStage_

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

readStage_

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

mutationVerbHandler_

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

tokenVerbHandler_

public static final java.lang.String tokenVerbHandler_
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

bootStrapInitiateVerbHandler_

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

bootStrapInitiateDoneVerbHandler_

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

bootStrapTerminateVerbHandler_

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

dataFileVerbHandler_

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

mbrshipCleanerVerbHandler_

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

bsMetadataVerbHandler_

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

rangeVerbHandler_

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

StorageService

public StorageService(boolean isBootstrapMode)
Method Detail

getLocalStorageEndPoint

public static EndPoint getLocalStorageEndPoint()

getLocalControlEndPoint

public static EndPoint getLocalControlEndPoint()

getPartitioner

public static IPartitioner getPartitioner()

instance

public static StorageService instance()

addBootstrapSource

public void addBootstrapSource(EndPoint s)

removeBootstrapSource

public boolean removeBootstrapSource(EndPoint s)

start

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

isBootstrapMode

public boolean isBootstrapMode()

getTokenMetadata

public TokenMetadata getTokenMetadata()

updateTokenMetadata

public void updateTokenMetadata(Token token,
                                EndPoint endpoint,
                                boolean bs)

getEndPointSnitch

public IEndPointSnitch getEndPointSnitch()

isInSameDataCenter

public boolean isInSameDataCenter(EndPoint endpoint)
                           throws java.io.IOException
Throws:
java.io.IOException

doConsistencyCheck

public void doConsistencyCheck(Row row,
                               java.util.List<EndPoint> endpoints,
                               ReadCommand command)

getRangeToEndPointMap

public java.util.Map<Range,java.util.List<EndPoint>> getRangeToEndPointMap()
Specified by:
getRangeToEndPointMap in interface StorageServiceMBean

constructRangeToEndPointMap

public java.util.Map<Range,java.util.List<EndPoint>> constructRangeToEndPointMap(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.

constructRangeToEndPointMap

public java.util.Map<Range,java.util.List<EndPoint>> constructRangeToEndPointMap(Range[] ranges,
                                                                                 java.util.Map<Token,EndPoint> tokenToEndPointMap)
Construct the range to endpoint mapping based on the view as dictated by the mapping of token to endpoints passed in.

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

constructEndPointToRangesMap

public java.util.Map<EndPoint,java.util.List<Range>> constructEndPointToRangesMap()
Construct a mapping from endpoint to ranges that endpoint is responsible for.

Returns:
the mapping from endpoint to the ranges it is responsible for.

onChange

public void onChange(EndPoint endpoint,
                     EndPointState epState)
Called when there is a change in application state. In particular we are interested in new tokens as a result of a new node or an existing node moving to a new location on the ring.

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

getLoadInfo

public java.lang.String getLoadInfo()
Get the count of primary keys from the sampler.

Specified by:
getLoadInfo in interface StorageServiceMBean

getLoadInfo

public java.lang.String getLoadInfo(EndPoint ep)
Get the primary count info for this endpoint. This is gossiped around and cached in the StorageLoadBalancer.


updateToken

public void updateToken(Token token)
                 throws java.io.IOException
Throws:
java.io.IOException

removeTokenState

public void removeTokenState(EndPoint endpoint)

relocate

public void relocate(java.lang.String[] keys)
              throws java.io.IOException
Throws:
java.io.IOException

doBootstrap

public final void doBootstrap(EndPoint endpoint,
                              Token token)
Starts the bootstrap operations for the specified endpoint.

Parameters:
endpoint -

deliverHints

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


getToken

public java.lang.String getToken(EndPoint ep)

getToken

public java.lang.String getToken()
Specified by:
getToken in interface StorageServiceMBean

getLiveNodes

public java.lang.String getLiveNodes()
Specified by:
getLiveNodes in interface StorageServiceMBean

getUnreachableNodes

public java.lang.String getUnreachableNodes()
Specified by:
getUnreachableNodes in interface StorageServiceMBean

getCurrentGenerationNumber

public int getCurrentGenerationNumber()
Specified by:
getCurrentGenerationNumber in interface StorageServiceMBean

loadAll

public void loadAll(java.lang.String nodes)
             throws java.net.UnknownHostException
Description copied from interface: StorageServiceMBean
This method will cause the local node initiate the bootstrap process for all the nodes specified in the string parameter passed in. This local node will calculate who gives what ranges to the nodes and then instructs the nodes to do so.

Specified by:
loadAll in interface StorageServiceMBean
Parameters:
nodes - colon delimited list of endpoints that need to be bootstrapped
Throws:
java.net.UnknownHostException

forceTableCleanup

public void forceTableCleanup()
                       throws java.io.IOException
Specified by:
forceTableCleanup in interface StorageServiceMBean
Throws:
java.io.IOException

forceTableCompaction

public void forceTableCompaction()
                          throws java.io.IOException
Trigger the immediate compaction of all tables.

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

forceHandoff

public void forceHandoff(java.util.List<java.lang.String> dataDirectories,
                         java.lang.String host)
                  throws java.io.IOException
Description copied from interface: StorageServiceMBean
Stream the files in the bootstrap directory over to the node being bootstrapped. This is used in case of normal bootstrap failure. Use a tool to re-calculate the cardinality at a later point at the destination.

Specified by:
forceHandoff in interface StorageServiceMBean
Parameters:
dataDirectories - colon separated list of directories from where files need to be picked up.
host - endpoint receiving data.
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

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

getSuccessor

public EndPoint getSuccessor(EndPoint ep)

getPrimaryRangeForEndPoint

public Range getPrimaryRangeForEndPoint(EndPoint ep)
Get the primary range for the specified endpoint.

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

getAllRanges

public Range[] getAllRanges()
Get all ranges that span the ring as per current snapshot of the token distribution.

Returns:
all ranges in sorted order.

getAllRanges

public Range[] getAllRanges(java.util.Set<Token> tokens)
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 EndPoint 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

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.

getReadStorageEndPoints

public EndPoint[] getReadStorageEndPoints(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

getLiveReadStorageEndPoints

public java.util.List<EndPoint> getLiveReadStorageEndPoints(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

getHintedStorageEndpointMap

public java.util.Map<EndPoint,EndPoint> getHintedStorageEndpointMap(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

findSuitableEndPoint

public EndPoint findSuitableEndPoint(java.lang.String key)
                              throws java.io.IOException,
                                     org.apache.cassandra.service.UnavailableException
This function finds the most suitable endpoint given a key. It checks for locality and alive test.

Throws:
java.io.IOException
org.apache.cassandra.service.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


Copyright © 2009 The Apache Software Foundation