accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject svn commit: r1459993 - in /accumulo/trunk: ./ assemble/ core/ examples/ fate/src/main/java/org/apache/accumulo/fate/ fate/src/main/java/org/apache/accumulo/fate/zookeeper/ server/ server/src/main/java/org/apache/accumulo/server/master/ src/
Date Fri, 22 Mar 2013 21:14:18 GMT
Author: kturner
Date: Fri Mar 22 21:14:17 2013
New Revision: 1459993

URL: http://svn.apache.org/r1459993
Log:
ACCUMULO-1048 cleaned up master lock acquisition

Modified:
    accumulo/trunk/   (props changed)
    accumulo/trunk/assemble/   (props changed)
    accumulo/trunk/core/   (props changed)
    accumulo/trunk/examples/   (props changed)
    accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java   (props changed)
    accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java 
 (props changed)
    accumulo/trunk/server/   (props changed)
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/master/Master.java
    accumulo/trunk/src/   (props changed)

Propchange: accumulo/trunk/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990

Propchange: accumulo/trunk/assemble/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/assemble:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990

Propchange: accumulo/trunk/core/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/core:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990

Propchange: accumulo/trunk/examples/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/examples:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990

Propchange: accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990

Propchange: accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990

Propchange: accumulo/trunk/server/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/server:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/master/Master.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/master/Master.java?rev=1459993&r1=1459992&r2=1459993&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/master/Master.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/master/Master.java Fri
Mar 22 21:14:17 2013
@@ -92,7 +92,6 @@ import org.apache.accumulo.fate.Fate;
 import org.apache.accumulo.fate.TStore.TStatus;
 import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
 import org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason;
-import org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher;
 import org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
@@ -2128,49 +2127,86 @@ public class Master implements LiveTServ
     return masterLock;
   }
   
-  private void getMasterLock(final String zMasterLoc) throws KeeperException, InterruptedException
{
-    log.info("trying to get master lock");
-    LockWatcher masterLockWatcher = new ZooLock.LockWatcher() {
-      @Override
-      public void lostLock(LockLossReason reason) {
-        Halt.halt("Master lock in zookeeper lost (reason = " + reason + "), exiting!", -1);
+  private static class MasterLockWatcher implements ZooLock.AsyncLockWatcher {
+    
+    boolean acquiredLock = false;
+    boolean failedToAcquireLock = false;
+    
+    @Override
+    public void lostLock(LockLossReason reason) {
+      Halt.halt("Master lock in zookeeper lost (reason = " + reason + "), exiting!", -1);
+    }
+    
+    @Override
+    public void unableToMonitorLockNode(final Throwable e) {
+      Halt.halt(-1, new Runnable() {
+        @Override
+        public void run() {
+          log.fatal("No longer able to monitor master lock node", e);
+        }
+      });
+      
+    }
+    
+    @Override
+    public synchronized void acquiredLock() {
+      
+      if (acquiredLock || failedToAcquireLock) {
+        Halt.halt("Zoolock in unexpected state AL " + acquiredLock + " " + failedToAcquireLock,
-1);
       }
+
+      acquiredLock = true;
+      notifyAll();
+    }
+    
+    @Override
+    public synchronized void failedToAcquireLock(Exception e) {
+      log.warn("Failed to get master lock " + e);
       
-      @Override
-      public void unableToMonitorLockNode(final Throwable e) {
-        Halt.halt(-1, new Runnable() {
-          @Override
-          public void run() {
-            log.fatal("No longer able to monitor master lock node", e);
-          }
-        });
-        
+      if (acquiredLock) {
+        Halt.halt("Zoolock in unexpected state FAL " + acquiredLock + " " + failedToAcquireLock,
-1);
+      }
+
+      failedToAcquireLock = true;
+      notifyAll();
+    }
+    
+    public synchronized void waitForChange() {
+      while (!acquiredLock && !failedToAcquireLock) {
+        try {
+          wait();
+        } catch (InterruptedException e) {}
       }
-    };
-    long current = System.currentTimeMillis();
-    final long waitTime = getSystemConfiguration().getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT);
+    }
+  }
+
+  private void getMasterLock(final String zMasterLoc) throws KeeperException, InterruptedException
{
+    log.info("trying to get master lock");
+
     final String masterClientAddress = org.apache.accumulo.core.util.AddressUtil.toString(new
InetSocketAddress(hostname, getSystemConfiguration().getPort(
         Property.MASTER_CLIENTPORT)));
     
-    boolean locked = false;
-    while (System.currentTimeMillis() - current < waitTime) {
+    while (true) {
+      
+      MasterLockWatcher masterLockWatcher = new MasterLockWatcher();
       masterLock = new ZooLock(zMasterLoc);
-      if (masterLock.tryLock(masterLockWatcher, masterClientAddress.getBytes())) {
-        locked = true;
+      masterLock.lockAsync(masterLockWatcher, masterClientAddress.getBytes());
+
+      masterLockWatcher.waitForChange();
+      
+      if (masterLockWatcher.acquiredLock) {
         break;
       }
-      UtilWaitThread.sleep(TIME_TO_WAIT_BETWEEN_LOCK_CHECKS);
-    }
-    if (!locked) {
-      log.info("Failed to get master lock, even after waiting for session timeout, becoming
back-up server");
-      while (true) {
-        masterLock = new ZooLock(zMasterLoc);
-        if (masterLock.tryLock(masterLockWatcher, masterClientAddress.getBytes())) {
-          break;
-        }
-        UtilWaitThread.sleep(TIME_TO_WAIT_BETWEEN_LOCK_CHECKS);
+      
+      if (!masterLockWatcher.failedToAcquireLock) {
+        throw new IllegalStateException("master lock in unknown state");
       }
+
+      masterLock.tryToCancelAsyncLockOrUnlock();
+
+      UtilWaitThread.sleep(TIME_TO_WAIT_BETWEEN_LOCK_CHECKS);
     }
+
     setMasterState(MasterState.HAVE_LOCK);
   }
   

Propchange: accumulo/trunk/src/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/src:r1459586-1459746,1459748-1459751,1459753-1459764,1459766-1459787,1459789-1459792,1459794-1459825,1459827-1459990



Mime
View raw message