Search in sources :

Example 6 with JournalReader

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

the class UfsJournalReaderTest method readIncompleteLogSecondary.

/**
 * Secondary master cannot read incomplete logs.
 */
@Test
public void readIncompleteLogSecondary() throws Exception {
    long endSN = 10;
    buildCompletedLog(0, endSN);
    buildIncompleteLog(endSN, endSN + 1);
    try (JournalReader reader = mJournal.getReader(false)) {
        int sn = 0;
        while (reader.advance() != State.DONE) {
            assertEquals(sn, reader.getEntry().getSequenceNumber());
            sn++;
        }
        assertEquals(endSN, sn);
        assertEquals(sn, reader.getNextSequenceNumber());
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Example 7 with JournalReader

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

the class UfsJournalReaderTest method readCheckpoint.

/**
 * Reads checkpoint.
 */
@Test
public void readCheckpoint() throws Exception {
    long endSN = CHECKPOINT_SIZE;
    byte[] checkpointBytes = buildCheckpoint(endSN);
    try (JournalReader reader = mJournal.getReader(true)) {
        State state;
        boolean foundCheckpoint = false;
        while ((state = reader.advance()) != State.DONE) {
            switch(state) {
                case CHECKPOINT:
                    foundCheckpoint = true;
                    assertArrayEquals(checkpointBytes, IOUtils.toByteArray(reader.getCheckpoint()));
                    break;
                case LOG:
                case DONE:
                default:
                    throw new IllegalStateException("Unexpected state: " + state);
            }
        }
        assertTrue(foundCheckpoint);
        assertEquals(endSN, reader.getNextSequenceNumber());
    }
}
Also used : State(alluxio.master.journal.JournalReader.State) JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Example 8 with JournalReader

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

the class UfsJournalReaderTest method readIncompleteLogPrimary.

/**
 * Reads incomplete logs in a primary master.
 */
@Test
public void readIncompleteLogPrimary() throws Exception {
    long endSN = 10;
    buildCompletedLog(0, endSN);
    buildIncompleteLog(endSN, endSN + 1);
    try (JournalReader reader = mJournal.getReader(true)) {
        int sn = 0;
        while (reader.advance() != State.DONE) {
            assertEquals(sn, reader.getEntry().getSequenceNumber());
            sn++;
        }
        assertEquals(endSN + 1, sn);
        assertEquals(sn, reader.getNextSequenceNumber());
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader) Test(org.junit.Test)

Example 9 with JournalReader

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

the class UfsJournalReaderTest method readCheckpointAndLogsSnNotMatch.

/**
 * Reads checkpoint and logs. The checkpoint's last sequence number does not match any one of
 * the logs' sequence number.
 */
@Test
public void readCheckpointAndLogsSnNotMatch() throws Exception {
    long fileSize = 10;
    buildCheckpoint(fileSize * 3 + 1);
    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 10 with JournalReader

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

the class UfsJournalLogWriterTest method checkJournalEntries.

/**
 * Checks that journal entries with sequence number between startSN (inclusive) and endSN
 * (exclusive) exist in the current journal files.
 *
 * @param startSN start sequence number (inclusive)
 * @param endSN end sequence number (exclusive)
 */
private void checkJournalEntries(long startSN, long endSN) throws IOException, InvalidJournalEntryException {
    try (JournalReader reader = new UfsJournalReader(mJournal, startSN, true)) {
        long seq = startSN;
        while (reader.advance() == State.LOG) {
            Assert.assertEquals(seq, reader.getEntry().getSequenceNumber());
            seq++;
        }
        Assert.assertEquals(endSN, seq);
    }
}
Also used : JournalReader(alluxio.master.journal.JournalReader)

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