Search in sources :

Example 6 with LockAndQueue

use of org.apache.hadoop.hbase.procedure2.LockAndQueue in project hbase by apache.

the class MasterProcedureScheduler method waitNamespaceExclusiveLock.

// ============================================================================
//  Namespace Locking Helpers
// ============================================================================
/**
   * Suspend the procedure if the specified namespace is already locked.
   * @see #wakeNamespaceExclusiveLock(Procedure,String)
   * @param procedure the procedure trying to acquire the lock
   * @param namespace Namespace to lock
   * @return true if the procedure has to wait for the namespace to be available
   */
public boolean waitNamespaceExclusiveLock(final Procedure procedure, final String namespace) {
    schedLock();
    try {
        final LockAndQueue systemNamespaceTableLock = locking.getTableLock(TableName.NAMESPACE_TABLE_NAME);
        if (!systemNamespaceTableLock.trySharedLock()) {
            waitProcedure(systemNamespaceTableLock, procedure);
            return true;
        }
        final LockAndQueue namespaceLock = locking.getNamespaceLock(namespace);
        if (!namespaceLock.tryExclusiveLock(procedure)) {
            systemNamespaceTableLock.releaseSharedLock();
            waitProcedure(namespaceLock, procedure);
            return true;
        }
        return false;
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 7 with LockAndQueue

use of org.apache.hadoop.hbase.procedure2.LockAndQueue in project hbase by apache.

the class MasterProcedureScheduler method wakeServerExclusiveLock.

/**
   * Wake the procedures waiting for the specified server
   * @see #waitServerExclusiveLock(Procedure,ServerName)
   * @param procedure the procedure releasing the lock
   * @param serverName the server that has the exclusive lock
   */
public void wakeServerExclusiveLock(final Procedure procedure, final ServerName serverName) {
    schedLock();
    try {
        final LockAndQueue lock = locking.getServerLock(serverName);
        lock.releaseExclusiveLock(procedure);
        addToRunQueue(serverRunQueue, getServerQueue(serverName));
        int waitingCount = wakeWaitingProcedures(lock);
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 8 with LockAndQueue

use of org.apache.hadoop.hbase.procedure2.LockAndQueue in project hbase by apache.

the class MasterProcedureScheduler method markTableAsDeleted.

/**
 * 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).
 */
boolean markTableAsDeleted(final TableName table, final Procedure<?> procedure) {
    schedLock();
    try {
        final TableQueue queue = getTableQueue(table);
        final LockAndQueue tableLock = locking.getTableLock(table);
        if (queue == null)
            return true;
        if (queue.isEmpty() && tableLock.tryExclusiveLock(procedure)) {
            // remove the table from the run-queue and the map
            if (AvlIterableList.isLinked(queue)) {
                tableRunQueue.remove(queue);
            }
            removeTableQueue(table);
        } else {
            // TODO: If there are no create, we can drop all the other ops
            return false;
        }
    } finally {
        schedUnlock();
    }
    return true;
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 9 with LockAndQueue

use of org.apache.hadoop.hbase.procedure2.LockAndQueue in project hbase by apache.

the class MasterProcedureScheduler method waitTableQueueSharedLock.

private TableQueue waitTableQueueSharedLock(final Procedure<?> procedure, final TableName table) {
    schedLock();
    try {
        final LockAndQueue namespaceLock = locking.getNamespaceLock(table.getNamespaceAsString());
        final LockAndQueue tableLock = locking.getTableLock(table);
        if (!namespaceLock.trySharedLock(procedure)) {
            waitProcedure(namespaceLock, procedure);
            return null;
        }
        if (!tableLock.trySharedLock(procedure)) {
            namespaceLock.releaseSharedLock();
            waitProcedure(tableLock, procedure);
            return null;
        }
        return getTableQueue(table);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 10 with LockAndQueue

use of org.apache.hadoop.hbase.procedure2.LockAndQueue in project hbase by apache.

the class MasterProcedureScheduler method tryCleanupPeerQueue.

private void tryCleanupPeerQueue(String peerId, Procedure<?> procedure) {
    schedLock();
    try {
        PeerQueue queue = AvlTree.get(peerMap, peerId, PEER_QUEUE_KEY_COMPARATOR);
        if (queue == null) {
            return;
        }
        final LockAndQueue lock = locking.getPeerLock(peerId);
        if (queue.isEmpty() && lock.tryExclusiveLock(procedure)) {
            removeFromRunQueue(peerRunQueue, queue, () -> "clean up peer queue after " + procedure + " completed");
            removePeerQueue(peerId);
        }
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Aggregations

LockAndQueue (org.apache.hadoop.hbase.procedure2.LockAndQueue)28 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 ServerName (org.apache.hadoop.hbase.ServerName)1 TableName (org.apache.hadoop.hbase.TableName)1 LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)1 LockType (org.apache.hadoop.hbase.procedure2.LockType)1 LockedResource (org.apache.hadoop.hbase.procedure2.LockedResource)1 LockedResourceType (org.apache.hadoop.hbase.procedure2.LockedResourceType)1 ImmutableMap (org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap)1 InterfaceAudience (org.apache.yetus.audience.InterfaceAudience)1