Skip to content

Commit 6df93e1

Browse files
committed
Tidy the map as we go
If the set has been emptied in and onCacheEviction call, then remove it from the map.
1 parent 2a2a958 commit 6df93e1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/DocumentSubsetBitsetCache.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ private void onCacheEviction(RemovalNotification<BitsetCacheKey, BitSet> notific
192192
// it's possible for the key to be back in the cache if it was immediately repopulated after it was evicted, so check
193193
if (bitsetCache.get(cacheKey) == null) {
194194
// key is no longer in the cache, make sure it is no longer in the lookup map either.
195-
final Set<BitsetCacheKey> keys = keysByIndex.get(indexKey);
196-
if (keys != null) {
197-
keys.remove(cacheKey);
198-
}
195+
keysByIndex.compute(indexKey, (ignored, keys) -> {
196+
if (keys != null) {
197+
keys.remove(cacheKey);
198+
if (keys.isEmpty()) {
199+
keys = null;
200+
}
201+
}
202+
return keys;
203+
});
199204
}
200205
}
201206
});
@@ -426,6 +431,11 @@ void verifyInternalConsistency() {
426431
throw new IllegalStateException("Key [" + cacheKey + "] is in the lookup map, but is not in the cache");
427432
}
428433
});
434+
keysByIndex.forEach((indexKey, keys) -> {
435+
if (keys == null || keys.isEmpty()) {
436+
throw new IllegalStateException("The lookup entry for [" + indexKey + "] is null or empty");
437+
}
438+
});
429439
}
430440

431441
}

0 commit comments

Comments
 (0)