Skip to content

Commit a8eb559

Browse files
javannaareek
authored andcommitted
Internal: auto create index to keep around headers and context of the request that caused it
Closes #7331
1 parent d015af0 commit a8eb559

File tree

7 files changed

+26
-4
lines changed

7 files changed

+26
-4
lines changed

src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.ElasticsearchIllegalArgumentException;
2626
import org.elasticsearch.ElasticsearchParseException;
2727
import org.elasticsearch.Version;
28+
import org.elasticsearch.action.ActionRequest;
2829
import org.elasticsearch.action.ActionRequestValidationException;
2930
import org.elasticsearch.action.admin.indices.alias.Alias;
3031
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
@@ -75,6 +76,14 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
7576
CreateIndexRequest() {
7677
}
7778

79+
/**
80+
* Constructs a new request to create an index that was triggered by a different request,
81+
* provided as an argument so that its headers and context can be copied to the new request.
82+
*/
83+
public CreateIndexRequest(ActionRequest request) {
84+
super(request);
85+
}
86+
7887
/**
7988
* Constructs a new request to create an index with the specified name.
8089
*/

src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected void doExecute(final BulkRequest bulkRequest, final ActionListener<Bul
120120
ClusterState state = clusterService.state();
121121
for (final String index : indices) {
122122
if (autoCreateIndex.shouldAutoCreate(index, state)) {
123-
createIndexAction.execute(new CreateIndexRequest(index).cause("auto(bulk api)").masterNodeTimeout(bulkRequest.timeout()), new ActionListener<CreateIndexResponse>() {
123+
createIndexAction.execute(new CreateIndexRequest(bulkRequest).index(index).cause("auto(bulk api)").masterNodeTimeout(bulkRequest.timeout()), new ActionListener<CreateIndexResponse>() {
124124
@Override
125125
public void onResponse(CreateIndexResponse result) {
126126
if (counter.decrementAndGet() == 0) {

src/main/java/org/elasticsearch/action/delete/TransportDeleteAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected String executor() {
7474
protected void doExecute(final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
7575
if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
7676
request.beforeLocalFork();
77-
createIndexAction.execute(new CreateIndexRequest(request.index()).cause("auto(delete api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
77+
createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
7878
@Override
7979
public void onResponse(CreateIndexResponse result) {
8080
innerExecute(request, listener);

src/main/java/org/elasticsearch/action/index/TransportIndexAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected void doExecute(final IndexRequest request, final ActionListener<IndexR
8383
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
8484
if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
8585
request.beforeLocalFork(); // we fork on another thread...
86-
createIndexAction.execute(new CreateIndexRequest(request.index()).cause("auto(index api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
86+
createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(index api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
8787
@Override
8888
public void onResponse(CreateIndexResponse result) {
8989
innerExecute(request, listener);

src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.elasticsearch.action.support.master;
2020

21+
import org.elasticsearch.action.ActionRequest;
2122
import org.elasticsearch.cluster.ack.AckedRequest;
2223
import org.elasticsearch.common.io.stream.StreamInput;
2324
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -41,6 +42,10 @@ public abstract class AcknowledgedRequest<T extends MasterNodeOperationRequest>
4142
protected AcknowledgedRequest() {
4243
}
4344

45+
protected AcknowledgedRequest(ActionRequest request) {
46+
super(request);
47+
}
48+
4449
/**
4550
* Allows to set the timeout
4651
* @param timeout timeout as a string (e.g. 1s)

src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public abstract class MasterNodeOperationRequest<T extends MasterNodeOperationRe
3535

3636
protected TimeValue masterNodeTimeout = DEFAULT_MASTER_NODE_TIMEOUT;
3737

38+
protected MasterNodeOperationRequest() {
39+
40+
}
41+
42+
protected MasterNodeOperationRequest(ActionRequest request) {
43+
super(request);
44+
}
45+
3846
/**
3947
* A timeout value in case the master has not been discovered yet or disconnected.
4048
*/

src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected void doExecute(final UpdateRequest request, final ActionListener<Updat
120120
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
121121
if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
122122
request.beforeLocalFork(); // we fork on another thread...
123-
createIndexAction.execute(new CreateIndexRequest(request.index()).cause("auto(update api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
123+
createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(update api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
124124
@Override
125125
public void onResponse(CreateIndexResponse result) {
126126
innerExecute(request, listener);

0 commit comments

Comments
 (0)