protected void rollMasterKeyExt() throws IOException {
    Map<Integer, DelegationKey> keys = reloadKeys();
    int currentKeyId = super.currentId;
    MetastoreDelegationTokenSupport.rollMasterKey(TokenStoreDelegationTokenSecretManager.this);
    List<DelegationKey> keysAfterRoll = Arrays.asList(getAllKeys());
    for (DelegationKey key : keysAfterRoll) {
      keys.remove(key.getKeyId());
      if (key.getKeyId() == currentKeyId) {
        tokenStore.updateMasterKey(currentKeyId, encodeWritable(key));
      }
    }
    for (DelegationKey expiredKey : keys.values()) {
      LOGGER.info("Removing expired key id={}", expiredKey.getKeyId());
      try {
        tokenStore.removeMasterKey(expiredKey.getKeyId());
      } catch (Exception e) {
        LOGGER.error("Error removing expired key id={}", expiredKey.getKeyId(), e);
      }
    }
  }
Extension of rollMasterKey to remove expired keys from store.

@throws IOException
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/security/TokenStoreDelegationTokenSecretManager.java