Example usage for org.apache.hadoop.hdfs.server.namenode EditLogFileInputStream EditLogFileInputStream

List of usage examples for org.apache.hadoop.hdfs.server.namenode EditLogFileInputStream EditLogFileInputStream

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.server.namenode EditLogFileInputStream EditLogFileInputStream.

Prototype

private EditLogFileInputStream(LogSource log, long firstTxId, long lastTxId, boolean isInProgress) 

Source Link

Usage

From source file:com.github.brandtg.switchboard.HdfsLogIndexer.java

License:Apache License

private void indexSegments(final EditLogType editLogType) throws IOException {
    File[] files = rootDir.listFiles(new FilenameFilter() {
        @Override/*from w  w  w  .  j a  v  a  2  s .co m*/
        public boolean accept(File dir, String name) {
            if (EditLogType.IN_PROGRESS.equals(editLogType)) {
                return name.startsWith("edits_inprogress");
            } else {
                return !name.startsWith("edits_inprogress") && name.startsWith("edits_");
            }
        }
    });

    if (files != null) {
        for (File file : files) {
            EditLogInputStream editLog;

            if (EditLogType.IN_PROGRESS.equals(editLogType)) {
                long startTxid = HdfsLogUtils.getInProgressLowWatermarkTxid(file.getName());
                long endTxid = -12345;
                editLog = new EditLogFileInputStream(file, startTxid, endTxid, true);
            } else {
                long startTxid = HdfsLogUtils.getLogHighWatermarkTxid(file.getName());
                long endTxid = HdfsLogUtils.getLogHighWatermarkTxid(file.getName());
                editLog = new EditLogFileInputStream(file, startTxid, endTxid, false);
            }

            FSEditLogOp op = null;
            long position = 0;
            while ((op = editLog.readOp()) != null) {
                LogRegion logRegion = new LogRegion(op.getTransactionId(), file.getAbsolutePath(), position,
                        editLog.getPosition());
                position = editLog.getPosition();
                logIndex.putLogRegion("*", logRegion);
            }

            LOG.info("Scanned {}", file);
        }
    }
}