smiklosovic commented on code in PR #2374:
URL: https://github.com/apache/cassandra/pull/2374#discussion_r1219014774


##########
src/java/org/apache/cassandra/service/StorageService.java:
##########
@@ -5127,100 +5128,113 @@ private void startLeaving()
 
     public void decommission(boolean force) throws InterruptedException
     {
-        TokenMetadata metadata = tokenMetadata.cloneAfterAllLeft();
-        if (operationMode != Mode.LEAVING)
+        try
         {
-            if 
(!tokenMetadata.isMember(FBUtilities.getBroadcastAddressAndPort()))
-                throw new UnsupportedOperationException("local node is not a 
member of the token ring yet");
-            if (metadata.getAllEndpoints().size() < 2)
+            TokenMetadata metadata = tokenMetadata.cloneAfterAllLeft();
+            if (operationMode != Mode.LEAVING)
+            {
+                if 
(!tokenMetadata.isMember(FBUtilities.getBroadcastAddressAndPort()))
+                    throw new UnsupportedOperationException("local node is not 
a member of the token ring yet");
+                if (metadata.getAllEndpoints().size() < 2)
                     throw new UnsupportedOperationException("no other normal 
nodes in the ring; decommission would be pointless");
-            if (operationMode != Mode.NORMAL)
-                throw new UnsupportedOperationException("Node in " + 
operationMode + " state; wait for status to become normal or restart");
-        }
-        if (!isDecommissioning.compareAndSet(false, true))
-            throw new IllegalStateException("Node is still decommissioning. 
Check nodetool netstats.");
+                if (operationMode != Mode.NORMAL)
+                    throw new UnsupportedOperationException("Node in " + 
operationMode + " state; wait for status to become normal or restart");
+            }
+            if (!isDecommissioning.compareAndSet(false, true))
+                throw new IllegalStateException("Node is still 
decommissioning. Check nodetool netstats.");
 
-        if (logger.isDebugEnabled())
-            logger.debug("DECOMMISSIONING");
+            if (logger.isDebugEnabled())
+                logger.debug("DECOMMISSIONING");
 
-        try
-        {
-            PendingRangeCalculatorService.instance.blockUntilFinished();
+            try
+            {
+                PendingRangeCalculatorService.instance.blockUntilFinished();
 
-            String dc = 
DatabaseDescriptor.getEndpointSnitch().getLocalDatacenter();
+                String dc = 
DatabaseDescriptor.getEndpointSnitch().getLocalDatacenter();
 
-            if (operationMode != Mode.LEAVING) // If we're already 
decommissioning there is no point checking RF/pending ranges
-            {
-                int rf, numNodes;
-                for (String keyspaceName : 
Schema.instance.getNonLocalStrategyKeyspaces().names())
+                if (operationMode != Mode.LEAVING) // If we're already 
decommissioning there is no point checking RF/pending ranges
                 {
-                    if (!force)
+                    int rf, numNodes;
+                    for (String keyspaceName : 
Schema.instance.getNonLocalStrategyKeyspaces().names())
                     {
-                        Keyspace keyspace = Keyspace.open(keyspaceName);
-                        if (keyspace.getReplicationStrategy() instanceof 
NetworkTopologyStrategy)
+                        if (!force)
                         {
-                            NetworkTopologyStrategy strategy = 
(NetworkTopologyStrategy) keyspace.getReplicationStrategy();
-                            rf = strategy.getReplicationFactor(dc).allReplicas;
-                            numNodes = 
metadata.getTopology().getDatacenterEndpoints().get(dc).size();
-                        }
-                        else
-                        {
-                            numNodes = metadata.getAllEndpoints().size();
-                            rf = 
keyspace.getReplicationStrategy().getReplicationFactor().allReplicas;
-                        }
+                            Keyspace keyspace = Keyspace.open(keyspaceName);
+                            if (keyspace.getReplicationStrategy() instanceof 
NetworkTopologyStrategy)
+                            {
+                                NetworkTopologyStrategy strategy = 
(NetworkTopologyStrategy) keyspace.getReplicationStrategy();
+                                rf = 
strategy.getReplicationFactor(dc).allReplicas;
+                                numNodes = 
metadata.getTopology().getDatacenterEndpoints().get(dc).size();
+                            }
+                            else
+                            {
+                                numNodes = metadata.getAllEndpoints().size();
+                                rf = 
keyspace.getReplicationStrategy().getReplicationFactor().allReplicas;
+                            }
 
-                        if (numNodes <= rf)
-                            throw new UnsupportedOperationException("Not 
enough live nodes to maintain replication factor in keyspace "
-                                                                    + 
keyspaceName + " (RF = " + rf + ", N = " + numNodes + ")."
-                                                                    + " 
Perform a forceful decommission to ignore.");
+                            if (numNodes <= rf)
+                                throw new UnsupportedOperationException("Not 
enough live nodes to maintain replication factor in keyspace "
+                                                                        + 
keyspaceName + " (RF = " + rf + ", N = " + numNodes + ")."
+                                                                        + " 
Perform a forceful decommission to ignore.");
+                        }
+                        // TODO: do we care about fixing transient/full 
self-movements here? probably
+                        if (tokenMetadata.getPendingRanges(keyspaceName, 
FBUtilities.getBroadcastAddressAndPort()).size() > 0)
+                            throw new UnsupportedOperationException("data is 
currently moving to this node; unable to leave the ring");
                     }
-                    // TODO: do we care about fixing transient/full 
self-movements here? probably
-                    if (tokenMetadata.getPendingRanges(keyspaceName, 
FBUtilities.getBroadcastAddressAndPort()).size() > 0)
-                        throw new UnsupportedOperationException("data is 
currently moving to this node; unable to leave the ring");
                 }
-            }
 
-            startLeaving();
-            long timeout = Math.max(RING_DELAY_MILLIS, 
BatchlogManager.instance.getBatchlogTimeout());
-            setMode(Mode.LEAVING, "sleeping " + timeout + " ms for batch 
processing and pending range setup", true);
-            Thread.sleep(timeout);
+                startLeaving();
+                long timeout = Math.max(RING_DELAY_MILLIS, 
BatchlogManager.instance.getBatchlogTimeout());
+                setMode(Mode.LEAVING, "sleeping " + timeout + " ms for batch 
processing and pending range setup", true);
+                Thread.sleep(timeout);

Review Comment:
   maybe it is good time to sleep uninterruptibly? Look into Uninterruptibles 
in google guava 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to