You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2014/01/07 02:42:54 UTC
[1/3] git commit: ACCUMULO-2128 added waitForZooKeeperClientThreads
method
Updated Branches:
refs/heads/1.4.5-SNAPSHOT 71f150a77 -> 8f9fe4175
ACCUMULO-2128 added waitForZooKeeperClientThreads method
Signed-off-by: Keith Turner <kt...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/c94a73f4
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/c94a73f4
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/c94a73f4
Branch: refs/heads/1.4.5-SNAPSHOT
Commit: c94a73f478c91a24e35583d41bb39102461c54fa
Parents: 715825b
Author: Jared Winick <ja...@koverse.com>
Authored: Thu Jan 2 22:30:59 2014 -0700
Committer: Keith Turner <kt...@apache.org>
Committed: Mon Jan 6 20:17:58 2014 -0500
----------------------------------------------------------------------
.../org/apache/accumulo/core/util/CleanUp.java | 32 ++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/c94a73f4/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java
----------------------------------------------------------------------
diff --git a/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java b/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java
index ba02f0b..5b2a4b9 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java
@@ -16,20 +16,48 @@
*/
package org.apache.accumulo.core.util;
+import java.util.Set;
+
import org.apache.accumulo.core.client.impl.ThriftTransportPool;
import org.apache.accumulo.core.zookeeper.ZooSession;
+import org.apache.log4j.Logger;
/**
*
*/
public class CleanUp {
+
+ private static final Logger log = Logger.getLogger(CleanUp.class);
+
/**
* kills all threads created by internal Accumulo singleton resources. After this method is called, no accumulo client will work in the current classloader.
*/
public static void shutdownNow() {
ThriftTransportPool.getInstance().shutdown();
ZooSession.shutdown();
- // need to get code from jared w
- // waitForZooKeeperClientThreads();
+ waitForZooKeeperClientThreads();
+ }
+
+ /**
+ * As documented in https://issues.apache.org/jira/browse/ZOOKEEPER-1816, ZooKeeper.close()
+ * is a non-blocking call. This method will wait on the ZooKeeper internal threads to exit.
+ */
+ private static void waitForZooKeeperClientThreads() {
+ Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
+ for (Thread thread : threadSet) {
+ // find ZooKeeper threads that were created in the same ClassLoader as the current thread.
+ if (thread.getClass().getName().startsWith("org.apache.zookeeper.ClientCnxn") &&
+ thread.getContextClassLoader().equals(Thread.currentThread().getContextClassLoader())) {
+
+ // wait for the thread the die
+ while (thread.isAlive()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
}
}
[3/3] git commit: ACCUMULO-2128 added test for static clean up utility
Posted by kt...@apache.org.
ACCUMULO-2128 added test for static clean up utility
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/8f9fe417
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/8f9fe417
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/8f9fe417
Branch: refs/heads/1.4.5-SNAPSHOT
Commit: 8f9fe41751415ab66ddbce6d6dec058999afc1d3
Parents: c94a73f
Author: Keith Turner <kt...@apache.org>
Authored: Mon Jan 6 20:17:45 2014 -0500
Committer: Keith Turner <kt...@apache.org>
Committed: Mon Jan 6 20:17:59 2014 -0500
----------------------------------------------------------------------
.../server/test/functional/CleanUpTest.java | 153 +++++++++++++++++++
test/system/auto/simple/cleanup.py | 30 ++++
2 files changed, 183 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/8f9fe417/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.java
----------------------------------------------------------------------
diff --git a/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.java b/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.java
new file mode 100644
index 0000000..99fbcfe
--- /dev/null
+++ b/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.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.accumulo.server.test.functional;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.CleanUp;
+
+/**
+ *
+ */
+public class CleanUpTest extends FunctionalTest {
+
+ @Override
+ public Map<String,String> getInitialConfig() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public List<TableSetup> getTablesToCreate() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void run() throws Exception {
+
+
+ getConnector().tableOperations().create("test");
+
+ BatchWriter bw = getConnector().createBatchWriter("test", 1000000, 60000, 1);
+
+ Mutation m1 = new Mutation("r1");
+ m1.put("cf1", "cq1", 1, "5");
+
+ bw.addMutation(m1);
+
+ bw.flush();
+
+ Scanner scanner = getConnector().createScanner("test", new Authorizations());
+
+ int count = 0;
+ for (Entry<Key,Value> entry : scanner) {
+ count++;
+ if (!entry.getValue().toString().equals("5")) {
+ throw new Exception("Unexpected value " + entry.getValue());
+ }
+ }
+
+ if (count != 1) {
+ throw new Exception("Unexpected count " + count);
+ }
+
+ if (countThreads() < 2) {
+ printThreadNames();
+ throw new Exception("Not seeing expected threads");
+ }
+
+ CleanUp.shutdownNow();
+
+ Mutation m2 = new Mutation("r2");
+ m2.put("cf1", "cq1", 1, "6");
+
+ try {
+ bw.addMutation(m1);
+ bw.flush();
+ throw new Exception("batch writer did not fail");
+ } catch (Exception e) {
+
+ }
+
+ try {
+ // expect this to fail also, want to clean up batch writer threads
+ bw.close();
+ throw new Exception("batch writer close not fail");
+ } catch (Exception e) {
+
+ }
+
+ try {
+ count = 0;
+ Iterator<Entry<Key,Value>> iter = scanner.iterator();
+ while (iter.hasNext()) {
+ iter.next();
+ count++;
+ }
+ throw new Exception("scanner did not fail");
+ } catch (Exception e) {
+
+ }
+
+ if (countThreads() > 0) {
+ printThreadNames();
+ throw new Exception("Threads did not go away");
+ }
+ }
+
+ private void printThreadNames() {
+ Set<Thread> threads = Thread.getAllStackTraces().keySet();
+ for (Thread thread : threads) {
+ System.out.println("thread name:" + thread.getName());
+ thread.getStackTrace();
+
+ }
+ }
+
+ /**
+ * count threads that should be cleaned up
+ *
+ */
+ private int countThreads() {
+ int count = 0;
+ Set<Thread> threads = Thread.getAllStackTraces().keySet();
+ for (Thread thread : threads) {
+
+ if (thread.getName().toLowerCase().contains("sendthread") || thread.getName().toLowerCase().contains("eventthread"))
+ count++;
+
+ if (thread.getName().toLowerCase().contains("thrift") && thread.getName().toLowerCase().contains("pool"))
+ count++;
+ }
+
+ return count;
+ }
+
+ @Override
+ public void cleanup() throws Exception {}
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/8f9fe417/test/system/auto/simple/cleanup.py
----------------------------------------------------------------------
diff --git a/test/system/auto/simple/cleanup.py b/test/system/auto/simple/cleanup.py
new file mode 100755
index 0000000..1ed8aff
--- /dev/null
+++ b/test/system/auto/simple/cleanup.py
@@ -0,0 +1,30 @@
+# 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.
+
+from JavaTest import JavaTest
+
+import unittest
+
+class CleanUpTest(JavaTest):
+ "Test clean up util"
+
+ order = 21
+ testClass="org.apache.accumulo.server.test.functional.CleanUpTest"
+
+
+def suite():
+ result = unittest.TestSuite()
+ result.addTest(CleanUpTest())
+ return result
[2/3] git commit: ACCUMULO-2128 added utility to cleanup accumulo
static resources
Posted by kt...@apache.org.
ACCUMULO-2128 added utility to cleanup accumulo static resources
Signed-off-by: Keith Turner <kt...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/715825b3
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/715825b3
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/715825b3
Branch: refs/heads/1.4.5-SNAPSHOT
Commit: 715825b3299fd742d8570971a7f271178b932812
Parents: 71f150a
Author: Keith Turner <kt...@apache.org>
Authored: Thu Jan 2 21:03:55 2014 -0500
Committer: Keith Turner <kt...@apache.org>
Committed: Mon Jan 6 20:17:58 2014 -0500
----------------------------------------------------------------------
.../core/client/impl/ThriftTransportPool.java | 102 +++++++++++++++----
.../org/apache/accumulo/core/util/CleanUp.java | 35 +++++++
.../accumulo/core/zookeeper/ZooSession.java | 23 ++++-
3 files changed, 140 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/715825b3/src/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftTransportPool.java
----------------------------------------------------------------------
diff --git a/src/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftTransportPool.java b/src/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftTransportPool.java
index ef3724b..7468051 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftTransportPool.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftTransportPool.java
@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
@@ -53,6 +54,8 @@ public class ThriftTransportPool {
private Map<ThriftTransportKey,Long> errorCount = new HashMap<ThriftTransportKey,Long>();
private Map<ThriftTransportKey,Long> errorTime = new HashMap<ThriftTransportKey,Long>();
private Set<ThriftTransportKey> serversWarnedAbout = new HashSet<ThriftTransportKey>();
+
+ private CountDownLatch closerExitLatch;
private static final Logger log = Logger.getLogger(ThriftTransportPool.class);
@@ -78,20 +81,26 @@ public class ThriftTransportPool {
long lastReturnTime;
}
+ public static class TransportPoolShutdownException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+ }
+
private static class Closer implements Runnable {
ThriftTransportPool pool;
-
- public Closer(ThriftTransportPool pool) {
+ private CountDownLatch closerExitLatch;
+
+ public Closer(ThriftTransportPool pool, CountDownLatch closerExitLatch) {
this.pool = pool;
+ this.closerExitLatch = closerExitLatch;
}
- public void run() {
+ private void closeConnections() {
while (true) {
ArrayList<CachedConnection> connectionsToClose = new ArrayList<CachedConnection>();
synchronized (pool) {
- for (List<CachedConnection> ccl : pool.cache.values()) {
+ for (List<CachedConnection> ccl : pool.getCache().values()) {
Iterator<CachedConnection> iter = ccl.iterator();
while (iter.hasNext()) {
CachedConnection cachedConnection = iter.next();
@@ -103,7 +112,7 @@ public class ThriftTransportPool {
}
}
- for (List<CachedConnection> ccl : pool.cache.values()) {
+ for (List<CachedConnection> ccl : pool.getCache().values()) {
for (CachedConnection cachedConnection : ccl) {
cachedConnection.transport.checkForStuckIO(STUCK_THRESHOLD);
}
@@ -132,6 +141,15 @@ public class ThriftTransportPool {
}
}
}
+
+ public void run() {
+ try {
+ closeConnections();
+ } catch (TransportPoolShutdownException e) {
+ } finally {
+ closerExitLatch.countDown();
+ }
+ }
}
static class CachedTTransport extends TTransport {
@@ -384,14 +402,14 @@ public class ThriftTransportPool {
synchronized (this) {
// randomly pick a server from the connection cache
- serversSet.retainAll(cache.keySet());
+ serversSet.retainAll(getCache().keySet());
if (serversSet.size() > 0) {
ArrayList<ThriftTransportKey> cachedServers = new ArrayList<ThriftTransportKey>(serversSet);
Collections.shuffle(cachedServers, random);
for (ThriftTransportKey ttk : cachedServers) {
- for (CachedConnection cachedConnection : cache.get(ttk)) {
+ for (CachedConnection cachedConnection : getCache().get(ttk)) {
if (!cachedConnection.isReserved()) {
cachedConnection.setReserved(true);
if (log.isTraceEnabled())
@@ -411,7 +429,7 @@ public class ThriftTransportPool {
if (!preferCachedConnection) {
synchronized (this) {
- List<CachedConnection> cachedConnList = cache.get(ttk);
+ List<CachedConnection> cachedConnList = getCache().get(ttk);
if (cachedConnList != null) {
for (CachedConnection cachedConnection : cachedConnList) {
if (!cachedConnection.isReserved()) {
@@ -444,11 +462,11 @@ public class ThriftTransportPool {
private TTransport getTransport(ThriftTransportKey cacheKey) throws TTransportException {
synchronized (this) {
// atomically reserve location if it exist in cache
- List<CachedConnection> ccl = cache.get(cacheKey);
+ List<CachedConnection> ccl = getCache().get(cacheKey);
if (ccl == null) {
ccl = new LinkedList<CachedConnection>();
- cache.put(cacheKey, ccl);
+ getCache().put(cacheKey, ccl);
}
for (CachedConnection cachedConnection : ccl) {
@@ -486,15 +504,20 @@ public class ThriftTransportPool {
CachedConnection cc = new CachedConnection(tsc);
cc.setReserved(true);
- synchronized (this) {
- List<CachedConnection> ccl = cache.get(cacheKey);
+ try {
+ synchronized (this) {
+ List<CachedConnection> ccl = getCache().get(cacheKey);
+
+ if (ccl == null) {
+ ccl = new LinkedList<CachedConnection>();
+ getCache().put(cacheKey, ccl);
+ }
- if (ccl == null) {
- ccl = new LinkedList<CachedConnection>();
- cache.put(cacheKey, ccl);
+ ccl.add(cc);
}
-
- ccl.add(cc);
+ } catch (TransportPoolShutdownException e) {
+ cc.transport.close();
+ throw e;
}
return cc.transport;
}
@@ -510,7 +533,7 @@ public class ThriftTransportPool {
ArrayList<CachedConnection> closeList = new ArrayList<ThriftTransportPool.CachedConnection>();
synchronized (this) {
- List<CachedConnection> ccl = cache.get(ctsc.getCacheKey());
+ List<CachedConnection> ccl = getCache().get(ctsc.getCacheKey());
for (Iterator<CachedConnection> iterator = ccl.iterator(); iterator.hasNext();) {
CachedConnection cachedConnection = iterator.next();
if (cachedConnection.transport == tsc) {
@@ -600,8 +623,49 @@ public class ThriftTransportPool {
}
if (daemonStarted.compareAndSet(false, true)) {
- new Daemon(new Closer(instance), "Thrift Connection Pool Checker").start();
+ CountDownLatch closerExitLatch = new CountDownLatch(1);
+ new Daemon(new Closer(instance, closerExitLatch), "Thrift Connection Pool Checker").start();
+ instance.setCloserExitLatch(closerExitLatch);
}
return instance;
}
+
+ private synchronized void setCloserExitLatch(CountDownLatch closerExitLatch) {
+ this.closerExitLatch = closerExitLatch;
+ }
+
+ public void shutdown() {
+ synchronized (this) {
+ if (cache == null)
+ return;
+
+ // close any connections in the pool... even ones that are in use
+ for (List<CachedConnection> ccl : getCache().values()) {
+ Iterator<CachedConnection> iter = ccl.iterator();
+ while (iter.hasNext()) {
+ CachedConnection cc = iter.next();
+ try {
+ cc.transport.close();
+ } catch (Exception e) {
+ log.debug("Error closing transport during shutdown", e);
+ }
+ }
+ }
+
+ // this will render the pool unusable and cause the background thread to exit
+ this.cache = null;
+ }
+
+ try {
+ closerExitLatch.await();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Map<ThriftTransportKey,List<CachedConnection>> getCache() {
+ if (cache == null)
+ throw new TransportPoolShutdownException();
+ return cache;
+ }
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/715825b3/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java
----------------------------------------------------------------------
diff --git a/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java b/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java
new file mode 100644
index 0000000..ba02f0b
--- /dev/null
+++ b/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java
@@ -0,0 +1,35 @@
+/*
+ * 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.accumulo.core.util;
+
+import org.apache.accumulo.core.client.impl.ThriftTransportPool;
+import org.apache.accumulo.core.zookeeper.ZooSession;
+
+/**
+ *
+ */
+public class CleanUp {
+ /**
+ * kills all threads created by internal Accumulo singleton resources. After this method is called, no accumulo client will work in the current classloader.
+ */
+ public static void shutdownNow() {
+ ThriftTransportPool.getInstance().shutdown();
+ ZooSession.shutdown();
+ // need to get code from jared w
+ // waitForZooKeeperClientThreads();
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/715825b3/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooSession.java
----------------------------------------------------------------------
diff --git a/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooSession.java b/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooSession.java
index b3db26f..e64f0c5 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooSession.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooSession.java
@@ -29,8 +29,14 @@ import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States;
-class ZooSession {
+public class ZooSession {
+ public static class ZooSessionShutdownException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ }
+
private static final Logger log = Logger.getLogger(ZooSession.class);
private static class ZooSessionInfo {
@@ -114,6 +120,9 @@ class ZooSession {
public static synchronized ZooKeeper getSession(String zooKeepers, int timeout, String auth) {
+ if (sessions == null)
+ throw new ZooSessionShutdownException();
+
String sessionKey = sessionKey(zooKeepers, timeout, auth);
// a read-only session can use a session with authorizations, so cache a copy for it w/out auths
@@ -137,4 +146,16 @@ class ZooSession {
}
return zsi.zooKeeper;
}
+
+ public static synchronized void shutdown() {
+ for (ZooSessionInfo zsi : sessions.values()) {
+ try {
+ zsi.zooKeeper.close();
+ } catch (Exception e) {
+ log.debug("Error closing zookeeper during shutdown", e);
+ }
+ }
+
+ sessions = null;
+ }
}