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
           
static class StorageService.BootstrapMode
           
static class StorageService.ConsistencyLevel
           
 
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 calloutDeployVerbHandler_
           
static java.lang.String dataFileVerbHandler_
           
static java.lang.String loadVerbHandler_
           
static java.lang.String mbrshipCleanerVerbHandler_
           
static java.lang.String mrStage_
           
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()
           
 
Method Summary
 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 doBootstrap(EndPoint endpoint, StorageService.BootstrapMode mode)
          Starts the bootstrap operations for the specified endpoint.
 void doConsistencyCheck(Row row, java.util.List<EndPoint> endpoints, ReadCommand command)
           
 void doGC()
           
 EndPoint findSuitableEndPoint(java.lang.String key)
          This function finds the most suitable endpoint given a key.
 java.util.Map<java.lang.String,EndPoint> findSuitableEndPoints(java.lang.String[] keys)
           
 void forceHandoff(java.lang.String directories, java.lang.String host)
          Stream the files in the bootstrap directory over to the node being bootstrapped.
 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.
 IEndPointSnitch getEndPointSnitch()
           
static java.lang.String getHostUrl()
           
 java.lang.String getLiveNodes()
           
 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()
           
 java.util.List<EndPoint> getNLiveStorageEndPoint(java.lang.String key)
          This method attempts to return N endpoints that are responsible for storing the specified key i.e for replication.
 EndPoint[] getNStorageEndPoint(java.lang.String key)
          This method returns the N endpoints that are responsible for storing the specified key i.e for replication.
 EndPoint[] getNStorageEndPoint(Token token)
          This method returns the N endpoints that are responsible for storing the specified token i.e for replication.
protected  EndPoint[] getNStorageEndPoint(Token token, java.util.Map<Token,EndPoint> tokenToEndPointMap)
          This method returns the N endpoints that are responsible for storing the specified token i.e for replication and are based on the token to endpoint mapping that is passed in.
 java.util.Map<EndPoint,EndPoint> getNStorageEndPointMap(java.lang.String key)
          This method returns the N endpoints that are responsible for storing the specified key i.e for replication.
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 getSuccessor(EndPoint ep)
           
 java.lang.String getToken()
           
 java.lang.String getToken(EndPoint ep)
           
 TokenMetadata getTokenMetadata()
           
 java.lang.String getUnreachableNodes()
           
protected  org.apache.zookeeper.ZooKeeper getZooKeeperHandle()
           
static StorageService instance()
           
 boolean isInSameDataCenter(EndPoint endpoint)
           
 boolean isPrimary(java.lang.String key)
          This method determines whether the local endpoint is the primary for the given key.
 boolean isShutdown()
           
 void killMe()
           
 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 registerComponentForShutdown(IComponentShutdown component)
           
 void relocate(java.lang.String[] keys)
           
 void removeTokenState(EndPoint endpoint)
           
 void shutdown()
           
 void start()
           
 void updateToken(Token token)
           
 void updateTokenMetadata(Token token, EndPoint endpoint)
           
 
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

mrStage_

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

loadVerbHandler_

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

calloutDeployVerbHandler_

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

rangeVerbHandler_

public static java.lang.String rangeVerbHandler_
Constructor Detail

StorageService

public StorageService()
Method Detail

getLocalStorageEndPoint

public static EndPoint getLocalStorageEndPoint()

getLocalControlEndPoint

public static EndPoint getLocalControlEndPoint()

getHostUrl

public static java.lang.String getHostUrl()

getPartitioner

public static IPartitioner getPartitioner()

instance

public static StorageService instance()

getZooKeeperHandle

protected org.apache.zookeeper.ZooKeeper getZooKeeperHandle()

registerComponentForShutdown

public void registerComponentForShutdown(IComponentShutdown component)

start

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

killMe

public void killMe()
            throws java.lang.Throwable
Throws:
java.lang.Throwable

isShutdown

public boolean isShutdown()

shutdown

public void shutdown()

getTokenMetadata

public TokenMetadata getTokenMetadata()

updateTokenMetadata

public void updateTokenMetadata(Token token,
                                EndPoint endpoint)

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()

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 occured.
epState - state that actually changed for the above endpoint.

getLoadInfo

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


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,
                              StorageService.BootstrapMode mode)
Starts the bootstrap operations for the specified endpoint. The name of this method is however a misnomer since it does handoff of data to the specified node when it has crashed and come back up, marked as alive after a network partition and also when it joins the ring either as an old node being relocated or as a brand new node.


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

loadAll

public void loadAll(java.lang.String nodes)
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

doGC

public void doGC()
Specified by:
doGC in interface StorageServiceMBean

forceHandoff

public void forceHandoff(java.lang.String directories,
                         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
host - endpoint receiving data.
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. param @ key - key for which we need to find the endpoint return 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.

getNStorageEndPoint

public EndPoint[] getNStorageEndPoint(java.lang.String key)
This method returns the N endpoints that are responsible for storing the specified key i.e for replication. param @ key - key for which we need to find the endpoint return value - the endpoint responsible for this key


getNLiveStorageEndPoint

public java.util.List<EndPoint> getNLiveStorageEndPoint(java.lang.String key)
This method attempts to return N endpoints that are responsible for storing the specified key i.e for replication. param @ key - key for which we need to find the endpoint return value - the endpoint responsible for this key


getNStorageEndPointMap

public java.util.Map<EndPoint,EndPoint> getNStorageEndPointMap(java.lang.String key)
This method returns the N endpoints that are responsible for storing the specified key i.e for replication. param @ key - key for which we need to find the endpoint return value - the endpoint responsible for this key


getNStorageEndPoint

public EndPoint[] getNStorageEndPoint(Token token)
This method returns the N endpoints that are responsible for storing the specified token i.e for replication. param @ token - position on the ring


getNStorageEndPoint

protected EndPoint[] getNStorageEndPoint(Token token,
                                         java.util.Map<Token,EndPoint> tokenToEndPointMap)
This method returns the N endpoints that are responsible for storing the specified token i.e for replication and are based on the token to endpoint mapping that is passed in. param @ token - position on the ring param @ tokens - w/o the following tokens in the token list


findSuitableEndPoint

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

Throws:
java.io.IOException

findSuitableEndPoints

public java.util.Map<java.lang.String,EndPoint> findSuitableEndPoints(java.lang.String[] keys)
                                                               throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2009 The Apache Software Foundation