public static void clearOldInactiveKeyIdsFromCommit()

in encryption/src/main/java/org/apache/solr/encryption/EncryptionUtil.java [159:180]


  public static void clearOldInactiveKeyIdsFromCommit(Map<String, String> commitUserData) {
    // List the inactive key references.
    String activeKeyRef = getActiveKeyRefFromCommit(commitUserData);
    List<Integer> inactiveKeyRefs = new ArrayList<>();
    for (String dataKey : commitUserData.keySet()) {
      if (dataKey.startsWith(COMMIT_KEY_ID)) {
        String keyRef = dataKey.substring(COMMIT_KEY_ID.length());
        if (!keyRef.equals(activeKeyRef)) {
          inactiveKeyRefs.add(Integer.parseInt(keyRef));
        }
      }
    }
    // Clear them except the most recent ones.
    if (inactiveKeyRefs.size() > INACTIVE_KEY_IDS_TO_KEEP) {
      inactiveKeyRefs.sort(Comparator.naturalOrder());
      for (Integer keyRef : inactiveKeyRefs.subList(0, inactiveKeyRefs.size() - INACTIVE_KEY_IDS_TO_KEEP)) {
        commitUserData.remove(COMMIT_KEY_ID + keyRef);
        commitUserData.remove(COMMIT_KEY_COOKIE + keyRef);
        log.info("Removing inactive key ref={}", keyRef);
      }
    }
  }