use of org.apache.hadoop.hbase.master.locking.LockProcedure in project hbase by apache.
the class TestLockManager method tearDown.
@After
public void tearDown() throws Exception {
for (ProcedureInfo procInfo : getMasterProcedureExecutor().listProcedures()) {
Procedure proc = getMasterProcedureExecutor().getProcedure(procInfo.getProcId());
if (proc instanceof LockProcedure) {
((LockProcedure) proc).unlock(getMasterProcedureExecutor().getEnvironment());
ProcedureTestingUtility.waitProcedure(getMasterProcedureExecutor(), proc);
}
}
assertEquals(0, getMasterProcedureExecutor().getEnvironment().getProcedureScheduler().size());
}
use of org.apache.hadoop.hbase.master.locking.LockProcedure in project hbase by apache.
the class TestMasterProcedureScheduler method testListLocksRegion.
@Test
public void testListLocksRegion() throws Exception {
LockProcedure procedure = createExclusiveLockProcedure(3);
RegionInfo regionInfo = RegionInfoBuilder.newBuilder(TableName.valueOf("ns3", "table3")).build();
queue.waitRegion(procedure, regionInfo);
List<LockedResource> resources = queue.getLocks();
assertEquals(3, resources.size());
LockedResource namespaceResource = resources.get(0);
assertLockResource(namespaceResource, LockedResourceType.NAMESPACE, "ns3");
assertSharedLock(namespaceResource, 1);
assertTrue(namespaceResource.getWaitingProcedures().isEmpty());
LockedResource tableResource = resources.get(1);
assertLockResource(tableResource, LockedResourceType.TABLE, "ns3:table3");
assertSharedLock(tableResource, 1);
assertTrue(tableResource.getWaitingProcedures().isEmpty());
LockedResource regionResource = resources.get(2);
assertLockResource(regionResource, LockedResourceType.REGION, regionInfo.getEncodedName());
assertExclusiveLock(regionResource, procedure);
assertTrue(regionResource.getWaitingProcedures().isEmpty());
}
use of org.apache.hadoop.hbase.master.locking.LockProcedure in project hbase by apache.
the class TestMasterProcedureScheduler method testListLocksTable.
@Test
public void testListLocksTable() throws Exception {
LockProcedure procedure = createExclusiveLockProcedure(2);
queue.waitTableExclusiveLock(procedure, TableName.valueOf("ns2", "table2"));
List<LockedResource> locks = queue.getLocks();
assertEquals(2, locks.size());
LockedResource namespaceResource = locks.get(0);
assertLockResource(namespaceResource, LockedResourceType.NAMESPACE, "ns2");
assertSharedLock(namespaceResource, 1);
assertTrue(namespaceResource.getWaitingProcedures().isEmpty());
LockedResource tableResource = locks.get(1);
assertLockResource(tableResource, LockedResourceType.TABLE, "ns2:table2");
assertExclusiveLock(tableResource, procedure);
assertTrue(tableResource.getWaitingProcedures().isEmpty());
}
use of org.apache.hadoop.hbase.master.locking.LockProcedure in project hbase by apache.
the class TestMasterProcedureScheduler method testListLocksNamespace.
@Test
public void testListLocksNamespace() throws Exception {
LockProcedure procedure = createExclusiveLockProcedure(1);
queue.waitNamespaceExclusiveLock(procedure, "ns1");
List<LockedResource> locks = queue.getLocks();
assertEquals(2, locks.size());
LockedResource namespaceResource = locks.get(0);
assertLockResource(namespaceResource, LockedResourceType.NAMESPACE, "ns1");
assertExclusiveLock(namespaceResource, procedure);
assertTrue(namespaceResource.getWaitingProcedures().isEmpty());
LockedResource tableResource = locks.get(1);
assertLockResource(tableResource, LockedResourceType.TABLE, TableProcedureInterface.DUMMY_NAMESPACE_TABLE_NAME.getNameAsString());
assertSharedLock(tableResource, 1);
assertTrue(tableResource.getWaitingProcedures().isEmpty());
}
use of org.apache.hadoop.hbase.master.locking.LockProcedure 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);
}
Aggregations