You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "Maxwell-Guo (via GitHub)" <gi...@apache.org> on 2023/06/08 06:57:30 UTC

[GitHub] [cassandra] Maxwell-Guo commented on a diff in pull request #2390: CASSANDRA-18555 expose failed decommission via system.local

Maxwell-Guo commented on code in PR #2390:
URL: https://github.com/apache/cassandra/pull/2390#discussion_r1222529561


##########
src/java/org/apache/cassandra/service/StorageService.java:
##########
@@ -5182,41 +5190,40 @@ public void decommission(boolean force) throws InterruptedException
             }
 
             startLeaving();
-            long timeout = Math.max(RING_DELAY_MILLIS, BatchlogManager.instance.getBatchlogTimeout());
+            long timeout = Math.max(RING_DELAY_MILLIS, BatchlogManager.getBatchlogTimeout());
             setMode(Mode.LEAVING, "sleeping " + timeout + " ms for batch processing and pending range setup", true);
-            Thread.sleep(timeout);
+            Uninterruptibles.sleepUninterruptibly(timeout, MILLISECONDS);
+
+            unbootstrap();
 
-            Runnable finishLeaving = new Runnable()
+            // shutdown cql, gossip, messaging, Stage and set state to DECOMMISSIONED
+
+            shutdownClientServers();
+            Gossiper.instance.stop();
+            try
             {
-                public void run()
-                {
-                    shutdownClientServers();
-                    Gossiper.instance.stop();
-                    try
-                    {
-                        MessagingService.instance().shutdown();
-                    }
-                    catch (IOError ioe)
-                    {
-                        logger.info("failed to shutdown message service: {}", ioe);
-                    }
+                MessagingService.instance().shutdown();
+            }
+            catch (IOError ioe)
+            {
+                logger.info("failed to shutdown message service", ioe);

Review Comment:
   what about change the logging level to warn ?



##########
test/distributed/org/apache/cassandra/distributed/test/DecommissionTest.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.distributed.test;
+
+import java.util.concurrent.Callable;
+import java.util.function.Supplier;
+
+import org.junit.Test;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.SuperCall;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.IInvokableInstance;
+import org.apache.cassandra.distributed.api.NodeToolResult;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.streaming.StreamState;
+import org.apache.cassandra.utils.concurrent.Future;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.apache.cassandra.db.SystemKeyspace.BootstrapState.COMPLETED;
+import static org.apache.cassandra.db.SystemKeyspace.BootstrapState.DECOMMISSIONED;
+import static org.apache.cassandra.db.SystemKeyspace.BootstrapState.DECOMMISSION_FAILED;
+import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
+import static org.apache.cassandra.distributed.api.Feature.JMX;
+import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL;
+import static org.apache.cassandra.distributed.api.Feature.NETWORK;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class DecommissionTest extends TestBaseImpl
+{
+    @Test
+    public void testDecommission() throws Throwable
+    {
+        try (Cluster cluster = init(Cluster.build(2)
+                                           .withConfig(config -> config.with(GOSSIP)
+                                                                       .with(NETWORK)
+                                                                       .with(JMX)
+                                                                       .with(NATIVE_PROTOCOL))
+                                           .withInstanceInitializer(DecommissionTest.BB::install)
+                                           .start()))
+        {
+            IInvokableInstance instance = cluster.get(1);
+
+            assertInfoBootstrapState(instance, COMPLETED);
+
+            instance.runOnInstance(() -> {
+                try
+                {
+                    StorageService.instance.decommission(true);
+                    fail("the first attempt to decommission should fail");
+                }
+                catch (Throwable t)
+                {
+                    assertEquals("Error while decommissioning node: simulated error in prepareUnbootstrapStreaming", t.getMessage());
+                }
+
+                assertTrue("system.local column 'bootstrapped' should contain value " + DECOMMISSION_FAILED,
+                           SystemKeyspace.hasDecommissionFailed());
+
+                assertEquals("system.local column 'bootstrapped' should contain value " + DECOMMISSION_FAILED,
+                             DECOMMISSION_FAILED.name(),
+                             StorageService.instance.getBootstrapState());
+            });
+
+            assertInfoBootstrapState(instance, DECOMMISSION_FAILED);
+
+            instance.runOnInstance(() -> {
+                try
+                {
+                    StorageService.instance.decommission(true);
+
+                    assertFalse("system.local column 'bootstrapped' should not contain value " + DECOMMISSION_FAILED,
+                                SystemKeyspace.hasDecommissionFailed());
+
+                    assertEquals("system.local column 'bootstrapped' should contain value " + DECOMMISSIONED,
+                                 DECOMMISSIONED.name(),
+                                 StorageService.instance.getBootstrapState());
+                }

Review Comment:
   should we add a fail("some messages "); after ` assertEquals("system.local column 'bootstrapped' should contain value " + DECOMMISSIONED,
                                    DECOMMISSIONED.name(),
                                    StorageService.instance.getBootstrapState());`
   as if the content in this try does not throw an exception? 



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org