Skip to content

Commit 1dbf57a

Browse files
committed
Apply some naming consistency
by always calling the IndexReader.CacheKey 'indexKey' and always calling the BitsetCacheKey 'cacheKey'.
1 parent 2baa7f1 commit 1dbf57a

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ public DocumentSubsetBitsetCache(Settings settings, ThreadPool threadPool) {
151151
}
152152

153153
@Override
154-
public void onClose(IndexReader.CacheKey ownerCoreCacheKey) {
155-
final Set<BitsetCacheKey> keys = keysByIndex.remove(ownerCoreCacheKey);
154+
public void onClose(IndexReader.CacheKey indexKey) {
155+
final Set<BitsetCacheKey> keys = keysByIndex.remove(indexKey);
156156
if (keys != null) {
157157
// Because this Set has been removed from the map, and the only update to the set is performed in a
158158
// Map#compute call, it should not be possible to get a concurrent modification here.
@@ -164,10 +164,10 @@ public void onClose(IndexReader.CacheKey ownerCoreCacheKey) {
164164
* Cleanup (synchronize) the internal state when an object is removed from the primary cache
165165
*/
166166
private void onCacheEviction(RemovalNotification<BitsetCacheKey, BitSet> notification) {
167-
final BitsetCacheKey bitsetKey = notification.getKey();
168-
final IndexReader.CacheKey indexKey = bitsetKey.index;
169-
if (keysByIndex.getOrDefault(indexKey, Set.of()).contains(bitsetKey) == false) {
170-
// If the bitsetKey isn't in the lookup map, then there's nothing to synchronize
167+
final BitsetCacheKey cacheKey = notification.getKey();
168+
final IndexReader.CacheKey indexKey = cacheKey.indexKey;
169+
if (keysByIndex.getOrDefault(indexKey, Set.of()).contains(cacheKey) == false) {
170+
// If the cacheKey isn't in the lookup map, then there's nothing to synchronize
171171
return;
172172
}
173173
// We push this to a background thread, so that it reduces the risk of blocking searches, but also so that the lock management is
@@ -177,9 +177,9 @@ private void onCacheEviction(RemovalNotification<BitsetCacheKey, BitSet> notific
177177
cleanupExecutor.submit(() -> {
178178
try (ReleasableLock ignored = cacheEvictionLock.acquire()) {
179179
// it's possible for the key to be back in the cache if it was immediately repopulated after it was evicted, so check
180-
if (bitsetCache.get(bitsetKey) == null) {
180+
if (bitsetCache.get(cacheKey) == null) {
181181
// key is no longer in the cache, make sure it is no longer in the lookup map either.
182-
Optional.ofNullable(keysByIndex.get(indexKey)).ifPresent(set -> set.remove(bitsetKey));
182+
Optional.ofNullable(keysByIndex.get(indexKey)).ifPresent(set -> set.remove(cacheKey));
183183
}
184184
}
185185
});
@@ -325,12 +325,12 @@ public Map<String, Object> usageStats() {
325325

326326
private static final class BitsetCacheKey {
327327

328-
final IndexReader.CacheKey index;
328+
final IndexReader.CacheKey indexKey;
329329
final Query query;
330330
final int hashCode;
331331

332-
private BitsetCacheKey(IndexReader.CacheKey index, Query query) {
333-
this.index = index;
332+
private BitsetCacheKey(IndexReader.CacheKey indexKey, Query query) {
333+
this.indexKey = indexKey;
334334
this.query = query;
335335
// compute the hashCode eagerly, since it's used multiple times in the cache implementation anyway -- the query here will
336336
// be a ConstantScoreQuery around a BooleanQuery, and BooleanQuery already *lazily* caches the hashCode, so this isn't
@@ -347,11 +347,11 @@ public boolean equals(Object other) {
347347
return false;
348348
}
349349
final BitsetCacheKey that = (BitsetCacheKey) other;
350-
return Objects.equals(this.index, that.index) && Objects.equals(this.query, that.query);
350+
return Objects.equals(this.indexKey, that.indexKey) && Objects.equals(this.query, that.query);
351351
}
352352

353353
private int computeHashCode() {
354-
int result = index.hashCode();
354+
int result = indexKey.hashCode();
355355
result = 31 * result + query.hashCode();
356356
return result;
357357
}
@@ -363,7 +363,7 @@ public int hashCode() {
363363

364364
@Override
365365
public String toString() {
366-
return getClass().getSimpleName() + "(" + index + "," + query + ")";
366+
return getClass().getSimpleName() + "(" + indexKey + "," + query + ")";
367367
}
368368
}
369369

@@ -373,15 +373,15 @@ public String toString() {
373373
*/
374374
void verifyInternalConsistency() {
375375
this.bitsetCache.keys().forEach(bck -> {
376-
final Set<BitsetCacheKey> set = this.keysByIndex.get(bck.index);
376+
final Set<BitsetCacheKey> set = this.keysByIndex.get(bck.indexKey);
377377
if (set == null) {
378378
throw new IllegalStateException(
379-
"Key [" + bck + "] is in the cache, but there is no entry for [" + bck.index + "] in the lookup map"
379+
"Key [" + bck + "] is in the cache, but there is no entry for [" + bck.indexKey + "] in the lookup map"
380380
);
381381
}
382382
if (set.contains(bck) == false) {
383383
throw new IllegalStateException(
384-
"Key [" + bck + "] is in the cache, but the lookup entry for [" + bck.index + "] does not contain that key"
384+
"Key [" + bck + "] is in the cache, but the lookup entry for [" + bck.indexKey + "] does not contain that key"
385385
);
386386
}
387387
});

0 commit comments

Comments
 (0)