Skip to content

Commit

Permalink
Suppress log warning if a future is cancelled or times out (fixes #597)
Browse files Browse the repository at this point in the history
Minimal backport of 1e52b10
  • Loading branch information
ben-manes committed Dec 1, 2021
1 parent 76349c2 commit 58bfc14
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.OptionalLong;
import java.util.Set;
import java.util.Spliterator;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -58,6 +59,7 @@
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiFunction;
import java.util.function.Consumer;
Expand Down Expand Up @@ -1219,7 +1221,9 @@ void refreshIfNeeded(Node<K, V> node, long now) {
refreshFuture.whenComplete((newValue, error) -> {
long loadTime = statsTicker().read() - startTime;
if (error != null) {
logger.log(Level.WARNING, "Exception thrown during refresh", error);
if (!(error instanceof CancellationException) && !(error instanceof TimeoutException)) {
logger.log(Level.WARNING, "Exception thrown during refresh", error);
}
node.casWriteTime(refreshWriteTime, oldWriteTime);
statsCounter().recordLoadFailure(loadTime);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -194,7 +196,8 @@ default void handleCompletion(K key, CompletableFuture<V> valueFuture,
}
long loadTime = cache().statsTicker().read() - startTime;
if (value == null) {
if (error != null) {
if ((error != null) && !(error instanceof CancellationException)
&& !(error instanceof TimeoutException)) {
logger.log(Level.WARNING, "Exception thrown during asynchronous load", error);
}
cache().remove(key, valueFuture);
Expand Down Expand Up @@ -239,7 +242,9 @@ public void accept(@Nullable Map<K, V> result, @Nullable Throwable error) {
entry.getValue().obtrudeException(error);
}
cache.statsCounter().recordLoadFailure(loadTime);
logger.log(Level.WARNING, "Exception thrown during asynchronous load", error);
if (!(error instanceof CancellationException) && !(error instanceof TimeoutException)) {
logger.log(Level.WARNING, "Exception thrown during asynchronous load", error);
}
} else {
fillProxies(result);
addNewEntries(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -153,7 +155,9 @@ public void refresh(K key) {
long loadTime = asyncCache.cache().statsTicker().read() - now;
if (error != null) {
asyncCache.cache().statsCounter().recordLoadFailure(loadTime);
logger.log(Level.WARNING, "Exception thrown during refresh", error);
if (!(error instanceof CancellationException) && !(error instanceof TimeoutException)) {
logger.log(Level.WARNING, "Exception thrown during refresh", error);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -101,7 +103,9 @@ default void refresh(K key) {
refreshFuture.whenComplete((newValue, error) -> {
long loadTime = cache().statsTicker().read() - startTime;
if (error != null) {
logger.log(Level.WARNING, "Exception thrown during refresh", error);
if (!(error instanceof CancellationException) && !(error instanceof TimeoutException)) {
logger.log(Level.WARNING, "Exception thrown during refresh", error);
}
cache().statsCounter().recordLoadFailure(loadTime);
return;
}
Expand Down

0 comments on commit 58bfc14

Please sign in to comment.