open context stats
- rename to open_contexts from open, we might have other open stats in the future related to search (lucene index searchers?) - add a test to verify it works
This commit is contained in:
parent
8a7f81104f
commit
f09ad507a4
|
@ -203,7 +203,7 @@ public class SearchStats implements Streamable, ToXContent {
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject(Fields.SEARCH);
|
||||
builder.field(Fields.OPEN, openContexts);
|
||||
builder.field(Fields.OPEN_CONTEXTS, openContexts);
|
||||
totalStats.toXContent(builder, params);
|
||||
if (groupStats != null && !groupStats.isEmpty()) {
|
||||
builder.startObject(Fields.GROUPS);
|
||||
|
@ -220,7 +220,7 @@ public class SearchStats implements Streamable, ToXContent {
|
|||
|
||||
static final class Fields {
|
||||
static final XContentBuilderString SEARCH = new XContentBuilderString("search");
|
||||
static final XContentBuilderString OPEN = new XContentBuilderString("open");
|
||||
static final XContentBuilderString OPEN_CONTEXTS = new XContentBuilderString("open_contexts");
|
||||
static final XContentBuilderString GROUPS = new XContentBuilderString("groups");
|
||||
static final XContentBuilderString QUERY_TOTAL = new XContentBuilderString("query_total");
|
||||
static final XContentBuilderString QUERY_TIME = new XContentBuilderString("query_time");
|
||||
|
|
|
@ -516,7 +516,8 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
|||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
freeContext(context);
|
||||
context.indexShard().searchService().onFreeContext(context);
|
||||
context.release();
|
||||
}
|
||||
|
||||
private void freeContext(SearchContext context) {
|
||||
|
|
|
@ -21,8 +21,11 @@ package org.elasticsearch.test.integration.search.stats;
|
|||
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.test.integration.AbstractNodesTests;
|
||||
import org.testng.annotations.AfterClass;
|
||||
|
@ -30,6 +33,7 @@ import org.testng.annotations.BeforeClass;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
|
@ -95,4 +99,30 @@ public class SearchStatsTests extends AbstractNodesTests {
|
|||
assertThat(nodeStats.getNodes()[0].getIndices().getSearch().getTotal().getQueryCount(), greaterThan(0l));
|
||||
assertThat(nodeStats.getNodes()[0].getIndices().getSearch().getTotal().getQueryTimeInMillis(), greaterThan(0l));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenContexts() {
|
||||
client.admin().indices().prepareDelete().execute().actionGet();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
client.prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
||||
}
|
||||
IndicesStatsResponse indicesStats = client.admin().indices().prepareStats().execute().actionGet();
|
||||
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0l));
|
||||
|
||||
SearchResponse searchResponse = client.prepareSearch()
|
||||
.setSearchType(SearchType.SCAN)
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(5)
|
||||
.setScroll(TimeValue.timeValueMinutes(2))
|
||||
.execute().actionGet();
|
||||
|
||||
indicesStats = client.admin().indices().prepareStats().execute().actionGet();
|
||||
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(3l)); // 3 shards
|
||||
|
||||
// scroll, but with no timeout (so no context)
|
||||
searchResponse = client.prepareSearchScroll(searchResponse.getScrollId()).execute().actionGet();
|
||||
|
||||
indicesStats = client.admin().indices().prepareStats().execute().actionGet();
|
||||
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0l));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue