Search in sources :

Example 6 with Procedure

use of org.apache.hadoop.hbase.procedure2.Procedure 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 7 with Procedure

use of org.apache.hadoop.hbase.procedure2.Procedure 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 8 with Procedure

use of org.apache.hadoop.hbase.procedure2.Procedure 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 9 with Procedure

use of org.apache.hadoop.hbase.procedure2.Procedure 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)

Example 10 with Procedure

use of org.apache.hadoop.hbase.procedure2.Procedure 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)

Aggregations

Procedure (org.apache.hadoop.hbase.procedure2.Procedure)29 TestProcedure (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure)26 Test (org.junit.Test)26 TableName (org.apache.hadoop.hbase.TableName)16 IOException (java.io.IOException)10 LockAndQueue (org.apache.hadoop.hbase.procedure2.LockAndQueue)10 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)6 SequentialProcedure (org.apache.hadoop.hbase.procedure2.SequentialProcedure)5 ByteSlot (org.apache.hadoop.hbase.procedure2.util.ByteSlot)5 FileStatus (org.apache.hadoop.fs.FileStatus)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)4 LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)4 LoadCounter (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter)4 ProcedureStore (org.apache.hadoop.hbase.procedure2.store.ProcedureStore)4 ProcedureIterator (org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureIterator)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)2 After (org.junit.After)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1