remove boolean return type from resolveRequest and needless listener arg

This commit is contained in:
javanna 2016-02-15 14:41:43 +01:00 committed by Luca Cavanna
parent 0fe73b51f9
commit 65f5cbe568
3 changed files with 9 additions and 17 deletions

View File

@ -35,10 +35,8 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.node.NodeClosedException; import org.elasticsearch.node.NodeClosedException;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.BaseTransportResponseHandler; import org.elasticsearch.transport.BaseTransportResponseHandler;
@ -91,11 +89,11 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
protected ClusterBlockException checkRequestBlock(ClusterState state, Request request) { protected ClusterBlockException checkRequestBlock(ClusterState state, Request request) {
return state.blocks().indexBlockedException(ClusterBlockLevel.WRITE, request.concreteIndex()); return state.blocks().indexBlockedException(ClusterBlockLevel.WRITE, request.concreteIndex());
} }
/** /**
* Resolves the request. If the resolve means a different execution, then return false * Resolves the request. Throws an exception if the request cannot be resolved.
* here to indicate not to continue and execute this request.
*/ */
protected abstract boolean resolveRequest(ClusterState state, Request request, ActionListener<Response> listener); protected abstract void resolveRequest(ClusterState state, Request request);
protected boolean retryOnFailure(Throwable e) { protected boolean retryOnFailure(Throwable e) {
return false; return false;
@ -141,11 +139,7 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
} }
} }
request.concreteIndex(indexNameExpressionResolver.concreteSingleIndex(observer.observedState(), request)); request.concreteIndex(indexNameExpressionResolver.concreteSingleIndex(observer.observedState(), request));
// check if we need to execute, and if not, return resolveRequest(observer.observedState(), request);
if (!resolveRequest(observer.observedState(), request, listener)) {
listener.onFailure(new IllegalStateException(LoggerMessageFormat.format("[{}][{}] request {} could not be resolved",request.index, request.shardId, actionName)));
return;
}
blockException = checkRequestBlock(observer.observedState(), request); blockException = checkRequestBlock(observer.observedState(), request);
if (blockException != null) { if (blockException != null) {
if (blockException.retryable()) { if (blockException.retryable()) {

View File

@ -100,9 +100,8 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
} }
@Override @Override
protected boolean resolveRequest(ClusterState state, UpdateRequest request, ActionListener<UpdateResponse> listener) { protected void resolveRequest(ClusterState state, UpdateRequest request) {
resolveAndValidateRouting(state.metaData(), request.concreteIndex(), request); resolveAndValidateRouting(state.metaData(), request.concreteIndex(), request);
return true;
} }
public static void resolveAndValidateRouting(MetaData metaData, String concreteIndex, UpdateRequest request) { public static void resolveAndValidateRouting(MetaData metaData, String concreteIndex, UpdateRequest request) {

View File

@ -108,8 +108,7 @@ public class TransportInstanceSingleOperationActionTests extends ESTestCase {
} }
@Override @Override
protected boolean resolveRequest(ClusterState state, Request request, ActionListener<Response> listener) { protected void resolveRequest(ClusterState state, Request request) {
return true;
} }
@Override @Override
@ -290,13 +289,13 @@ public class TransportInstanceSingleOperationActionTests extends ESTestCase {
Settings.EMPTY, Settings.EMPTY,
"indices:admin/test_unresolvable", "indices:admin/test_unresolvable",
transportService, transportService,
new ActionFilters(new HashSet<ActionFilter>()), new ActionFilters(new HashSet<>()),
new MyResolver(), new MyResolver(),
Request::new Request::new
) { ) {
@Override @Override
protected boolean resolveRequest(ClusterState state, Request request, ActionListener<Response> listener) { protected void resolveRequest(ClusterState state, Request request) {
return false; throw new IllegalStateException("request cannot be resolved");
} }
}; };
Request request = new Request().index("test"); Request request = new Request().index("test");