add constructor overloads for primary result

This commit is contained in:
Areek Zillur 2016-10-26 12:07:32 -04:00
parent 65832b987f
commit a3fcfe8196
4 changed files with 18 additions and 9 deletions

View File

@ -54,14 +54,14 @@ public class TransportShardFlushAction extends TransportReplicationAction<ShardF
protected PrimaryResult shardOperationOnPrimary(ShardFlushRequest shardRequest, IndexShard primary) {
primary.flush(shardRequest.getRequest());
logger.trace("{} flush request executed on primary", primary.shardId());
return new PrimaryResult(shardRequest, new ReplicationResponse(), null);
return new PrimaryResult(shardRequest, new ReplicationResponse());
}
@Override
protected ReplicaResult shardOperationOnReplica(ShardFlushRequest request, IndexShard replica) {
replica.flush(request.getRequest());
logger.trace("{} flush request executed on replica", replica.shardId());
return new ReplicaResult(null);
return new ReplicaResult();
}
@Override

View File

@ -57,14 +57,14 @@ public class TransportShardRefreshAction
protected PrimaryResult shardOperationOnPrimary(BasicReplicationRequest shardRequest, IndexShard primary) {
primary.refresh("api");
logger.trace("{} refresh request executed on primary", primary.shardId());
return new PrimaryResult(shardRequest, new ReplicationResponse(), null);
return new PrimaryResult(shardRequest, new ReplicationResponse());
}
@Override
protected ReplicaResult shardOperationOnReplica(BasicReplicationRequest request, IndexShard replica) {
replica.refresh("api");
logger.trace("{} refresh request executed on replica", replica.shardId());
return new ReplicaResult(null);
return new ReplicaResult();
}
@Override

View File

@ -24,6 +24,7 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionListenerResponseHandler;
import org.elasticsearch.action.UnavailableShardsException;
import org.elasticsearch.action.admin.indices.flush.ShardFlushRequest;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.TransportAction;
@ -383,6 +384,10 @@ public abstract class TransportReplicationAction<
this.finalFailure = finalFailure;
}
public PrimaryResult(ReplicaRequest replicaRequest, Response replicationResponse) {
this(replicaRequest, replicationResponse, null);
}
@Override
public ReplicaRequest replicaRequest() {
return replicaRequest;
@ -411,6 +416,10 @@ public abstract class TransportReplicationAction<
this.finalFailure = finalFailure;
}
public ReplicaResult() {
this(null);
}
public void respond(ActionListener<TransportResponse.Empty> listener) {
if (finalFailure == null) {
listener.onResponse(TransportResponse.Empty.INSTANCE);

View File

@ -718,7 +718,7 @@ public class TransportReplicationActionTests extends ESTestCase {
if (throwException) {
throw new ElasticsearchException("simulated");
}
return new ReplicaResult(null);
return new ReplicaResult();
}
};
final Action.ReplicaOperationTransportHandler replicaOperationTransportHandler = action.new ReplicaOperationTransportHandler();
@ -837,7 +837,7 @@ public class TransportReplicationActionTests extends ESTestCase {
if (throwException.get()) {
throw new RetryOnReplicaException(shardId, "simulation");
}
return new ReplicaResult(null);
return new ReplicaResult();
}
};
final Action.ReplicaOperationTransportHandler replicaOperationTransportHandler = action.new ReplicaOperationTransportHandler();
@ -961,13 +961,13 @@ public class TransportReplicationActionTests extends ESTestCase {
protected PrimaryResult shardOperationOnPrimary(Request shardRequest, IndexShard primary) throws Exception {
boolean executedBefore = shardRequest.processedOnPrimary.getAndSet(true);
assert executedBefore == false : "request has already been executed on the primary";
return new PrimaryResult(shardRequest, new Response(), null);
return new PrimaryResult(shardRequest, new Response());
}
@Override
protected ReplicaResult shardOperationOnReplica(Request request, IndexShard replica) {
request.processedOnReplicas.incrementAndGet();
return new ReplicaResult(null);
return new ReplicaResult();
}
@Override
@ -1053,7 +1053,7 @@ public class TransportReplicationActionTests extends ESTestCase {
@Override
public void execute() throws Exception {
this.resultListener.onResponse(action.new PrimaryResult(null, new Response(), null));
this.resultListener.onResponse(action.new PrimaryResult(null, new Response()));
}
}