Example usage for org.apache.hadoop.hdfs.server.namenode FSEditLogOp getTransactionId

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

Introduction

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

Prototype

public long getTransactionId() 

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  ww.  ja v a2 s .c  o  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);
        }
    }
}