public LogEntryProto nextEntry()

in ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogInputStream.java [103:141]


  public LogEntryProto nextEntry() throws IOException {
    if (state.isUnopened()) {
        try {
          init();
        } catch (Exception e) {
          if (e.getCause() instanceof ClosedByInterruptException) {
            LOG.warn("Initialization is interrupted: {}", this, e);
          } else {
            LOG.error("Failed to initialize {}", this, e);
          }
          throw IOUtils.asIOException(e);
        }
    }

    Preconditions.assertTrue(!state.isUnopened());
    if (state.isOpened()) {
        final LogEntryProto entry = reader.readEntry();
        if (entry != null) {
          long index = entry.getIndex();
          if (!startEnd.isOpen() && index >= startEnd.getEndIndex()) {
            /*
             * The end index may be derived from the segment recovery
             * process. It is possible that we still have some uncleaned garbage
             * in the end. We should skip them.
             */
            long skipAmt = logFile.length() - reader.getPos();
            if (skipAmt > 0) {
              LOG.info("Skipping {} bytes at the end of log '{}': reached entry {} out of [{}]",
                  skipAmt, getName(), index, startEnd);
              reader.skipFully(skipAmt);
            }
          }
        }
        return entry;
    } else if (state.isClosed()) {
      return null;
    }
    throw new IOException("Failed to get next entry from " + this, state.getThrowable());
  }