You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jj...@apache.org on 2020/05/07 18:15:00 UTC

[geode] branch support/1.12 updated: GEODE-8071: Use daemon threads in RebalanceCommand (#5054)

This is an automated email from the ASF dual-hosted git repository.

jjramos pushed a commit to branch support/1.12
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/support/1.12 by this push:
     new 5a3a24e  GEODE-8071: Use daemon threads in RebalanceCommand (#5054)
5a3a24e is described below

commit 5a3a24e4724ba7278bc2f9482d25302ede964319
Author: Juan José Ramos <ju...@users.noreply.github.com>
AuthorDate: Wed May 6 12:37:10 2020 +0100

    GEODE-8071: Use daemon threads in RebalanceCommand (#5054)
    
    Changed the ExecutorService within RebalanceCommand to use daemon
    threads, otherwise the locator refuses to gracefully shutdown.
    
    - Fixed minor warnings.
    - Added distributed tests.
    - Refactored RebalanceCommandDistributedTest.
    
    (cherry picked from commit d8e86cb720c054b154a16cc88fee88e73db709f3)
---
 .../commands/RebalanceCommandDistributedTest.java  | 173 +++++++++++++++++++++
 .../RebalanceCommandDistributedTestBase.java       | 101 ------------
 .../commands/RebalanceCommandDistributedTest.java  |  18 ---
 .../internal/cli/commands/RebalanceCommand.java    |   9 +-
 .../RebalanceCommandOverHttpDistributedTest.java   |  24 ---
 5 files changed, 177 insertions(+), 148 deletions(-)

diff --git a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
new file mode 100644
index 0000000..c9a4fae
--- /dev/null
+++ b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.management.internal.cli.commands;
+
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static org.apache.geode.test.junit.rules.GfshCommandRule.PortType.http;
+import static org.apache.geode.test.junit.rules.GfshCommandRule.PortType.jmxManager;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.management.internal.i18n.CliStrings;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.assertions.TabularResultModelAssert;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+import org.apache.geode.test.junit.rules.MemberStarterRule;
+
+@RunWith(Parameterized.class)
+public class RebalanceCommandDistributedTest implements Serializable {
+  private static final int ENTRIES_PER_REGION = 200;
+  private static final String REGION_ONE_NAME = "region-1";
+  private static final String REGION_TWO_NAME = "region-2";
+  private static final String REGION_THREE_NAME = "region-3";
+
+  @Rule
+  public transient GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule();
+
+  protected MemberVM locator, server1, server2;
+
+  @Parameterized.Parameters(name = "ConnectionType:{0}")
+  public static GfshCommandRule.PortType[] connectionTypes() {
+    return new GfshCommandRule.PortType[] {http, jmxManager};
+  }
+
+  @Parameterized.Parameter
+  public static GfshCommandRule.PortType portType;
+
+  private void setUpRegions() {
+    server1.invoke(() -> {
+      Cache cache = ClusterStartupRule.getCache();
+      assertThat(cache).isNotNull();
+      RegionFactory<String, String> dataRegionFactory =
+          cache.createRegionFactory(RegionShortcut.PARTITION);
+      Region<String, String> region1 = dataRegionFactory.create(REGION_ONE_NAME);
+      Region<String, String> region2 = dataRegionFactory.create(REGION_TWO_NAME);
+
+      for (int i = 0; i < ENTRIES_PER_REGION; i++) {
+        region1.put("key" + i, "Value" + i);
+        region2.put("key" + i, "Value" + i);
+      }
+    });
+
+    server2.invoke(() -> {
+      // no need to close cache as it will be closed as part of teardown2
+      Cache cache = ClusterStartupRule.getCache();
+      assertThat(cache).isNotNull();
+      RegionFactory<String, String> dataRegionFactory =
+          cache.createRegionFactory(RegionShortcut.PARTITION);
+      dataRegionFactory.create(REGION_ONE_NAME);
+      Region<String, String> region3 = dataRegionFactory.create(REGION_THREE_NAME);
+
+      for (int i = 0; i < ENTRIES_PER_REGION; i++) {
+        region3.put("key" + i, "Value" + i);
+      }
+    });
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    locator = cluster.startLocatorVM(0, MemberStarterRule::withHttpService);
+    int locatorPort = locator.getPort();
+
+    server1 = cluster.startServerVM(1, "localhost", locatorPort);
+    server2 = cluster.startServerVM(2, "localhost", locatorPort);
+    setUpRegions();
+
+    switch (portType) {
+      case http:
+        gfsh.connectAndVerify(locator.getHttpPort(), http);
+        break;
+      case jmxManager:
+        gfsh.connectAndVerify(locator.getJmxPort(), jmxManager);
+        break;
+
+      default:
+        throw new IllegalArgumentException("Invalid PortType Configured");
+    }
+  }
+
+  @Test
+  public void testSimulateForEntireDSWithTimeout() {
+    // check if DistributedRegionMXBean is available so that command will not fail
+    locator.waitUntilRegionIsReadyOnExactlyThisManyServers(SEPARATOR + REGION_ONE_NAME, 2);
+    locator.waitUntilRegionIsReadyOnExactlyThisManyServers(SEPARATOR + REGION_TWO_NAME, 1);
+    locator.waitUntilRegionIsReadyOnExactlyThisManyServers(SEPARATOR + REGION_THREE_NAME, 1);
+
+    String command = "rebalance --simulate=true --time-out=-1";
+
+    gfsh.executeAndAssertThat(command).statusIsSuccess();
+  }
+
+  @Test
+  public void testRebalanceResultOutput() {
+    // check if DistributedRegionMXBean is available so that command will not fail
+    locator.waitUntilRegionIsReadyOnExactlyThisManyServers(SEPARATOR + REGION_ONE_NAME, 2);
+
+    String command = "rebalance";
+
+    TabularResultModelAssert rebalanceResult =
+        gfsh.executeAndAssertThat(command).statusIsSuccess().hasTableSection();
+
+    rebalanceResult.hasHeader().contains("Rebalanced partition regions");
+    rebalanceResult.hasRow(0).contains(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES);
+    rebalanceResult.hasRow(1).contains(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM);
+    rebalanceResult.hasRow(2).contains(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED);
+    rebalanceResult.hasRow(3).contains(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES);
+    rebalanceResult.hasRow(4).contains(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME);
+    rebalanceResult.hasRow(5).contains(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED);
+    rebalanceResult.hasRow(6).contains(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERTIME);
+    rebalanceResult.hasRow(7).contains(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERSCOMPLETED);
+    rebalanceResult.hasRow(8).contains(CliStrings.REBALANCE__MSG__TOTALTIME);
+  }
+
+  /**
+   * See GEODE-8071.
+   * The test asserts that the amount of non-daemon threads on the locator VM remains constant
+   * before and after executing the re-balance command.
+   */
+  @Test
+  public void rebalanceCommandShouldNotLaunchNonDaemonThreads() {
+    long nonDaemonThreadsBeforeCommand = locator.invoke(() -> Thread.getAllStackTraces()
+        .keySet()
+        .stream()
+        .filter(thread -> !thread.isDaemon())
+        .count());
+
+    gfsh.executeAndAssertThat("rebalance").statusIsSuccess();
+
+    long daemonThreadsAfterCommand = locator.invoke(() -> Thread.getAllStackTraces()
+        .keySet()
+        .stream()
+        .filter(thread -> !thread.isDaemon())
+        .count());
+
+    assertThat(daemonThreadsAfterCommand).isEqualTo(nonDaemonThreadsBeforeCommand);
+  }
+}
diff --git a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTestBase.java b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTestBase.java
deleted file mode 100644
index 186b515..0000000
--- a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTestBase.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.geode.management.internal.cli.commands;
-
-
-import static org.apache.geode.test.junit.rules.GfshCommandRule.PortType.jmxManager;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.test.dunit.rules.ClusterStartupRule;
-import org.apache.geode.test.dunit.rules.MemberVM;
-import org.apache.geode.test.junit.rules.GfshCommandRule;
-
-@SuppressWarnings("serial")
-public class RebalanceCommandDistributedTestBase {
-
-  @ClassRule
-  public static ClusterStartupRule cluster = new ClusterStartupRule();
-
-  @ClassRule
-  public static GfshCommandRule gfsh = new GfshCommandRule();
-
-  protected static MemberVM locator, server1, server2;
-
-  @BeforeClass
-  public static void beforeClass() {
-    locator = cluster.startLocatorVM(0, l -> l.withHttpService());
-
-    int locatorPort = locator.getPort();
-    server1 = cluster.startServerVM(1, "localhost", locatorPort);
-    server2 = cluster.startServerVM(2, "localhost", locatorPort);
-
-    setUpRegions();
-  }
-
-  @Before
-  public void before() throws Exception {
-    gfsh.connect(locator.getJmxPort(), jmxManager);
-  }
-
-  @Test
-  public void testSimulateForEntireDSWithTimeout() {
-    // check if DistributedRegionMXBean is available so that command will not fail
-    locator.waitUntilRegionIsReadyOnExactlyThisManyServers("/region-1", 2);
-    locator.waitUntilRegionIsReadyOnExactlyThisManyServers("/region-2", 1);
-    locator.waitUntilRegionIsReadyOnExactlyThisManyServers("/region-3", 1);
-
-    String command = "rebalance --simulate=true --time-out=-1";
-
-    gfsh.executeAndAssertThat(command).statusIsSuccess();
-  }
-
-  private static void setUpRegions() {
-    server1.invoke(() -> {
-      Cache cache = ClusterStartupRule.getCache();
-      RegionFactory<Integer, Integer> dataRegionFactory =
-          cache.createRegionFactory(RegionShortcut.PARTITION);
-      Region region = dataRegionFactory.create("region-1");
-      for (int i = 0; i < 10; i++) {
-        region.put("key" + (i + 200), "value" + (i + 200));
-      }
-      region = dataRegionFactory.create("region-2");
-      for (int i = 0; i < 100; i++) {
-        region.put("key" + (i + 200), "value" + (i + 200));
-      }
-    });
-    server2.invoke(() -> {
-      // no need to close cache as it will be closed as part of teardown2
-      Cache cache = ClusterStartupRule.getCache();
-      RegionFactory<Integer, Integer> dataRegionFactory =
-          cache.createRegionFactory(RegionShortcut.PARTITION);
-      Region region = dataRegionFactory.create("region-1");
-      for (int i = 0; i < 100; i++) {
-        region.put("key" + (i + 400), "value" + (i + 400));
-      }
-      region = dataRegionFactory.create("region-3");
-      for (int i = 0; i < 10; i++) {
-        region.put("key" + (i + 200), "value" + (i + 200));
-      }
-    });
-  }
-}
diff --git a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java b/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
deleted file mode 100644
index c224dd5..0000000
--- a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * 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.geode.management.internal.cli.commands;
-
-public class RebalanceCommandDistributedTest extends RebalanceCommandDistributedTestBase {
-}
diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java
index fbd2508..51a3dd7 100644
--- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java
+++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java
@@ -60,7 +60,7 @@ public class RebalanceCommand extends GfshCommand {
           help = CliStrings.REBALANCE__SIMULATE__HELP) boolean simulate) {
 
     ExecutorService commandExecutors =
-        LoggingExecutors.newSingleThreadExecutor("RebalanceCommand", false);
+        LoggingExecutors.newSingleThreadExecutor("RebalanceCommand", true);
     List<Future<ResultModel>> commandResult = new ArrayList<>();
     ResultModel result;
     try {
@@ -186,11 +186,10 @@ public class RebalanceCommand extends GfshCommand {
 
   // TODO EY Move this to its own class
   private class ExecuteRebalanceWithTimeout implements Callable<ResultModel> {
-
-    String[] includeRegions = null;
-    String[] excludeRegions = null;
     boolean simulate;
-    InternalCache cache = null;
+    InternalCache cache;
+    String[] includeRegions;
+    String[] excludeRegions;
 
     @Override
     public ResultModel call() throws Exception {
diff --git a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandOverHttpDistributedTest.java b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandOverHttpDistributedTest.java
deleted file mode 100644
index a4acb20..0000000
--- a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandOverHttpDistributedTest.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.geode.management.internal.cli.commands;
-
-import static org.apache.geode.test.junit.rules.GfshCommandRule.PortType.http;
-
-public class RebalanceCommandOverHttpDistributedTest extends RebalanceCommandDistributedTestBase {
-  @Override
-  public void before() throws Exception {
-    gfsh.connectAndVerify(locator.getHttpPort(), http);
-  }
-}