use of org.apache.hadoop.hbase.procedure2.LockedResource in project hbase by apache.
the class SchemaLocking method createLockedResource.
private LockedResource createLockedResource(LockedResourceType resourceType, String resourceName, LockAndQueue queue) {
LockType lockType;
Procedure<?> exclusiveLockOwnerProcedure;
int sharedLockCount;
if (queue.hasExclusiveLock()) {
lockType = LockType.EXCLUSIVE;
exclusiveLockOwnerProcedure = queue.getExclusiveLockOwnerProcedure();
sharedLockCount = 0;
} else {
lockType = LockType.SHARED;
exclusiveLockOwnerProcedure = null;
sharedLockCount = queue.getSharedLockCount();
}
List<Procedure<?>> waitingProcedures = new ArrayList<>();
queue.filterWaitingQueue(p -> p instanceof LockProcedure).forEachOrdered(waitingProcedures::add);
return new LockedResource(resourceType, resourceName, lockType, exclusiveLockOwnerProcedure, sharedLockCount, waitingProcedures);
}
use of org.apache.hadoop.hbase.procedure2.LockedResource in project hbase by apache.
the class TestMasterProcedureScheduler method testListLocksWaiting.
@Test
public void testListLocksWaiting() throws Exception {
LockProcedure procedure1 = createExclusiveLockProcedure(1);
queue.waitTableExclusiveLock(procedure1, TableName.valueOf("ns4", "table4"));
LockProcedure procedure2 = createSharedLockProcedure(2);
queue.waitTableSharedLock(procedure2, TableName.valueOf("ns4", "table4"));
LockProcedure procedure3 = createExclusiveLockProcedure(3);
queue.waitTableExclusiveLock(procedure3, TableName.valueOf("ns4", "table4"));
List<LockedResource> resources = queue.getLocks();
assertEquals(2, resources.size());
LockedResource namespaceResource = resources.get(0);
assertLockResource(namespaceResource, LockedResourceType.NAMESPACE, "ns4");
assertSharedLock(namespaceResource, 1);
assertTrue(namespaceResource.getWaitingProcedures().isEmpty());
LockedResource tableLock = resources.get(1);
assertLockResource(tableLock, LockedResourceType.TABLE, "ns4:table4");
assertExclusiveLock(tableLock, procedure1);
List<Procedure<?>> waitingProcedures = tableLock.getWaitingProcedures();
assertEquals(2, waitingProcedures.size());
LockProcedure waitingProcedure2 = (LockProcedure) waitingProcedures.get(0);
assertEquals(LockType.SHARED, waitingProcedure2.getType());
assertEquals(procedure2, waitingProcedure2);
LockProcedure waitingProcedure3 = (LockProcedure) waitingProcedures.get(1);
assertEquals(LockType.EXCLUSIVE, waitingProcedure3.getType());
assertEquals(procedure3, waitingProcedure3);
}
use of org.apache.hadoop.hbase.procedure2.LockedResource in project hbase by apache.
the class TestMasterProcedureScheduler method testListLocksServer.
@Test
public void testListLocksServer() throws Exception {
LockProcedure procedure = createExclusiveLockProcedure(0);
queue.waitServerExclusiveLock(procedure, ServerName.valueOf("server1,1234,0"));
List<LockedResource> resources = queue.getLocks();
assertEquals(1, resources.size());
LockedResource serverResource = resources.get(0);
assertLockResource(serverResource, LockedResourceType.SERVER, "server1,1234,0");
assertExclusiveLock(serverResource, procedure);
assertTrue(serverResource.getWaitingProcedures().isEmpty());
}
use of org.apache.hadoop.hbase.procedure2.LockedResource in project hbase by apache.
the class TestMasterProcedureScheduler method testListLocksPeer.
@Test
public void testListLocksPeer() throws Exception {
String peerId = "1";
LockProcedure procedure = createExclusiveLockProcedure(4);
queue.waitPeerExclusiveLock(procedure, peerId);
List<LockedResource> locks = queue.getLocks();
assertEquals(1, locks.size());
LockedResource resource = locks.get(0);
assertLockResource(resource, LockedResourceType.PEER, peerId);
assertExclusiveLock(resource, procedure);
assertTrue(resource.getWaitingProcedures().isEmpty());
// Try to acquire the exclusive lock again with same procedure
assertFalse(queue.waitPeerExclusiveLock(procedure, peerId));
// Try to acquire the exclusive lock again with new procedure
LockProcedure procedure2 = createExclusiveLockProcedure(5);
assertTrue(queue.waitPeerExclusiveLock(procedure2, peerId));
// Same peerId, still only has 1 LockedResource
locks = queue.getLocks();
assertEquals(1, locks.size());
resource = locks.get(0);
assertLockResource(resource, LockedResourceType.PEER, peerId);
// LockedResource owner still is the origin procedure
assertExclusiveLock(resource, procedure);
// The new procedure should in the waiting list
assertEquals(1, resource.getWaitingProcedures().size());
}
Aggregations