Skip to content

Commit c518d58

Browse files
author
Peter Alfonsi
committed
Address Sagar's comment
Signed-off-by: Peter Alfonsi <[email protected]>
1 parent ff2f1e5 commit c518d58

File tree

6 files changed

+20
-32
lines changed

6 files changed

+20
-32
lines changed

modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ static class TieredSpilloverCacheSegment<K, V> implements ICache<K, V> {
150150

151151
private final TieredSpilloverCacheStatsHolder statsHolder;
152152

153+
private final long onHeapCacheMaxWeight;
154+
private final long diskCacheMaxWeight;
155+
153156
/**
154157
* This map is used to handle concurrent requests for same key in computeIfAbsent() to ensure we load the value
155158
* only once.
@@ -218,6 +221,8 @@ static class TieredSpilloverCacheSegment<K, V> implements ICache<K, V> {
218221
cacheListMap.put(diskCache, new TierInfo(isDiskCacheEnabled, TIER_DIMENSION_VALUE_DISK));
219222
this.caches = Collections.synchronizedMap(cacheListMap);
220223
this.policies = builder.policies; // Will never be null; builder initializes it to an empty list
224+
this.onHeapCacheMaxWeight = onHeapCacheSizeInBytes;
225+
this.diskCacheMaxWeight = diskCacheSizeInBytes;
221226
}
222227

223228
// Package private for testing
@@ -526,12 +531,14 @@ void updateStatsOnPut(String destinationTierValue, ICacheKey<K> key, V value) {
526531
statsHolder.incrementSizeInBytes(dimensionValues, weigher.applyAsLong(key, value));
527532
}
528533

529-
@Override
530-
public long getMaximumWeight() {
531-
if (caches.get(diskCache).isEnabled()) {
532-
return onHeapCache.getMaximumWeight() + diskCache.getMaximumWeight();
533-
}
534-
return onHeapCache.getMaximumWeight();
534+
// pkg-private for testing
535+
long getOnHeapCacheMaxWeight() {
536+
return onHeapCacheMaxWeight;
537+
}
538+
539+
// pkg-private for testing
540+
long getDiskCacheMaxWeight() {
541+
return diskCacheMaxWeight;
535542
}
536543

537544
/**
@@ -700,11 +707,6 @@ long diskCacheCount() {
700707
return diskCacheEntries;
701708
}
702709

703-
@Override
704-
public long getMaximumWeight() {
705-
return tieredSpilloverCacheSegments[0].getMaximumWeight() * numberOfSegments;
706-
}
707-
708710
/**
709711
* ConcatenatedIterables which combines cache iterables and supports remove() functionality as well if underlying
710712
* iterator supports it.

modules/cache-common/src/test/java/org/opensearch/cache/common/tier/MockDiskCache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public void close() {
128128

129129
}
130130

131-
@Override
132-
public long getMaximumWeight() {
131+
long getMaximumWeight() {
133132
return maxSize;
134133
}
135134

modules/cache-common/src/test/java/org/opensearch/cache/common/tier/TieredSpilloverCacheTests.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,19 +2290,9 @@ public void testSegmentSizesWhenNotUsingFactory() {
22902290
}
22912291

22922292
private void checkSegmentSizes(TieredSpilloverCache<String, String> cache, long expectedHeapSize, long expectedDiskSize) {
2293-
OpenSearchOnHeapCache<String, String> segmentHeapCache = (OpenSearchOnHeapCache<
2294-
String,
2295-
String>) cache.tieredSpilloverCacheSegments[0].getOnHeapCache();
2296-
assertEquals(expectedHeapSize / cache.getNumberOfSegments(), segmentHeapCache.getMaximumWeight());
2297-
2298-
MockDiskCache<String, String> segmentDiskCache = (MockDiskCache<String, String>) cache.tieredSpilloverCacheSegments[0]
2299-
.getDiskCache();
2300-
assertEquals(expectedDiskSize / cache.getNumberOfSegments(), segmentDiskCache.getMaximumWeight());
2301-
assertEquals(
2302-
expectedHeapSize / cache.getNumberOfSegments() + expectedDiskSize / cache.getNumberOfSegments(),
2303-
cache.tieredSpilloverCacheSegments[0].getMaximumWeight()
2304-
);
2305-
assertEquals(expectedHeapSize + expectedDiskSize, cache.getMaximumWeight());
2293+
TieredSpilloverCache.TieredSpilloverCacheSegment<String, String> segment = cache.tieredSpilloverCacheSegments[0];
2294+
assertEquals(expectedHeapSize / cache.getNumberOfSegments(), segment.getOnHeapCacheMaxWeight());
2295+
assertEquals(expectedDiskSize / cache.getNumberOfSegments(), segment.getDiskCacheMaxWeight());
23062296
}
23072297

23082298
private List<String> getMockDimensions() {

plugins/cache-ehcache/src/main/java/org/opensearch/cache/store/disk/EhcacheDiskCache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,7 @@ private V deserializeValue(ByteArrayWrapper binary) {
681681
}
682682

683683
// Pkg-private for testing.
684-
@Override
685-
public long getMaximumWeight() {
684+
long getMaximumWeight() {
686685
return maxWeightInBytes;
687686
}
688687

server/src/main/java/org/opensearch/common/cache/ICache.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ default ImmutableCacheStatsHolder stats() {
5353
// Return stats aggregated by the provided levels. If levels is null or an empty array, return total stats only.
5454
ImmutableCacheStatsHolder stats(String[] levels);
5555

56-
long getMaximumWeight();
57-
5856
/**
5957
* Factory to create objects.
6058
*/

server/src/main/java/org/opensearch/common/cache/store/OpenSearchOnHeapCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public OpenSearchOnHeapCache(Builder<K, V> builder) {
8181
this.weigher = builder.getWeigher();
8282
}
8383

84-
@Override
85-
public long getMaximumWeight() {
84+
// pkg-private for testing
85+
long getMaximumWeight() {
8686
return this.maximumWeight;
8787
}
8888

0 commit comments

Comments
 (0)