Free all pending search contexts if index is closed or removed
Today we only clear search contexts for deleted indies. Yet, we should do the same for closed indices to ensure they can be reopened quickly. Closes #12116
This commit is contained in:
parent
fcf8d2408f
commit
164212940b
|
@ -159,7 +159,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
|||
indicesService.indicesLifecycle().addListener(new IndicesLifecycle.Listener() {
|
||||
|
||||
@Override
|
||||
public void afterIndexDeleted(Index index, @IndexSettings Settings indexSettings) {
|
||||
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.
|
||||
freeAllContextForIndex(index);
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
|||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
@ -576,4 +577,31 @@ public class SearchScrollTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testCloseAndReopenOrDeleteWithActiveScroll() throws IOException {
|
||||
createIndex("test");
|
||||
for (int i = 0; i < 100; i++) {
|
||||
client().prepareIndex("test", "type1", Integer.toString(i)).setSource(jsonBuilder().startObject().field("field", i).endObject()).execute().actionGet();
|
||||
}
|
||||
refresh();
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(35)
|
||||
.setScroll(TimeValue.timeValueMinutes(2))
|
||||
.addSort("field", SortOrder.ASC)
|
||||
.execute().actionGet();
|
||||
long counter = 0;
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(100l));
|
||||
assertThat(searchResponse.getHits().hits().length, equalTo(35));
|
||||
for (SearchHit hit : searchResponse.getHits()) {
|
||||
assertThat(((Number) hit.sortValues()[0]).longValue(), equalTo(counter++));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
client().admin().indices().prepareClose("test").get();
|
||||
client().admin().indices().prepareOpen("test").get();
|
||||
ensureGreen("test");
|
||||
} else {
|
||||
client().admin().indices().prepareDelete("test").get();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue