Search in sources :

Example 26 with LockAndQueue

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

the class MasterProcedureScheduler method wakeNamespaceExclusiveLock.

/**
 * Wake the procedures waiting for the specified namespace
 * @see #waitNamespaceExclusiveLock(Procedure,String)
 * @param procedure the procedure releasing the lock
 * @param namespace the namespace that has the exclusive lock
 */
public void wakeNamespaceExclusiveLock(final Procedure<?> procedure, final String namespace) {
    schedLock();
    try {
        final LockAndQueue namespaceLock = locking.getNamespaceLock(namespace);
        final LockAndQueue systemNamespaceTableLock = locking.getTableLock(TableProcedureInterface.DUMMY_NAMESPACE_TABLE_NAME);
        int waitingCount = 0;
        if (namespaceLock.releaseExclusiveLock(procedure)) {
            waitingCount += wakeWaitingProcedures(namespaceLock);
        }
        if (systemNamespaceTableLock.releaseSharedLock()) {
            addToRunQueue(tableRunQueue, getTableQueue(TableProcedureInterface.DUMMY_NAMESPACE_TABLE_NAME), () -> procedure + " released namespace exclusive lock");
            waitingCount += wakeWaitingProcedures(systemNamespaceTableLock);
        }
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 27 with LockAndQueue

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

the class MasterProcedureScheduler method waitTableExclusiveLock.

/**
 * Suspend the procedure if the specified table is already locked.
 * 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
 * @return true if the procedure has to wait for the table to be available
 */
public boolean waitTableExclusiveLock(final Procedure<?> procedure, final TableName table) {
    schedLock();
    try {
        final String namespace = table.getNamespaceAsString();
        final LockAndQueue namespaceLock = locking.getNamespaceLock(namespace);
        final LockAndQueue tableLock = locking.getTableLock(table);
        if (!namespaceLock.trySharedLock(procedure)) {
            waitProcedure(namespaceLock, procedure);
            logLockedResource(LockedResourceType.NAMESPACE, namespace);
            return true;
        }
        if (!tableLock.tryExclusiveLock(procedure)) {
            namespaceLock.releaseSharedLock();
            waitProcedure(tableLock, procedure);
            logLockedResource(LockedResourceType.TABLE, table.getNameAsString());
            return true;
        }
        removeFromRunQueue(tableRunQueue, getTableQueue(table), () -> procedure + " held the exclusive lock");
        return false;
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 28 with LockAndQueue

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

the class MasterProcedureScheduler method wakePeerExclusiveLock.

/**
 * Wake the procedures waiting for the specified peer
 * @see #waitPeerExclusiveLock(Procedure, String)
 * @param procedure the procedure releasing the lock
 * @param peerId the peer that has the exclusive lock
 */
public void wakePeerExclusiveLock(Procedure<?> procedure, String peerId) {
    schedLock();
    try {
        final LockAndQueue lock = locking.getPeerLock(peerId);
        if (lock.releaseExclusiveLock(procedure)) {
            addToRunQueue(peerRunQueue, getPeerQueue(peerId), () -> procedure + " released exclusive lock");
            int waitingCount = wakeWaitingProcedures(lock);
            wakePollIfNeeded(waitingCount);
        }
    } 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