Search in sources :

Example 21 with LockAndQueue

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

the class SchemaLocking method createLockedResource.

private LockedResource createLockedResource(LockedResourceType resourceType, String resourceName, LockAndQueue queue) {
    LockType lockType;
    Procedure<?> exclusiveLockOwnerProcedure;
    int sharedLockCount;
    if (queue.hasExclusiveLock()) {
        lockType = LockType.EXCLUSIVE;
        exclusiveLockOwnerProcedure = queue.getExclusiveLockOwnerProcedure();
        sharedLockCount = 0;
    } else {
        lockType = LockType.SHARED;
        exclusiveLockOwnerProcedure = null;
        sharedLockCount = queue.getSharedLockCount();
    }
    List<Procedure<?>> waitingProcedures = new ArrayList<>();
    queue.filterWaitingQueue(p -> p instanceof LockProcedure).forEachOrdered(waitingProcedures::add);
    return new LockedResource(resourceType, resourceName, lockType, exclusiveLockOwnerProcedure, sharedLockCount, waitingProcedures);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) LockedResourceType(org.apache.hadoop.hbase.procedure2.LockedResourceType) ImmutableMap(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) Function(java.util.function.Function) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) LockType(org.apache.hadoop.hbase.procedure2.LockType) ArrayList(java.util.ArrayList) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Map(java.util.Map) ServerName(org.apache.hadoop.hbase.ServerName) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) ArrayList(java.util.ArrayList) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) LockType(org.apache.hadoop.hbase.procedure2.LockType)

Example 22 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);
        // Only SCP will acquire/release server lock so do not need to check the return value here.
        lock.releaseExclusiveLock(procedure);
        // In tests we may pass procedures other than ServerProcedureInterface, just pass null if
        // so.
        addToRunQueue(serverRunQueue, getServerQueue(serverName, procedure instanceof ServerProcedureInterface ? (ServerProcedureInterface) procedure : null), () -> procedure + " released exclusive lock");
        int waitingCount = wakeWaitingProcedures(lock);
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 23 with LockAndQueue

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

the class MasterProcedureScheduler method tryCleanupServerQueue.

private void tryCleanupServerQueue(ServerName serverName, Procedure<?> proc) {
    schedLock();
    try {
        int index = getBucketIndex(serverBuckets, serverName.hashCode());
        ServerQueue node = AvlTree.get(serverBuckets[index], serverName, SERVER_QUEUE_KEY_COMPARATOR);
        if (node == null) {
            return;
        }
        LockAndQueue lock = locking.getServerLock(serverName);
        if (node.isEmpty() && lock.tryExclusiveLock(proc)) {
            removeFromRunQueue(serverRunQueue, node, () -> "clean up server queue after " + proc + " completed");
            removeServerQueue(serverName);
        }
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 24 with LockAndQueue

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

the class MasterProcedureScheduler method wakeMetaExclusiveLock.

/**
 * Wake the procedures waiting for meta.
 * @see #waitMetaExclusiveLock(Procedure)
 * @param procedure the procedure releasing the lock
 * @deprecated only used for {@link RecoverMetaProcedure}. Should be removed along with
 *             {@link RecoverMetaProcedure}.
 */
@Deprecated
public void wakeMetaExclusiveLock(Procedure<?> procedure) {
    schedLock();
    try {
        final LockAndQueue lock = locking.getMetaLock();
        lock.releaseExclusiveLock(procedure);
        addToRunQueue(metaRunQueue, getMetaQueue(), () -> procedure + " released exclusive lock");
        int waitingCount = wakeWaitingProcedures(lock);
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 25 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(Procedure<?> procedure, String namespace) {
    schedLock();
    try {
        final LockAndQueue systemNamespaceTableLock = locking.getTableLock(TableProcedureInterface.DUMMY_NAMESPACE_TABLE_NAME);
        if (!systemNamespaceTableLock.trySharedLock(procedure)) {
            waitProcedure(systemNamespaceTableLock, procedure);
            logLockedResource(LockedResourceType.TABLE, TableProcedureInterface.DUMMY_NAMESPACE_TABLE_NAME.getNameAsString());
            return true;
        }
        final LockAndQueue namespaceLock = locking.getNamespaceLock(namespace);
        if (!namespaceLock.tryExclusiveLock(procedure)) {
            systemNamespaceTableLock.releaseSharedLock();
            waitProcedure(namespaceLock, procedure);
            logLockedResource(LockedResourceType.NAMESPACE, namespace);
            return true;
        }
        return false;
    } 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