Skip to content

Commit

Permalink
Changing cacheEntity function name and removing volatile with concurr…
Browse files Browse the repository at this point in the history
…entHashMap

Signed-off-by: Sagar Upadhyaya <[email protected]>
  • Loading branch information
sgup432 committed Jan 8, 2024
1 parent f051604 commit bb232f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public final class IndicesRequestCache implements RemovalListener<IndicesRequest
private final ByteSizeValue size;
private final TimeValue expire;
private final Cache<Key, BytesReference> cache;
private final Function<ShardId, CacheEntity> cacheEntityFunction;
private final Function<ShardId, CacheEntity> cacheEntityLookup;

IndicesRequestCache(Settings settings, Function<ShardId, CacheEntity> cacheEntityFunction) {
this.size = INDICES_CACHE_QUERY_SIZE.get(settings);
Expand All @@ -130,7 +130,7 @@ public final class IndicesRequestCache implements RemovalListener<IndicesRequest
cacheBuilder.setExpireAfterAccess(expire);
}
cache = cacheBuilder.build();
this.cacheEntityFunction = cacheEntityFunction;
this.cacheEntityLookup = cacheEntityFunction;
}

@Override
Expand All @@ -145,7 +145,7 @@ void clear(CacheEntity entity) {

@Override
public void onRemoval(RemovalNotification<Key, BytesReference> notification) {
cacheEntityFunction.apply(notification.getKey().shardId).onRemoval(notification);
cacheEntityLookup.apply(notification.getKey().shardId).onRemoval(notification);
}

BytesReference getOrCompute(
Expand Down Expand Up @@ -379,10 +379,10 @@ synchronized void cleanCache() {
if (!currentKeysToClean.isEmpty() || !currentFullClean.isEmpty()) {
for (Iterator<Key> iterator = cache.keys().iterator(); iterator.hasNext();) {
Key key = iterator.next();
if (currentFullClean.contains(cacheEntityFunction.apply(key.shardId).getCacheIdentity())) {
if (currentFullClean.contains(cacheEntityLookup.apply(key.shardId).getCacheIdentity())) {
iterator.remove();
} else {
if (currentKeysToClean.contains(new CleanupKey(cacheEntityFunction.apply(key.shardId), key.readerCacheKeyId))) {
if (currentKeysToClean.contains(new CleanupKey(cacheEntityLookup.apply(key.shardId), key.readerCacheKeyId))) {
iterator.remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public class IndicesService extends AbstractLifecycleComponent
private final ScriptService scriptService;
private final ClusterService clusterService;
private final Client client;
private volatile Map<String, IndexService> indices = new ConcurrentHashMap<>();
private Map<String, IndexService> indices = new ConcurrentHashMap<>();
private final Map<Index, List<PendingDelete>> pendingDeletes = new HashMap<>();
private final AtomicInteger numUncompletedDeletes = new AtomicInteger();
private final OldShardsStats oldShardsStats = new OldShardsStats();
Expand Down

0 comments on commit bb232f2

Please sign in to comment.