Search in sources :

Example 1 with CheckpointOutputStream

use of alluxio.master.journal.checkpoint.CheckpointOutputStream in project alluxio by Alluxio.

the class JournalUtilsTest method restoreInvalidJournalEntryCheckpoint.

@Test
public void restoreInvalidJournalEntryCheckpoint() throws IOException {
    Journaled journaled = new TestJournaled(0);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Checkpoint version doesn't match Constants.JOURNAL_ENTRY_CHECKPOINT_VERSION.
    CheckpointOutputStream cos = new CheckpointOutputStream(baos, CheckpointType.COMPOUND);
    cos.flush();
    mThrown.expect(IllegalStateException.class);
    mThrown.expectMessage("Unrecognized checkpoint type");
    JournalUtils.restoreJournalEntryCheckpoint(new CheckpointInputStream(new ByteArrayInputStream(baos.toByteArray())), journaled);
}
Also used : CheckpointOutputStream(alluxio.master.journal.checkpoint.CheckpointOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CheckpointInputStream(alluxio.master.journal.checkpoint.CheckpointInputStream) Test(org.junit.Test)

Example 2 with CheckpointOutputStream

use of alluxio.master.journal.checkpoint.CheckpointOutputStream in project alluxio by Alluxio.

the class JournalUtils method writeJournalEntryCheckpoint.

/**
 * Writes a checkpoint of the entries in the given iterable.
 *
 * This is the complement of
 * {@link #restoreJournalEntryCheckpoint(CheckpointInputStream, Journaled)}.
 *
 * @param output the stream to write to
 * @param iterable the iterable for fetching journal entries
 */
public static void writeJournalEntryCheckpoint(OutputStream output, JournalEntryIterable iterable) throws IOException, InterruptedException {
    output = new CheckpointOutputStream(output, CheckpointType.JOURNAL_ENTRY);
    try (CloseableIterator<JournalEntry> it = iterable.getJournalEntryIterator()) {
        LOG.info("Write journal entry checkpoint");
        while (it.get().hasNext()) {
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
            it.get().next().writeDelimitedTo(output);
        }
    }
    output.flush();
}
Also used : CheckpointOutputStream(alluxio.master.journal.checkpoint.CheckpointOutputStream) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 3 with CheckpointOutputStream

use of alluxio.master.journal.checkpoint.CheckpointOutputStream in project alluxio by Alluxio.

the class JournalUtils method writeToCheckpoint.

/**
 * Writes a composite checkpoint for the given checkpointed components.
 *
 * This is the complement of {@link #restoreFromCheckpoint(CheckpointInputStream, List)}.
 *
 * @param output the stream to write to
 * @param components the components to checkpoint
 */
public static void writeToCheckpoint(OutputStream output, List<? extends Checkpointed> components) throws IOException, InterruptedException {
    OutputChunked chunked = new OutputChunked(new CheckpointOutputStream(output, CheckpointType.COMPOUND), 64 * Constants.KB);
    for (Checkpointed component : components) {
        chunked.writeString(component.getCheckpointName().toString());
        component.writeToCheckpoint(chunked);
        chunked.endChunks();
    }
    chunked.flush();
}
Also used : CheckpointOutputStream(alluxio.master.journal.checkpoint.CheckpointOutputStream) Checkpointed(alluxio.master.journal.checkpoint.Checkpointed) OutputChunked(com.esotericsoftware.kryo.io.OutputChunked)

Example 4 with CheckpointOutputStream

use of alluxio.master.journal.checkpoint.CheckpointOutputStream in project alluxio by Alluxio.

the class InodeCounter method writeToCheckpoint.

@Override
public void writeToCheckpoint(OutputStream output) throws IOException, InterruptedException {
    CheckpointOutputStream stream = new CheckpointOutputStream(output, CheckpointType.LONG);
    stream.writeLong(longValue());
    stream.flush();
}
Also used : CheckpointOutputStream(alluxio.master.journal.checkpoint.CheckpointOutputStream)

Example 5 with CheckpointOutputStream

use of alluxio.master.journal.checkpoint.CheckpointOutputStream in project alluxio by Alluxio.

the class RocksStore method writeToCheckpoint.

/**
 * Writes a checkpoint of the database's content to the given output stream.
 *
 * @param output the stream to write to
 */
public synchronized void writeToCheckpoint(OutputStream output) throws IOException, InterruptedException {
    LOG.info("Creating rocksdb checkpoint at {}", mDbCheckpointPath);
    long startNano = System.nanoTime();
    CheckpointOutputStream out = new CheckpointOutputStream(output, CheckpointType.ROCKS);
    try {
        // createCheckpoint requires that the directory not already exist.
        FileUtils.deletePathRecursively(mDbCheckpointPath);
        mCheckpoint.createCheckpoint(mDbCheckpointPath);
    } catch (RocksDBException e) {
        throw new IOException(e);
    }
    LOG.info("Checkpoint complete, creating tarball");
    TarUtils.writeTarGz(Paths.get(mDbCheckpointPath), out);
    LOG.info("Completed rocksdb checkpoint in {}ms", (System.nanoTime() - startNano) / 1_000_000);
    // Checkpoint is no longer needed, delete to save space.
    FileUtils.deletePathRecursively(mDbCheckpointPath);
}
Also used : RocksDBException(org.rocksdb.RocksDBException) CheckpointOutputStream(alluxio.master.journal.checkpoint.CheckpointOutputStream) IOException(java.io.IOException)

Aggregations

CheckpointOutputStream (alluxio.master.journal.checkpoint.CheckpointOutputStream)6 CheckpointInputStream (alluxio.master.journal.checkpoint.CheckpointInputStream)1 Checkpointed (alluxio.master.journal.checkpoint.Checkpointed)1 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)1 OutputChunked (com.esotericsoftware.kryo.io.OutputChunked)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 RocksDBException (org.rocksdb.RocksDBException)1