StoreFindToken resetTokenIfRequired(StoreFindToken storeToken) throws StoreException {
    UUID remoteIncarnationId = storeToken.getIncarnationId();
    // if incarnationId is null, for backwards compatibility purposes, the token is considered as good.
    /// if not null, we check for a match
    if (!storeToken.getType().equals(FindTokenType.Uninitialized) && remoteIncarnationId != null
        && !remoteIncarnationId.equals(incarnationId)) {
      // incarnationId mismatch, hence resetting the token to beginning
      logger.info("Index : {} resetting offset after incarnation, new incarnation Id {}, "
          + "incarnationId from store token {}", dataDir, incarnationId, remoteIncarnationId);
      storeToken = new StoreFindToken();
    } else if (storeToken.getSessionId() == null || storeToken.getSessionId().compareTo(sessionId) != 0) {
      // the session has changed. check if we had an unclean shutdown on startup
      if (!cleanShutdown) {
        // if we had an unclean shutdown and the token offset is larger than the logEndOffsetOnStartup
        // we reset the token to logEndOffsetOnStartup
        if (!storeToken.getType().equals(FindTokenType.Uninitialized)
            && storeToken.getOffset().compareTo(logEndOffsetOnStartup) > 0) {
          logger.info("Index : {} resetting offset after not clean shutdown {} before offset {}", dataDir,
              logEndOffsetOnStartup, storeToken.getOffset());
          IndexSegment segmentOfToken = validIndexSegments.floorEntry(logEndOffsetOnStartup).getValue();
          storeToken =
              new StoreFindToken(logEndOffsetOnStartup, sessionId, incarnationId, true, segmentOfToken.getResetKey(),
                  segmentOfToken.getResetKeyType(), segmentOfToken.getResetKeyLifeVersion());
        }
      } else if (!storeToken.getType().equals(FindTokenType.Uninitialized)
          && storeToken.getOffset().compareTo(logEndOffsetOnStartup) > 0) {
        logger.error("Index : {} invalid token. Provided offset is outside the log range after clean shutdown",
            dataDir);
        // if the shutdown was clean, the offset should always be lesser or equal to the logEndOffsetOnStartup
        throw new IllegalArgumentException(
            "Invalid token. Provided offset is outside the log range after clean shutdown");
      }
    }
    return storeToken;
  }
Validate the {@link StoreFindToken} and reset if required.
There are several cases where the {@code storeFindToken} has to be reset.
<li>Incarnation id is different, meaning that we reconstructed the store, orders of keys might be different.</li>
<li>Blob shuts down ungracefully and the offset in the token is larger than the log, meaning the token is ahead of the log.</li>
@param storeToken the {@link StoreFindToken} that needs to be validated
@return the new {@link StoreFindToken} after validating
ambry-store/src/main/java/com/github/ambry/store/PersistentIndex.java