accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject accumulo git commit: ACCUMULO-3328 Write a log message when GC acquires ZK lock. Improve "wait" logic inside ReplicationIT for GC to run.
Date Thu, 13 Nov 2014 00:23:49 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master 581aed8a2 -> e595c1725


ACCUMULO-3328 Write a log message when GC acquires ZK lock. Improve "wait" logic inside ReplicationIT
for GC to run.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/e595c172
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/e595c172
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/e595c172

Branch: refs/heads/master
Commit: e595c17255f046a9459390d61c818ff6f1d1eb5d
Parents: 581aed8
Author: Josh Elser <elserj@apache.org>
Authored: Wed Nov 12 16:11:17 2014 -0800
Committer: Josh Elser <elserj@apache.org>
Committed: Wed Nov 12 16:11:17 2014 -0800

----------------------------------------------------------------------
 .../accumulo/gc/SimpleGarbageCollector.java     |  4 ++-
 .../test/replication/ReplicationIT.java         | 31 +++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/e595c172/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
----------------------------------------------------------------------
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
index d7ff148..f6ea8f7 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
@@ -747,8 +747,10 @@ public class SimpleGarbageCollector implements Iface {
     while (true) {
       lock = new ZooLock(path);
       if (lock.tryLock(lockWatcher, new ServerServices(addr.toString(), Service.GC_CLIENT).toString().getBytes()))
{
-        break;
+        log.debug("Got GC ZooKeeper lock");
+        return;
       }
+      log.debug("Failed to get GC ZooKeeper lock, will retry");
       UtilWaitThread.sleep(1000);
     }
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/e595c172/test/src/test/java/org/apache/accumulo/test/replication/ReplicationIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/replication/ReplicationIT.java b/test/src/test/java/org/apache/accumulo/test/replication/ReplicationIT.java
index 8a385d1..9f63cb0 100644
--- a/test/src/test/java/org/apache/accumulo/test/replication/ReplicationIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/replication/ReplicationIT.java
@@ -31,6 +31,7 @@ import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.BatchWriter;
@@ -40,6 +41,7 @@ import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.client.IteratorSetting.Column;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
 import org.apache.accumulo.core.client.admin.TableOperations;
 import org.apache.accumulo.core.client.replication.ReplicaSystemFactory;
 import org.apache.accumulo.core.conf.Property;
@@ -66,6 +68,10 @@ import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.core.security.TablePermission;
 import org.apache.accumulo.core.tabletserver.log.LogEntry;
 import org.apache.accumulo.core.util.UtilWaitThread;
+import org.apache.accumulo.core.zookeeper.ZooUtil;
+import org.apache.accumulo.fate.zookeeper.ZooCache;
+import org.apache.accumulo.fate.zookeeper.ZooCacheFactory;
+import org.apache.accumulo.fate.zookeeper.ZooLock;
 import org.apache.accumulo.gc.SimpleGarbageCollector;
 import org.apache.accumulo.minicluster.ServerType;
 import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
@@ -140,6 +146,21 @@ public class ReplicationIT extends ConfigurableMacIT {
     return logs;
   }
 
+  private void waitForGCLock(Connector conn) throws InterruptedException {
+    // Check if the GC process has the lock before wasting our retry attempts
+    ZooKeeperInstance zki = (ZooKeeperInstance) conn.getInstance();
+    ZooCacheFactory zcf = new ZooCacheFactory();
+    ZooCache zcache = zcf.getZooCache(zki.getZooKeepers(), zki.getZooKeepersSessionTimeOut());
+    String zkPath = ZooUtil.getRoot(conn.getInstance()) + Constants.ZGC_LOCK;
+    log.info("Looking for GC lock at {}", zkPath);
+    byte[] data = ZooLock.getLockData(zcache, zkPath, null);
+    while (null == data) {
+      log.info("Waiting for GC ZooKeeper lock to be acquired");
+      Thread.sleep(1000);
+      data = ZooLock.getLockData(zcache, zkPath, null);
+    }
+  }
+
   @Test
   public void replicationTableCreated() throws AccumuloException, AccumuloSecurityException
{
     Assert.assertTrue(getConnector().tableOperations().exists(ReplicationTable.NAME));
@@ -1246,6 +1267,12 @@ public class ReplicationIT extends ConfigurableMacIT {
     // in the metadata table, and then in the replication table
     Process gc = cluster.exec(SimpleGarbageCollector.class);
 
+    waitForGCLock(conn);
+
+    Thread.sleep(1000);
+
+    log.info("GC is up and should have had time to run at least once by now");
+
     try {
       boolean allClosed = true;
 
@@ -1491,7 +1518,9 @@ public class ReplicationIT extends ConfigurableMacIT {
     getCluster().exec(SimpleGarbageCollector.class);
 
     // Wait for a bit since the GC has to run (should be running after a one second delay)
-    Thread.sleep(5000);
+    waitForGCLock(conn);
+
+    Thread.sleep(1000);
 
     // We expect no records in the metadata table after compaction. We have to poll
     // because we have to wait for the StatusMaker's next iteration which will clean


Mime
View raw message