Skip to content

Commit

Permalink
Fix improper recording of stats (fixes #240)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed May 9, 2018
1 parent 689b726 commit aa7756f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ void refreshIfNeeded(Node<K, V> node, long now) {
&& node.casWriteTime(oldWriteTime, refreshWriteTime)) {
try {
CompletableFuture<V> refreshFuture;
long startTime = statsTicker().read();
if (isAsync) {
@SuppressWarnings("unchecked")
CompletableFuture<V> future = (CompletableFuture<V>) oldValue;
Expand All @@ -892,7 +893,7 @@ void refreshIfNeeded(Node<K, V> node, long now) {
refreshFuture = refresh;
}
refreshFuture.whenComplete((newValue, error) -> {
long loadTime = statsTicker().read() - now;
long loadTime = statsTicker().read() - startTime;
if (error != null) {
logger.log(Level.WARNING, "Exception thrown during refresh", error);
node.casWriteTime(refreshWriteTime, oldWriteTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void accept(@Nullable Map<K, V> result, @Nullable Throwable error) {
} else {
fillProxies(result);
addNewEntries(result);
cache.statsCounter().recordLoadSuccess(result.size());
cache.statsCounter().recordLoadSuccess(loadTime);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadLocalRandom;
Expand Down Expand Up @@ -480,5 +481,11 @@ public String toString() {
}

@SuppressWarnings("serial")
static final class SerializableFakeTicker extends FakeTicker implements Serializable {}
static final class SerializableFakeTicker extends FakeTicker implements Serializable {
private static final long START_TIME = new Random().nextLong();

public SerializableFakeTicker() {
advance(START_TIME);
}
}
}
20 changes: 10 additions & 10 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ext {
fastutil: '8.1.1',
flipTables: '1.0.2',
guava: '25.0-jre',
javapoet: '1.10.0',
javapoet: '1.11.0',
jcache: '1.1.0',
jsr305: '3.0.2',
jsr330: '1',
Expand Down Expand Up @@ -63,7 +63,7 @@ ext {
jackrabbit: '1.9.0',
jamm: '0.3.2',
javaObjectLayout: '0.9',
jmh: '1.20',
jmh: '1.21',
koloboke: '0.6.8',
ohc: '0.6.1',
rapidoid: '5.5.4',
Expand All @@ -72,28 +72,28 @@ ext {
]
pluginVersions = [
apt: '0.15',
buildscan: '1.13.1',
buildscan: '1.13.2',
buildscanRecipes: '0.2.3',
checkstyle: '8.9',
checkstyle: '8.10',
coveralls: '2.8.2',
coverity: '1.0.10',
errorProne: '0.0.13',
errorProne: '0.0.14',
jacoco: '0.8.1',
jmh: '0.4.5',
jmhReport: '0.7.0',
nexus: '2.3.1',
pmd: '6.0.1',
propdeps: '0.0.10.RELEASE',
semanticVersioning: '1.1.0',
shadow: '2.0.3',
shadow: '2.0.4',
sonarqube: '2.6.2',
spotbugs: '3.1.1',
spotbugsPlugin: '1.6.0',
spotbugs: '3.1.3',
spotbugsPlugin: '1.6.1',
stats: '0.2.2',
versions: '0.17.0',
]
annotationProcessorVersions = [
nullaway: '0.4.3',
nullaway: '0.4.5',
]

libraries = [
Expand Down Expand Up @@ -193,7 +193,7 @@ ext {
semanticVersioning: "io.ehdev:gradle-semantic-versioning:${pluginVersions.semanticVersioning}",
shadow: "com.github.jengelman.gradle.plugins:shadow:${pluginVersions.shadow}",
sonarqube: "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${pluginVersions.sonarqube}",
spotbugs: "gradle.plugin.com.github.spotbugs:gradlePlugin:${pluginVersions.spotbugsPlugin}",
spotbugs: "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:${pluginVersions.spotbugsPlugin}",
stats: "org.kordamp.gradle:stats-gradle-plugin:${pluginVersions.stats}",
versions: "com.github.ben-manes:gradle-versions-plugin:${pluginVersions.versions}",
]
Expand Down

0 comments on commit aa7756f

Please sign in to comment.