Search in sources :

Example 1 with JournalReader

use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.

the class UfsJournalReaderTest method resumeReadingWithinCheckpoint.

/**
 * Reads checkpoint and logs from a non-zero sequence number. The given sequence number is within
 * the checkpoint.
 */
@Test
public void resumeReadingWithinCheckpoint() throws Exception {
    long fileSize = 10;
    buildCheckpoint(fileSize * 3);
    for (int i = 0; i < 10; i++) {
        buildCompletedLog(i * fileSize, (i + 1) * fileSize);
    }
    try (JournalReader reader = new UfsJournalReader(mJournal, fileSize * 2, true)) {
        while (reader.advance() != State.DONE) {
        }
        assertEquals(10 * fileSize, reader.getNextSequenceNumber());
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Example 2 with JournalReader

use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.

the class UfsJournalReaderTest method readCheckpointAndLogsSnMatch.

/**
 * Reads checkpoint and logs. The checkpoint's last sequence number matches one of
 * the logs' sequence number.
 */
@Test
public void readCheckpointAndLogsSnMatch() throws Exception {
    long fileSize = 10;
    buildCheckpoint(fileSize * 3);
    for (int i = 0; i < 10; i++) {
        buildCompletedLog(i * fileSize, (i + 1) * fileSize);
    }
    try (JournalReader reader = mJournal.getReader(true)) {
        while (reader.advance() != State.DONE) {
        }
        assertEquals(10 * fileSize, reader.getNextSequenceNumber());
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Example 3 with JournalReader

use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.

the class UfsJournalReaderTest method resumeReadingAfterCheckpoint.

/**
 * Reads checkpoint and logs from a non-zero sequence number. The given sequence number is after
 * the checkpoint.
 */
@Test
public void resumeReadingAfterCheckpoint() throws Exception {
    long fileSize = 10;
    buildCheckpoint(fileSize * 3);
    for (int i = 0; i < 10; i++) {
        buildCompletedLog(i * fileSize, (i + 1) * fileSize);
    }
    try (JournalReader reader = new UfsJournalReader(mJournal, fileSize * 3 + 1, true)) {
        while (reader.advance() != State.DONE) {
        }
        assertEquals(10 * fileSize, reader.getNextSequenceNumber());
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Example 4 with JournalReader

use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.

the class UfsJournalReaderTest method readCompletedLog.

/**
 * Reads completed logs.
 */
@Test
public void readCompletedLog() throws Exception {
    long fileSize = 10;
    long endSN = 10 * fileSize;
    for (long i = 0; i < endSN / fileSize; i++) {
        buildCompletedLog(i * fileSize, i * fileSize + fileSize);
    }
    try (JournalReader reader = mJournal.getReader(true)) {
        int sn = 0;
        while (reader.advance() != State.DONE) {
            assertEquals(sn, reader.getEntry().getSequenceNumber());
            sn++;
        }
        assertEquals(endSN, sn);
        assertEquals(sn, reader.getNextSequenceNumber());
        // Further advances should return State.DONE
        assertEquals(State.DONE, reader.advance());
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Example 5 with JournalReader

use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.

the class UfsJournalReaderTest method readNewLogs.

/**
 * Reads logs created while reading the journal.
 */
@Test
public void readNewLogs() throws Exception {
    long endSN = 10;
    buildCompletedLog(0, endSN);
    try (JournalReader reader = mJournal.getReader(true)) {
        int sn = 0;
        while (reader.advance() != State.DONE) {
            assertEquals(sn, reader.getEntry().getSequenceNumber());
            sn++;
        }
        assertEquals(endSN, sn);
        assertEquals(sn, reader.getNextSequenceNumber());
        // Write another two logs.
        buildCompletedLog(endSN, endSN * 2);
        buildIncompleteLog(endSN * 2, endSN * 2 + 1);
        while (reader.advance() != State.DONE) {
            assertEquals(sn, reader.getEntry().getSequenceNumber());
            sn++;
        }
        assertEquals(endSN * 2 + 1, sn);
        assertEquals(sn, reader.getNextSequenceNumber());
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Aggregations

JournalReader (alluxio.master.journal.JournalReader)14 Test (org.junit.Test)9 NoopMaster (alluxio.master.NoopMaster)3 Journal (alluxio.proto.journal.Journal)2 IOException (java.io.IOException)2 InvalidJournalEntryException (alluxio.exception.InvalidJournalEntryException)1 State (alluxio.master.journal.JournalReader.State)1 CheckpointInputStream (alluxio.master.journal.checkpoint.CheckpointInputStream)1 UfsJournal (alluxio.master.journal.ufs.UfsJournal)1 UfsJournalReader (alluxio.master.journal.ufs.UfsJournalReader)1 UfsJournalSystem (alluxio.master.journal.ufs.UfsJournalSystem)1 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1