Search in sources :

Example 16 with LockAndQueue

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

the class MasterProcedureScheduler method waitMetaExclusiveLock.

// ============================================================================
// Meta Locking Helpers
// ============================================================================
/**
 * Try to acquire the exclusive lock on meta.
 * @see #wakeMetaExclusiveLock(Procedure)
 * @param procedure the procedure trying to acquire the lock
 * @return true if the procedure has to wait for meta to be available
 * @deprecated only used for {@link RecoverMetaProcedure}. Should be removed along with
 *             {@link RecoverMetaProcedure}.
 */
@Deprecated
public boolean waitMetaExclusiveLock(Procedure<?> procedure) {
    schedLock();
    try {
        final LockAndQueue lock = locking.getMetaLock();
        if (lock.tryExclusiveLock(procedure)) {
            removeFromRunQueue(metaRunQueue, getMetaQueue(), () -> procedure + " held exclusive lock");
            return false;
        }
        waitProcedure(lock, procedure);
        logLockedResource(LockedResourceType.META, TableName.META_TABLE_NAME.getNameAsString());
        return true;
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 17 with LockAndQueue

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

the class MasterProcedureScheduler method markTableAsDeleted.

/**
   * Tries to remove the queue and the table-lock of the specified table.
   * If there are new operations pending (e.g. a new create),
   * the remove will not be performed.
   * @param table the name of the table that should be marked as deleted
   * @param procedure the procedure that is removing the table
   * @return true if deletion succeeded, false otherwise meaning that there are
   *     other new operations pending for that table (e.g. a new create).
   */
@VisibleForTesting
protected boolean markTableAsDeleted(final TableName table, final Procedure procedure) {
    schedLock();
    try {
        final TableQueue queue = getTableQueue(table);
        final LockAndQueue tableLock = locking.getTableLock(table);
        if (queue == null)
            return true;
        if (queue.isEmpty() && tableLock.tryExclusiveLock(procedure)) {
            // remove the table from the run-queue and the map
            if (AvlIterableList.isLinked(queue)) {
                tableRunQueue.remove(queue);
            }
            removeTableQueue(table);
        } else {
            // TODO: If there are no create, we can drop all the other ops
            return false;
        }
    } finally {
        schedUnlock();
    }
    return true;
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 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));
            waitingCount += wakeWaitingProcedures(tableLock);
        }
        if (namespaceLock.releaseSharedLock()) {
            waitingCount += wakeWaitingProcedures(namespaceLock);
        }
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

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

Example 20 with LockAndQueue

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

the class SchemaLocking method getLock.

private <T> LockAndQueue getLock(Map<T, LockAndQueue> map, T key) {
    LockAndQueue lock = map.get(key);
    if (lock == null) {
        lock = new LockAndQueue(procedureRetriever);
        map.put(key, lock);
    }
    return lock;
}
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