Search in sources :

Example 1 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()) {
            waitProcedure(namespaceLock, procedure);
            return null;
        }
        if (!tableLock.trySharedLock()) {
            namespaceLock.releaseSharedLock();
            waitProcedure(tableLock, procedure);
            return null;
        }
        return getTableQueue(table);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 2 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.hasParentLock(procedure)) {
            tableLock.releaseExclusiveLock(procedure);
            waitingCount += wakeWaitingProcedures(tableLock);
        }
        if (namespaceLock.releaseSharedLock()) {
            waitingCount += wakeWaitingProcedures(namespaceLock);
        }
        addToRunQueue(tableRunQueue, getTableQueue(table));
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 3 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 LockAndQueue namespaceLock = locking.getNamespaceLock(table.getNamespaceAsString());
        final LockAndQueue tableLock = locking.getTableLock(table);
        if (!namespaceLock.trySharedLock()) {
            waitProcedure(namespaceLock, procedure);
            return true;
        }
        if (!tableLock.tryExclusiveLock(procedure)) {
            namespaceLock.releaseSharedLock();
            waitProcedure(tableLock, procedure);
            return true;
        }
        removeFromRunQueue(tableRunQueue, getTableQueue(table));
        return false;
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 4 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)) {
            removeFromRunQueue(serverRunQueue, getServerQueue(serverName));
            return false;
        }
        waitProcedure(lock, procedure);
        return true;
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 5 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 regionInfo the list of regions the procedure was holding
   */
public void wakeRegions(final Procedure procedure, final TableName table, final HRegionInfo... regionInfo) {
    Arrays.sort(regionInfo);
    schedLock();
    try {
        int numProcs = 0;
        final Procedure[] nextProcs = new Procedure[regionInfo.length];
        for (int i = 0; i < regionInfo.length; ++i) {
            assert regionInfo[i].getTable().equals(table);
            assert i == 0 || regionInfo[i] != regionInfo[i - 1] : "duplicate region: " + regionInfo[i];
            LockAndQueue regionLock = locking.getRegionLock(regionInfo[i].getEncodedName());
            if (regionLock.releaseExclusiveLock(procedure)) {
                if (!regionLock.isEmpty()) {
                    // release one procedure at the time since regions has an xlock
                    nextProcs[numProcs++] = regionLock.removeFirst();
                } else {
                    locking.removeRegionLock(regionInfo[i].getEncodedName());
                }
            }
        }
        // awake procedures if any
        for (int i = numProcs - 1; i >= 0; --i) {
            wakeProcedure(nextProcs[i]);
        }
        wakePollIfNeeded(numProcs);
        if (!procedure.hasParent()) {
            // release the table shared-lock.
            // (if we have a parent, it is holding an xlock so we didn't take the shared-lock)
            wakeTableSharedLock(procedure, table);
        }
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) Procedure(org.apache.hadoop.hbase.procedure2.Procedure)

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