public void renewIfRequired(DelegationTokenIdentifier id, DelegationTokenInformation tokenInfo)
          throws InvalidToken {
    long currentTime = System.currentTimeMillis();
    if (tokenInfo != null) {
      if (currentTime > tokenInfo.getRenewDate() && currentTime < id.getMaxDate()) {
        // This will be the case when now > tokenInfo.getRenewDate() but less than the token expiration/max time.
        LOGGER.info("Trying to renew the token: " + id);
        try {
          DelegationKey key = getDelegationKey(id.getMasterKeyId());
          Token<DelegationTokenIdentifier> t = new Token<>(id.getBytes(), createPassword(id.getBytes(), key.getKey()),
                  id.getKind(), new Text());
          renewToken(t, getTokenIdentifier(t).getRenewer().toString());
        } catch (IOException e) {
          throw new InvalidToken("Unable to renew token: " + id + " due to " + e.getMessage());
        }
      } else if (currentTime > id.getMaxDate()) {
        // In this case expiry time has passed and this token cannot be further renewed.
        throw new InvalidToken("Expiration time passed. Cannot renew the token.");
      }
    }
  }
Remove expired tokens. Replaces logic in {@link AbstractDelegationTokenSecretManager}
that cannot be reused due to private method access. Logic here can more efficiently
deal with external token store by only loading into memory the minimum data needed.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/security/TokenStoreDelegationTokenSecretManager.java