From aaaa13f2a7fb9eb2a566de6ec52c964cf9e31d63 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 20 Oct 2014 16:53:22 +0200 Subject: [PATCH] Core: Add warmer listener only when index service is set, in order to prevent possible NPE. The IndicesWarmer gets set before the InternalIndexService gets set, which can lead to a small time window were InternalIndexService isn't set Closes #8140 Closes #8168 --- .../cache/fixedbitset/FixedBitSetFilterCache.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java b/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java index 176008d431413..cbd37c8461f7d 100644 --- a/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java +++ b/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java @@ -94,6 +94,13 @@ public FixedBitSetFilterCache(Index index, @IndexSettings Settings indexSettings @Inject(optional = true) public void setIndicesWarmer(IndicesWarmer indicesWarmer) { this.indicesWarmer = indicesWarmer; + } + + public void setIndexService(InternalIndexService indexService) { + this.indexService = indexService; + // First the indicesWarmer is set and then the indexService is set, because of this there is a small window of + // time where indexService is null. This is why the warmer should only registered after indexService has been set. + // Otherwise there is a small chance of the warmer running into a NPE, since it uses the indexService indicesWarmer.addListener(warmer); } @@ -164,10 +171,6 @@ public Value call() throws Exception { }).fixedBitSet; } - public void setIndexService(InternalIndexService indexService) { - this.indexService = indexService; - } - @Override public void onRemoval(RemovalNotification> notification) { Object key = notification.getKey(); @@ -283,10 +286,10 @@ public void run() { final long start = System.nanoTime(); getAndLoadIfNotPresent(filterToWarm, ctx); if (indexShard.warmerService().logger().isTraceEnabled()) { - indexShard.warmerService().logger().trace("warmed random access for [{}], took [{}]", filterToWarm, TimeValue.timeValueNanos(System.nanoTime() - start)); + indexShard.warmerService().logger().trace("warmed fixed bitset for [{}], took [{}]", filterToWarm, TimeValue.timeValueNanos(System.nanoTime() - start)); } } catch (Throwable t) { - indexShard.warmerService().logger().warn("failed to load random access for [{}]", t, filterToWarm); + indexShard.warmerService().logger().warn("failed to load fixed bitset for [{}]", t, filterToWarm); } finally { latch.countDown(); }