Search in sources :

Example 6 with CheckpointMetadata

use of org.apache.bookkeeper.stream.proto.kv.store.CheckpointMetadata in project bookkeeper by apache.

the class RocksCheckpointerTest method testRestoreCleanupCheckpoints.

@Test
public void testRestoreCleanupCheckpoints() throws Exception {
    // create 3 checkpoints and leave them locally
    List<String> checkpointIds = createMultipleCheckpoints(3, false, false);
    store.close();
    List<String> remoteCheckpoints = checkpointStore.listFiles(RocksUtils.getDestCheckpointsPath(store.name()));
    assertEquals(checkpointIds.size(), remoteCheckpoints.size());
    for (String checkpoint : checkpointIds) {
        assertTrue(remoteCheckpoints.contains(checkpoint));
        assertTrue(new File(localCheckpointsDir, checkpoint).exists());
    }
    // restore from checkpoints
    CheckpointMetadata metadata = RocksCheckpointer.restore(store.name(), localDir, checkpointStore);
    assertNotNull(metadata);
    assertArrayEquals("checkpoint-2".getBytes(UTF_8), metadata.getTxid().toByteArray());
    for (int i = 0; i < 3; i++) {
        String checkpoint = checkpointIds.get(i);
        if (i == 2) {
            assertTrue(new File(localCheckpointsDir, checkpoint).exists());
        } else {
            assertFalse(new File(localCheckpointsDir, checkpoint).exists());
        }
        assertTrue(checkpointStore.fileExists(RocksUtils.getDestCheckpointPath(store.name(), checkpoint)));
    }
    // restore from the latest checkpoint
    store = new RocksdbKVStore<>();
    store.init(spec);
    verifyNumKvs(300);
}
Also used : File(java.io.File) CheckpointMetadata(org.apache.bookkeeper.stream.proto.kv.store.CheckpointMetadata) Checkpoint(org.rocksdb.Checkpoint) Test(org.junit.Test)

Aggregations

CheckpointMetadata (org.apache.bookkeeper.stream.proto.kv.store.CheckpointMetadata)6 File (java.io.File)5 Test (org.junit.Test)4 Checkpoint (org.rocksdb.Checkpoint)4 InputStream (java.io.InputStream)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Cleanup (lombok.Cleanup)1 StateStoreException (org.apache.bookkeeper.statelib.api.exceptions.StateStoreException)1