cleanup queryHint since its not was never used

preference ended up as the way to control routing
This commit is contained in:
Shay Banon 2013-01-07 04:02:45 +01:00
parent bcdda811ef
commit 2c4b9d9ba2
14 changed files with 18 additions and 104 deletions

View File

@ -103,7 +103,7 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct
protected GroupShardsIterator shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) { protected GroupShardsIterator shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) {
// Hard-code routing to limit request to a single shard, but still, randomize it... // Hard-code routing to limit request to a single shard, but still, randomize it...
Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(Integer.toString(ThreadLocalRandom.current().nextInt(1000)), request.indices()); Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(Integer.toString(ThreadLocalRandom.current().nextInt(1000)), request.indices());
return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, null, routingMap, "_local"); return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, routingMap, "_local");
} }
@Override @Override

View File

@ -59,8 +59,6 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
private float minScore = DEFAULT_MIN_SCORE; private float minScore = DEFAULT_MIN_SCORE;
@Nullable
protected String queryHint;
@Nullable @Nullable
protected String routing; protected String routing;
@ -78,7 +76,6 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
*/ */
public CountRequest(String... indices) { public CountRequest(String... indices) {
super(indices); super(indices);
this.queryHint = null;
} }
@Override @Override
@ -87,10 +84,6 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
return validationException; return validationException;
} }
public String queryHint() {
return queryHint;
}
@Override @Override
protected void beforeStart() { protected void beforeStart() {
if (querySourceUnsafe) { if (querySourceUnsafe) {
@ -99,14 +92,6 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
} }
} }
/**
* A query hint to optionally later be used when routing the request.
*/
public CountRequest queryHint(String queryHint) {
this.queryHint = queryHint;
return this;
}
/** /**
* The minimum score of the documents to include in the count. * The minimum score of the documents to include in the count.
*/ */
@ -239,50 +224,19 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
minScore = in.readFloat(); minScore = in.readFloat();
routing = in.readOptionalString();
if (in.readBoolean()) {
queryHint = in.readUTF();
}
if (in.readBoolean()) {
routing = in.readUTF();
}
querySourceUnsafe = false; querySourceUnsafe = false;
querySource = in.readBytesReference(); querySource = in.readBytesReference();
types = in.readStringArray();
int typesSize = in.readVInt();
if (typesSize > 0) {
types = new String[typesSize];
for (int i = 0; i < typesSize; i++) {
types[i] = in.readUTF();
}
}
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeFloat(minScore); out.writeFloat(minScore);
out.writeOptionalString(routing);
if (queryHint == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeUTF(queryHint);
}
if (routing == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeUTF(routing);
}
out.writeBytesReference(querySource); out.writeBytesReference(querySource);
out.writeStringArray(types);
out.writeVInt(types.length);
for (String type : types) {
out.writeUTF(type);
}
} }
@Override @Override

View File

@ -52,14 +52,6 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder<CountR
return this; return this;
} }
/**
* A query hint to optionally later be used when routing the request.
*/
public CountRequestBuilder setQueryHint(String queryHint) {
request.queryHint(queryHint);
return this;
}
/** /**
* A comma separated list of routing values to control the shards the search will be executed on. * A comma separated list of routing values to control the shards the search will be executed on.
*/ */

View File

@ -104,7 +104,7 @@ public class TransportCountAction extends TransportBroadcastOperationAction<Coun
@Override @Override
protected GroupShardsIterator shards(ClusterState clusterState, CountRequest request, String[] concreteIndices) { protected GroupShardsIterator shards(ClusterState clusterState, CountRequest request, String[] concreteIndices) {
Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices()); Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices());
return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, request.queryHint(), routingMap, null); return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, routingMap, null);
} }
@Override @Override

View File

@ -121,8 +121,6 @@ public class MultiSearchRequest extends ActionRequest<MultiSearchRequest> {
searchRequest.preference(parser.text()); searchRequest.preference(parser.text());
} else if ("routing".equals(currentFieldName)) { } else if ("routing".equals(currentFieldName)) {
searchRequest.routing(parser.text()); searchRequest.routing(parser.text());
} else if ("query_hint".equals(currentFieldName) || "queryHint".equals(currentFieldName)) {
searchRequest.queryHint(parser.text());
} else if ("ignore_indices".equals(currentFieldName) || "ignoreIndices".equals(currentFieldName)) { } else if ("ignore_indices".equals(currentFieldName) || "ignoreIndices".equals(currentFieldName)) {
searchRequest.ignoreIndices(IgnoreIndices.fromString(parser.text())); searchRequest.ignoreIndices(IgnoreIndices.fromString(parser.text()));
} }

