Search in sources :

Example 1 with LockProcedure

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

Example 2 with LockProcedure

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

Example 3 with LockProcedure

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

Example 4 with LockProcedure

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

Example 5 with LockProcedure

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) LockedResourceType(org.apache.hadoop.hbase.procedure2.LockedResourceType) ImmutableMap(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) Function(java.util.function.Function) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) LockType(org.apache.hadoop.hbase.procedure2.LockType) ArrayList(java.util.ArrayList) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Map(java.util.Map) ServerName(org.apache.hadoop.hbase.ServerName) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) ArrayList(java.util.ArrayList) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) LockType(org.apache.hadoop.hbase.procedure2.LockType)

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