@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DCN_NULLPOINTER_EXCEPTION",
        justification = "HDFS-4380")
    private WALStreamReader openReader(Path path, long startPosition) throws IOException {
      long retryInterval = 2000; // 2 sec
      int maxAttempts = 30;
      int attempt = 0;
      Exception ee = null;
      WALStreamReader reader = null;
      while (reader == null && attempt++ < maxAttempts) {
        try {
          // Detect if this is a new file, if so get a new reader else
          // reset the current reader so that we see the new data
          reader =
            WALFactory.createStreamReader(path.getFileSystem(conf), path, conf, startPosition);
          return reader;
        } catch (LeaseNotRecoveredException lnre) {
          // HBASE-15019 the WAL was not closed due to some hiccup.
          LOG.warn("Try to recover the WAL lease " + path, lnre);
          AbstractFSWALProvider.recoverLease(conf, path);
          reader = null;
          ee = lnre;
        } catch (NullPointerException npe) {
          // Workaround for race condition in HDFS-4380
          // which throws a NPE if we open a file before any data node has the most recent block
          // Just sleep and retry. Will require re-reading compressed WALs for compressionContext.
          LOG.warn("Got NPE opening reader, will retry.");
          reader = null;
          ee = npe;
        }
        if (reader == null) {
          // sleep before next attempt
          try {
            Thread.sleep(retryInterval);
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
          }
        }
      }
      throw new IOException("Could not open reader", ee);
    }
{@link RecordReader} for an {@link WAL} file. Implementation shared with deprecated
HLogInputFormat.
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/WALInputFormat.java