You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sa...@apache.org on 2017/09/02 09:24:13 UTC
phoenix git commit: PHOENIX-4110 Shutdown mini cluster when number of
tables grows beyond a threshold
Repository: phoenix
Updated Branches:
refs/heads/master a8f119cb6 -> 01dbd123b
PHOENIX-4110 Shutdown mini cluster when number of tables grows beyond a threshold
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/01dbd123
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/01dbd123
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/01dbd123
Branch: refs/heads/master
Commit: 01dbd123bd70fec5391531f833ba9b73e1178f2b
Parents: a8f119c
Author: Samarth Jain <sa...@apache.org>
Authored: Sat Sep 2 02:24:03 2017 -0700
Committer: Samarth Jain <sa...@apache.org>
Committed: Sat Sep 2 02:24:03 2017 -0700
----------------------------------------------------------------------
.../phoenix/end2end/ParallelRunListener.java | 42 --------
.../end2end/ParallelStatsDisabledIT.java | 6 ++
.../phoenix/end2end/ParallelStatsEnabledIT.java | 10 +-
.../apache/phoenix/rpc/PhoenixClientRpcIT.java | 1 -
.../java/org/apache/phoenix/query/BaseTest.java | 103 +++++++++++++++----
pom.xml | 24 -----
6 files changed, 96 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01dbd123/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelRunListener.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelRunListener.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelRunListener.java
deleted file mode 100644
index 69a6cef..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelRunListener.java
+++ /dev/null
@@ -1,42 +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.phoenix.end2end;
-
-import org.apache.phoenix.query.BaseTest;
-import org.junit.runner.Result;
-import org.junit.runner.notification.RunListener;
-
-public class ParallelRunListener extends RunListener {
- // This causes output to go to the console when run through maven
- // private static final Log LOG = LogFactory.getLog(ParallelRunListener.class);
- private static final int TEAR_DOWN_THRESHOLD = 20;
-
- private int testRuns = 0;
-
- @Override
- public void testRunFinished(Result result) throws Exception {
- testRuns += result.getRunCount();
- if (testRuns > TEAR_DOWN_THRESHOLD) {
- // LOG.info("Tearing down mini cluster after " + testRuns + " test runs");
- testRuns = 0;
- BaseTest.tearDownMiniCluster();
- }
-
- super.testRunFinished(result);
- }
-}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01dbd123/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java
index 19a208d..fb980a3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java
@@ -20,6 +20,7 @@ package org.apache.phoenix.end2end;
import org.apache.phoenix.query.BaseTest;
import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.experimental.categories.Category;
@@ -35,4 +36,9 @@ public abstract class ParallelStatsDisabledIT extends BaseTest {
public static void doSetup() throws Exception {
setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);
}
+
+ @AfterClass
+ public static void tearDownMiniCluster() throws Exception {
+ BaseTest.tearDownMiniClusterIfBeyondThreshold();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01dbd123/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java
index 328a76f..a62d50d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.phoenix.query.BaseTest;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.experimental.categories.Category;
@@ -35,12 +36,17 @@ import com.google.common.collect.Maps;
*/
@Category(ParallelStatsEnabledTest.class)
public abstract class ParallelStatsEnabledIT extends BaseTest {
-
+
@BeforeClass
public static void doSetup() throws Exception {
- Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
+ Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, Boolean.toString(true));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
+
+ @AfterClass
+ public static void tearDownMiniCluster() throws Exception {
+ BaseTest.tearDownMiniClusterIfBeyondThreshold();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01dbd123/phoenix-core/src/it/java/org/apache/phoenix/rpc/PhoenixClientRpcIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/rpc/PhoenixClientRpcIT.java b/phoenix-core/src/it/java/org/apache/phoenix/rpc/PhoenixClientRpcIT.java
index 8b7d5f2..43df7a1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/rpc/PhoenixClientRpcIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/rpc/PhoenixClientRpcIT.java
@@ -53,7 +53,6 @@ public class PhoenixClientRpcIT extends BaseUniqueNamesOwnClusterIT {
@AfterClass
public static void cleanUpAfterTestSuite() throws Exception {
TestPhoenixIndexRpcSchedulerFactory.reset();
- tearDownMiniCluster();
}
@Before
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01dbd123/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index 782e878..fe6d847 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -17,6 +17,7 @@
*/
package org.apache.phoenix.query;
+import static org.apache.phoenix.hbase.index.write.ParallelWriterIndexCommitter.NUM_CONCURRENT_INDEX_WRITER_THREADS_CONF_KEY;
import static org.apache.phoenix.query.QueryConstants.MILLIS_IN_DAY;
import static org.apache.phoenix.util.PhoenixRuntime.CURRENT_SCN_ATTRIB;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
@@ -398,8 +399,23 @@ public abstract class BaseTest {
protected static PhoenixTestDriver driver;
protected static boolean clusterInitialized = false;
private static HBaseTestingUtility utility;
- protected static final Configuration config = HBaseConfiguration.create();
-
+ protected static final Configuration config = HBaseConfiguration.create();
+
+ private static class TearDownMiniClusterThreadFactory implements ThreadFactory {
+ private static final AtomicInteger threadNumber = new AtomicInteger(1);
+ private static final String NAME_PREFIX = "PHOENIX-TEARDOWN-MINICLUSTER-thread-";
+
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r, NAME_PREFIX + threadNumber.getAndIncrement());
+ t.setDaemon(true);
+ return t;
+ }
+ }
+
+ private static ExecutorService tearDownClusterService =
+ Executors.newSingleThreadExecutor(new TearDownMiniClusterThreadFactory());
+
protected static String getUrl() {
if (!clusterInitialized) {
throw new IllegalStateException("Cluster must be initialized before attempting to get the URL");
@@ -426,7 +442,7 @@ public abstract class BaseTest {
}
return url;
}
-
+
private static void checkTxManagerInitialized(ReadOnlyProps clientProps) throws SQLException, IOException {
setupTxManager();
}
@@ -445,10 +461,12 @@ public abstract class BaseTest {
}
}
- protected static void destroyDriver() throws Exception {
+ protected static void destroyDriver() {
if (driver != null) {
try {
assertTrue(destroyDriver(driver));
+ } catch (Throwable t) {
+ logger.error("Exception caught when destroying phoenix test driver", t);
} finally {
driver = null;
}
@@ -463,38 +481,56 @@ public abstract class BaseTest {
}
}
- public static void tearDownMiniCluster() throws Exception {
+ public static void tearDownMiniClusterAsync(final int numTables) {
+ final HBaseTestingUtility u = utility;
try {
destroyDriver();
- } finally {
try {
tearDownTxManager();
- } finally {
- try {
- if (utility != null) {
+ } catch (Throwable t) {
+ logger.error("Exception caught when shutting down tx manager", t);
+ }
+ utility = null;
+ clusterInitialized = false;
+ } finally {
+ tearDownClusterService.submit(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ long startTime = System.currentTimeMillis();
+ if (u != null) {
try {
- utility.shutdownMiniMapReduceCluster();
+ u.shutdownMiniMapReduceCluster();
+ } catch (Throwable t) {
+ logger.error(
+ "Exception caught when shutting down mini map reduce cluster", t);
} finally {
- utility.shutdownMiniCluster();
+ try {
+ u.shutdownMiniCluster();
+ } catch (Throwable t) {
+ logger.error("Exception caught when shutting down mini cluster", t);
+ } finally {
+ logger.info(
+ "Time in seconds spent in shutting down mini cluster with "
+ + numTables + " tables: "
+ + (System.currentTimeMillis() - startTime) / 1000);
+ }
}
}
- } finally {
- utility = null;
- clusterInitialized = false;
+ return null;
}
- }
+ });
}
}
-
+
protected static void setUpTestDriver(ReadOnlyProps props) throws Exception {
setUpTestDriver(props, props);
}
protected static void setUpTestDriver(ReadOnlyProps serverProps, ReadOnlyProps clientProps) throws Exception {
- setTxnConfigs();
- String url = checkClusterInitialized(serverProps);
- checkTxManagerInitialized(serverProps);
if (driver == null) {
+ setTxnConfigs();
+ String url = checkClusterInitialized(serverProps);
+ checkTxManagerInitialized(serverProps);
driver = initAndRegisterTestDriver(url, clientProps);
}
}
@@ -596,6 +632,7 @@ public abstract class BaseTest {
conf.setInt("hbase.assignment.zkevent.workers", 5);
conf.setInt("hbase.assignment.threads.max", 5);
conf.setInt("hbase.catalogjanitor.interval", 5000);
+ conf.setInt(NUM_CONCURRENT_INDEX_WRITER_THREADS_CONF_KEY, 1);
return conf;
}
@@ -676,14 +713,38 @@ public abstract class BaseTest {
private static AtomicInteger NAME_SUFFIX = new AtomicInteger(0);
private static final int MAX_SUFFIX_VALUE = 1000000;
-
+
+ /**
+ * Counter to track number of tables we have created. This isn't really accurate since this
+ * counter will be incremented when we call {@link #generateUniqueName()}for getting unique
+ * schema and sequence names too. But this will have to do.
+ */
+ private static final AtomicInteger TABLE_COUNTER = new AtomicInteger(0);
+ /*
+ * Threshold to monitor if we need to restart mini-cluster since we created too many tables.
+ * Note, we can't have this value too high since we don't want the shutdown to take too
+ * long a time either.
+ */
+ private static final int TEARDOWN_THRESHOLD = 30;
+
public static String generateUniqueName() {
int nextName = NAME_SUFFIX.incrementAndGet();
if (nextName >= MAX_SUFFIX_VALUE) {
throw new IllegalStateException("Used up all unique names");
}
+ TABLE_COUNTER.incrementAndGet();
return "T" + Integer.toString(MAX_SUFFIX_VALUE + nextName).substring(1);
- //return RandomStringUtils.randomAlphabetic(20).toUpperCase();
+ }
+
+ public static void tearDownMiniClusterIfBeyondThreshold() throws Exception {
+ if (TABLE_COUNTER.get() > TEARDOWN_THRESHOLD) {
+ int numTables = TABLE_COUNTER.get();
+ TABLE_COUNTER.set(0);
+ logger.info(
+ "Shutting down mini cluster because number of tables on this mini cluster is likely greater than "
+ + TEARDOWN_THRESHOLD);
+ tearDownMiniClusterAsync(numTables);
+ }
}
protected static void createTestTable(String url, String ddl) throws SQLException {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01dbd123/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5c20a3c..64681a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -248,12 +248,6 @@
<shutdown>kill</shutdown>
<testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
<groups>org.apache.phoenix.end2end.ParallelStatsEnabledTest</groups>
- <properties>
- <property>
- <name>listener</name>
- <value>org.apache.phoenix.end2end.ParallelRunListener</value>
- </property>
- </properties>
</configuration>
<goals>
<goal>integration-test</goal>
@@ -283,12 +277,6 @@
<shutdown>kill</shutdown>
<testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
<groups>org.apache.phoenix.end2end.ParallelStatsDisabledTest</groups>
- <properties>
- <property>
- <name>listener</name>
- <value>org.apache.phoenix.end2end.ParallelRunListener</value>
- </property>
- </properties>
</configuration>
<goals>
<goal>integration-test</goal>
@@ -307,12 +295,6 @@
<testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
<groups>org.apache.phoenix.end2end.ClientManagedTimeTest</groups>
<shutdown>kill</shutdown>
- <properties>
- <property>
- <name>listener</name>
- <value>org.apache.phoenix.end2end.ParallelRunListener</value>
- </property>
- </properties>
</configuration>
<goals>
<goal>integration-test</goal>
@@ -349,12 +331,6 @@
<testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
<groups>org.apache.phoenix.end2end.NeedsOwnMiniClusterTest</groups>
<shutdown>kill</shutdown>
- <properties>
- <property>
- <name>listener</name>
- <value>org.apache.phoenix.end2end.ParallelRunListener</value>
- </property>
- </properties>
</configuration>
<goals>
<goal>integration-test</goal>