private void validateFileSpan(FileSpan fileSpan, boolean checkWithinSingleSegment) {
    if (getCurrentEndOffset().compareTo(fileSpan.getStartOffset()) > 0) {
      throw new IllegalArgumentException(
          "The start offset " + fileSpan.getStartOffset() + " of the FileSpan provided " + " to " + dataDir
              + " is lesser than the current index end offset " + getCurrentEndOffset());
    }
    if (checkWithinSingleSegment && !fileSpan.getStartOffset().getName().equals(fileSpan.getEndOffset().getName())) {
      throw new IllegalArgumentException(
          "The FileSpan provided [" + fileSpan + "] does not lie within a single log " + "segment");
    }
  }
Ensures that the provided {@link FileSpan} is greater than the current index end offset and, if required, that it
is within a single segment.
@param fileSpan The filespan that needs to be verified
@param checkWithinSingleSegment if {@code true}, checks whether the end and start offsets in {@code fileSpan} lie
                                in the same log segment.
ambry-store/src/main/java/com/github/ambry/store/PersistentIndex.java