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);
}
}
}
}
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;
}
}
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;
}
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;
}
Aggregations