Skip to content

Commit d116c7e

Browse files
authored
Cache updates (#50)
Outstanding changes from projectnessie/nessie#10629 (other parts are already there)
1 parent 66816a4 commit d116c7e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

nosql/persistence/cache/src/main/java/org/apache/polaris/persistence/cache/CaffeineCacheBackend.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class CaffeineCacheBackend implements CacheBackend {
7676
private static final Logger LOGGER = LoggerFactory.getLogger(CaffeineCacheBackend.class);
7777

7878
public static final String METER_CACHE_CAPACITY = "cache.capacity";
79+
public static final String METER_CACHE_ADMIT_CAPACITY = "cache.capacity.admitted";
7980
public static final String METER_CACHE_WEIGHT = "cache.weight-reported";
80-
public static final String METER_CACHE_REJECTIONS = "cache.rejections";
8181
public static final String METER_CACHE_REJECTED_WEIGHT = "cache.rejected-weight";
8282

8383
public static final String CACHE_NAME = "polaris-objects";
@@ -170,13 +170,13 @@ public long expireAfterRead(
170170
.tag("cache", CACHE_NAME)
171171
.baseUnit(BaseUnits.BYTES)
172172
.register(reg);
173-
Gauge.builder(METER_CACHE_WEIGHT, "", x -> (double) currentWeightReported())
174-
.description("Current reported weight of the objects cache in bytes.")
173+
Gauge.builder(METER_CACHE_ADMIT_CAPACITY, "", x -> admitWeight)
174+
.description("Admitted capacity of the objects cache in bytes.")
175175
.tag("cache", CACHE_NAME)
176176
.baseUnit(BaseUnits.BYTES)
177177
.register(reg);
178-
Gauge.builder(METER_CACHE_REJECTIONS, "", x -> rejections.get())
179-
.description("Number of cache-puts that have been rejected.")
178+
Gauge.builder(METER_CACHE_WEIGHT, "", x -> (double) currentWeightReported())
179+
.description("Current reported weight of the objects cache in bytes.")
180180
.tag("cache", CACHE_NAME)
181181
.baseUnit(BaseUnits.BYTES)
182182
.register(reg);

nosql/persistence/cache/src/test/java/org/apache/polaris/persistence/cache/TestCacheOvershoot.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
package org.apache.polaris.persistence.cache;
2020

2121
import static java.util.concurrent.CompletableFuture.delayedExecutor;
22+
import static org.apache.polaris.persistence.cache.CaffeineCacheBackend.METER_CACHE_ADMIT_CAPACITY;
23+
import static org.apache.polaris.persistence.cache.CaffeineCacheBackend.METER_CACHE_CAPACITY;
2224
import static org.apache.polaris.persistence.cache.CaffeineCacheBackend.METER_CACHE_REJECTED_WEIGHT;
23-
import static org.apache.polaris.persistence.cache.CaffeineCacheBackend.METER_CACHE_REJECTIONS;
2425
import static org.apache.polaris.persistence.cache.CaffeineCacheBackend.METER_CACHE_WEIGHT;
2526

2627
import com.google.common.base.Strings;
@@ -76,9 +77,10 @@ private void testCacheOvershoot(Executor evictionExecutor) throws Exception {
7677
meterRegistry.getMeters().stream()
7778
.collect(Collectors.toMap(m -> m.getId().getName(), Function.identity(), (a, b) -> a));
7879
soft.assertThat(metersByName)
79-
.containsKeys(METER_CACHE_WEIGHT, METER_CACHE_REJECTIONS, METER_CACHE_REJECTED_WEIGHT);
80+
.containsKeys(METER_CACHE_WEIGHT, METER_CACHE_ADMIT_CAPACITY, METER_CACHE_REJECTED_WEIGHT);
8081
var meterWeightReported = (Gauge) metersByName.get(METER_CACHE_WEIGHT);
81-
var meterRejections = (Gauge) metersByName.get(METER_CACHE_REJECTIONS);
82+
var meterAdmittedCapacity = (Gauge) metersByName.get(METER_CACHE_ADMIT_CAPACITY);
83+
var meterCapacity = (Gauge) metersByName.get(METER_CACHE_CAPACITY);
8284
var meterRejectedWeight = (DistributionSummary) metersByName.get(METER_CACHE_REJECTED_WEIGHT);
8385

8486
var maxWeight = cache.capacityBytes();
@@ -97,7 +99,9 @@ private void testCacheOvershoot(Executor evictionExecutor) throws Exception {
9799
soft.assertThat(cache.currentWeightReported()).isLessThanOrEqualTo(maxWeight);
98100
soft.assertThat(cache.rejections()).isEqualTo(0L);
99101
soft.assertThat(meterWeightReported.value()).isGreaterThan(0d);
100-
soft.assertThat(meterRejections.value()).isEqualTo((double) cache.rejections());
102+
soft.assertThat(meterAdmittedCapacity.value()).isEqualTo((double) admitWeight);
103+
soft.assertThat(meterCapacity.value())
104+
.isEqualTo((double) config.sizing().orElseThrow().fixedSize().orElseThrow().asLong());
101105

102106
var seenOvershoot = false;
103107
var stop = new AtomicBoolean();
@@ -126,7 +130,6 @@ private void testCacheOvershoot(Executor evictionExecutor) throws Exception {
126130

127131
soft.assertThat(cache.currentWeightReported()).isLessThanOrEqualTo(admitWeight);
128132
soft.assertThat(cache.rejections()).isEqualTo(0L);
129-
soft.assertThat(meterRejections.value()).isEqualTo(0d);
130133
soft.assertThat(meterRejectedWeight.totalAmount()).isEqualTo(0d);
131134
soft.assertThat(seenOvershoot).isFalse();
132135
}

0 commit comments

Comments
 (0)