Search in sources :

Example 6 with LockedResource

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);
}
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)

Example 7 with LockedResource

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);
}
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 LockedResource

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

Example 9 with LockedResource

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

Aggregations

LockedResource (org.apache.hadoop.hbase.procedure2.LockedResource)9 LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)7 Test (org.junit.Test)6 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)2 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 ServerName (org.apache.hadoop.hbase.ServerName)1 TableName (org.apache.hadoop.hbase.TableName)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 MasterProcedureScheduler (org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler)1 LockAndQueue (org.apache.hadoop.hbase.procedure2.LockAndQueue)1 LockType (org.apache.hadoop.hbase.procedure2.LockType)1 LockedResourceType (org.apache.hadoop.hbase.procedure2.LockedResourceType)1 TestProcedure (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure)1 ImmutableMap (org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap)1 InterfaceAudience (org.apache.yetus.audience.InterfaceAudience)1