hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhang...@apache.org
Subject [1/2] hbase git commit: HBASE-20846 Restore procedure locks when master restarts
Date Wed, 25 Jul 2018 06:43:04 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-2 ca558bc85 -> 0b283dae0


http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/RootProcedureState.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/RootProcedureState.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/RootProcedureState.java
index 46185ea..2fc0030 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/RootProcedureState.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/RootProcedureState.java
@@ -22,11 +22,9 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
 import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState;
 
 /**
@@ -42,8 +40,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.Procedu
  */
 @InterfaceAudience.Private
 @InterfaceStability.Evolving
-class RootProcedureState {
-  private static final Logger LOG = LoggerFactory.getLogger(RootProcedureState.class);
+class RootProcedureState<TEnvironment> {
 
   private enum State {
     RUNNING,         // The Procedure is running or ready to run
@@ -51,8 +48,8 @@ class RootProcedureState {
     ROLLINGBACK,     // The Procedure failed and the execution was rolledback
   }
 
-  private Set<Procedure> subprocs = null;
-  private ArrayList<Procedure> subprocStack = null;
+  private Set<Procedure<TEnvironment>> subprocs = null;
+  private ArrayList<Procedure<TEnvironment>> subprocStack = null;
   private State state = State.RUNNING;
   private int running = 0;
 
@@ -91,22 +88,19 @@ class RootProcedureState {
   }
 
   protected synchronized long[] getSubprocedureIds() {
-    if (subprocs == null) return null;
-    int index = 0;
-    final long[] subIds = new long[subprocs.size()];
-    for (Procedure proc: subprocs) {
-      subIds[index++] = proc.getProcId();
+    if (subprocs == null) {
+      return null;
     }
-    return subIds;
+    return subprocs.stream().mapToLong(Procedure::getProcId).toArray();
   }
 
-  protected synchronized List<Procedure> getSubproceduresStack() {
+  protected synchronized List<Procedure<TEnvironment>> getSubproceduresStack() {
     return subprocStack;
   }
 
   protected synchronized RemoteProcedureException getException() {
     if (subprocStack != null) {
-      for (Procedure proc: subprocStack) {
+      for (Procedure<TEnvironment> proc: subprocStack) {
         if (proc.hasException()) {
           return proc.getException();
         }
@@ -118,8 +112,10 @@ class RootProcedureState {
   /**
    * Called by the ProcedureExecutor to mark the procedure step as running.
    */
-  protected synchronized boolean acquire(final Procedure proc) {
-    if (state != State.RUNNING) return false;
+  protected synchronized boolean acquire(Procedure<TEnvironment> proc) {
+    if (state != State.RUNNING) {
+      return false;
+    }
 
     running++;
     return true;
@@ -128,7 +124,7 @@ class RootProcedureState {
   /**
    * Called by the ProcedureExecutor to mark the procedure step as finished.
    */
-  protected synchronized void release(final Procedure proc) {
+  protected synchronized void release(Procedure<TEnvironment> proc) {
     running--;
   }
 
@@ -142,7 +138,7 @@ class RootProcedureState {
    * Called by the ProcedureExecutor after the procedure step is completed,
    * to add the step to the rollback list (or procedure stack)
    */
-  protected synchronized void addRollbackStep(final Procedure proc) {
+  protected synchronized void addRollbackStep(Procedure<TEnvironment> proc) {
     if (proc.isFailed()) {
       state = State.FAILED;
     }
@@ -153,8 +149,10 @@ class RootProcedureState {
     subprocStack.add(proc);
   }
 
-  protected synchronized void addSubProcedure(final Procedure proc) {
-    if (!proc.hasParent()) return;
+  protected synchronized void addSubProcedure(Procedure<TEnvironment> proc) {
+    if (!proc.hasParent()) {
+      return;
+    }
     if (subprocs == null) {
       subprocs = new HashSet<>();
     }
@@ -168,7 +166,7 @@ class RootProcedureState {
    * to the store only the Procedure we executed, and nothing else.
    * on load we recreate the full stack by aggregating each procedure stack-positions.
    */
-  protected synchronized void loadStack(final Procedure proc) {
+  protected synchronized void loadStack(Procedure<TEnvironment> proc) {
     addSubProcedure(proc);
     int[] stackIndexes = proc.getStackIndexes();
     if (stackIndexes != null) {
@@ -196,7 +194,7 @@ class RootProcedureState {
    */
   protected synchronized boolean isValid() {
     if (subprocStack != null) {
-      for (Procedure proc: subprocStack) {
+      for (Procedure<TEnvironment> proc : subprocStack) {
         if (proc == null) {
           return false;
         }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/TimeoutExecutorThread.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/TimeoutExecutorThread.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/TimeoutExecutorThread.java
index e5e3230..9e050a2 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/TimeoutExecutorThread.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/TimeoutExecutorThread.java
@@ -31,15 +31,15 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.Procedu
  * @see InlineChore
  */
 @InterfaceAudience.Private
-class TimeoutExecutorThread extends StoppableThread {
+class TimeoutExecutorThread<TEnvironment> extends StoppableThread {
 
   private static final Logger LOG = LoggerFactory.getLogger(TimeoutExecutorThread.class);
 
-  private final ProcedureExecutor<?> executor;
+  private final ProcedureExecutor<TEnvironment> executor;
 
   private final DelayQueue<DelayedWithTimeout> queue = new DelayQueue<>();
 
-  public TimeoutExecutorThread(ProcedureExecutor<?> executor, ThreadGroup group) {
+  public TimeoutExecutorThread(ProcedureExecutor<TEnvironment> executor, ThreadGroup group) {
     super(group, "ProcExecTimeout");
     setDaemon(true);
     this.executor = executor;
@@ -65,7 +65,7 @@ class TimeoutExecutorThread extends StoppableThread {
       if (task instanceof InlineChore) {
         execInlineChore((InlineChore) task);
       } else if (task instanceof DelayedProcedure) {
-        execDelayedProcedure((DelayedProcedure) task);
+        execDelayedProcedure((DelayedProcedure<TEnvironment>) task);
       } else {
         LOG.error("CODE-BUG unknown timeout task type {}", task);
       }
@@ -77,15 +77,15 @@ class TimeoutExecutorThread extends StoppableThread {
     queue.add(chore);
   }
 
-  public void add(Procedure<?> procedure) {
+  public void add(Procedure<TEnvironment> procedure) {
     assert procedure.getState() == ProcedureState.WAITING_TIMEOUT;
     LOG.info("ADDED {}; timeout={}, timestamp={}", procedure, procedure.getTimeout(),
       procedure.getTimeoutTimestamp());
-    queue.add(new DelayedProcedure(procedure));
+    queue.add(new DelayedProcedure<>(procedure));
   }
 
-  public boolean remove(Procedure<?> procedure) {
-    return queue.remove(new DelayedProcedure(procedure));
+  public boolean remove(Procedure<TEnvironment> procedure) {
+    return queue.remove(new DelayedProcedure<>(procedure));
   }
 
   private void execInlineChore(InlineChore chore) {
@@ -93,13 +93,13 @@ class TimeoutExecutorThread extends StoppableThread {
     add(chore);
   }
 
-  private void execDelayedProcedure(DelayedProcedure delayed) {
+  private void execDelayedProcedure(DelayedProcedure<TEnvironment> delayed) {
     // TODO: treat this as a normal procedure, add it to the scheduler and
     // let one of the workers handle it.
     // Today we consider ProcedureInMemoryChore as InlineChores
-    Procedure<?> procedure = delayed.getObject();
+    Procedure<TEnvironment> procedure = delayed.getObject();
     if (procedure instanceof ProcedureInMemoryChore) {
-      executeInMemoryChore((ProcedureInMemoryChore) procedure);
+      executeInMemoryChore((ProcedureInMemoryChore<TEnvironment>) procedure);
       // if the procedure is in a waiting state again, put it back in the queue
       procedure.updateTimestamp();
       if (procedure.isWaiting()) {
@@ -111,7 +111,7 @@ class TimeoutExecutorThread extends StoppableThread {
     }
   }
 
-  private void executeInMemoryChore(ProcedureInMemoryChore chore) {
+  private void executeInMemoryChore(ProcedureInMemoryChore<TEnvironment> chore) {
     if (!chore.isWaiting()) {
       return;
     }
@@ -126,12 +126,12 @@ class TimeoutExecutorThread extends StoppableThread {
     }
   }
 
-  private void executeTimedoutProcedure(Procedure proc) {
+  private void executeTimedoutProcedure(Procedure<TEnvironment> proc) {
     // The procedure received a timeout. if the procedure itself does not handle it,
     // call abort() and add the procedure back in the queue for rollback.
     if (proc.setTimeoutFailure(executor.getEnvironment())) {
       long rootProcId = executor.getRootProcedureId(proc);
-      RootProcedureState procStack = executor.getProcStack(rootProcId);
+      RootProcedureState<TEnvironment> procStack = executor.getProcStack(rootProcId);
       procStack.abort();
       executor.getStore().update(proc);
       executor.getScheduler().addFront(proc);

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureReplayOrder.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureReplayOrder.java b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureReplayOrder.java
index 319ddb2..2bbd53d 100644
--- a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureReplayOrder.java
+++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureReplayOrder.java
@@ -35,6 +35,7 @@ import org.apache.hadoop.hbase.testclassification.MasterTests;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.slf4j.Logger;
@@ -42,7 +43,12 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.hbase.thirdparty.com.google.protobuf.Int64Value;
 
-@Category({MasterTests.class, LargeTests.class})
+/**
+ * For now we do not guarantee this, we will restore the locks when restarting ProcedureExecutor so
+ * we should use lock to obtain the correct order. Ignored.
+ */
+@Ignore
+@Category({ MasterTests.class, LargeTests.class })
 public class TestProcedureReplayOrder {
 
   @ClassRule

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureSuspended.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureSuspended.java b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureSuspended.java
index a9e919c..c1c9187 100644
--- a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureSuspended.java
+++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureSuspended.java
@@ -227,7 +227,6 @@ public class TestProcedureSuspended {
     protected void releaseLock(final TestProcEnv env) {
       LOG.info("RELEASE LOCK " + this + " " + hasLock);
       lock.set(false);
-      hasLock = false;
     }
 
     @Override
@@ -235,11 +234,6 @@ public class TestProcedureSuspended {
       return true;
     }
 
-    @Override
-    protected boolean hasLock(final TestProcEnv env) {
-      return hasLock;
-    }
-
     public ArrayList<Long> getTimestamps() {
       return timestamps;
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-protocol-shaded/src/main/protobuf/Procedure.proto
----------------------------------------------------------------------
diff --git a/hbase-protocol-shaded/src/main/protobuf/Procedure.proto b/hbase-protocol-shaded/src/main/protobuf/Procedure.proto
index 2c5f1aa..b4a3107 100644
--- a/hbase-protocol-shaded/src/main/protobuf/Procedure.proto
+++ b/hbase-protocol-shaded/src/main/protobuf/Procedure.proto
@@ -63,6 +63,9 @@ message Procedure {
   // Nonce to prevent same procedure submit by multiple times
   optional uint64 nonce_group = 13 [default = 0];
   optional uint64 nonce = 14 [default = 0];
+
+  // whether the procedure has held the lock
+  optional bool locked = 16 [default = false];
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java
index 7ad5b56..5af7614 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java
@@ -81,8 +81,8 @@ class ClusterSchemaServiceImpl extends AbstractService implements ClusterSchemaS
     return this.tableNamespaceManager;
   }
 
-  private long submitProcedure(final Procedure<?> procedure, final NonceKey nonceKey)
-      throws ServiceNotRunningException {
+  private long submitProcedure(final Procedure<MasterProcedureEnv> procedure,
+      final NonceKey nonceKey) throws ServiceNotRunningException {
     checkIsRunning();
     ProcedureExecutor<MasterProcedureEnv> pe = this.masterServices.getMasterProcedureExecutor();
     return pe.submitProcedure(procedure, nonceKey);

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index b430efb..aaf6347 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -910,7 +910,7 @@ public class HMaster extends HRegionServer implements MasterServices {
     InitMetaProcedure initMetaProc = null;
     if (assignmentManager.getRegionStates().getRegionState(RegionInfoBuilder.FIRST_META_REGIONINFO)
       .isOffline()) {
-      Optional<Procedure<?>> optProc = procedureExecutor.getProcedures().stream()
+      Optional<Procedure<MasterProcedureEnv>> optProc = procedureExecutor.getProcedures().stream()
         .filter(p -> p instanceof InitMetaProcedure).findAny();
       if (optProc.isPresent()) {
         initMetaProc = (InitMetaProcedure) optProc.get();
@@ -3188,7 +3188,8 @@ public class HMaster extends HRegionServer implements MasterServices {
       cpHost.preGetProcedures();
     }
 
-    final List<Procedure<?>> procList = this.procedureExecutor.getProcedures();
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    List<Procedure<?>> procList = (List) this.procedureExecutor.getProcedures();
 
     if (cpHost != null) {
       cpHost.postGetProcedures(procList);
@@ -3693,7 +3694,7 @@ public class HMaster extends HRegionServer implements MasterServices {
     HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> replicationLoadSourceMap =
         new HashMap<>(peerList.size());
     peerList.stream()
-        .forEach(peer -> replicationLoadSourceMap.put(peer.getPeerId(), new ArrayList()));
+        .forEach(peer -> replicationLoadSourceMap.put(peer.getPeerId(), new ArrayList<>()));
     for (ServerName serverName : serverNames) {
       List<ReplicationLoadSource> replicationLoadSources =
           getServerManager().getLoad(serverName).getReplicationLoadSourceList();

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/GCRegionProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/GCRegionProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/GCRegionProcedure.java
index bbb27e1..0b6e45b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/GCRegionProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/GCRegionProcedure.java
@@ -148,9 +148,4 @@ public class GCRegionProcedure extends AbstractStateMachineRegionProcedure<GCReg
         serializer.deserialize(MasterProcedureProtos.GCRegionStateData.class);
     setRegion(ProtobufUtil.toRegionInfo(msg.getRegionInfo()));
   }
-
-  @Override
-  protected org.apache.hadoop.hbase.procedure2.Procedure.LockState acquireLock(MasterProcedureEnv env) {
-    return super.acquireLock(env);
-  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/MergeTableRegionsProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/MergeTableRegionsProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/MergeTableRegionsProcedure.java
index f45cd5d..580b9a9 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/MergeTableRegionsProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/MergeTableRegionsProcedure.java
@@ -82,7 +82,6 @@ public class MergeTableRegionsProcedure
     extends AbstractStateMachineTableProcedure<MergeTableRegionsState> {
   private static final Logger LOG = LoggerFactory.getLogger(MergeTableRegionsProcedure.class);
   private Boolean traceEnabled;
-  private volatile boolean lock = false;
   private ServerName regionLocation;
   private RegionInfo[] regionsToMerge;
   private RegionInfo mergedRegion;
@@ -420,24 +419,20 @@ public class MergeTableRegionsProcedure
 
   @Override
   protected LockState acquireLock(final MasterProcedureEnv env) {
-    if (env.waitInitialized(this)) return LockState.LOCK_EVENT_WAIT;
     if (env.getProcedureScheduler().waitRegions(this, getTableName(),
         mergedRegion, regionsToMerge[0], regionsToMerge[1])) {
       try {
         LOG.debug(LockState.LOCK_EVENT_WAIT + " " + env.getProcedureScheduler().dumpLocks());
       } catch (IOException e) {
-        // TODO Auto-generated catch block
-        e.printStackTrace();
+        // Ignore, just for logging
       }
       return LockState.LOCK_EVENT_WAIT;
     }
-    this.lock = true;
     return LockState.LOCK_ACQUIRED;
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    this.lock = false;
     env.getProcedureScheduler().wakeRegions(this, getTableName(),
       mergedRegion, regionsToMerge[0], regionsToMerge[1]);
   }
@@ -448,11 +443,6 @@ public class MergeTableRegionsProcedure
   }
 
   @Override
-  protected boolean hasLock(MasterProcedureEnv env) {
-    return this.lock;
-  }
-
-  @Override
   public TableName getTableName() {
     return mergedRegion.getTable();
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionTransitionProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionTransitionProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionTransitionProcedure.java
index c3b2458..4054778 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionTransitionProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionTransitionProcedure.java
@@ -34,14 +34,16 @@ import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
 import org.apache.hadoop.hbase.procedure2.RemoteProcedureDispatcher.RemoteOperation;
 import org.apache.hadoop.hbase.procedure2.RemoteProcedureDispatcher.RemoteProcedure;
 import org.apache.hadoop.hbase.procedure2.RemoteProcedureException;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionState;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
-import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
+
+import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionState;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
+
 /**
  * Base class for the Assign and Unassign Procedure.
  *
@@ -114,8 +116,6 @@ public abstract class RegionTransitionProcedure
    */
   private int attempt;
 
-  private volatile boolean lock = false;
-
   // Required by the Procedure framework to create the procedure on replay
   public RegionTransitionProcedure() {}
 
@@ -419,15 +419,17 @@ public abstract class RegionTransitionProcedure
   }
 
   @Override
-  protected LockState acquireLock(final MasterProcedureEnv env) {
+  protected boolean waitInitialized(MasterProcedureEnv env) {
     // Unless we are assigning meta, wait for meta to be available and loaded.
-    if (!isMeta()) {
-      AssignmentManager am = env.getAssignmentManager();
-      if (am.waitMetaLoaded(this) || am.waitMetaAssigned(this, regionInfo)) {
-        return LockState.LOCK_EVENT_WAIT;
-      }
+    if (isMeta()) {
+      return false;
     }
+    AssignmentManager am = env.getAssignmentManager();
+    return am.waitMetaLoaded(this) || am.waitMetaAssigned(this, regionInfo);
+  }
 
+  @Override
+  protected LockState acquireLock(final MasterProcedureEnv env) {
     // TODO: Revisit this and move it to the executor
     if (env.getProcedureScheduler().waitRegion(this, getRegionInfo())) {
       try {
@@ -438,14 +440,12 @@ public abstract class RegionTransitionProcedure
       }
       return LockState.LOCK_EVENT_WAIT;
     }
-    this.lock = true;
     return LockState.LOCK_ACQUIRED;
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
     env.getProcedureScheduler().wakeRegion(this, getRegionInfo());
-    lock = false;
   }
 
   @Override
@@ -454,11 +454,6 @@ public abstract class RegionTransitionProcedure
   }
 
   @Override
-  protected boolean hasLock(final MasterProcedureEnv env) {
-    return lock;
-  }
-
-  @Override
   protected boolean shouldWaitClientAck(MasterProcedureEnv env) {
     // The operation is triggered internally on the server
     // the client does not know about this procedure.

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/locking/LockProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/locking/LockProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/locking/LockProcedure.java
index b4c55f4..3a87bbc 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/locking/LockProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/locking/LockProcedure.java
@@ -76,8 +76,6 @@ public final class LockProcedure extends Procedure<MasterProcedureEnv>
   private String description;
   // True when recovery of master lock from WALs
   private boolean recoveredMasterLock;
-  // this is for internal working
-  private boolean hasLock;
 
   private final ProcedureEvent<LockProcedure> event = new ProcedureEvent<>(this);
   // True if this proc acquired relevant locks. This value is for client checks.
@@ -306,7 +304,6 @@ public final class LockProcedure extends Procedure<MasterProcedureEnv>
   protected LockState acquireLock(final MasterProcedureEnv env) {
     boolean ret = lock.acquireLock(env);
     locked.set(ret);
-    hasLock = ret;
     if (ret) {
       if (LOG.isDebugEnabled()) {
         LOG.debug("LOCKED " + toString());
@@ -321,7 +318,6 @@ public final class LockProcedure extends Procedure<MasterProcedureEnv>
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
     lock.releaseLock(env);
-    hasLock = false;
   }
 
   /**
@@ -423,11 +419,6 @@ public final class LockProcedure extends Procedure<MasterProcedureEnv>
     return true;
   }
 
-  @Override
-  public boolean hasLock(final MasterProcedureEnv env) {
-    return hasLock;
-  }
-
   ///////////////////////
   // LOCK IMPLEMENTATIONS
   ///////////////////////

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineNamespaceProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineNamespaceProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineNamespaceProcedure.java
index 574706a..341d116 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineNamespaceProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineNamespaceProcedure.java
@@ -66,8 +66,12 @@ public abstract class AbstractStateMachineNamespaceProcedure<TState>
   }
 
   @Override
+  protected boolean waitInitialized(MasterProcedureEnv env) {
+    return env.waitInitialized(this);
+  }
+
+  @Override
   protected LockState acquireLock(final MasterProcedureEnv env) {
-    if (env.waitInitialized(this)) return LockState.LOCK_EVENT_WAIT;
     if (env.getProcedureScheduler().waitNamespaceExclusiveLock(this, getNamespaceName())) {
       return LockState.LOCK_EVENT_WAIT;
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java
index e711ca0..3b5e3b5 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java
@@ -39,7 +39,6 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
 public abstract class AbstractStateMachineRegionProcedure<TState>
     extends AbstractStateMachineTableProcedure<TState> {
   private RegionInfo hri;
-  private volatile boolean lock = false;
 
   public AbstractStateMachineRegionProcedure(final MasterProcedureEnv env,
       final RegionInfo hri) {
@@ -100,25 +99,17 @@ public abstract class AbstractStateMachineRegionProcedure<TState>
 
   @Override
   protected LockState acquireLock(final MasterProcedureEnv env) {
-    if (env.waitInitialized(this)) return LockState.LOCK_EVENT_WAIT;
     if (env.getProcedureScheduler().waitRegions(this, getTableName(), getRegion())) {
       return LockState.LOCK_EVENT_WAIT;
     }
-    this.lock = true;
     return LockState.LOCK_ACQUIRED;
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    this.lock = false;
     env.getProcedureScheduler().wakeRegions(this, getTableName(), getRegion());
   }
 
-  @Override
-  protected boolean hasLock(final MasterProcedureEnv env) {
-    return this.lock;
-  }
-
   protected void setFailure(Throwable cause) {
     super.setFailure(getClass().getSimpleName(), cause);
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java
index 1af2445..50a0149 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java
@@ -89,10 +89,12 @@ public abstract class AbstractStateMachineTableProcedure<TState>
   }
 
   @Override
+  protected boolean waitInitialized(MasterProcedureEnv env) {
+    return env.waitInitialized(this);
+  }
+
+  @Override
   protected LockState acquireLock(final MasterProcedureEnv env) {
-    if (env.waitInitialized(this)) {
-      return LockState.LOCK_EVENT_WAIT;
-    }
     if (env.getProcedureScheduler().waitTableExclusiveLock(this, getTableName())) {
       return LockState.LOCK_EVENT_WAIT;
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java
index c63f420..2f56e83 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java
@@ -131,7 +131,7 @@ public class CreateNamespaceProcedure
 
   @Override
   protected CreateNamespaceState getState(final int stateId) {
-    return CreateNamespaceState.valueOf(stateId);
+    return CreateNamespaceState.forNumber(stateId);
   }
 
   @Override
@@ -171,15 +171,18 @@ public class CreateNamespaceProcedure
   }
 
   @Override
-  protected LockState acquireLock(final MasterProcedureEnv env) {
-    if (!env.getMasterServices().isInitialized()) {
-      // Namespace manager might not be ready if master is not fully initialized,
-      // return false to reject user namespace creation; return true for default
-      // and system namespace creation (this is part of master initialization).
-      if (!isBootstrapNamespace() && env.waitInitialized(this)) {
-        return LockState.LOCK_EVENT_WAIT;
-      }
+  protected boolean waitInitialized(MasterProcedureEnv env) {
+    // Namespace manager might not be ready if master is not fully initialized,
+    // return false to reject user namespace creation; return true for default
+    // and system namespace creation (this is part of master initialization).
+    if (isBootstrapNamespace()) {
+      return false;
     }
+    return env.waitInitialized(this);
+  }
+
+  @Override
+  protected LockState acquireLock(final MasterProcedureEnv env) {
     if (env.getProcedureScheduler().waitNamespaceExclusiveLock(this, getNamespaceName())) {
       return LockState.LOCK_EVENT_WAIT;
     }
@@ -263,20 +266,6 @@ public class CreateNamespaceProcedure
     }
   }
 
-  /**
-   * remove quota for the namespace if exists
-   * @param env MasterProcedureEnv
-   * @throws IOException
-   **/
-  private void rollbackSetNamespaceQuota(final MasterProcedureEnv env) throws IOException {
-    try {
-      DeleteNamespaceProcedure.removeNamespaceQuota(env, nsDescriptor.getName());
-    } catch (Exception e) {
-      // Ignore exception
-      LOG.debug("Rollback of setNamespaceQuota throws exception: " + e);
-    }
-  }
-
   private static TableNamespaceManager getTableNamespaceManager(final MasterProcedureEnv env) {
     return env.getMasterServices().getClusterSchema().getTableNamespaceManager();
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
index acee1af..faad3dd 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
@@ -220,10 +220,16 @@ public class CreateTableProcedure
   }
 
   @Override
-  protected LockState acquireLock(final MasterProcedureEnv env) {
-    if (!getTableName().isSystemTable() && env.waitInitialized(this)) {
-      return LockState.LOCK_EVENT_WAIT;
+  protected boolean waitInitialized(MasterProcedureEnv env) {
+    if (getTableName().isSystemTable()) {
+      // Creating system table is part of the initialization, so do not wait here.
+      return false;
     }
+    return super.waitInitialized(env);
+  }
+
+  @Override
+  protected LockState acquireLock(final MasterProcedureEnv env) {
     if (env.getProcedureScheduler().waitTableExclusiveLock(this, getTableName())) {
       return LockState.LOCK_EVENT_WAIT;
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/InitMetaProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/InitMetaProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/InitMetaProcedure.java
index 4736d65..d984632 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/InitMetaProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/InitMetaProcedure.java
@@ -63,8 +63,13 @@ public class InitMetaProcedure extends AbstractStateMachineTableProcedure<InitMe
   }
 
   @Override
-  protected LockState acquireLock(MasterProcedureEnv env) {
+  protected boolean waitInitialized(MasterProcedureEnv env) {
     // we do not need to wait for master initialized, we are part of the initialization.
+    return false;
+  }
+
+  @Override
+  protected LockState acquireLock(MasterProcedureEnv env) {
     if (env.getProcedureScheduler().waitTableExclusiveLock(this, getTableName())) {
       return LockState.LOCK_EVENT_WAIT;
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureScheduler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureScheduler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureScheduler.java
index 096979b..12b4267 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureScheduler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureScheduler.java
@@ -144,21 +144,13 @@ public class MasterProcedureScheduler extends AbstractProcedureScheduler {
 
   private <T extends Comparable<T>> void doAdd(final FairQueue<T> fairq,
       final Queue<T> queue, final Procedure<?> proc, final boolean addFront) {
-    if (!queue.getLockStatus().hasExclusiveLock() ||
-      queue.getLockStatus().isLockOwner(proc.getProcId())) {
-      // if the queue was not remove for an xlock execution
-      // or the proc is the lock owner, put the queue back into execution
+    if (!queue.getLockStatus().hasExclusiveLock()) {
+      // if the queue was not remove for an xlock execution,put the queue back into execution
       queue.add(proc, addFront);
       addToRunQueue(fairq, queue);
-    } else if (queue.getLockStatus().hasParentLock(proc)) {
-      // always add it to front as its parent has the xlock
-      // usually the addFront is true if we arrive here as we will call addFront for adding sub
-      // proc, but sometimes we may retry on the proc which means we will arrive here through yield,
-      // so it is possible the addFront here is false.
+    } else if (queue.getLockStatus().hasLockAccess(proc)) {
+      // always add it to front as the have the lock access.
       queue.add(proc, true);
-      // our (proc) parent has the xlock,
-      // so the queue is not in the fairq (run-queue)
-      // add it back to let the child run (inherit the lock)
       addToRunQueue(fairq, queue);
     } else {
       queue.add(proc, addFront);
@@ -386,9 +378,6 @@ public class MasterProcedureScheduler extends AbstractProcedureScheduler {
     if (proc != null) {
       priority = MasterProcedureUtil.getServerPriority(proc);
     } else {
-      LOG.warn("Usually this should not happen as proc can only be null when calling from " +
-        "wait/wake lock, which means at least we should have one procedure in the queue which " +
-        "wants to acquire the lock or just released the lock.");
       priority = 1;
     }
     node = new ServerQueue(serverName, priority, locking.getServerLock(serverName));
@@ -848,9 +837,12 @@ public class MasterProcedureScheduler extends AbstractProcedureScheduler {
     try {
       final LockAndQueue lock = locking.getServerLock(serverName);
       if (lock.tryExclusiveLock(procedure)) {
-        // We do not need to create a new queue so just pass null, as in tests we may pass
-        // procedures other than ServerProcedureInterface
-        removeFromRunQueue(serverRunQueue, getServerQueue(serverName, null));
+        // In tests we may pass procedures other than ServerProcedureInterface, just pass null if
+        // so.
+        removeFromRunQueue(serverRunQueue,
+          getServerQueue(serverName,
+            procedure instanceof ServerProcedureInterface ? (ServerProcedureInterface) procedure
+              : null));
         return false;
       }
       waitProcedure(lock, procedure);
@@ -873,9 +865,12 @@ public class MasterProcedureScheduler extends AbstractProcedureScheduler {
       final LockAndQueue lock = locking.getServerLock(serverName);
       // Only SCP will acquire/release server lock so do not need to check the return value here.
       lock.releaseExclusiveLock(procedure);
-      // We do not need to create a new queue so just pass null, as in tests we may pass procedures
-      // other than ServerProcedureInterface
-      addToRunQueue(serverRunQueue, getServerQueue(serverName, null));
+      // In tests we may pass procedures other than ServerProcedureInterface, just pass null if
+      // so.
+      addToRunQueue(serverRunQueue,
+        getServerQueue(serverName,
+          procedure instanceof ServerProcedureInterface ? (ServerProcedureInterface) procedure
+            : null));
       int waitingCount = wakeWaitingProcedures(lock);
       wakePollIfNeeded(waitingCount);
     } finally {

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureUtil.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureUtil.java
index 587cc82..58263d3 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureUtil.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureUtil.java
@@ -99,7 +99,7 @@ public final class MasterProcedureUtil {
     protected abstract void run() throws IOException;
     protected abstract String getDescription();
 
-    protected long submitProcedure(final Procedure<?> proc) {
+    protected long submitProcedure(final Procedure<MasterProcedureEnv> proc) {
       assert procId == null : "submitProcedure() was already called, running procId=" + procId;
       procId = getProcedureExecutor().submitProcedure(proc, nonceKey);
       return procId;

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/PeerQueue.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/PeerQueue.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/PeerQueue.java
index 0e58e08..9178233 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/PeerQueue.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/PeerQueue.java
@@ -30,20 +30,6 @@ class PeerQueue extends Queue<String> {
   }
 
   @Override
-  public boolean isAvailable() {
-    if (isEmpty()) {
-      return false;
-    }
-    if (getLockStatus().hasExclusiveLock()) {
-      // if we have an exclusive lock already taken
-      // only child of the lock owner can be executed
-      Procedure<?> nextProc = peek();
-      return nextProc != null && getLockStatus().hasLockAccess(nextProc);
-    }
-    return true;
-  }
-
-  @Override
   public boolean requireExclusiveLock(Procedure<?> proc) {
     return requirePeerExclusiveLock((PeerProcedureInterface) proc);
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ProcedureSyncWait.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ProcedureSyncWait.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ProcedureSyncWait.java
index df0875e..328ac00 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ProcedureSyncWait.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ProcedureSyncWait.java
@@ -106,7 +106,7 @@ public final class ProcedureSyncWait {
     }
 
   public static Future<byte[]> submitProcedure(final ProcedureExecutor<MasterProcedureEnv> procExec,
-      final Procedure<?> proc) {
+      final Procedure<MasterProcedureEnv> proc) {
     if (proc.isInitializing()) {
       procExec.submitProcedure(proc);
     }
@@ -114,7 +114,7 @@ public final class ProcedureSyncWait {
   }
 
   public static byte[] submitAndWaitProcedure(ProcedureExecutor<MasterProcedureEnv> procExec,
-      final Procedure<?> proc) throws IOException {
+      final Procedure<MasterProcedureEnv> proc) throws IOException {
     if (proc.isInitializing()) {
       procExec.submitProcedure(proc);
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/Queue.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/Queue.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/Queue.java
index f7bea2a..43e66d0 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/Queue.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/Queue.java
@@ -63,7 +63,18 @@ abstract class Queue<TKey extends Comparable<TKey>> extends AvlLinkedNode<Queue<
   // This should go away when we have the new AM and its events
   // and we move xlock to the lock-event-queue.
   public boolean isAvailable() {
-    return !lockStatus.hasExclusiveLock() && !isEmpty();
+    if (isEmpty()) {
+      return false;
+    }
+    if (getLockStatus().hasExclusiveLock()) {
+      // If we have an exclusive lock already taken, only child of the lock owner can be executed
+      // And now we will restore locks when master restarts, so it is possible that the procedure
+      // which is holding the lock is also in the queue, so we need to use hasLockAccess here
+      // instead of hasParentLock
+      Procedure<?> nextProc = peek();
+      return nextProc != null && getLockStatus().hasLockAccess(nextProc);
+    }
+    return true;
   }
 
   // ======================================================================

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
index 0ad8a63..8718cb8 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
@@ -36,8 +36,6 @@ public abstract class AbstractPeerProcedure<TState>
 
   protected String peerId;
 
-  private volatile boolean locked;
-
   // used to keep compatible with old client where we can only returns after updateStorage.
   protected ProcedurePrepareLatch latch;
 
@@ -59,17 +57,20 @@ public abstract class AbstractPeerProcedure<TState>
   }
 
   @Override
+  protected boolean waitInitialized(MasterProcedureEnv env) {
+    return env.waitInitialized(this);
+  }
+
+  @Override
   protected LockState acquireLock(MasterProcedureEnv env) {
     if (env.getProcedureScheduler().waitPeerExclusiveLock(this, peerId)) {
       return LockState.LOCK_EVENT_WAIT;
     }
-    locked = true;
     return LockState.LOCK_ACQUIRED;
   }
 
   @Override
   protected void releaseLock(MasterProcedureEnv env) {
-    locked = false;
     env.getProcedureScheduler().wakePeerExclusiveLock(this, peerId);
   }
 
@@ -79,11 +80,6 @@ public abstract class AbstractPeerProcedure<TState>
   }
 
   @Override
-  protected boolean hasLock(MasterProcedureEnv env) {
-    return locked;
-  }
-
-  @Override
   protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
     super.serializeStateData(serializer);
     serializer.serialize(PeerProcedureStateData.newBuilder().setPeerId(peerId).build());

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp b/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp
index 4e546cd..f617237 100644
--- a/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp
+++ b/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp
@@ -46,7 +46,7 @@
   long millisFromLastRoll = walStore.getMillisFromLastRoll();
   ArrayList<ProcedureWALFile> procedureWALFiles = walStore.getActiveLogs();
   Set<ProcedureWALFile> corruptedWALFiles = walStore.getCorruptedLogs();
-  List<Procedure<?>> procedures = procExecutor.getProcedures();
+  List<Procedure<MasterProcedureEnv>> procedures = procExecutor.getProcedures();
   Collections.sort(procedures, new Comparator<Procedure>() {
     @Override
     public int compare(Procedure lhs, Procedure rhs) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetProcedureResult.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetProcedureResult.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetProcedureResult.java
index 8b1584f..4186594 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetProcedureResult.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetProcedureResult.java
@@ -124,7 +124,7 @@ public class TestGetProcedureResult {
 
   @Test
   public void testRace() throws Exception {
-    ProcedureExecutor<?> executor =
+    ProcedureExecutor<MasterProcedureEnv> executor =
       UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
     DummyProcedure p = new DummyProcedure();
     long procId = executor.submitProcedure(p);

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestAssignmentManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestAssignmentManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestAssignmentManager.java
index 08ecb81..443bbab 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestAssignmentManager.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestAssignmentManager.java
@@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
 import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.master.RegionState.State;
 import org.apache.hadoop.hbase.master.procedure.MasterProcedureConstants;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
 import org.apache.hadoop.hbase.master.procedure.ProcedureSyncWait;
 import org.apache.hadoop.hbase.master.procedure.RSProcedureDispatcher;
 import org.apache.hadoop.hbase.procedure2.Procedure;
@@ -434,7 +435,7 @@ public class TestAssignmentManager {
     am.wakeMetaLoadedEvent();
   }
 
-  private Future<byte[]> submitProcedure(final Procedure<?> proc) {
+  private Future<byte[]> submitProcedure(final Procedure<MasterProcedureEnv> proc) {
     return ProcedureSyncWait.submitProcedure(master.getMasterProcedureExecutor(), proc);
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.java
index 9a0e2f6..a56e842 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.java
@@ -111,7 +111,7 @@ public class TestMasterProcedureEvents {
   }
 
   private void testProcedureEventWaitWake(final HMaster master, final ProcedureEvent<?> event,
-      final Procedure<?> proc) throws Exception {
+      final Procedure<MasterProcedureEnv> proc) throws Exception {
     final ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
     final MasterProcedureScheduler procSched = procExec.getEnvironment().getProcedureScheduler();
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestProcedureAdmin.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestProcedureAdmin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestProcedureAdmin.java
index c003379..02f0257 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestProcedureAdmin.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestProcedureAdmin.java
@@ -207,7 +207,7 @@ public class TestProcedureAdmin {
     // Wait for one step to complete
     ProcedureTestingUtility.waitProcedure(procExec, procId);
 
-    List<Procedure<?>> procedures = procExec.getProcedures();
+    List<Procedure<MasterProcedureEnv>> procedures = procExec.getProcedures();
     assertTrue(procedures.size() >= 1);
     boolean found = false;
     for (Procedure<?> proc: procedures) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java
index 3e21951..1402bbd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor;
 import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
 import org.apache.hadoop.hbase.coprocessor.MasterObserver;
 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
 import org.apache.hadoop.hbase.procedure2.Procedure;
 import org.apache.hadoop.hbase.security.AccessDeniedException;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
@@ -88,7 +89,7 @@ public class TestFailedProcCleanup {
       LOG.debug("Ignoring exception: ", e);
       Thread.sleep(evictionDelay * 3);
     }
-    List<Procedure<?>> procedureInfos =
+    List<Procedure<MasterProcedureEnv>> procedureInfos =
         TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getProcedures();
     for (Procedure procedureInfo : procedureInfos) {
       if (procedureInfo.getProcName().equals("CreateTableProcedure")
@@ -109,7 +110,7 @@ public class TestFailedProcCleanup {
       LOG.debug("Ignoring exception: ", e);
       Thread.sleep(evictionDelay * 3);
     }
-    List<Procedure<?>> procedureInfos =
+    List<Procedure<MasterProcedureEnv>> procedureInfos =
         TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getProcedures();
     for (Procedure procedureInfo : procedureInfos) {
       if (procedureInfo.getProcName().equals("CreateTableProcedure")

http://git-wip-us.apache.org/repos/asf/hbase/blob/0b283dae/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java
index 6bcd77c..ae53328 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java
@@ -584,7 +584,7 @@ public class TestAccessController extends SecureTestUtil {
     Procedure proc = new TestTableDDLProcedure(procExec.getEnvironment(), tableName);
     proc.setOwner(USER_OWNER);
     procExec.submitProcedure(proc);
-    final List<Procedure<?>> procList = procExec.getProcedures();
+    final List<Procedure<MasterProcedureEnv>> procList = procExec.getProcedures();
 
     AccessTestAction getProceduresAction = new AccessTestAction() {
       @Override


Mime
View raw message