View File

@ -64,8 +64,6 @@ public class SearchRequest extends ActionRequest<SearchRequest> {
private String[] indices; private String[] indices;
@Nullable
private String queryHint;
@Nullable @Nullable
private String routing; private String routing;
@Nullable @Nullable
@ -409,21 +407,6 @@ public class SearchRequest extends ActionRequest<SearchRequest> {
return indices; return indices;
} }
/**
* A query hint to optionally later be used when routing the request.
*/
public SearchRequest queryHint(String queryHint) {
this.queryHint = queryHint;
return this;
}
/**
* A query hint to optionally later be used when routing the request.
*/
public String queryHint() {
return queryHint;
}
/** /**
* If set, will enable scrolling of the search request. * If set, will enable scrolling of the search request.
*/ */
@ -464,7 +447,6 @@ public class SearchRequest extends ActionRequest<SearchRequest> {
indices[i] = in.readString(); indices[i] = in.readString();
} }
queryHint = in.readOptionalString();
routing = in.readOptionalString(); routing = in.readOptionalString();
preference = in.readOptionalString(); preference = in.readOptionalString();
@ -493,7 +475,6 @@ public class SearchRequest extends ActionRequest<SearchRequest> {
out.writeString(index); out.writeString(index);
} }
out.writeOptionalString(queryHint);
out.writeOptionalString(routing); out.writeOptionalString(routing);
out.writeOptionalString(preference); out.writeOptionalString(preference);

View File

@ -126,14 +126,6 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se
return this; return this;
} }
/**
* A query hint to optionally later be used when routing the request.
*/
public SearchRequestBuilder setQueryHint(String queryHint) {
request.queryHint(queryHint);
return this;
}
/** /**
* A comma separated list of routing values to control the shards the search will be executed on. * A comma separated list of routing values to control the shards the search will be executed on.
*/ */

View File

@ -21,7 +21,6 @@ package org.elasticsearch.action.search;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.search.type.*; import org.elasticsearch.action.search.type.*;
import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
@ -90,7 +89,7 @@ public class TransportSearchAction extends TransportAction<SearchRequest, Search
ClusterState clusterState = clusterService.state(); ClusterState clusterState = clusterService.state();
String[] concreteIndices = clusterState.metaData().concreteIndices(searchRequest.indices(), searchRequest.ignoreIndices(), true); String[] concreteIndices = clusterState.metaData().concreteIndices(searchRequest.indices(), searchRequest.ignoreIndices(), true);
Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(searchRequest.routing(), searchRequest.indices()); Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(searchRequest.routing(), searchRequest.indices());
int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, searchRequest.indices(), concreteIndices, searchRequest.queryHint(), routingMap, searchRequest.preference()); int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, searchRequest.indices(), concreteIndices, routingMap, searchRequest.preference());
if (shardCount == 1) { if (shardCount == 1) {
// if we only have one group, then we always want Q_A_F, no need for DFS, and no need to do THEN since we hit one shard // if we only have one group, then we always want Q_A_F, no need for DFS, and no need to do THEN since we hit one shard
searchRequest.searchType(QUERY_AND_FETCH); searchRequest.searchType(QUERY_AND_FETCH);

View File

@ -116,7 +116,7 @@ public abstract class TransportSearchTypeAction extends TransportAction<SearchRe
Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices()); Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices());
shardsIts = clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, request.queryHint(), routingMap, request.preference()); shardsIts = clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, routingMap, request.preference());
expectedSuccessfulOps = shardsIts.size(); expectedSuccessfulOps = shardsIts.size();
// we need to add 1 for non active partition, since we count it in the total! // we need to add 1 for non active partition, since we count it in the total!
expectedTotalOps = shardsIts.totalSizeWith1ForEmpty(); expectedTotalOps = shardsIts.totalSizeWith1ForEmpty();

View File

