Search in sources :

Example 11 with TestProcedure

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());
    }
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) ProcedureStoreTracker(org.apache.hadoop.hbase.procedure2.store.ProcedureStoreTracker) Test(org.junit.Test)

Example 12 with TestProcedure

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

Example 13 with TestProcedure

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);
    }
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) ProcedureStore(org.apache.hadoop.hbase.procedure2.store.ProcedureStore) WALProcedureStore(org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore) HMaster(org.apache.hadoop.hbase.master.HMaster) TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) WALProcedureStore(org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore) IOException(java.io.IOException)

Example 14 with TestProcedure

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));
    }
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) FileStatus(org.apache.hadoop.fs.FileStatus) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) SequentialProcedure(org.apache.hadoop.hbase.procedure2.SequentialProcedure) TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) Test(org.junit.Test)

Example 15 with TestProcedure

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

Aggregations

TestProcedure (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure)16 Test (org.junit.Test)15 LoadCounter (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter)5 ProcedureStore (org.apache.hadoop.hbase.procedure2.store.ProcedureStore)4 IOException (java.io.IOException)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)2 ProcedureIterator (org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureIterator)2 WALProcedureStore (org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore)2 FileNotFoundException (java.io.FileNotFoundException)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)1 HMaster (org.apache.hadoop.hbase.master.HMaster)1 SequentialProcedure (org.apache.hadoop.hbase.procedure2.SequentialProcedure)1 ProcedureStoreTracker (org.apache.hadoop.hbase.procedure2.store.ProcedureStoreTracker)1 ProcedureProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos)1