Skip to content

Commit

Permalink
Core: Add warmer listener only when index service is set, in order to…
Browse files Browse the repository at this point in the history
… 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 elastic#8140
Closes elastic#8168
  • Loading branch information
martijnvg committed Oct 22, 2014
1 parent 7214a77 commit aaaa13f
Showing 1 changed file with 9 additions and 6 deletions.
Expand Up @@ -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);
}

Expand Down Expand Up @@ -164,10 +171,6 @@ public Value call() throws Exception {
}).fixedBitSet;
}

public void setIndexService(InternalIndexService indexService) {
this.indexService = indexService;
}

@Override
public void onRemoval(RemovalNotification<Object, Cache<Filter, Value>> notification) {
Object key = notification.getKey();
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit aaaa13f

Please sign in to comment.