Search in sources :

Example 11 with JournalReader

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

the class UfsJournalDumper method dumpJournal.

@Override
public void dumpJournal() throws Throwable {
    try (UfsJournal journal = new UfsJournalSystem(getJournalLocation(mInputDir), 0).createJournal(new NoopMaster(mMaster));
        PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(mJournalEntryFile)));
        JournalReader reader = new UfsJournalReader(journal, mStart, true)) {
        boolean done = false;
        while (!done && reader.getNextSequenceNumber() < mEnd) {
            JournalReader.State state = reader.advance();
            switch(state) {
                case CHECKPOINT:
                    try (CheckpointInputStream checkpoint = reader.getCheckpoint()) {
                        Path dir = Paths.get(mCheckpointsDir + "-" + reader.getNextSequenceNumber());
                        Files.createDirectories(dir);
                        readCheckpoint(checkpoint, dir);
                    }
                    break;
                case LOG:
                    Journal.JournalEntry entry = reader.getEntry();
                    out.println(ENTRY_SEPARATOR);
                    out.print(entry);
                    break;
                case DONE:
                    done = true;
                    break;
                default:
                    throw new RuntimeException("Unknown state: " + state);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) UfsJournal(alluxio.master.journal.ufs.UfsJournal) Journal(alluxio.proto.journal.Journal) CheckpointInputStream(alluxio.master.journal.checkpoint.CheckpointInputStream) FileOutputStream(java.io.FileOutputStream) UfsJournalReader(alluxio.master.journal.ufs.UfsJournalReader) UfsJournalSystem(alluxio.master.journal.ufs.UfsJournalSystem) BufferedOutputStream(java.io.BufferedOutputStream) UfsJournal(alluxio.master.journal.ufs.UfsJournal) NoopMaster(alluxio.master.NoopMaster) JournalReader(alluxio.master.journal.JournalReader) UfsJournalReader(alluxio.master.journal.ufs.UfsJournalReader)

Example 12 with JournalReader

use of alluxio.master.journal.JournalReader in project SSM by Intel-bigdata.

the class AlluxioEntryFetcher method canReadFromLastSeqNum.

public static boolean canReadFromLastSeqNum(Long lastSn) {
    try {
        if (AlluxioJournalUtil.getCurrentSeqNum(conf) == lastSn) {
            return true;
        }
        JournalReader reader = AlluxioJournalUtil.getJournalReaderFromSn(conf, lastSn);
        JournalEntry entry = reader.read();
        return entry != null;
    } catch (Exception e) {
        return false;
    }
}
Also used : JournalEntry(alluxio.proto.journal.Journal.JournalEntry) InvalidJournalEntryException(alluxio.exception.InvalidJournalEntryException) IOException(java.io.IOException) MetaStoreException(org.smartdata.metastore.MetaStoreException) JournalReader(alluxio.master.journal.JournalReader)

Example 13 with JournalReader

use of alluxio.master.journal.JournalReader in project SSM by Intel-bigdata.

the class AlluxioJournalUtil method getJournalReaderFromSn.

/**
 * @param conf smart configuration
 * @param startSn journal entry sequence number
 * @return journal reader
 */
public static JournalReader getJournalReaderFromSn(SmartConf conf, Long startSn) {
    UfsJournal journal = new UfsJournalSystem(getJournalLocation(conf), 0).createJournal(new NoopMaster(sMaster));
    JournalReader reader = new UfsJournalReader(journal, startSn, true);
    return reader;
}
Also used : NoopMaster(alluxio.master.NoopMaster) JournalReader(alluxio.master.journal.JournalReader)

Example 14 with JournalReader

use of alluxio.master.journal.JournalReader in project SSM by Intel-bigdata.

the class AlluxioJournalUtil method getCurrentSeqNum.

/**
 * @param conf smart configuration
 * @return the current entry sequence number
 */
public static Long getCurrentSeqNum(SmartConf conf) {
    UfsJournal journal = new UfsJournalSystem(getJournalLocation(conf), 0).createJournal(new NoopMaster(sMaster));
    UfsJournalFile currentLog;
    try {
        currentLog = UfsJournalSnapshot.getCurrentLog(journal);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    long sn = -1L;
    if (currentLog != null) {
        try (JournalReader reader = new UfsJournalReader(journal, currentLog.getStart(), true)) {
            Journal.JournalEntry entry;
            while ((entry = reader.read()) != null) {
                sn = entry.getSequenceNumber();
                if (sn >= Long.MAX_VALUE) {
                    break;
                }
            }
        } catch (Exception e) {
            LOG.error("Failed to read next journal entry.", e);
        }
    }
    return sn;
}
Also used : Journal(alluxio.proto.journal.Journal) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NoopMaster(alluxio.master.NoopMaster) 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