@ -46,7 +46,7 @@ public interface OperationRouting {
GroupShardsIterator deleteByQueryShards(ClusterState clusterState, String index, @Nullable Set<String> routing) throws IndexMissingException; GroupShardsIterator deleteByQueryShards(ClusterState clusterState, String index, @Nullable Set<String> routing) throws IndexMissingException;
int searchShardsCount(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable String queryHint, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException; int searchShardsCount(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException;
GroupShardsIterator searchShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable String queryHint, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException; GroupShardsIterator searchShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException;
} }

View File

@ -111,7 +111,7 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
} }
@Override @Override
public int searchShardsCount(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable String queryHint, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException { public int searchShardsCount(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException {
if (concreteIndices == null || concreteIndices.length == 0) { if (concreteIndices == null || concreteIndices.length == 0) {
concreteIndices = clusterState.metaData().concreteAllOpenIndices(); concreteIndices = clusterState.metaData().concreteAllOpenIndices();
} }
@ -145,7 +145,7 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
} }
@Override @Override
public GroupShardsIterator searchShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable String queryHint, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException { public GroupShardsIterator searchShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException {
if (concreteIndices == null || concreteIndices.length == 0) { if (concreteIndices == null || concreteIndices.length == 0) {
concreteIndices = clusterState.metaData().concreteAllOpenIndices(); concreteIndices = clusterState.metaData().concreteAllOpenIndices();
} }

View File

@ -86,7 +86,6 @@ public class RestCountAction extends BaseRestHandler {
} }
} }
} }
countRequest.queryHint(request.param("query_hint"));
countRequest.routing(request.param("routing")); countRequest.routing(request.param("routing"));
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE)); countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
countRequest.types(splitTypes(request.param("type"))); countRequest.types(splitTypes(request.param("type")));

View File

@ -139,7 +139,6 @@ public class RestSearchAction extends BaseRestHandler {
} }
searchRequest.types(RestActions.splitTypes(request.param("type"))); searchRequest.types(RestActions.splitTypes(request.param("type")));
searchRequest.queryHint(request.param("query_hint"));
searchRequest.routing(request.param("routing")); searchRequest.routing(request.param("routing"));
searchRequest.preference(request.param("preference")); searchRequest.preference(request.param("preference"));
if (request.hasParam("ignore_indices")) { if (request.hasParam("ignore_indices")) {

View File

@ -333,31 +333,31 @@ public class RoutingIteratorTests {
PlainOperationRouting operationRouting = new PlainOperationRouting(ImmutableSettings.Builder.EMPTY_SETTINGS, new DjbHashFunction(), new AwarenessAllocationDecider()); PlainOperationRouting operationRouting = new PlainOperationRouting(ImmutableSettings.Builder.EMPTY_SETTINGS, new DjbHashFunction(), new AwarenessAllocationDecider());
GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, null, "_shards:0"); GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, "_shards:0");
assertThat(shardIterators.size(), equalTo(1)); assertThat(shardIterators.size(), equalTo(1));
assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0)); assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0));
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, null, "_shards:1"); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, "_shards:1");
assertThat(shardIterators.size(), equalTo(1)); assertThat(shardIterators.size(), equalTo(1));
assertThat(shardIterators.iterator().next().shardId().id(), equalTo(1)); assertThat(shardIterators.iterator().next().shardId().id(), equalTo(1));
//check node preference, first without preference to see they switch //check node preference, first without preference to see they switch
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, null, "_shards:0;"); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, "_shards:0;");
assertThat(shardIterators.size(), equalTo(1)); assertThat(shardIterators.size(), equalTo(1));
assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0)); assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0));
String firstRoundNodeId = shardIterators.iterator().next().nextOrNull().currentNodeId(); String firstRoundNodeId = shardIterators.iterator().next().nextOrNull().currentNodeId();
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, null, "_shards:0"); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, "_shards:0");
assertThat(shardIterators.size(), equalTo(1)); assertThat(shardIterators.size(), equalTo(1));
assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0)); assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0));
assertThat(shardIterators.iterator().next().nextOrNull().currentNodeId(), not(equalTo(firstRoundNodeId))); assertThat(shardIterators.iterator().next().nextOrNull().currentNodeId(), not(equalTo(firstRoundNodeId)));
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, null, "_shards:0;_prefer_node:node1"); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, "_shards:0;_prefer_node:node1");
assertThat(shardIterators.size(), equalTo(1)); assertThat(shardIterators.size(), equalTo(1));
assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0)); assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0));
assertThat(shardIterators.iterator().next().nextOrNull().currentNodeId(), equalTo("node1")); assertThat(shardIterators.iterator().next().nextOrNull().currentNodeId(), equalTo("node1"));
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, null, "_shards:0;_prefer_node:node1"); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, new String[]{"test"}, null, "_shards:0;_prefer_node:node1");
assertThat(shardIterators.size(), equalTo(1)); assertThat(shardIterators.size(), equalTo(1));
assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0)); assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0));
assertThat(shardIterators.iterator().next().nextOrNull().currentNodeId(), equalTo("node1")); assertThat(shardIterators.iterator().next().nextOrNull().currentNodeId(), equalTo("node1"));