diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java index c146a27d9eaea..8b9afa55de375 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java @@ -169,7 +169,8 @@ public ClusterState execute(ClusterState currentState) throws Exception { request.index(), dataStreamDescriptor, request.masterNodeTimeout(), - request.timeout() + request.timeout(), + false ); ClusterState clusterState = metadataCreateDataStreamService.createDataStream(createRequest, currentState); indexNameRef.set(clusterState.metadata().dataStreams().get(request.index()).getIndices().get(0).getName()); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java index 8da848ac5f5cd..b7d2fc593e8fe 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java @@ -97,21 +97,23 @@ public ClusterState createDataStream(CreateDataStreamClusterStateUpdateRequest r public static final class CreateDataStreamClusterStateUpdateRequest extends ClusterStateUpdateRequest< CreateDataStreamClusterStateUpdateRequest> { + private final boolean performReroute; private final String name; private final long startTime; private final SystemDataStreamDescriptor descriptor; public CreateDataStreamClusterStateUpdateRequest(String name) { - this(name, System.currentTimeMillis(), null, TimeValue.ZERO, TimeValue.ZERO); + this(name, System.currentTimeMillis(), null, TimeValue.ZERO, TimeValue.ZERO, true); } public CreateDataStreamClusterStateUpdateRequest( String name, SystemDataStreamDescriptor systemDataStreamDescriptor, TimeValue masterNodeTimeout, - TimeValue timeout + TimeValue timeout, + boolean performReroute ) { - this(name, System.currentTimeMillis(), systemDataStreamDescriptor, masterNodeTimeout, timeout); + this(name, System.currentTimeMillis(), systemDataStreamDescriptor, masterNodeTimeout, timeout, performReroute); } public CreateDataStreamClusterStateUpdateRequest( @@ -119,11 +121,13 @@ public CreateDataStreamClusterStateUpdateRequest( long startTime, SystemDataStreamDescriptor systemDataStreamDescriptor, TimeValue masterNodeTimeout, - TimeValue timeout + TimeValue timeout, + boolean performReroute ) { this.name = name; this.startTime = startTime; this.descriptor = systemDataStreamDescriptor; + this.performReroute = performReroute; masterNodeTimeout(masterNodeTimeout); ackTimeout(timeout); } @@ -132,6 +136,10 @@ public boolean isSystem() { return descriptor != null; } + public boolean performReroute() { + return performReroute; + } + public SystemDataStreamDescriptor getSystemDataStreamDescriptor() { return descriptor; } @@ -201,7 +209,10 @@ static ClusterState createDataStream( "initialize_data_stream", firstBackingIndexName, firstBackingIndexName - ).dataStreamName(dataStreamName).systemDataStreamDescriptor(systemDataStreamDescriptor).nameResolvedInstant(request.startTime); + ).dataStreamName(dataStreamName) + .systemDataStreamDescriptor(systemDataStreamDescriptor) + .nameResolvedInstant(request.startTime) + .performReroute(request.performReroute()); if (isSystem) { createIndexRequest.settings(SystemIndexDescriptor.DEFAULT_SETTINGS); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamServiceTests.java index 57cbfb4d07503..e0a85af682d3c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamServiceTests.java @@ -199,7 +199,8 @@ public void testCreateSystemDataStream() throws Exception { dataStreamName, systemDataStreamDescriptor(), TimeValue.MAX_VALUE, - TimeValue.ZERO + TimeValue.ZERO, + true ); ClusterState newState = MetadataCreateDataStreamService.createDataStream(metadataCreateIndexService, cs, req); assertThat(newState.metadata().dataStreams().size(), equalTo(1)); diff --git a/x-pack/plugin/data-streams/src/main/java/org/elasticsearch/xpack/datastreams/action/CreateDataStreamTransportAction.java b/x-pack/plugin/data-streams/src/main/java/org/elasticsearch/xpack/datastreams/action/CreateDataStreamTransportAction.java index ee387e61fb37d..cce3f83795e70 100644 --- a/x-pack/plugin/data-streams/src/main/java/org/elasticsearch/xpack/datastreams/action/CreateDataStreamTransportAction.java +++ b/x-pack/plugin/data-streams/src/main/java/org/elasticsearch/xpack/datastreams/action/CreateDataStreamTransportAction.java @@ -70,7 +70,8 @@ protected void masterOperation( request.getStartTime(), systemDataStreamDescriptor, request.masterNodeTimeout(), - request.timeout() + request.timeout(), + true ); metadataCreateDataStreamService.createDataStream(updateRequest, listener); }