hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mberto...@apache.org
Subject [3/3] hbase git commit: HBASE-15106 Procedure v2 - Procedure Queue pass Procedure for better debuggability
Date Tue, 19 Jan 2016 20:22:18 GMT
HBASE-15106 Procedure v2 - Procedure Queue pass Procedure for better debuggability


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

Branch: refs/heads/branch-1.2
Commit: 4fb7babad94d60f739667812802bbde5e8065c5e
Parents: b945068
Author: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Authored: Tue Jan 19 11:54:24 2016 -0800
Committer: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Committed: Tue Jan 19 12:20:05 2016 -0800

----------------------------------------------------------------------
 .../procedure/AddColumnFamilyProcedure.java     |   4 +-
 .../master/procedure/CreateTableProcedure.java  |   4 +-
 .../procedure/DeleteColumnFamilyProcedure.java  |   4 +-
 .../master/procedure/DeleteTableProcedure.java  |   4 +-
 .../master/procedure/DisableTableProcedure.java |   4 +-
 .../master/procedure/EnableTableProcedure.java  |   4 +-
 .../procedure/MasterProcedureScheduler.java     |  89 ++++++++-----
 .../procedure/ModifyColumnFamilyProcedure.java  |   4 +-
 .../master/procedure/ModifyTableProcedure.java  |   4 +-
 .../master/procedure/ServerCrashProcedure.java  |   4 +-
 .../procedure/TruncateTableProcedure.java       |   4 +-
 .../procedure/TestMasterProcedureScheduler.java | 133 ++++++++++---------
 12 files changed, 147 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java
