Search in sources :

Example 6 with LockProcedure

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());
    }
}
Also used : MasterLock(org.apache.hadoop.hbase.master.locking.LockManager.MasterLock) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockType(org.apache.hadoop.hbase.procedure2.LockType) UncheckedIOException(java.io.UncheckedIOException) Assert.assertNull(org.junit.Assert.assertNull) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) Table(org.apache.hadoop.hbase.client.Table) ClassRule(org.junit.ClassRule) Bytes(org.apache.hadoop.hbase.util.Bytes) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) UncheckedIOException(java.io.UncheckedIOException) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MasterLock(org.apache.hadoop.hbase.master.locking.LockManager.MasterLock) Test(org.junit.Test)

Example 7 with LockProcedure

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);
}
Also used : LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) Test(org.junit.Test)

Example 8 with LockProcedure

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());
}
Also used : LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) Test(org.junit.Test)

Example 9 with LockProcedure

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());
}
Also used : LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) Test(org.junit.Test)

Example 10 with LockProcedure

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;
}
Also used : Field(java.lang.reflect.Field) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Method(java.lang.reflect.Method)

Aggregations

LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)11 Test (org.junit.Test)8 LockedResource (org.apache.hadoop.hbase.procedure2.LockedResource)7 TableName (org.apache.hadoop.hbase.TableName)3 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)2 LockType (org.apache.hadoop.hbase.procedure2.LockType)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)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 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)1 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)1 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)1 ServerName (org.apache.hadoop.hbase.ServerName)1