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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations