Search in sources :

Example 1 with LoadCounter

use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter in project hbase by apache.

the class TestWALProcedureStore method testProcIdHoles.

@Test
public void testProcIdHoles() throws Exception {
    // Insert
    for (int i = 0; i < 100; i += 2) {
        procStore.insert(new TestProcedure(i), null);
        if (i > 0 && (i % 10) == 0) {
            LoadCounter loader = new LoadCounter();
            storeRestart(loader);
            assertEquals(0, loader.getCorruptedCount());
            assertEquals((i / 2) + 1, loader.getLoadedCount());
        }
    }
    assertEquals(10, procStore.getActiveLogs().size());
    // Delete
    for (int i = 0; i < 100; i += 2) {
        procStore.delete(i);
    }
    assertEquals(1, procStore.getActiveLogs().size());
    LoadCounter loader = new LoadCounter();
    storeRestart(loader);
    assertEquals(0, loader.getLoadedCount());
    assertEquals(0, loader.getCorruptedCount());
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) Test(org.junit.Test)

Example 2 with LoadCounter

use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter in project hbase by apache.

the class TestWALProcedureStore method testCorruptedTrailer.

@Test
public void testCorruptedTrailer() throws Exception {
    // Insert something
    for (int i = 0; i < 100; ++i) {
        procStore.insert(new TestSequentialProcedure(), null);
    }
    // Stop the store
    procStore.stop(false);
    // Remove 4 byte from the trailer
    FileStatus[] logs = fs.listStatus(logDir);
    assertEquals(1, logs.length);
    corruptLog(logs[0], 4);
    LoadCounter loader = new LoadCounter();
    storeRestart(loader);
    assertEquals(100, loader.getLoadedCount());
    assertEquals(0, loader.getCorruptedCount());
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) Test(org.junit.Test)

Example 3 with LoadCounter

use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter in project hbase by apache.

the class TestWALProcedureStore method testBatchDelete.

@Test
public void testBatchDelete() throws Exception {
    for (int i = 1; i < 10; ++i) {
        procStore.insert(new TestProcedure(i), null);
    }
    // delete nothing
    long[] toDelete = new long[] { 1, 2, 3, 4 };
    procStore.delete(toDelete, 2, 0);
    LoadCounter loader = restartAndAssert(9, 9, 0, 0);
    for (int i = 1; i < 10; ++i) {
        assertEquals(true, loader.isRunnable(i));
    }
    // delete the full "toDelete" array (2, 4, 6, 8)
    toDelete = new long[] { 2, 4, 6, 8 };
    procStore.delete(toDelete, 0, toDelete.length);
    loader = restartAndAssert(9, 5, 0, 0);
    for (int i = 1; i < 10; ++i) {
        assertEquals(i % 2 != 0, loader.isRunnable(i));
    }
    // delete a slice of "toDelete" (1, 3)
    toDelete = new long[] { 5, 7, 1, 3, 9 };
    procStore.delete(toDelete, 2, 2);
    loader = restartAndAssert(9, 3, 0, 0);
    for (int i = 1; i < 10; ++i) {
        assertEquals(i > 3 && i % 2 != 0, loader.isRunnable(i));
    }
    // delete a single item (5)
    toDelete = new long[] { 5 };
    procStore.delete(toDelete, 0, 1);
    loader = restartAndAssert(9, 2, 0, 0);
    for (int i = 1; i < 10; ++i) {
        assertEquals(i > 5 && i % 2 != 0, loader.isRunnable(i));
    }
    // delete remaining using a slice of "toDelete" (7, 9)
    toDelete = new long[] { 0, 7, 9 };
    procStore.delete(toDelete, 1, 2);
    loader = restartAndAssert(0, 0, 0, 0);
    for (int i = 1; i < 10; ++i) {
        assertEquals(false, loader.isRunnable(i));
    }
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) Test(org.junit.Test)

Example 4 with LoadCounter

use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter in project hbase by apache.

the class TestWALProcedureStore method verifyProcIdsOnRestart.

private void verifyProcIdsOnRestart(final Set<Long> procIds) throws Exception {
    LOG.debug("expected: " + procIds);
    LoadCounter loader = new LoadCounter();
    storeRestart(loader);
    assertEquals(procIds.size(), loader.getLoadedCount());
    assertEquals(0, loader.getCorruptedCount());
}
Also used : LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter)

Example 5 with LoadCounter

use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter in project hbase by apache.

the class TestWALProcedureStore method testFileNotFoundDuringLeaseRecovery.

@Test
public void testFileNotFoundDuringLeaseRecovery() throws IOException {
    final TestProcedure[] procs = new TestProcedure[3];
    for (int i = 0; i < procs.length; ++i) {
        procs[i] = new TestProcedure(i + 1, 0);
        procStore.insert(procs[i], null);
    }
    procStore.rollWriterForTesting();
    for (int i = 0; i < procs.length; ++i) {
        procStore.update(procs[i]);
        procStore.rollWriterForTesting();
    }
    procStore.stop(false);
    FileStatus[] status = fs.listStatus(logDir);
    assertEquals(procs.length + 1, status.length);
    // simulate another active master removing the wals
    procStore = new WALProcedureStore(htu.getConfiguration(), fs, logDir, new WALProcedureStore.LeaseRecovery() {

        private int count = 0;

        @Override
        public void recoverFileLease(FileSystem fs, Path path) throws IOException {
            if (++count <= 2) {
                fs.delete(path, false);
                LOG.debug("Simulate FileNotFound at count=" + count + " for " + path);
                throw new FileNotFoundException("test file not found " + path);
            }
            LOG.debug("Simulate recoverFileLease() at count=" + count + " for " + path);
        }
    });
    final LoadCounter loader = new LoadCounter();
    procStore.start(PROCEDURE_STORE_SLOTS);
    procStore.recoverLease();
    procStore.load(loader);
    assertEquals(procs.length, loader.getMaxProcId());
    assertEquals(1, loader.getRunnableCount());
    assertEquals(0, loader.getCompletedCount());
    assertEquals(0, loader.getCorruptedCount());
}
Also used : Path(org.apache.hadoop.fs.Path) TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) FileStatus(org.apache.hadoop.fs.FileStatus) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Aggregations

LoadCounter (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter)14 Test (org.junit.Test)11 FileStatus (org.apache.hadoop.fs.FileStatus)7 TestProcedure (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure)7 Path (org.apache.hadoop.fs.Path)3 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)3 SequentialProcedure (org.apache.hadoop.hbase.procedure2.SequentialProcedure)3 HBaseCommonTestingUtility (org.apache.hadoop.hbase.HBaseCommonTestingUtility)2 Before (org.junit.Before)2 FileNotFoundException (java.io.FileNotFoundException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 ProcedureStoreTracker (org.apache.hadoop.hbase.procedure2.store.ProcedureStoreTracker)1