private <T extends Comparable<T>, TNode extends Queue<T>> boolean tryCleanupQueue(T id,
    Procedure<?> proc, Supplier<TNode> getMap, AvlKeyComparator<TNode> comparator,
    Function<T, LockAndQueue> getLock, FairQueue<T> runQueue, Consumer<T> removeQueue) {
    schedLock();
    try {
      Queue<T> queue = AvlTree.get(getMap.get(), id, comparator);
      if (queue == null) {
        return true;
      }

      LockAndQueue lock = getLock.apply(id);
      if (queue.isEmpty() && lock.isWaitingQueueEmpty() && !lock.isLocked()) {
        // 1. the queue is empty
        // 2. no procedure is in the lock's waiting queue
        // 3. no other one holds the lock. It is possible that someone else holds the lock, usually
        // our parent procedures
        // If we can meet all the above conditions, it is safe for us to remove the queue
        removeFromRunQueue(runQueue, queue, () -> "clean up queue after " + proc + " completed");
        removeQueue.accept(id);
        return true;
      } else {
        return false;
      }

    } finally {
      schedUnlock();
    }
  }
Tries to remove the queue and the table-lock of the specified table. If there are new
operations pending (e.g. a new create), the remove will not be performed.
@param table     the name of the table that should be marked as deleted
@param procedure the procedure that is removing the table
@return true if deletion succeeded, false otherwise meaning that there are other new operations
        pending for that table (e.g. a new create).
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureScheduler.java