src/java/org/apache/cassandra/service/StorageService.java
/**
     * Remove a node that has died, attempting to restore the replica count.
     * If the node is alive, decommission should be attempted.  If decommission
     * fails, then removeToken should be called.  If we fail while trying to
     * restore the replica count, finally forceRemoveCompleteion should be
     * called to forcibly remove the node without regard to replica count.
     *
     * @param tokenString token for the node
     */
Remove a node that has died, attempting to restore the replica count.
If the node is alive, decommission should be attempted.  If decommission
fails, then removeToken should be called.  If we fail while trying to
restore the replica count, finally forceRemoveCompleteion should be
called to forcibly remove the node without regard to replica count.

@param tokenString token for the node
Remove a node that has died attempting to restore the replica count . If the node is alive decommission should be attempted . If decommission fails then removeToken should be called . If we fail while trying to restore the replica count finally forceRemoveCompleteion should be called to forcibly remove the node without regard to replica count . @param tokenString token for the node
@Override
    public void removeToken(String tokenString)
    {
        InetAddress myAddress = FBUtilities.getBroadcastAddress();
        Token localToken = tokenMetadata_.getToken(myAddress);
        Token token = partitioner.getTokenFactory().fromString(tokenString);
        InetAddress endpoint = tokenMetadata_.getEndpoint(token);
        if (endpoint == null)
            throw new UnsupportedOperationException("Token not found.");
        if (endpoint.equals(myAddress))
             throw new UnsupportedOperationException("Cannot remove node's own token");
        if (Gossiper.instance.getLiveMembers().contains(endpoint))
            throw new UnsupportedOperationException("Node " + endpoint + " is alive and owns this token. Use decommission command to remove it from the ring");
        if (tokenMetadata_.isLeaving(endpoint))
            logger_.warn("Node " + endpoint + " is already being removed, continuing removal anyway");
        if (!replicatingNodes.isEmpty())
            throw new UnsupportedOperationException("This node is already processing a removal. Wait for it to complete, or use 'removetoken force' if this has failed.");
        for (String table : Schema.instance.getNonSystemTables())
        {
            if (Table.open(table).getReplicationStrategy().getReplicationFactor() == 1)
                continue;
            Multimap<Range<Token>, InetAddress> changedRanges = getChangedRangesForLeaving(table, endpoint);
            IFailureDetector failureDetector = FailureDetector.instance;
            for (InetAddress ep : changedRanges.values())
            {
                if (failureDetector.isAlive(ep))
                    replicatingNodes.add(ep);
                else
                    logger_.warn("Endpoint " + ep + " is down and will not receive data for re-replication of " + endpoint);
            }
        }
        removingNode = endpoint;
        tokenMetadata_.addLeavingEndpoint(endpoint);
        calculatePendingRanges();
        Gossiper.instance.advertiseRemoving(endpoint, token, localToken);
        restoreReplicaCount(endpoint, myAddress);
        while (!replicatingNodes.isEmpty())
        {
            try
            {
                Thread.sleep(100);
            }
            catch (InterruptedException e)
            {
                throw new AssertionError(e);
            }
        }
        excise(token, endpoint);
        Gossiper.instance.advertiseTokenRemoved(endpoint, token);
        replicatingNodes.clear();
        removingNode = null;
    }
@ Override public void removeToken ( String tokenString ) { InetAddress myAddress = FBUtilities . getBroadcastAddress ( ) ; Token localToken = tokenMetadata_ . getToken ( myAddress ) ; Token token = partitioner . getTokenFactory ( ) . fromString ( tokenString ) ; InetAddress endpoint = tokenMetadata_ . getEndpoint ( token ) ; if ( endpoint == null ) throw new UnsupportedOperationException ( "Token not found." ) ; if ( endpoint . equals ( myAddress ) ) throw new UnsupportedOperationException ( "Cannot remove node's own token" ) ; if ( Gossiper . instance . getLiveMembers ( ) . contains ( endpoint ) ) throw new UnsupportedOperationException ( "Node " + endpoint + " is alive and owns this token. Use decommission command to remove it from the ring" ) ; if ( tokenMetadata_ . isLeaving ( endpoint ) ) logger_ . warn ( "Node " + endpoint + " is already being removed, continuing removal anyway" ) ; if ( ! replicatingNodes . isEmpty ( ) ) throw new UnsupportedOperationException ( "This node is already processing a removal. Wait for it to complete, or use 'removetoken force' if this has failed." ) ; for ( String table : Schema . instance . getNonSystemTables ( ) ) { if ( Table . open ( table ) . getReplicationStrategy ( ) . getReplicationFactor ( ) == 1 ) continue ; Multimap < Range < Token > , InetAddress > changedRanges = getChangedRangesForLeaving ( table , endpoint ) ; IFailureDetector failureDetector = FailureDetector . instance ; for ( InetAddress ep : changedRanges . values ( ) ) { if ( failureDetector . isAlive ( ep ) ) replicatingNodes . add ( ep ) ; else logger_ . warn ( "Endpoint " + ep + " is down and will not receive data for re-replication of " + endpoint ) ; } } removingNode = endpoint ; tokenMetadata_ . addLeavingEndpoint ( endpoint ) ; calculatePendingRanges ( ) ; Gossiper . instance . advertiseRemoving ( endpoint , token , localToken ) ; restoreReplicaCount ( endpoint , myAddress ) ; while ( ! replicatingNodes . isEmpty ( ) ) { try { Thread . sleep ( 100 ) ; } catch ( InterruptedException e ) { throw new AssertionError ( e ) ; } } excise ( token , endpoint ) ; Gossiper . instance . advertiseTokenRemoved ( endpoint , token ) ; replicatingNodes . clear ( ) ; removingNode = null ; }
Remove a node that has died, attempting to restore the replica count.
Remove a node that has died attempting to restore the replica count .
// A leaving endpoint that is dead is already being removed. // Find the endpoints that are going to become responsible for data // if the replication factor is 1 the data is lost so we shouldn't wait for confirmation // get all ranges that change ownership (that is, a node needs // to take responsibility for new range) // the gossiper will handle spoofing this node's state to REMOVING_TOKEN for us // we add our own token so other nodes to let us know when they're done // kick off streaming commands // wait for ReplicationFinishedVerbHandler to signal we're done // gossiper will indicate the token has left