use of org.apache.hadoop.hbase.procedure2.Procedure in project hbase by apache.
the class TestMasterProcedureScheduler method testInheritedXLockAndChildrenXLock.
private void testInheritedXLockAndChildrenXLock(final TableName tableName, final TestTableProcedure rootProc, final TestTableProcedure childProc) throws Exception {
queue.addBack(rootProc);
// fetch and acquire first xlock proc
Procedure parentProc = queue.poll();
assertEquals(rootProc, parentProc);
assertEquals(false, queue.waitTableExclusiveLock(parentProc, tableName));
// add child procedure
queue.addFront(childProc);
// fetch the other xlock proc
Procedure proc = queue.poll();
assertEquals(childProc, proc);
assertEquals(false, queue.waitTableExclusiveLock(proc, tableName));
queue.wakeTableExclusiveLock(proc, tableName);
// release xlock
queue.wakeTableExclusiveLock(parentProc, tableName);
}
use of org.apache.hadoop.hbase.procedure2.Procedure in project hbase by apache.
the class TestMasterProcedureScheduler method testSuspendedProcedure.
@Test
public void testSuspendedProcedure() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
queue.addBack(new TestTableProcedure(1, tableName, TableProcedureInterface.TableOperationType.READ));
queue.addBack(new TestTableProcedure(2, tableName, TableProcedureInterface.TableOperationType.READ));
Procedure proc = queue.poll();
assertEquals(1, proc.getProcId());
// suspend
ProcedureEvent event = new ProcedureEvent("testSuspendedProcedureEvent");
assertEquals(true, queue.waitEvent(event, proc));
proc = queue.poll();
assertEquals(2, proc.getProcId());
assertEquals(null, queue.poll(0));
// resume
queue.wakeEvent(event);
proc = queue.poll();
assertEquals(1, proc.getProcId());
assertEquals(null, queue.poll(0));
}
use of org.apache.hadoop.hbase.procedure2.Procedure in project hbase by apache.
the class TestMasterProcedureScheduler method testVerifyRegionLocks.
@Test
public void testVerifyRegionLocks() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
final HRegionInfo regionA = new HRegionInfo(tableName, Bytes.toBytes("a"), Bytes.toBytes("b"));
final HRegionInfo regionB = new HRegionInfo(tableName, Bytes.toBytes("b"), Bytes.toBytes("c"));
final HRegionInfo regionC = new HRegionInfo(tableName, Bytes.toBytes("c"), Bytes.toBytes("d"));
queue.addBack(new TestTableProcedure(1, tableName, TableProcedureInterface.TableOperationType.EDIT));
queue.addBack(new TestRegionProcedure(2, tableName, TableProcedureInterface.TableOperationType.MERGE, regionA, regionB));
queue.addBack(new TestRegionProcedure(3, tableName, TableProcedureInterface.TableOperationType.SPLIT, regionA));
queue.addBack(new TestRegionProcedure(4, tableName, TableProcedureInterface.TableOperationType.SPLIT, regionB));
queue.addBack(new TestRegionProcedure(5, tableName, TableProcedureInterface.TableOperationType.UNASSIGN, regionC));
// Fetch the 1st item and take the write lock
Procedure proc = queue.poll();
assertEquals(1, proc.getProcId());
assertEquals(false, queue.waitTableExclusiveLock(proc, tableName));
// everything is locked by the table operation
assertEquals(null, queue.poll(0));
// release the table lock
queue.wakeTableExclusiveLock(proc, tableName);
// Fetch the 2nd item and the the lock on regionA and regionB
Procedure mergeProc = queue.poll();
assertEquals(2, mergeProc.getProcId());
assertEquals(false, queue.waitRegions(mergeProc, tableName, regionA, regionB));
// Fetch the 3rd item and the try to lock region A which will fail
// because already locked. this procedure will go in waiting.
// (this stuff will be explicit until we get rid of the zk-lock)
Procedure procA = queue.poll();
assertEquals(3, procA.getProcId());
assertEquals(true, queue.waitRegions(procA, tableName, regionA));
// Fetch the 4th item, same story as the 3rd
Procedure procB = queue.poll();
assertEquals(4, procB.getProcId());
assertEquals(true, queue.waitRegions(procB, tableName, regionB));
// Fetch the 5th item, since it is a non-locked region we are able to execute it
Procedure procC = queue.poll();
assertEquals(5, procC.getProcId());
assertEquals(false, queue.waitRegions(procC, tableName, regionC));
// 3rd and 4th are in the region suspended queue
assertEquals(null, queue.poll(0));
// Release region A-B from merge operation (procId=2)
queue.wakeRegions(mergeProc, tableName, regionA, regionB);
// Fetch the 3rd item, now the lock on the region is available
procA = queue.poll();
assertEquals(3, procA.getProcId());
assertEquals(false, queue.waitRegions(procA, tableName, regionA));
// Fetch the 4th item, now the lock on the region is available
procB = queue.poll();
assertEquals(4, procB.getProcId());
assertEquals(false, queue.waitRegions(procB, tableName, regionB));
// release the locks on the regions
queue.wakeRegions(procA, tableName, regionA);
queue.wakeRegions(procB, tableName, regionB);
queue.wakeRegions(procC, tableName, regionC);
}
use of org.apache.hadoop.hbase.procedure2.Procedure in project hbase by apache.
the class TestMasterProcedureScheduler method testVerifySubProcRegionLocks.
@Test
public void testVerifySubProcRegionLocks() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
final HRegionInfo regionA = new HRegionInfo(tableName, Bytes.toBytes("a"), Bytes.toBytes("b"));
final HRegionInfo regionB = new HRegionInfo(tableName, Bytes.toBytes("b"), Bytes.toBytes("c"));
final HRegionInfo regionC = new HRegionInfo(tableName, Bytes.toBytes("c"), Bytes.toBytes("d"));
queue.addBack(new TestTableProcedure(1, tableName, TableProcedureInterface.TableOperationType.ENABLE));
// Fetch the 1st item from the queue, "the root procedure" and take the table lock
Procedure rootProc = queue.poll();
assertEquals(1, rootProc.getProcId());
assertEquals(false, queue.waitTableExclusiveLock(rootProc, tableName));
assertEquals(null, queue.poll(0));
// Execute the 1st step of the root-proc.
// we should get 3 sub-proc back, one for each region.
// (this step is done by the executor/rootProc, we are simulating it)
Procedure[] subProcs = new Procedure[] { new TestRegionProcedure(1, 2, tableName, TableProcedureInterface.TableOperationType.REGION_EDIT, regionA), new TestRegionProcedure(1, 3, tableName, TableProcedureInterface.TableOperationType.REGION_EDIT, regionB), new TestRegionProcedure(1, 4, tableName, TableProcedureInterface.TableOperationType.REGION_EDIT, regionC) };
// (this step is done by the executor, we are simulating it)
for (int i = subProcs.length - 1; i >= 0; --i) {
queue.addFront(subProcs[i]);
}
assertEquals(subProcs.length, queue.size());
// since they are operating on different regions
for (int i = 0; i < subProcs.length; ++i) {
TestRegionProcedure regionProc = (TestRegionProcedure) queue.poll(0);
assertEquals(subProcs[i].getProcId(), regionProc.getProcId());
assertEquals(false, queue.waitRegions(regionProc, tableName, regionProc.getRegionInfo()));
}
// nothing else in the queue
assertEquals(null, queue.poll(0));
// release all the region locks
for (int i = 0; i < subProcs.length; ++i) {
TestRegionProcedure regionProc = (TestRegionProcedure) subProcs[i];
queue.wakeRegions(regionProc, tableName, regionProc.getRegionInfo());
}
// nothing else in the queue
assertEquals(null, queue.poll(0));
// release the table lock (for the root procedure)
queue.wakeTableExclusiveLock(rootProc, tableName);
}
use of org.apache.hadoop.hbase.procedure2.Procedure in project hbase by apache.
the class TestLockProcedure method tearDown.
@After
public void tearDown() throws Exception {
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false);
// Kill all running procedures.
for (ProcedureInfo procInfo : procExec.listProcedures()) {
Procedure proc = procExec.getProcedure(procInfo.getProcId());
if (proc == null)
continue;
procExec.abort(procInfo.getProcId());
ProcedureTestingUtility.waitProcedure(procExec, proc);
}
assertEquals(0, procExec.getEnvironment().getProcedureScheduler().size());
}
Aggregations