Internal: get request while percolating existing documents to keep around headers and context of the original percolate request

Closes #7333
This commit is contained in:
javanna 2014-08-19 10:44:07 +02:00 committed by Luca Cavanna
parent b1f532eb85
commit 8458138b8c
5 changed files with 42 additions and 4 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.action.get;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.action.support.single.shard.SingleShardOperationRequest;
@ -66,6 +67,26 @@ public class GetRequest extends SingleShardOperationRequest<GetRequest> {
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, ActionRequest originalRequest) {
super(originalRequest);
this.index = getRequest.index;
this.type = getRequest.type;
this.id = getRequest.id;
this.routing = getRequest.routing;
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)}
* must be set.

View File

@ -246,8 +246,6 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
}
}
private boolean listenerThreaded = false;
String preference;
Boolean realtime;
boolean refresh;
@ -255,6 +253,18 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
List<Item> items = new ArrayList<>();
public MultiGetRequest() {
}
/**
* Creates a multi get request caused by some other request, which is provided as an
* argument so that its headers and context can be copied to the new request
*/
public MultiGetRequest(ActionRequest request) {
super(request);
}
public List<Item> getItems() {
return this.items;
}

View File

@ -93,7 +93,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
}
if (!existingDocsRequests.isEmpty()) {
final MultiGetRequest multiGetRequest = new MultiGetRequest();
final MultiGetRequest multiGetRequest = new MultiGetRequest(request);
for (GetRequest getRequest : existingDocsRequests) {
multiGetRequest.add(
new MultiGetRequest.Item(getRequest.index(), getRequest.type(), getRequest.id())

View File

@ -21,6 +21,7 @@ package org.elasticsearch.action.percolate;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.TransportGetAction;
import org.elasticsearch.action.support.ActionFilters;
@ -70,7 +71,9 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
protected void doExecute(final PercolateRequest request, final ActionListener<PercolateResponse> listener) {
request.startTime = System.currentTimeMillis();
if (request.getRequest() != null) {
getAction.execute(request.getRequest(), new ActionListener<GetResponse>() {
//create a new get request to make sure it has the same headers and context as the original percolate request
GetRequest getRequest = new GetRequest(request.getRequest(), request);
getAction.execute(getRequest, new ActionListener<GetResponse>() {
@Override
public void onResponse(GetResponse getResponse) {
if (!getResponse.isExists()) {

View File

@ -43,6 +43,10 @@ public abstract class SingleShardOperationRequest<T extends SingleShardOperation
protected SingleShardOperationRequest() {
}
protected SingleShardOperationRequest(ActionRequest request) {
super(request);
}
public SingleShardOperationRequest(String index) {
this.index = index;
}