From 1a780e59c811a65e6168a4275237b1a0cba05d95 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sun, 13 Nov 2022 21:26:20 -0800 Subject: [PATCH] fix the simulator's GD-Wheel policy if the entry exceeds the max size --- .github/workflows/dependency-review.yml | 2 +- gradle/dependencies.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 +- .../snia/keyvalue/ObjectStoreTraceReader.java | 15 ++++++++------- .../policy/greedy_dual/GDWheelPolicy.java | 9 +++++---- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 61aaa8823a..252041f127 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -15,4 +15,4 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 - name: Dependency Review - uses: actions/dependency-review-action@v2 + uses: actions/dependency-review-action@v3 diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index ec10117a58..d3f2789db7 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -35,7 +35,7 @@ ext { commonsIo: '2.11.0', concurrentlinkedhashmap: '1.4.2', config: '1.4.2', - ehcache3: '3.10.2', + ehcache3: '3.10.3', errorprone: '2.16', errorproneSupport: '0.5.0', expiringMap: '0.5.10', @@ -110,7 +110,7 @@ ext { spotbugsContrib: '7.4.7', spotbugsPlugin: '5.0.13', stats: '0.47.0', - versions: '0.43.0', + versions: '0.44.0', ] platformVerrsions = [ asm: '9.4', diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b6b4c2aa05..9a27dc448e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-rc-2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-rc-3-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index eb6078f6ee..c672c7fc46 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.gradle.enterprise' version '3.11.3' + id 'com.gradle.enterprise' version '3.11.4' id 'com.gradle.common-custom-user-data-gradle-plugin' version '1.8.2' } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/keyvalue/ObjectStoreTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/keyvalue/ObjectStoreTraceReader.java index efc124d4c8..c3caff9461 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/keyvalue/ObjectStoreTraceReader.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/keyvalue/ObjectStoreTraceReader.java @@ -18,6 +18,7 @@ import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED; import java.math.BigInteger; +import java.util.Objects; import java.util.Set; import java.util.stream.Stream; @@ -48,15 +49,15 @@ public Stream events() { return lines() .map(line -> line.split(" ")) .filter(array -> array[1].equals("REST.GET.OBJECT")) - .flatMap(array -> { - long key = new BigInteger(array[2], 16).longValue(); + .map(array -> { long start = Long.parseLong(array[4]); long end = Long.parseLong(array[5]); - int weight = Ints.saturatedCast(end - start); - if (weight < 0) { - return Stream.empty(); + int weight = Ints.saturatedCast(end - start); + if (weight <= 0) { + return null; } - return Stream.of(AccessEvent.forKeyAndWeight(key, weight)); - }); + long key = new BigInteger(array[2], 16).longValue(); + return AccessEvent.forKeyAndWeight(key, weight); + }).filter(Objects::nonNull); } } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/greedy_dual/GDWheelPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/greedy_dual/GDWheelPolicy.java index 9651d8b3b0..542d627993 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/greedy_dual/GDWheelPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/greedy_dual/GDWheelPolicy.java @@ -84,8 +84,10 @@ public void record(AccessEvent event) { } private void onMiss(AccessEvent event, Node node) { - evict(event); - add(event, node); + if (event.weight() <= maximumSize) { + evict(event); + add(event, node); + } } private void evict(AccessEvent event) { @@ -148,8 +150,7 @@ private void migrate(int level) { private void onHit(AccessEvent event, Node node) { remove(node); - evict(event); - add(event, node); + onMiss(event, node); } private void remove(Node node) {