From 6717de9e46944a6fb2364c21ff03ff6fa5ebd14b Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 16 Sep 2014 14:35:14 +0200 Subject: [PATCH] Internal: make sure that update internal requests share the same original headers and request context Update request internally executes index and delete operations. We need to make sure that those internal operations hold the same headers and context as the original update request. Achieved via copy constructors that accept the current request and the original request. Closes #7766 --- .../action/delete/DeleteRequest.java | 19 ++++++++++++---- .../action/index/IndexRequest.java | 22 +++++++++++++++++++ .../ShardReplicationOperationRequest.java | 16 +++++++++++++- .../action/update/TransportUpdateAction.java | 6 ++--- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java b/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java index 104575f874b..a0fb3e79181 100644 --- a/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java +++ b/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java @@ -53,6 +53,9 @@ public class DeleteRequest extends ShardReplicationOperationRequest super(request); } + /** + * 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, ActionRequest originalRequest) { + super(indexRequest, originalRequest); + 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.sourceUnsafe = indexRequest.sourceUnsafe; + this.opType = indexRequest.opType; + this.autoGeneratedId = indexRequest.autoGeneratedId; + 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)} * {@link #source(byte[])} must be set. diff --git a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java index 7e902d3ad3e..79f9cef94dc 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java @@ -54,12 +54,26 @@ public abstract class ShardReplicationOperationRequest() { @@ -211,7 +211,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio }); break; case INDEX: - IndexRequest indexRequest = result.action(); + IndexRequest indexRequest = new IndexRequest((IndexRequest)result.action(), request.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(); indexAction.execute(indexRequest, new ActionListener() { @@ -241,7 +241,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio }); break; case DELETE: - DeleteRequest deleteRequest = result.action(); + DeleteRequest deleteRequest = new DeleteRequest((DeleteRequest)result.action(), request.request()); deleteAction.execute(deleteRequest, new ActionListener() { @Override public void onResponse(DeleteResponse response) {