use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure in project hbase by apache.
the class TestWALProcedureStore method trackersLoadedForAllOldLogs.
/**
* Tests that tracker for all old logs are loaded back after procedure store is restarted.
*/
@Test
public void trackersLoadedForAllOldLogs() throws Exception {
for (int i = 0; i <= 20; ++i) {
procStore.insert(new TestProcedure(i), null);
if (i > 0 && (i % 5) == 0) {
LoadCounter loader = new LoadCounter();
storeRestart(loader);
}
}
assertEquals(5, procStore.getActiveLogs().size());
for (int i = 0; i < procStore.getActiveLogs().size() - 1; ++i) {
ProcedureStoreTracker tracker = procStore.getActiveLogs().get(i).getTracker();
assertTrue(tracker != null && !tracker.isEmpty());
}
}
use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure in project hbase by apache.
the class TestWALProcedureStore method testLoadChildren.
@Test
public void testLoadChildren() throws Exception {
TestProcedure a = new TestProcedure(1, 0);
TestProcedure b = new TestProcedure(2, 1);
TestProcedure c = new TestProcedure(3, 1);
// INIT
procStore.insert(a, null);
// Run A first step
a.addStackId(0);
procStore.update(a);
// Run A second step
a.addStackId(1);
procStore.insert(a, new Procedure[] { b, c });
// Run B first step
b.addStackId(2);
procStore.update(b);
// Run C first and last step
c.addStackId(3);
procStore.update(c);
// Run B second setp
b.addStackId(4);
procStore.update(b);
// back to A
a.addStackId(5);
a.setFinishedState();
procStore.delete(a, new long[] { b.getProcId(), c.getProcId() });
restartAndAssert(3, 0, 1, 0);
}
use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure in project hbase by apache.
the class TestMasterProcedureWalLease method testWALfencing.
public void testWALfencing(boolean walRolls) throws IOException {
final ProcedureStore procStore = getMasterProcedureExecutor().getStore();
assertTrue("expected WALStore for this test", procStore instanceof WALProcedureStore);
HMaster firstMaster = UTIL.getHBaseCluster().getMaster();
// cause WAL rolling after a delete in WAL:
firstMaster.getConfiguration().setLong(WALProcedureStore.ROLL_THRESHOLD_CONF_KEY, 1);
HMaster backupMaster3 = Mockito.mock(HMaster.class);
Mockito.doReturn(firstMaster.getConfiguration()).when(backupMaster3).getConfiguration();
Mockito.doReturn(true).when(backupMaster3).isActiveMaster();
final WALProcedureStore procStore2 = new WALProcedureStore(firstMaster.getConfiguration(), firstMaster.getMasterFileSystem().getFileSystem(), ((WALProcedureStore) procStore).getWALDir(), new MasterProcedureEnv.WALStoreLeaseRecovery(backupMaster3));
// start a second store which should fence the first one out
LOG.info("Starting new WALProcedureStore");
procStore2.start(1);
procStore2.recoverLease();
// to delete the old WAL files).
if (walRolls) {
LOG.info("Inserting into second WALProcedureStore, causing WAL rolls");
for (int i = 0; i < 512; i++) {
// insert something to the second store then delete it, causing a WAL roll(s)
Procedure proc2 = new TestProcedure(i);
procStore2.insert(proc2, null);
// delete the procedure so that the WAL is removed later
procStore2.delete(proc2.getProcId());
}
}
// Now, insert something to the first store, should fail.
// If the store does a WAL roll and continue with another logId without checking higher logIds
// it will incorrectly succeed.
LOG.info("Inserting into first WALProcedureStore");
try {
procStore.insert(new TestProcedure(11), null);
fail("Inserting into Procedure Store should have failed");
} catch (Exception ex) {
LOG.info("Received expected exception", ex);
}
}
use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure in project hbase by apache.
the class TestWALProcedureStore method testCorruptedProcedures.
@Test
public void testCorruptedProcedures() throws Exception {
// Insert root-procedures
TestProcedure[] rootProcs = new TestProcedure[10];
for (int i = 1; i <= rootProcs.length; i++) {
rootProcs[i - 1] = new TestProcedure(i, 0);
procStore.insert(rootProcs[i - 1], null);
rootProcs[i - 1].addStackId(0);
procStore.update(rootProcs[i - 1]);
}
// insert root-child txn
procStore.rollWriterForTesting();
for (int i = 1; i <= rootProcs.length; i++) {
TestProcedure b = new TestProcedure(rootProcs.length + i, i);
rootProcs[i - 1].addStackId(1);
procStore.insert(rootProcs[i - 1], new Procedure[] { b });
}
// insert child updates
procStore.rollWriterForTesting();
for (int i = 1; i <= rootProcs.length; i++) {
procStore.update(new TestProcedure(rootProcs.length + i, i));
}
// Stop the store
procStore.stop(false);
// the first log was removed,
// we have insert-txn and updates in the others so everything is fine
FileStatus[] logs = fs.listStatus(logDir);
assertEquals(Arrays.toString(logs), 2, logs.length);
Arrays.sort(logs, new Comparator<FileStatus>() {
@Override
public int compare(FileStatus o1, FileStatus o2) {
return o1.getPath().getName().compareTo(o2.getPath().getName());
}
});
LoadCounter loader = new LoadCounter();
storeRestart(loader);
assertEquals(rootProcs.length * 2, loader.getLoadedCount());
assertEquals(0, loader.getCorruptedCount());
// Remove the second log, we have lost all the root/parent references
fs.delete(logs[0].getPath(), false);
loader.reset();
storeRestart(loader);
assertEquals(0, loader.getLoadedCount());
assertEquals(rootProcs.length, loader.getCorruptedCount());
for (Procedure proc : loader.getCorrupted()) {
assertTrue(proc.toString(), proc.getParentProcId() <= rootProcs.length);
assertTrue(proc.toString(), proc.getProcId() > rootProcs.length && proc.getProcId() <= (rootProcs.length * 2));
}
}
use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure in project hbase by apache.
the class TestWALProcedureStore method testBatchInsert.
@Test
public void testBatchInsert() throws Exception {
final int count = 10;
final TestProcedure[] procs = new TestProcedure[count];
for (int i = 0; i < procs.length; ++i) {
procs[i] = new TestProcedure(i + 1);
}
procStore.insert(procs);
restartAndAssert(count, count, 0, 0);
for (int i = 0; i < procs.length; ++i) {
final long procId = procs[i].getProcId();
procStore.delete(procId);
restartAndAssert(procId != count ? count : 0, count - (i + 1), 0, 0);
}
procStore.removeInactiveLogsForTesting();
assertEquals("WALs=" + procStore.getActiveLogs(), 1, procStore.getActiveLogs().size());
}
Aggregations