Search in sources :

Example 1 with LogSegmentPath

use of org.apache.ratis.server.raftlog.segmented.LogSegmentPath in project alluxio by Alluxio.

the class RaftJournalDumper method readRatisLogFromDir.

private void readRatisLogFromDir() {
    try (PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(mJournalEntryFile)));
        RaftStorage storage = new RaftStorageImpl(getJournalDir(), RaftServerConfigKeys.Log.CorruptionPolicy.getDefault())) {
        List<LogSegmentPath> paths = LogSegmentPath.getLogSegmentPaths(storage);
        for (LogSegmentPath path : paths) {
            final int entryCount = LogSegment.readSegmentFile(path.getPath().toFile(), path.getStartEnd(), RaftServerConfigKeys.Log.CorruptionPolicy.EXCEPTION, null, (proto) -> {
                if (proto.hasStateMachineLogEntry()) {
                    try {
                        Journal.JournalEntry entry = Journal.JournalEntry.parseFrom(proto.getStateMachineLogEntry().getLogData().asReadOnlyByteBuffer());
                        writeSelected(out, entry);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            LOG.info("Read {} entries from log {}.", entryCount, path.getPath());
        }
    } catch (Exception e) {
        LOG.error("Failed to read logs from journal.", e);
    }
}
Also used : PrintStream(java.io.PrintStream) RaftStorage(org.apache.ratis.server.storage.RaftStorage) FileOutputStream(java.io.FileOutputStream) LogSegmentPath(org.apache.ratis.server.raftlog.segmented.LogSegmentPath) Journal(alluxio.proto.journal.Journal) RaftStorageImpl(org.apache.ratis.server.storage.RaftStorageImpl) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Journal (alluxio.proto.journal.Journal)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 LogSegmentPath (org.apache.ratis.server.raftlog.segmented.LogSegmentPath)1 RaftStorage (org.apache.ratis.server.storage.RaftStorage)1 RaftStorageImpl (org.apache.ratis.server.storage.RaftStorageImpl)1