Search in sources :

Example 1 with Checkpointed

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

the class JournalUtils method restoreFromCheckpoint.

/**
 * Restores the given checkpointed components from a composite checkpoint.
 *
 * This is the complement of {@link #writeToCheckpoint(OutputStream, List)}.
 *
 * @param input the stream to read from
 * @param components the components to restore
 */
public static void restoreFromCheckpoint(CheckpointInputStream input, List<? extends Checkpointed> components) throws IOException {
    CompoundCheckpointReader reader = new CompoundCheckpointReader(input);
    Optional<Entry> next;
    while ((next = reader.nextCheckpoint()).isPresent()) {
        Entry nextEntry = next.get();
        boolean found = false;
        for (Checkpointed component : components) {
            if (component.getCheckpointName().equals(nextEntry.getName())) {
                component.restoreFromCheckpoint(nextEntry.getStream());
                found = true;
                break;
            }
        }
        if (!found) {
            throw new RuntimeException(String.format("Unrecognized checkpoint name: %s. Existing components: %s", nextEntry.getName(), Arrays.toString(StreamUtils.map(Checkpointed::getCheckpointName, components).toArray())));
        }
    }
}
Also used : Entry(alluxio.master.journal.checkpoint.CompoundCheckpointFormat.CompoundCheckpointReader.Entry) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) Checkpointed(alluxio.master.journal.checkpoint.Checkpointed) CompoundCheckpointReader(alluxio.master.journal.checkpoint.CompoundCheckpointFormat.CompoundCheckpointReader)

Example 2 with Checkpointed

use of alluxio.master.journal.checkpoint.Checkpointed 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)

Aggregations

Checkpointed (alluxio.master.journal.checkpoint.Checkpointed)2 CheckpointOutputStream (alluxio.master.journal.checkpoint.CheckpointOutputStream)1 CompoundCheckpointReader (alluxio.master.journal.checkpoint.CompoundCheckpointFormat.CompoundCheckpointReader)1 Entry (alluxio.master.journal.checkpoint.CompoundCheckpointFormat.CompoundCheckpointReader.Entry)1 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)1 OutputChunked (com.esotericsoftware.kryo.io.OutputChunked)1