Skip to content

Commit

Permalink
Only clear open search ctx if the index is delete or closed via API
Browse files Browse the repository at this point in the history
A change in #12116 introduces closing / cleaning of search ctx even if
the index service was closed due to a relocation of it's last shard. This
is not desired since in that case it's fine to serve the pending requests from
the relocated shard. This commit adds an extra check to ensure that the index is
either removed (delete) or closed via API.
  • Loading branch information
s1monw committed Jul 13, 2015
1 parent ca56d44 commit 2e2bb25
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/src/main/java/org/elasticsearch/search/SearchService.java
Expand Up @@ -157,11 +157,23 @@ public SearchService(Settings settings, ClusterService clusterService, IndicesSe
this.clusterService = clusterService;
this.indicesService = indicesService;
indicesService.indicesLifecycle().addListener(new IndicesLifecycle.Listener() {

@Override
public void afterIndexClosed(Index index, @IndexSettings Settings indexSettings) {
// once an index is closed we can just clean up all the pending search context information
// to release memory and let references to the filesystem go etc.
IndexMetaData idxMeta = SearchService.this.clusterService.state().metaData().index(index.getName());
if (idxMeta != null && idxMeta.state() == IndexMetaData.State.CLOSE) {
// we need to check if it's really closed
// since sometimes due to a relocation we already closed the shard and that causes the index to be closed
// if we then close all the contexts we can get some search failures along the way which are not expected.
// it's fine to keep the contexts open if the index is still "alive"
// unfortunately we don't have a clear way to signal today why an index is closed.
afterIndexDeleted(index, indexSettings);
}
}

@Override
public void afterIndexDeleted(Index index, @IndexSettings Settings indexSettings) {
freeAllContextForIndex(index);
}
});
Expand Down

0 comments on commit 2e2bb25

Please sign in to comment.