private Offset generateReferenceIndexSegmentStartOffset(Offset recordOffset) {
    if (referenceIndex.size() == 0) {
      return recordOffset;
    }

    Map.Entry<Offset, TreeMap<MockId, TreeSet<IndexValue>>> lastEntry = referenceIndex.lastEntry();
    Offset indexSegmentStartOffset = lastEntry.getKey();
    if (!indexSegmentStartOffset.getName().equals(recordOffset.getName())
        || lastEntry.getValue().size() == getMaxInMemElements()) {
      indexSegmentStartOffset = recordOffset;
    } else if (lastEntry.getValue().entrySet().iterator().next().getValue().iterator().next().getFormatVersion()
        != PersistentIndex.CURRENT_VERSION) {
      // the persistent index version changed.
      indexSegmentStartOffset = recordOffset;
    } else {
      final AtomicInteger numElements = new AtomicInteger(0);
      lastEntry.getValue().values().forEach(values -> numElements.addAndGet(values.size()));
      if (numElements.get() == getMaxInMemElements()) {
        indexSegmentStartOffset = recordOffset;
      }
    }
    return indexSegmentStartOffset;
  }
Given an offset, generates the start offset of the index segment that the record at that offset has to go to.
<p/>
Use only for the latest record - does not work for offsets that are below the current index end offset.
@param recordOffset the offset of the record being added to the index.
@return the index segment start offset of the index segment that the record belongs to.
ambry-store/src/test/java/com/github/ambry/store/CuratedLogIndexState.java