Search in sources :

Example 1 with CheckpointInputStream

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

the class JournalUtilsTest method checkpointAndRestore.

@Test
public void checkpointAndRestore() throws IOException, InterruptedException {
    Journaled journaled = new TestJournaled(0);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JournalUtils.writeJournalEntryCheckpoint(baos, journaled);
    JournalUtils.restoreJournalEntryCheckpoint(new CheckpointInputStream(new ByteArrayInputStream(baos.toByteArray())), journaled);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CheckpointInputStream(alluxio.master.journal.checkpoint.CheckpointInputStream) Test(org.junit.Test)

Example 2 with CheckpointInputStream

use of alluxio.master.journal.checkpoint.CheckpointInputStream 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 3 with CheckpointInputStream

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

the class JournalStateMachine method install.

private void install(File snapshotFile) {
    if (mClosed) {
        return;
    }
    if (mIgnoreApplys) {
        LOG.warn("Unexpected request to install a snapshot on a read-only journal state machine");
        return;
    }
    long snapshotId = 0L;
    try (Timer.Context ctx = MetricsSystem.timer(MetricKey.MASTER_EMBEDDED_JOURNAL_SNAPSHOT_REPLAY_TIMER.getName()).time();
        DataInputStream stream = new DataInputStream(new FileInputStream(snapshotFile))) {
        snapshotId = stream.readLong();
        JournalUtils.restoreFromCheckpoint(new CheckpointInputStream(stream), getStateMachines());
    } catch (Exception e) {
        JournalUtils.handleJournalReplayFailure(LOG, e, "Failed to install snapshot: %s", snapshotId);
        if (ServerConfiguration.getBoolean(PropertyKey.MASTER_JOURNAL_TOLERATE_CORRUPTION)) {
            return;
        }
    }
    if (snapshotId < mNextSequenceNumberToRead - 1) {
        LOG.warn("Installed snapshot for SN {} but next SN to read is {}", snapshotId, mNextSequenceNumberToRead);
    }
    mNextSequenceNumberToRead = snapshotId + 1;
    LOG.info("Successfully installed snapshot up to SN {}", snapshotId);
}
Also used : Timer(com.codahale.metrics.Timer) DataInputStream(java.io.DataInputStream) CheckpointInputStream(alluxio.master.journal.checkpoint.CheckpointInputStream) FileInputStream(java.io.FileInputStream) CompletionException(java.util.concurrent.CompletionException) FileNotFoundException(java.io.FileNotFoundException) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException)

Example 4 with CheckpointInputStream

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

the class UfsJournalReader method updateInputStream.

/**
 * Updates the journal input stream by closing the current journal input stream if it is done and
 * opening a new one.
 */
private void updateInputStream() throws IOException {
    if (mInputStream != null && (mInputStream.mFile.isIncompleteLog() || !mInputStream.isDone(mNextSequenceNumber))) {
        return;
    }
    if (mInputStream != null) {
        mInputStream.close();
        mInputStream = null;
    }
    if (mFilesToProcess.isEmpty()) {
        UfsJournalSnapshot snapshot = UfsJournalSnapshot.getSnapshot(mJournal);
        if (snapshot.getCheckpoints().isEmpty() && snapshot.getLogs().isEmpty()) {
            return;
        }
        int index = 0;
        if (!snapshot.getCheckpoints().isEmpty()) {
            UfsJournalFile checkpoint = snapshot.getLatestCheckpoint();
            if (mNextSequenceNumber < checkpoint.getEnd()) {
                String location = checkpoint.getLocation().toString();
                LOG.info("Reading checkpoint {}", location);
                mCheckpointStream = new CheckpointInputStream(mUfs.open(location, OpenOptions.defaults().setRecoverFailedOpen(true)));
                mNextSequenceNumber = checkpoint.getEnd();
            }
            for (; index < snapshot.getLogs().size(); index++) {
                UfsJournalFile file = snapshot.getLogs().get(index);
                if (file.getEnd() > checkpoint.getEnd()) {
                    break;
                }
            }
        // index now points to the first log with mEnd > checkpoint.mEnd.
        }
        for (; index < snapshot.getLogs().size(); index++) {
            UfsJournalFile file = snapshot.getLogs().get(index);
            if ((!mReadIncompleteLog && file.isIncompleteLog()) || mNextSequenceNumber >= file.getEnd()) {
                continue;
            }
            mFilesToProcess.add(snapshot.getLogs().get(index));
        }
    }
    if (!mFilesToProcess.isEmpty()) {
        mInputStream = new JournalInputStream(mFilesToProcess.poll(), mUfs);
    }
}
Also used : CheckpointInputStream(alluxio.master.journal.checkpoint.CheckpointInputStream)

Example 5 with CheckpointInputStream

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

the class JournalUtilsTest method checkpointAndRestoreComponents.

@Test
public void checkpointAndRestoreComponents() throws Exception {
    List<TestJournaled> components = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        components.add(new TestJournaled(i));
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JournalUtils.writeToCheckpoint(baos, components);
    components.forEach(c -> assertEquals(0, c.getNumEntriesProcessed()));
    JournalUtils.restoreFromCheckpoint(new CheckpointInputStream(new ByteArrayInputStream(baos.toByteArray())), components);
    components.forEach(c -> assertEquals(1, c.getNumEntriesProcessed()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CheckpointInputStream(alluxio.master.journal.checkpoint.CheckpointInputStream) Test(org.junit.Test)

Aggregations

CheckpointInputStream (alluxio.master.journal.checkpoint.CheckpointInputStream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Test (org.junit.Test)5 FileInputStream (java.io.FileInputStream)3 BufferedOutputStream (java.io.BufferedOutputStream)2 DataInputStream (java.io.DataInputStream)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 UnavailableException (alluxio.exception.status.UnavailableException)1 NoopMaster (alluxio.master.NoopMaster)1 MutableInodeDirectory (alluxio.master.file.meta.MutableInodeDirectory)1 JournalReader (alluxio.master.journal.JournalReader)1 CheckpointOutputStream (alluxio.master.journal.checkpoint.CheckpointOutputStream)1 UfsJournal (alluxio.master.journal.ufs.UfsJournal)1 UfsJournalReader (alluxio.master.journal.ufs.UfsJournalReader)1 UfsJournalSystem (alluxio.master.journal.ufs.UfsJournalSystem)1 Journal (alluxio.proto.journal.Journal)1