Java api: remove needless copy constructors from request classes
After #15776 got in, we don't need these copy constructors anymore. When we used to copy requests it was to make sure that headers and context were copied from the parent requests (e.g. index/delete as part of update). This is not a problem anymore.
This commit is contained in:
parent
b5aee2075f
commit
5849646baa
|
@ -272,7 +272,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
requestsByShard.put(shardIt.shardId(), list);
|
requestsByShard.put(shardIt.shardId(), list);
|
||||||
}
|
}
|
||||||
list.add(new BulkItemRequest(i, new DeleteRequest(deleteRequest)));
|
list.add(new BulkItemRequest(i, deleteRequest));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, deleteRequest.type(), deleteRequest.id(), deleteRequest.routing()).shardId();
|
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, deleteRequest.type(), deleteRequest.id(), deleteRequest.routing()).shardId();
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.delete;
|
package org.elasticsearch.action.delete;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.DocumentRequest;
|
import org.elasticsearch.action.DocumentRequest;
|
||||||
import org.elasticsearch.action.support.replication.ReplicationRequest;
|
import org.elasticsearch.action.support.replication.ReplicationRequest;
|
||||||
|
@ -80,28 +79,6 @@ public class DeleteRequest extends ReplicationRequest<DeleteRequest> implements
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor that creates a new delete request that is a copy of the one provided as an argument.
|
|
||||||
*/
|
|
||||||
public DeleteRequest(DeleteRequest request) {
|
|
||||||
this(request, request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor that creates a new delete request that is a copy of the one provided as an argument.
|
|
||||||
* The new request will inherit though headers and context from the original request that caused it.
|
|
||||||
*/
|
|
||||||
public DeleteRequest(DeleteRequest request, ActionRequest originalRequest) {
|
|
||||||
super(request);
|
|
||||||
this.type = request.type();
|
|
||||||
this.id = request.id();
|
|
||||||
this.routing = request.routing();
|
|
||||||
this.parent = request.parent();
|
|
||||||
this.refresh = request.refresh();
|
|
||||||
this.version = request.version();
|
|
||||||
this.versionType = request.versionType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionRequestValidationException validate() {
|
public ActionRequestValidationException validate() {
|
||||||
ActionRequestValidationException validationException = super.validate();
|
ActionRequestValidationException validationException = super.validate();
|
||||||
|
|
|
@ -67,26 +67,6 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
||||||
type = "_all";
|
type = "_all";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor that creates a new get request that is a copy of the one provided as an argument.
|
|
||||||
* The new request will inherit though headers and context from the original request that caused it.
|
|
||||||
*/
|
|
||||||
public GetRequest(GetRequest getRequest) {
|
|
||||||
this.index = getRequest.index;
|
|
||||||
this.type = getRequest.type;
|
|
||||||
this.id = getRequest.id;
|
|
||||||
this.routing = getRequest.routing;
|
|
||||||
this.parent = getRequest.parent;
|
|
||||||
this.preference = getRequest.preference;
|
|
||||||
this.fields = getRequest.fields;
|
|
||||||
this.fetchSourceContext = getRequest.fetchSourceContext;
|
|
||||||
this.refresh = getRequest.refresh;
|
|
||||||
this.realtime = getRequest.realtime;
|
|
||||||
this.version = getRequest.version;
|
|
||||||
this.versionType = getRequest.versionType;
|
|
||||||
this.ignoreErrorsOnGeneratedFields = getRequest.ignoreErrorsOnGeneratedFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new get request against the specified index. The {@link #type(String)} and {@link #id(String)}
|
* Constructs a new get request against the specified index. The {@link #type(String)} and {@link #id(String)}
|
||||||
* must be set.
|
* must be set.
|
||||||
|
|
|
@ -159,26 +159,6 @@ public class IndexRequest extends ReplicationRequest<IndexRequest> implements Do
|
||||||
public IndexRequest() {
|
public IndexRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor that creates a new index request that is a copy of the one provided as an argument.
|
|
||||||
* The new request will inherit though headers and context from the original request that caused it.
|
|
||||||
*/
|
|
||||||
public IndexRequest(IndexRequest indexRequest) {
|
|
||||||
super(indexRequest);
|
|
||||||
this.type = indexRequest.type;
|
|
||||||
this.id = indexRequest.id;
|
|
||||||
this.routing = indexRequest.routing;
|
|
||||||
this.parent = indexRequest.parent;
|
|
||||||
this.timestamp = indexRequest.timestamp;
|
|
||||||
this.ttl = indexRequest.ttl;
|
|
||||||
this.source = indexRequest.source;
|
|
||||||
this.opType = indexRequest.opType;
|
|
||||||
this.refresh = indexRequest.refresh;
|
|
||||||
this.version = indexRequest.version;
|
|
||||||
this.versionType = indexRequest.versionType;
|
|
||||||
this.contentType = indexRequest.contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new index request against the specific index. The {@link #type(String)}
|
* Constructs a new index request against the specific index. The {@link #type(String)}
|
||||||
* {@link #source(byte[])} must be set.
|
* {@link #source(byte[])} must be set.
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.action.percolate;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.ShardOperationFailedException;
|
import org.elasticsearch.action.ShardOperationFailedException;
|
||||||
import org.elasticsearch.action.get.GetRequest;
|
|
||||||
import org.elasticsearch.action.get.GetResponse;
|
import org.elasticsearch.action.get.GetResponse;
|
||||||
import org.elasticsearch.action.get.TransportGetAction;
|
import org.elasticsearch.action.get.TransportGetAction;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
|
@ -74,9 +73,7 @@ public class TransportPercolateAction extends TransportBroadcastAction<Percolate
|
||||||
protected void doExecute(Task task, final PercolateRequest request, final ActionListener<PercolateResponse> listener) {
|
protected void doExecute(Task task, final PercolateRequest request, final ActionListener<PercolateResponse> listener) {
|
||||||
request.startTime = System.currentTimeMillis();
|
request.startTime = System.currentTimeMillis();
|
||||||
if (request.getRequest() != null) {
|
if (request.getRequest() != null) {
|
||||||
//create a new get request to make sure it has the same headers and context as the original percolate request
|
getAction.execute(request.getRequest(), new ActionListener<GetResponse>() {
|
||||||
GetRequest getRequest = new GetRequest(request.getRequest());
|
|
||||||
getAction.execute(getRequest, new ActionListener<GetResponse>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(GetResponse getResponse) {
|
public void onResponse(GetResponse getResponse) {
|
||||||
if (!getResponse.isExists()) {
|
if (!getResponse.isExists()) {
|
||||||
|
|
|
@ -76,23 +76,6 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
|
||||||
public SearchRequest() {
|
public SearchRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor that creates a new search request that is a copy of the one provided as an argument.
|
|
||||||
* The new request will inherit though headers and context from the original request that caused it.
|
|
||||||
*/
|
|
||||||
public SearchRequest(SearchRequest searchRequest) {
|
|
||||||
this.searchType = searchRequest.searchType;
|
|
||||||
this.indices = searchRequest.indices;
|
|
||||||
this.routing = searchRequest.routing;
|
|
||||||
this.preference = searchRequest.preference;
|
|
||||||
this.template = searchRequest.template;
|
|
||||||
this.source = searchRequest.source;
|
|
||||||
this.requestCache = searchRequest.requestCache;
|
|
||||||
this.scroll = searchRequest.scroll;
|
|
||||||
this.types = searchRequest.types;
|
|
||||||
this.indicesOptions = searchRequest.indicesOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new search request against the indices. No indices provided here means that search
|
* Constructs a new search request against the indices. No indices provided here means that search
|
||||||
* will run against all indices.
|
* will run against all indices.
|
||||||
|
|
|
@ -59,8 +59,7 @@ public class TransportMultiSearchAction extends HandledTransportAction<MultiSear
|
||||||
final AtomicInteger counter = new AtomicInteger(responses.length());
|
final AtomicInteger counter = new AtomicInteger(responses.length());
|
||||||
for (int i = 0; i < responses.length(); i++) {
|
for (int i = 0; i < responses.length(); i++) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
SearchRequest searchRequest = new SearchRequest(request.requests().get(i));
|
searchAction.execute(request.requests().get(i), new ActionListener<SearchResponse>() {
|
||||||
searchAction.execute(searchRequest, new ActionListener<SearchResponse>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(SearchResponse searchResponse) {
|
public void onResponse(SearchResponse searchResponse) {
|
||||||
responses.set(index, new MultiSearchResponse.Item(searchResponse, null));
|
responses.set(index, new MultiSearchResponse.Item(searchResponse, null));
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.support.replication;
|
package org.elasticsearch.action.support.replication;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
|
||||||
import org.elasticsearch.index.shard.ShardId;
|
import org.elasticsearch.index.shard.ShardId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,13 +37,4 @@ public class BasicReplicationRequest extends ReplicationRequest<BasicReplication
|
||||||
public BasicReplicationRequest(ShardId shardId) {
|
public BasicReplicationRequest(ShardId shardId) {
|
||||||
super(shardId);
|
super(shardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor that creates a new request that is a copy of the one
|
|
||||||
* provided as an argument.
|
|
||||||
*/
|
|
||||||
protected BasicReplicationRequest(BasicReplicationRequest request) {
|
|
||||||
super(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,16 +70,6 @@ public abstract class ReplicationRequest<Request extends ReplicationRequest<Requ
|
||||||
this.shardId = shardId;
|
this.shardId = shardId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor that creates a new request that is a copy of the one provided as an argument.
|
|
||||||
* The new request will inherit though headers and context from the original request that caused it.
|
|
||||||
*/
|
|
||||||
protected ReplicationRequest(Request request) {
|
|
||||||
this.timeout = request.timeout();
|
|
||||||
this.index = request.index();
|
|
||||||
this.consistencyLevel = request.consistencyLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A timeout to wait if the index operation can't be performed immediately. Defaults to <tt>1m</tt>.
|
* A timeout to wait if the index operation can't be performed immediately. Defaults to <tt>1m</tt>.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.action.RoutingMissingException;
|
||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||||
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
|
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
|
||||||
import org.elasticsearch.action.delete.DeleteRequest;
|
|
||||||
import org.elasticsearch.action.delete.DeleteResponse;
|
import org.elasticsearch.action.delete.DeleteResponse;
|
||||||
import org.elasticsearch.action.delete.TransportDeleteAction;
|
import org.elasticsearch.action.delete.TransportDeleteAction;
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
|
@ -169,7 +168,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
||||||
final UpdateHelper.Result result = updateHelper.prepare(request, indexShard);
|
final UpdateHelper.Result result = updateHelper.prepare(request, indexShard);
|
||||||
switch (result.operation()) {
|
switch (result.operation()) {
|
||||||
case UPSERT:
|
case UPSERT:
|
||||||
IndexRequest upsertRequest = new IndexRequest((IndexRequest)result.action());
|
IndexRequest upsertRequest = result.action();
|
||||||
// we fetch it from the index request so we don't generate the bytes twice, its already done in the index request
|
// we fetch it from the index request so we don't generate the bytes twice, its already done in the index request
|
||||||
final BytesReference upsertSourceBytes = upsertRequest.source();
|
final BytesReference upsertSourceBytes = upsertRequest.source();
|
||||||
indexAction.execute(upsertRequest, new ActionListener<IndexResponse>() {
|
indexAction.execute(upsertRequest, new ActionListener<IndexResponse>() {
|
||||||
|
@ -206,7 +205,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case INDEX:
|
case INDEX:
|
||||||
IndexRequest indexRequest = new IndexRequest((IndexRequest)result.action());
|
IndexRequest indexRequest = result.action();
|
||||||
// we fetch it from the index request so we don't generate the bytes twice, its already done in the index request
|
// we fetch it from the index request so we don't generate the bytes twice, its already done in the index request
|
||||||
final BytesReference indexSourceBytes = indexRequest.source();
|
final BytesReference indexSourceBytes = indexRequest.source();
|
||||||
indexAction.execute(indexRequest, new ActionListener<IndexResponse>() {
|
indexAction.execute(indexRequest, new ActionListener<IndexResponse>() {
|
||||||
|
@ -236,8 +235,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
DeleteRequest deleteRequest = new DeleteRequest(result.action(), request);
|
deleteAction.execute(result.action(), new ActionListener<DeleteResponse>() {
|
||||||
deleteAction.execute(deleteRequest, new ActionListener<DeleteResponse>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(DeleteResponse response) {
|
public void onResponse(DeleteResponse response) {
|
||||||
UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), false);
|
UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), false);
|
||||||
|
|
|
@ -32,7 +32,6 @@ public abstract class TransportRequest extends TransportMessage<TransportRequest
|
||||||
public TransportRequest() {
|
public TransportRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the task object that should be used to keep track of the processing of the request.
|
* Returns the task object that should be used to keep track of the processing of the request.
|
||||||
*
|
*
|
||||||
|
@ -48,5 +47,4 @@ public abstract class TransportRequest extends TransportMessage<TransportRequest
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue