Skip to content

Commit

Permalink
Fix max size for shouldCache check
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Dec 12, 2024
1 parent 96a6eed commit c802a55
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ public ImmutableCacheStatsHolder stats(String[] levels) {
return null;
}

@Override
public long getMaxHeapBytes() {
return onHeapCache.getMaxHeapBytes();
}

@Override
public void close() throws IOException {
for (Map.Entry<ICache<K, V>, TierInfo> cacheEntry : caches.entrySet()) {
Expand Down Expand Up @@ -654,6 +659,11 @@ public ImmutableCacheStatsHolder stats(String[] levels) {
return statsHolder.getImmutableCacheStatsHolder(levels);
}

@Override
public long getMaxHeapBytes() {
return numberOfSegments * tieredSpilloverCacheSegments[0].getMaxHeapBytes();
}

// Package private for testing.
@SuppressWarnings({ "unchecked" })
Iterable<ICacheKey<K>> getOnHeapCacheKeys() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public ImmutableCacheStatsHolder stats(String[] levels) {
return null;
}

@Override
public long getMaxHeapBytes() {
return 0;
}

@Override
public void close() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ public ImmutableCacheStatsHolder stats(String[] levels) {
return cacheStatsHolder.getImmutableCacheStatsHolder(levels);
}

@Override
public long getMaxHeapBytes() {
return 0;
}

/**
* This iterator wraps ehCache iterator and only iterates over its keys.
* @param <K> Type of key
Expand Down
3 changes: 3 additions & 0 deletions server/src/main/java/org/opensearch/common/cache/ICache.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ default ImmutableCacheStatsHolder stats() {
// Return stats aggregated by the provided levels. If levels is null or an empty array, return total stats only.
ImmutableCacheStatsHolder stats(String[] levels);

// Return the bytes in memory this cache can consume.
long getMaxHeapBytes();

/**
* Factory to create objects.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public ImmutableCacheStatsHolder stats(String[] levels) {
return cacheStatsHolder.getImmutableCacheStatsHolder(levels);
}

@Override
public long getMaxHeapBytes() {
return maximumWeight;
}

@Override
public void onRemoval(RemovalNotification<ICacheKey<K>, V> notification) {
removalListener.onRemoval(notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ public PluggableQueryCache(
.build(),
CacheType.INDICES_QUERY_CACHE
);
this.maxRamBytesUsed = 1_000_000; // TODO: i think this just controls the max size going in rn. Didnt want to deal w the settings rn
this.maxRamBytesUsed = innerCache.getMaxHeapBytes();
int k = 0;
// In theory it may be useful to test this with non-TSC internal caches for regression purposes.
// For example, if we just do an OpenSearchOnHeapCache of the same size, how much worse does it perform?
}
Expand Down

0 comments on commit c802a55

Please sign in to comment.