Example usage for org.apache.hadoop.hdfs.server.namenode EditLogInputStream readOp

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

Introduction

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

Prototype

public FSEditLogOp readOp() throws IOException 

Source Link

Document

Read an operation from the stream

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/*ww  w .  j  a v a2  s .  c om*/
        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);
        }
    }
}