use of org.apache.hadoop.hbase.master.locking.LockProcedure in project hbase by apache.
the class TestSnapshotWhileRSCrashes method test.
@Test
public void test() throws InterruptedException, IOException {
String snName = "sn";
MasterLock lock = UTIL.getMiniHBaseCluster().getMaster().getLockManager().createMasterLock(NAME, LockType.EXCLUSIVE, "for testing");
lock.acquire();
Thread t = new Thread(() -> {
try {
UTIL.getAdmin().snapshot(snName, NAME);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
t.setDaemon(true);
t.start();
ProcedureExecutor<MasterProcedureEnv> procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
UTIL.waitFor(10000, () -> procExec.getProcedures().stream().filter(p -> !p.isFinished()).filter(p -> p instanceof LockProcedure).map(p -> (LockProcedure) p).filter(p -> NAME.equals(p.getTableName())).anyMatch(p -> !p.isLocked()));
UTIL.getMiniHBaseCluster().stopRegionServer(0);
lock.release();
// sure that the regions could online
try (Table table = UTIL.getConnection().getTable(NAME);
ResultScanner scanner = table.getScanner(CF)) {
assertNull(scanner.next());
}
}
use of org.apache.hadoop.hbase.master.locking.LockProcedure 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.master.locking.LockProcedure 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.master.locking.LockProcedure 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());
}
use of org.apache.hadoop.hbase.master.locking.LockProcedure in project hbase by apache.
the class TestMasterProcedureScheduler method createLockProcedure.
private static LockProcedure createLockProcedure(LockType lockType, long procId) throws Exception {
LockProcedure procedure = new LockProcedure();
Field typeField = LockProcedure.class.getDeclaredField("type");
typeField.setAccessible(true);
typeField.set(procedure, lockType);
Method setProcIdMethod = Procedure.class.getDeclaredMethod("setProcId", long.class);
setProcIdMethod.setAccessible(true);
setProcIdMethod.invoke(procedure, procId);
return procedure;
}
Aggregations