Search in sources :

Example 11 with LockAndQueue

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

the class MasterProcedureScheduler method wakeTableExclusiveLock.

/**
 * Wake the procedures waiting for the specified table
 * @param procedure the procedure releasing the lock
 * @param table the name of the table that has the exclusive lock
 */
public void wakeTableExclusiveLock(final Procedure<?> procedure, final TableName table) {
    schedLock();
    try {
        final LockAndQueue namespaceLock = locking.getNamespaceLock(table.getNamespaceAsString());
        final LockAndQueue tableLock = locking.getTableLock(table);
        int waitingCount = 0;
        if (tableLock.releaseExclusiveLock(procedure)) {
            waitingCount += wakeWaitingProcedures(tableLock);
        }
        if (namespaceLock.releaseSharedLock()) {
            waitingCount += wakeWaitingProcedures(namespaceLock);
        }
        addToRunQueue(tableRunQueue, getTableQueue(table), () -> procedure + " released the exclusive lock");
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 12 with LockAndQueue

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

the class MasterProcedureScheduler method wakeTableSharedLock.

/**
 * Wake the procedures waiting for the specified table
 * @param procedure the procedure releasing the lock
 * @param table the name of the table that has the shared lock
 */
public void wakeTableSharedLock(final Procedure<?> procedure, final TableName table) {
    schedLock();
    try {
        final LockAndQueue namespaceLock = locking.getNamespaceLock(table.getNamespaceAsString());
        final LockAndQueue tableLock = locking.getTableLock(table);
        int waitingCount = 0;
        if (tableLock.releaseSharedLock()) {
            addToRunQueue(tableRunQueue, getTableQueue(table), () -> procedure + " released the shared lock");
            waitingCount += wakeWaitingProcedures(tableLock);
        }
        if (namespaceLock.releaseSharedLock()) {
            waitingCount += wakeWaitingProcedures(namespaceLock);
        }
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 13 with LockAndQueue

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

the class MasterProcedureScheduler method wakeRegions.

/**
 * Wake the procedures waiting for the specified regions
 * @param procedure the procedure that was holding the regions
 * @param regionInfos the list of regions the procedure was holding
 */
public void wakeRegions(final Procedure<?> procedure, final TableName table, final RegionInfo... regionInfos) {
    Arrays.sort(regionInfos, RegionInfo.COMPARATOR);
    schedLock();
    try {
        int numProcs = 0;
        final Procedure<?>[] nextProcs = new Procedure[regionInfos.length];
        for (int i = 0; i < regionInfos.length; ++i) {
            assert regionInfos[i].getTable().equals(table);
            assert i == 0 || regionInfos[i] != regionInfos[i - 1] : "duplicate region: " + regionInfos[i];
            LockAndQueue regionLock = locking.getRegionLock(regionInfos[i].getEncodedName());
            if (regionLock.releaseExclusiveLock(procedure)) {
                if (!regionLock.isWaitingQueueEmpty()) {
                    // release one procedure at the time since regions has an xlock
                    nextProcs[numProcs++] = regionLock.removeFirst();
                } else {
                    locking.removeRegionLock(regionInfos[i].getEncodedName());
                }
            }
        }
        // awake procedures if any
        for (int i = numProcs - 1; i >= 0; --i) {
            wakeProcedure(nextProcs[i]);
        }
        wakePollIfNeeded(numProcs);
        // release the table shared-lock.
        wakeTableSharedLock(procedure, table);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) Procedure(org.apache.hadoop.hbase.procedure2.Procedure)

Example 14 with LockAndQueue

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

the class MasterProcedureScheduler method waitPeerExclusiveLock.

// ============================================================================
// Peer Locking Helpers
// ============================================================================
/**
 * Try to acquire the exclusive lock on the specified peer.
 * @see #wakePeerExclusiveLock(Procedure, String)
 * @param procedure the procedure trying to acquire the lock
 * @param peerId peer to lock
 * @return true if the procedure has to wait for the peer to be available
 */
public boolean waitPeerExclusiveLock(Procedure<?> procedure, String peerId) {
    schedLock();
    try {
        final LockAndQueue lock = locking.getPeerLock(peerId);
        if (lock.tryExclusiveLock(procedure)) {
            removeFromRunQueue(peerRunQueue, getPeerQueue(peerId), () -> procedure + " held exclusive lock");
            return false;
        }
        waitProcedure(lock, procedure);
        logLockedResource(LockedResourceType.PEER, peerId);
        return true;
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 15 with LockAndQueue

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

the class MasterProcedureScheduler method waitServerExclusiveLock.

// ============================================================================
// Server Locking Helpers
// ============================================================================
/**
 * Try to acquire the exclusive lock on the specified server.
 * @see #wakeServerExclusiveLock(Procedure,ServerName)
 * @param procedure the procedure trying to acquire the lock
 * @param serverName Server to lock
 * @return true if the procedure has to wait for the server to be available
 */
public boolean waitServerExclusiveLock(final Procedure<?> procedure, final ServerName serverName) {
    schedLock();
    try {
        final LockAndQueue lock = locking.getServerLock(serverName);
        if (lock.tryExclusiveLock(procedure)) {
            // In tests we may pass procedures other than ServerProcedureInterface, just pass null if
            // so.
            removeFromRunQueue(serverRunQueue, getServerQueue(serverName, procedure instanceof ServerProcedureInterface ? (ServerProcedureInterface) procedure : null), () -> procedure + " held exclusive lock");
            return false;
        }
        waitProcedure(lock, procedure);
        logLockedResource(LockedResourceType.SERVER, serverName.getServerName());
        return true;
    } 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