Searching while an index is being allocated and no active shards exists within a "shard replication group" can cause search "misses", closes #736.
This commit is contained in:
parent
578b752425
commit
faefc772a4
|
@ -112,7 +112,8 @@ public abstract class TransportSearchTypeAction extends BaseAction<SearchRequest
|
||||||
|
|
||||||
shardsIts = clusterService.operationRouting().searchShards(clusterState, request.indices(), request.queryHint(), request.routing());
|
shardsIts = clusterService.operationRouting().searchShards(clusterState, request.indices(), request.queryHint(), request.routing());
|
||||||
expectedSuccessfulOps = shardsIts.size();
|
expectedSuccessfulOps = shardsIts.size();
|
||||||
expectedTotalOps = shardsIts.totalSizeActive();
|
// we need to add 1 for non active partition, since we count it in the total!
|
||||||
|
expectedTotalOps = shardsIts.totalSizeActiveWith1ForEmpty();
|
||||||
|
|
||||||
if (expectedSuccessfulOps == 0) {
|
if (expectedSuccessfulOps == 0) {
|
||||||
// not search shards to search on...
|
// not search shards to search on...
|
||||||
|
|
|
@ -41,6 +41,19 @@ public class GroupShardsIterator implements Iterable<ShardIterator> {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int totalSizeActiveWith1ForEmpty() {
|
||||||
|
int size = 0;
|
||||||
|
for (ShardIterator shard : iterators) {
|
||||||
|
int sizeActive = shard.sizeActive();
|
||||||
|
if (sizeActive == 0) {
|
||||||
|
size += 1;
|
||||||
|
} else {
|
||||||
|
size += sizeActive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
public int totalSizeActive() {
|
public int totalSizeActive() {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
for (ShardIterator shard : iterators) {
|
for (ShardIterator shard : iterators) {
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elastic Search and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. Elastic Search licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.test.integration.search.basic;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.index.query.xcontent.QueryBuilders;
|
||||||
|
import org.elasticsearch.node.Node;
|
||||||
|
import org.elasticsearch.test.integration.AbstractNodesTests;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.elasticsearch.common.settings.ImmutableSettings.*;
|
||||||
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
public class SearchWhileCreatingIndexTests extends AbstractNodesTests {
|
||||||
|
|
||||||
|
@AfterMethod public void closeAll() {
|
||||||
|
closeAllNodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test basically verifies that search with a single shard active (cause we indexed to it) and other
|
||||||
|
* shards possibly not active at all (cause they haven't allocated) will still work.
|
||||||
|
*/
|
||||||
|
@Test public void searchWhileCreatingIndex() {
|
||||||
|
Node node = startNode("node1");
|
||||||
|
|
||||||
|
try {
|
||||||
|
node.client().admin().indices().prepareDelete("test").execute().actionGet();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
node.client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("number_of_shards", 10)).execute().actionGet();
|
||||||
|
|
||||||
|
node.client().prepareIndex("test", "type1").setSource("field", "test").execute().actionGet();
|
||||||
|
node.client().admin().indices().prepareRefresh().execute().actionGet();
|
||||||
|
|
||||||
|
SearchResponse searchResponse = node.client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||||
|
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||||
|
|
||||||
|
node.client().admin().indices().prepareDelete("test").execute().actionGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
node.client().admin().indices().prepareDelete("test").execute().actionGet();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue