private StoreFindToken generateTokenBasedOnResetKey(StoreFindToken token,
      ConcurrentSkipListMap<Offset, IndexSegment> indexSegments) throws StoreException {
    StoreKey resetKey = token.getResetKey();
    IndexEntryType resetKeyType = token.getResetKeyType();
    short resetKeyLifeVersion = token.getResetKeyVersion();
    List<IndexValue> indexValues = findAllIndexValuesForKey(resetKey, null, EnumSet.of(resetKeyType), indexSegments);
    IndexValue resetKeyIndexValue = null;
    if (indexValues != null) {
      for (IndexValue indexValue : indexValues) {
        if (indexValue.getLifeVersion() == resetKeyLifeVersion) {
          resetKeyIndexValue = indexValue;
          break;
        }
      }
    }
    StoreFindToken newToken = new StoreFindToken();
    if (resetKeyIndexValue == null) {
      // reset key is not found in current valid index segments, reset it to very beginning
      logger.info("Index {}: Reset key {} is not found in current index, token is reset to the beginning of whole log",
          dataDir, resetKey);
    } else {
      if (config.storeRebuildTokenBasedOnResetKey) {
        IndexSegment targetIndexSegment = indexSegments.floorEntry(resetKeyIndexValue.getOffset()).getValue();
        // We set inclusive = true in new token to make index segment find all entries it has (including the first one).
        // The new token should always be index-based
        newToken = new StoreFindToken(FindTokenType.IndexBased, targetIndexSegment.getStartOffset(),
            targetIndexSegment.getFirstKeyInSealedSegment(), sessionId, incarnationId, true,
            StoreFindToken.CURRENT_VERSION, targetIndexSegment.getResetKey(), targetIndexSegment.getResetKeyType(),
            targetIndexSegment.getResetKeyLifeVersion());
      }
      metrics.resetKeyFoundInCurrentIndex.inc();
    }
    return newToken;
  }
Generate store find token based on reset key within old token.
@param token the old {@link StoreFindToken} that contains reset key.
@param indexSegments current valid index segments to find.
@return new created token.
ambry-store/src/main/java/com/github/ambry/store/PersistentIndex.java