From 24581e72520fa2df498c0644522093bc1e156933 Mon Sep 17 00:00:00 2001 From: kaijianding Date: Wed, 25 Apr 2018 22:37:28 +0800 Subject: [PATCH] fix cache populate incorrect content when numBackgroundThreads>1 on broker --- .../druid/client/CachingClusteredClient.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/io/druid/client/CachingClusteredClient.java b/server/src/main/java/io/druid/client/CachingClusteredClient.java index 2be0a819a351..71654e7c3800 100644 --- a/server/src/main/java/io/druid/client/CachingClusteredClient.java +++ b/server/src/main/java/io/druid/client/CachingClusteredClient.java @@ -37,6 +37,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.google.common.util.concurrent.SettableFuture; import com.google.inject.Inject; import io.druid.client.cache.Cache; import io.druid.client.cache.CacheConfig; @@ -611,7 +612,24 @@ private Sequence getAndCacheServerResults( .map(r -> { if (cachePopulator != null) { // only compute cache data if populating cache - cachePopulator.cacheFutures.add(backgroundExecutorService.submit(() -> cacheFn.apply(r))); + final SettableFuture future = SettableFuture.create(); + cachePopulator.cacheFutures.add(future); + backgroundExecutorService.submit( + new Runnable() + { + @Override + public void run() + { + try { + future.set(cacheFn.apply(r)); + } + catch (Exception e) { + // if there is exception, should setException to quit the caching processing + future.setException(e); + } + } + } + ); } return r; })