index 3a98b0c..9905767 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java
@@ -185,12 +185,12 @@ public class AddColumnFamilyProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(tableName, "add family");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, tableName);
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(tableName);
+    env.getProcedureQueue().releaseTableExclusiveLock(this, tableName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/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 ad069bc..cdb5d61 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
@@ -273,12 +273,12 @@ public class CreateTableProcedure
     if (!getTableName().isSystemTable() && env.waitInitialized(this)) {
       return false;
     }
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(getTableName(), "create table");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, getTableName());
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(getTableName());
+    env.getProcedureQueue().releaseTableExclusiveLock(this, getTableName());
   }
 
   private boolean prepareCreate(final MasterProcedureEnv env) throws IOException {

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
index 17cf5b6..54d8fe5 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
@@ -201,12 +201,12 @@ public class DeleteColumnFamilyProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(tableName, "delete family");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, tableName);
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(tableName);
+    env.getProcedureQueue().releaseTableExclusiveLock(this, tableName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java
index 71c6c2d..38b83a2 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java
@@ -199,12 +199,12 @@ public class DeleteTableProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(getTableName(), "delete table");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, getTableName());
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(getTableName());
+    env.getProcedureQueue().releaseTableExclusiveLock(this, getTableName());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java
index a616c6b..9491fb1 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java
@@ -215,12 +215,12 @@ public class DisableTableProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(tableName, "disable table");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, tableName);
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(tableName);
+    env.getProcedureQueue().releaseTableExclusiveLock(this, tableName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java
index e54d6f8..e7d6685 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java
@@ -240,12 +240,12 @@ public class EnableTableProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(tableName, "enable table");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, tableName);
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(tableName);
+    env.getProcedureQueue().releaseTableExclusiveLock(this, tableName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/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 9a3714f..e78fe06 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
@@ -659,15 +659,15 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
   /**
    * Try to acquire the exclusive lock on the specified table.
    * other operations in the table-queue will be executed after the lock is released.
+   * @param procedure the procedure trying to acquire the lock
    * @param table Table to lock
-   * @param purpose Human readable reason for locking the table
    * @return true if we were able to acquire the lock on the table, otherwise false.
    */
-  public boolean tryAcquireTableExclusiveLock(final TableName table, final String purpose)
{
+  public boolean tryAcquireTableExclusiveLock(final Procedure procedure, final TableName
table) {
     schedLock.lock();
     TableQueue queue = getTableQueue(table);
-    boolean hasXLock = queue.tryExclusiveLock();
-    if (!hasXLock) {
+
+    if (!queue.tryExclusiveLock(procedure.getProcId())) {
       schedLock.unlock();
       return false;
     }
@@ -676,7 +676,7 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
     schedLock.unlock();
 
     // Zk lock is expensive...
-    hasXLock = queue.tryZkExclusiveLock(lockManager, purpose);
+    boolean hasXLock = queue.tryZkExclusiveLock(lockManager, procedure.toString());
     if (!hasXLock) {
       schedLock.lock();
       queue.releaseExclusiveLock();
@@ -688,9 +688,10 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
 
   /**
    * Release the exclusive lock taken with tryAcquireTableWrite()
+   * @param procedure the procedure releasing the lock
    * @param table the name of the table that has the exclusive lock
    */
-  public void releaseTableExclusiveLock(final TableName table) {
+  public void releaseTableExclusiveLock(final Procedure procedure, final TableName table)
{
     schedLock.lock();
     TableQueue queue = getTableQueue(table);
     schedLock.unlock();
@@ -707,19 +708,29 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
   /**
    * Try to acquire the shared lock on the specified table.
    * other "read" operations in the table-queue may be executed concurrently,
+   * @param procedure the procedure trying to acquire the lock
    * @param table Table to lock
-   * @param purpose Human readable reason for locking the table
    * @return true if we were able to acquire the lock on the table, otherwise false.
    */
-  public boolean tryAcquireTableSharedLock(final TableName table, final String purpose) {
-    return getTableQueueWithLock(table).trySharedLock(lockManager, purpose);
+  public boolean tryAcquireTableSharedLock(final Procedure procedure, final TableName table)
{
+    return tryAcquireTableQueueSharedLock(procedure, table) != null;
+  }
+
+  private TableQueue tryAcquireTableQueueSharedLock(final Procedure procedure,
+      final TableName table) {
+    TableQueue queue = getTableQueueWithLock(table);
+    if (!queue.trySharedLock(lockManager, procedure.toString())) {
+      return null;
+    }
+    return queue;
   }
 
   /**
    * Release the shared lock taken with tryAcquireTableRead()
+   * @param procedure the procedure releasing the lock
    * @param table the name of the table that has the shared lock
    */
-  public void releaseTableSharedLock(final TableName table) {
+  public void releaseTableSharedLock(final Procedure procedure, final TableName table) {
     getTableQueueWithLock(table).releaseSharedLock(lockManager);
   }
 
@@ -738,7 +749,7 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
       TableQueue queue = getTableQueue(table);
       if (queue == null) return true;
 
-      if (queue.isEmpty() && queue.acquireDeleteLock()) {
+      if (queue.isEmpty() && queue.tryExclusiveLock(0)) {
         // remove the table from the run-queue and the map
         if (IterableList.isLinked(queue)) {
           tableRunQueue.remove(queue);
@@ -766,15 +777,18 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
   //  Server Locking Helpers
   // ============================================================================
   /**
-   * Release the exclusive lock
-   * @see #tryAcquireServerExclusiveLock(ServerName)
-   * @param serverName the server that has the exclusive lock
+   * Try to acquire the exclusive lock on the specified server.
+   * @see #releaseServerExclusiveLock(Procedure,ServerName)
+   * @param procedure the procedure trying to acquire the lock
+   * @param serverName Server to lock
+   * @return true if we were able to acquire the lock on the server, otherwise false.
    */
-  public boolean tryAcquireServerExclusiveLock(final ServerName serverName) {
+  public boolean tryAcquireServerExclusiveLock(final Procedure procedure,
+      final ServerName serverName) {
     schedLock.lock();
     try {
       ServerQueue queue = getServerQueue(serverName);
-      if (queue.tryExclusiveLock()) {
+      if (queue.tryExclusiveLock(procedure.getProcId())) {
         removeFromRunQueue(serverRunQueue, queue);
         return true;
       }
@@ -786,10 +800,12 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
 
   /**
    * Release the exclusive lock
-   * @see #tryAcquireServerExclusiveLock(ServerName)
+   * @see #tryAcquireServerExclusiveLock(Procedure,ServerName)
+   * @param procedure the procedure releasing the lock
    * @param serverName the server that has the exclusive lock
    */
-  public void releaseServerExclusiveLock(final ServerName serverName) {
+  public void releaseServerExclusiveLock(final Procedure procedure,
+      final ServerName serverName) {
     schedLock.lock();
     try {
       ServerQueue queue = getServerQueue(serverName);
@@ -802,20 +818,24 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
 
   /**
    * Try to acquire the shared lock on the specified server.
-   * @see #releaseServerSharedLock(ServerName)
+   * @see #releaseServerSharedLock(Procedure,ServerName)
+   * @param procedure the procedure releasing the lock
    * @param serverName Server to lock
    * @return true if we were able to acquire the lock on the server, otherwise false.
    */
-  public boolean tryAcquireServerSharedLock(final ServerName serverName) {
+  public boolean tryAcquireServerSharedLock(final Procedure procedure,
+      final ServerName serverName) {
     return getServerQueueWithLock(serverName).trySharedLock();
   }
 
   /**
    * Release the shared lock taken
-   * @see #tryAcquireServerSharedLock(ServerName)
+   * @see #tryAcquireServerSharedLock(Procedure,ServerName)
+   * @param procedure the procedure releasing the lock
    * @param serverName the server that has the shared lock
    */
-  public void releaseServerSharedLock(final ServerName serverName) {
+  public void releaseServerSharedLock(final Procedure procedure,
+      final ServerName serverName) {
     getServerQueueWithLock(serverName).releaseSharedLock();
   }
 
@@ -826,8 +846,10 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
     boolean isAvailable();
     boolean isEmpty();
     int size();
+
     void add(Procedure proc, boolean addFront);
     boolean requireExclusiveLock(Procedure proc);
+    Procedure peek();
     Procedure poll();
 
     boolean isSuspended();
@@ -842,7 +864,7 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
     private Queue<TKey> iterPrev = null;
     private boolean suspended = false;
 
-    private boolean exclusiveLock = false;
+    private long exclusiveLockProcIdOwner = Long.MIN_VALUE;
     private int sharedLock = 0;
 
     private final TKey key;
@@ -886,7 +908,7 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
     }
 
     public synchronized boolean hasExclusiveLock() {
-      return this.exclusiveLock;
+      return this.exclusiveLockProcIdOwner != Long.MIN_VALUE;
     }
 
     public synchronized boolean trySharedLock() {
@@ -903,24 +925,21 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
       return sharedLock == 1;
     }
 
-    public synchronized boolean tryExclusiveLock() {
+    public synchronized boolean tryExclusiveLock(long procIdOwner) {
+      assert procIdOwner != Long.MIN_VALUE;
       if (isLocked()) return false;
-      exclusiveLock = true;
+      exclusiveLockProcIdOwner = procIdOwner;
       return true;
     }
 
     public synchronized void releaseExclusiveLock() {
-      exclusiveLock = false;
-    }
-
-    public synchronized boolean acquireDeleteLock() {
-      return tryExclusiveLock();
+      exclusiveLockProcIdOwner = Long.MIN_VALUE;
     }
 
     // This should go away when we have the new AM and its events
     // and we move xlock to the lock-event-queue.
     public synchronized boolean isAvailable() {
-      return !exclusiveLock && !isEmpty();
+      return !hasExclusiveLock() && !isEmpty();
     }
 
     // ======================================================================
@@ -970,6 +989,10 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
       runnables.addLast(proc);
     }
 
+    public Procedure peek() {
+      return runnables.peek();
+    }
+
     @Override
     public Procedure poll() {
       return runnables.poll();
@@ -1238,4 +1261,4 @@ public class MasterProcedureScheduler implements ProcedureRunnableSet
{
       return node.iterPrev != null && node.iterNext != null;
     }
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java
index bd4f9e5..fd212eb 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java
@@ -182,12 +182,12 @@ public class ModifyColumnFamilyProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(tableName, "modify family");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, tableName);
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(tableName);
+    env.getProcedureQueue().releaseTableExclusiveLock(this, tableName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java
index 329f717..ddbc9ef 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java
@@ -216,12 +216,12 @@ public class ModifyTableProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(getTableName(), "modify table");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, getTableName());
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(getTableName());
+    env.getProcedureQueue().releaseTableExclusiveLock(this, getTableName());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ServerCrashProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ServerCrashProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ServerCrashProcedure.java
index cb8b637..d402b38 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ServerCrashProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ServerCrashProcedure.java
@@ -589,12 +589,12 @@ implements ServerProcedureInterface {
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitServerCrashProcessingEnabled(this)) return false;
-    return env.getProcedureQueue().tryAcquireServerExclusiveLock(getServerName());
+    return env.getProcedureQueue().tryAcquireServerExclusiveLock(this, getServerName());
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseServerExclusiveLock(getServerName());
+    env.getProcedureQueue().releaseServerExclusiveLock(this, getServerName());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java
index da220f4..3623f35 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java
@@ -182,12 +182,12 @@ public class TruncateTableProcedure
   @Override
   protected boolean acquireLock(final MasterProcedureEnv env) {
     if (env.waitInitialized(this)) return false;
-    return env.getProcedureQueue().tryAcquireTableExclusiveLock(getTableName(), "truncate
table");
+    return env.getProcedureQueue().tryAcquireTableExclusiveLock(this, getTableName());
   }
 
   @Override
   protected void releaseLock(final MasterProcedureEnv env) {
-    env.getProcedureQueue().releaseTableExclusiveLock(getTableName());
+    env.getProcedureQueue().releaseTableExclusiveLock(this, getTableName());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/4fb7baba/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureScheduler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureScheduler.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureScheduler.java
index 2b92e52..4543486 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureScheduler.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureScheduler.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.master.procedure;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Map;
@@ -75,9 +76,11 @@ public class TestMasterProcedureScheduler {
       @Override
       public void run() {
         try {
+          TestTableProcedure proc = new TestTableProcedure(1, table,
+              TableProcedureInterface.TableOperationType.CREATE);
           while (running.get() && !failure.get()) {
-            if (procQueue.tryAcquireTableExclusiveLock(table, "create")) {
-              procQueue.releaseTableExclusiveLock(table);
+            if (procQueue.tryAcquireTableExclusiveLock(proc, table)) {
+              procQueue.releaseTableExclusiveLock(proc, table);
             }
           }
         } catch (Throwable e) {
@@ -91,9 +94,11 @@ public class TestMasterProcedureScheduler {
       @Override
       public void run() {
         try {
+          TestTableProcedure proc = new TestTableProcedure(2, table,
+              TableProcedureInterface.TableOperationType.DELETE);
           while (running.get() && !failure.get()) {
-            if (procQueue.tryAcquireTableExclusiveLock(table, "delete")) {
-              procQueue.releaseTableExclusiveLock(table);
+            if (procQueue.tryAcquireTableExclusiveLock(proc, table)) {
+              procQueue.releaseTableExclusiveLock(proc, table);
             }
             procQueue.markTableAsDeleted(table);
           }
@@ -140,8 +145,8 @@ public class TestMasterProcedureScheduler {
         Procedure proc = queue.poll();
         assertTrue(proc != null);
         TableName tableName = ((TestTableProcedure)proc).getTableName();
-        queue.tryAcquireTableExclusiveLock(tableName, "test");
-        queue.releaseTableExclusiveLock(tableName);
+        queue.tryAcquireTableExclusiveLock(proc, tableName);
+        queue.releaseTableExclusiveLock(proc, tableName);
         queue.completionCleanup(proc);
         assertEquals(--count, queue.size());
         assertEquals(i * 1000 + j, proc.getProcId());
@@ -171,14 +176,15 @@ public class TestMasterProcedureScheduler {
     assertFalse(queue.markTableAsDeleted(tableName));
 
     // fetch item and take a lock
-    assertEquals(1, queue.poll().getProcId());
+    Procedure proc = queue.poll();
+    assertEquals(1, proc.getProcId());
     // take the xlock
-    assertTrue(queue.tryAcquireTableExclusiveLock(tableName, "write"));
+    assertTrue(queue.tryAcquireTableExclusiveLock(proc, tableName));
     // table can't be deleted because we have the lock
     assertEquals(0, queue.size());
     assertFalse(queue.markTableAsDeleted(tableName));
     // release the xlock
-    queue.releaseTableExclusiveLock(tableName);
+    queue.releaseTableExclusiveLock(proc, tableName);
     // complete the table deletion
     assertTrue(queue.markTableAsDeleted(tableName));
   }
@@ -200,20 +206,22 @@ public class TestMasterProcedureScheduler {
     // table can't be deleted because one item is in the queue
     assertFalse(queue.markTableAsDeleted(tableName));
 
-    for (int i = 1; i <= nitems; ++i) {
+    Procedure[] procs = new Procedure[nitems];
+    for (int i = 0; i < nitems; ++i) {
       // fetch item and take a lock
-      assertEquals(i, queue.poll().getProcId());
+      Procedure proc = procs[i] = queue.poll();
+      assertEquals(i + 1, proc.getProcId());
       // take the rlock
-      assertTrue(queue.tryAcquireTableSharedLock(tableName, "read " + i));
+      assertTrue(queue.tryAcquireTableSharedLock(proc, tableName));
       // table can't be deleted because we have locks and/or items in the queue
       assertFalse(queue.markTableAsDeleted(tableName));
     }
 
-    for (int i = 1; i <= nitems; ++i) {
+    for (int i = 0; i < nitems; ++i) {
       // table can't be deleted because we have locks
       assertFalse(queue.markTableAsDeleted(tableName));
       // release the rlock
-      queue.releaseTableSharedLock(tableName);
+      queue.releaseTableSharedLock(procs[i], tableName);
     }
 
     // there are no items and no lock in the queeu
@@ -240,49 +248,49 @@ public class TestMasterProcedureScheduler {
           TableProcedureInterface.TableOperationType.READ));
 
     // Fetch the 1st item and take the write lock
-    long procId = queue.poll().getProcId();
-    assertEquals(1, procId);
-    assertEquals(true, queue.tryAcquireTableExclusiveLock(tableName, "write " + procId));
+    Procedure proc = queue.poll();
+    assertEquals(1, proc.getProcId());
+    assertEquals(true, queue.tryAcquireTableExclusiveLock(proc, tableName));
 
     // Fetch the 2nd item and verify that the lock can't be acquired
     assertEquals(null, queue.poll(0));
 
     // Release the write lock and acquire the read lock
-    queue.releaseTableExclusiveLock(tableName);
+    queue.releaseTableExclusiveLock(proc, tableName);
 
     // Fetch the 2nd item and take the read lock
-    procId = queue.poll().getProcId();
-    assertEquals(2, procId);
-    assertEquals(true, queue.tryAcquireTableSharedLock(tableName, "read " + procId));
+    Procedure rdProc = queue.poll();
+    assertEquals(2, rdProc.getProcId());
+    assertEquals(true, queue.tryAcquireTableSharedLock(rdProc, tableName));
 
     // Fetch the 3rd item and verify that the lock can't be acquired
-    procId = queue.poll().getProcId();
-    assertEquals(3, procId);
-    assertEquals(false, queue.tryAcquireTableExclusiveLock(tableName, "write " + procId));
+    Procedure wrProc = queue.poll();
+    assertEquals(3, wrProc.getProcId());
+    assertEquals(false, queue.tryAcquireTableExclusiveLock(wrProc, tableName));
 
     // release the rdlock of item 2 and take the wrlock for the 3d item
-    queue.releaseTableSharedLock(tableName);
-    assertEquals(true, queue.tryAcquireTableExclusiveLock(tableName, "write " + procId));
+    queue.releaseTableSharedLock(rdProc, tableName);
+    assertEquals(true, queue.tryAcquireTableExclusiveLock(wrProc, tableName));
 
     // Fetch 4th item and verify that the lock can't be acquired
     assertEquals(null, queue.poll(0));
 
     // Release the write lock and acquire the read lock
-    queue.releaseTableExclusiveLock(tableName);
+    queue.releaseTableExclusiveLock(wrProc, tableName);
 
     // Fetch the 4th item and take the read lock
-    procId = queue.poll().getProcId();
-    assertEquals(4, procId);
-    assertEquals(true, queue.tryAcquireTableSharedLock(tableName, "read " + procId));
+    rdProc = queue.poll();
+    assertEquals(4, rdProc.getProcId());
+    assertEquals(true, queue.tryAcquireTableSharedLock(rdProc, tableName));
 
     // Fetch the 4th item and take the read lock
-    procId = queue.poll().getProcId();
-    assertEquals(5, procId);
-    assertEquals(true, queue.tryAcquireTableSharedLock(tableName, "read " + procId));
+    Procedure rdProc2 = queue.poll();
+    assertEquals(5, rdProc2.getProcId());
+    assertEquals(true, queue.tryAcquireTableSharedLock(rdProc2, tableName));
 
     // Release 4th and 5th read-lock
-    queue.releaseTableSharedLock(tableName);
-    queue.releaseTableSharedLock(tableName);
+    queue.releaseTableSharedLock(rdProc, tableName);
+    queue.releaseTableSharedLock(rdProc2, tableName);
 
     // remove table queue
     assertEquals(0, queue.size());
@@ -320,7 +328,7 @@ public class TestMasterProcedureScheduler {
         public void run() {
           while (opsCount.get() > 0) {
             try {
-              TableProcedureInterface proc = procSet.acquire();
+              Procedure proc = procSet.acquire();
               if (proc == null) {
                 queue.signalAll();
                 if (opsCount.get() > 0) {
@@ -328,14 +336,14 @@ public class TestMasterProcedureScheduler {
                 }
                 break;
               }
+
+              TableName tableId = procSet.getTableName(proc);
               synchronized (concurrentTables) {
-                assertTrue("unexpected concurrency on " + proc.getTableName(),
-                  concurrentTables.add(proc.getTableName()));
+                assertTrue("unexpected concurrency on " + tableId, concurrentTables.add(tableId));
               }
               assertTrue(opsCount.decrementAndGet() >= 0);
               try {
-                long procId = ((Procedure)proc).getProcId();
-                TableName tableId = proc.getTableName();
+                long procId = proc.getProcId();
                 int concurrent = concurrentCount.incrementAndGet();
                 assertTrue("inc-concurrent="+ concurrent +" 1 <= concurrent <= "+ NUM_TABLES,
                   concurrent >= 1 && concurrent <= NUM_TABLES);
@@ -346,7 +354,7 @@ public class TestMasterProcedureScheduler {
                 assertTrue("dec-concurrent=" + concurrent, concurrent < NUM_TABLES);
               } finally {
                 synchronized (concurrentTables) {
-                  assertTrue(concurrentTables.remove(proc.getTableName()));
+                  assertTrue(concurrentTables.remove(tableId));
                 }
                 procSet.release(proc);
               }
@@ -378,43 +386,36 @@ public class TestMasterProcedureScheduler {
 
   public static class TestTableProcSet {
     private final MasterProcedureScheduler queue;
-    private Map<Long, TableProcedureInterface> procsMap =
-      new ConcurrentHashMap<Long, TableProcedureInterface>();
 
     public TestTableProcSet(final MasterProcedureScheduler queue) {
       this.queue = queue;
     }
 
-    public void addBack(TableProcedureInterface tableProc) {
-      Procedure proc = (Procedure)tableProc;
-      procsMap.put(proc.getProcId(), tableProc);
+    public void addBack(Procedure proc) {
       queue.addBack(proc);
     }
 
-    public void addFront(TableProcedureInterface tableProc) {
-      Procedure proc = (Procedure)tableProc;
-      procsMap.put(proc.getProcId(), tableProc);
+    public void addFront(Procedure proc) {
       queue.addFront(proc);
     }
 
-    public TableProcedureInterface acquire() {
-      TableProcedureInterface proc = null;
+    public Procedure acquire() {
+      Procedure proc = null;
       boolean avail = false;
       while (!avail) {
-        Procedure xProc = queue.poll();
-        proc = xProc != null ? procsMap.remove(xProc.getProcId()) : null;
+        proc = queue.poll();
         if (proc == null) break;
-        switch (proc.getTableOperationType()) {
+        switch (getTableOperationType(proc)) {
           case CREATE:
           case DELETE:
           case EDIT:
-            avail = queue.tryAcquireTableExclusiveLock(proc.getTableName(),
-              "op="+ proc.getTableOperationType());
+            avail = queue.tryAcquireTableExclusiveLock(proc, getTableName(proc));
             break;
           case READ:
-            avail = queue.tryAcquireTableSharedLock(proc.getTableName(),
-              "op="+ proc.getTableOperationType());
+            avail = queue.tryAcquireTableSharedLock(proc, getTableName(proc));
             break;
+          default:
+            throw new UnsupportedOperationException();
         }
         if (!avail) {
           addFront(proc);
@@ -424,18 +425,26 @@ public class TestMasterProcedureScheduler {
       return proc;
     }
 
-    public void release(TableProcedureInterface proc) {
-      switch (proc.getTableOperationType()) {
+    public void release(Procedure proc) {
+      switch (getTableOperationType(proc)) {
         case CREATE:
         case DELETE:
         case EDIT:
-          queue.releaseTableExclusiveLock(proc.getTableName());
+          queue.releaseTableExclusiveLock(proc, getTableName(proc));
           break;
         case READ:
-          queue.releaseTableSharedLock(proc.getTableName());
+          queue.releaseTableSharedLock(proc, getTableName(proc));
           break;
       }
     }
+
+    public TableName getTableName(Procedure proc) {
+      return ((TableProcedureInterface)proc).getTableName();
+    }
+
+    public TableProcedureInterface.TableOperationType getTableOperationType(Procedure proc)
{
+      return ((TableProcedureInterface)proc).getTableOperationType();
+    }
   }
 
   public static class TestTableProcedure extends Procedure<Void>


Mime
View raw message