void addToIndex(IndexEntry entry, FileSpan fileSpan) throws StoreException {
    validateFileSpan(fileSpan, true);
    if (needToRollOverIndex(entry)) {
      int valueSize = entry.getValue().getBytes().capacity();
      int entrySize = entry.getKey().sizeInBytes() + valueSize;
      IndexSegment info =
          new IndexSegment(dataDir, entry.getValue().getOffset(), factory, entrySize, valueSize, config, metrics, time);
      info.addEntry(entry, fileSpan.getEndOffset());
      // always add to both valid and in-flux index segment map to account for the fact that changeIndexSegments()
      // might be in the process of updating the reference to validIndexSegments
      validIndexSegments.put(info.getStartOffset(), info);
      inFluxIndexSegments.put(info.getStartOffset(), info);
    } else {
      validIndexSegments.lastEntry().getValue().addEntry(entry, fileSpan.getEndOffset());
    }
    journal.addEntry(entry.getValue().getOffset(), entry.getKey(), entry.getCrc());
  }
Adds a new entry to the index. For recovery, only the index segments belongs to last log segment should be put into
journal, otherwise it won't be compacted. And we will face the issue when last log segment is empty but journal size
is non-zero.
@param entry The entry to be added to the index
@param fileSpan The file span that this entry represents in the log
@throws StoreException
ambry-store/src/main/java/com/github/ambry/store/PersistentIndex.java