void verifyRealIndexSanity() throws StoreException {
    IndexSegment prevIndexSegment = null;
    Map<MockId, Boolean> keyToDeleteSeenMap = new HashMap<>();
    Map<MockId, Boolean> keyToTtlUpdateSeenMap = new HashMap<>();
    Map<MockId, Short> keyToLifeVersionMap = new HashMap<>();
    for (IndexSegment indexSegment : index.getIndexSegments().values()) {
      Offset indexSegmentStartOffset = indexSegment.getStartOffset();
      if (prevIndexSegment == null) {
        assertEquals("There are offsets in the log not accounted for in index", log.getFirstSegment().getStartOffset(),
            indexSegmentStartOffset.getOffset());
      } else if (prevIndexSegment.getLogSegmentName().equals(indexSegment.getLogSegmentName())) {
        assertEquals("There are offsets in the log not accounted for in index", prevIndexSegment.getEndOffset(),
            indexSegmentStartOffset);
      } else {
        LogSegment segment = log.getSegment(prevIndexSegment.getLogSegmentName());
        assertEquals("There are offsets in the log not accounted for in index", segment.getEndOffset(),
            prevIndexSegment.getEndOffset().getOffset());
        segment = log.getNextSegment(segment);
        assertEquals("There are offsets in the log not accounted for in index", segment.getStartOffset(),
            indexSegmentStartOffset.getOffset());
      }

      List<IndexEntry> indexEntries = new ArrayList<>();
      indexSegment.getIndexEntriesSince(null, new FindEntriesCondition(Long.MAX_VALUE), indexEntries, new AtomicLong(0),
          false, false);
      for (IndexEntry entry : indexEntries) {
        MockId id = (MockId) entry.getKey();
        IndexValue value = entry.getValue();
        Boolean deleteSeen = keyToDeleteSeenMap.get(id);
        Boolean ttlUpdateSeen = keyToTtlUpdateSeenMap.get(id);
        if (value.isDelete()) {
          // should not be repeated
          assertTrue("Duplicated DELETE record for " + id, deleteSeen == null || !deleteSeen);
          keyToDeleteSeenMap.put(id, true);
        } else if (value.isUndelete()) {
          Short prevLifeVersion = keyToLifeVersionMap.put(id, value.getLifeVersion());
          short currentLifeVersion = value.getLifeVersion();
          if (PersistentIndex.CURRENT_VERSION >= PersistentIndex.VERSION_3 && prevLifeVersion != null) {
            assertTrue("Undelete's lifeVersion should be greater than previous one, Undelete: " + currentLifeVersion
                + " Previous: " + prevLifeVersion, prevLifeVersion < currentLifeVersion);
          }
          keyToDeleteSeenMap.put(id, false);
        } else if (value.isTtlUpdate()) {
          // should not be repeated
          assertTrue("Duplicated TTL update record for " + id, ttlUpdateSeen == null || !ttlUpdateSeen);
          // should not after a delete record
          assertTrue("TTL update record after delete record for " + id, deleteSeen == null || !deleteSeen);
          keyToTtlUpdateSeenMap.put(id, true);
          keyToDeleteSeenMap.putIfAbsent(id, false);
        } else {
          if (deleteSeen != null) {
            if (deleteSeen) {
              fail("PUT record after delete record for " + id);
            } else {
              fail("Duplicated PUT record for " + id);
            }
          }
          assertNull("Put record encountered after TTL update record", ttlUpdateSeen);
          keyToTtlUpdateSeenMap.put(id, false);
          keyToDeleteSeenMap.put(id, false);
        }
        keyToLifeVersionMap.put(id, value.getLifeVersion());
      }
      long expectedOffset = indexSegmentStartOffset.getOffset();
      NavigableSet<IndexEntry> indexEntriesByOffset = new TreeSet<>(PersistentIndex.INDEX_ENTRIES_OFFSET_COMPARATOR);
      indexEntriesByOffset.addAll(indexEntries);
      for (IndexEntry entry : indexEntriesByOffset) {
        IndexValue value = entry.getValue();
        assertEquals("There are offsets in the log not accounted for in index", expectedOffset,
            value.getOffset().getOffset());
        expectedOffset += value.getSize();
      }
      if (prevIndexSegment != null) {
        assertTrue("Last modified time of an older index segment (" + prevIndexSegment.getLastModifiedTimeMs()
                + ") > newer index segment (" + indexSegment.getLastModifiedTimeMs() + ")",
            prevIndexSegment.getLastModifiedTimeMs() <= indexSegment.getLastModifiedTimeMs());
      }
      prevIndexSegment = indexSegment;
    }
  }
Ensures that the {@link PersistentIndex} is sane and correct by checking that
1. It contains no duplicate entries.
2. The ordering of PUT and DELETE entries is correct.
3. There are no offsets in the log not accounted for in the index.
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/CuratedLogIndexState.java