|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.migrate.task; |
9 | 9 |
|
| 10 | +import org.apache.logging.log4j.LogManager; |
| 11 | +import org.apache.logging.log4j.Logger; |
10 | 12 | import org.elasticsearch.ElasticsearchException; |
11 | 13 | import org.elasticsearch.action.ActionListener; |
12 | 14 | import org.elasticsearch.action.admin.indices.rollover.RolloverAction; |
|
19 | 21 | import org.elasticsearch.cluster.metadata.DataStream; |
20 | 22 | import org.elasticsearch.cluster.metadata.DataStreamAction; |
21 | 23 | import org.elasticsearch.cluster.service.ClusterService; |
| 24 | +import org.elasticsearch.common.settings.Setting; |
22 | 25 | import org.elasticsearch.core.Nullable; |
23 | 26 | import org.elasticsearch.core.TimeValue; |
24 | 27 | import org.elasticsearch.index.Index; |
|
39 | 42 | import static org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate.getReindexRequiredPredicate; |
40 | 43 |
|
41 | 44 | public class ReindexDataStreamPersistentTaskExecutor extends PersistentTasksExecutor<ReindexDataStreamTaskParams> { |
| 45 | + /* |
| 46 | + * This setting controls how many indices we reindex concurrently for a single data stream. This is not an overall limit -- if five |
| 47 | + * data streams are being reindexed, then each of them can have this many indices being reindexed at once. This setting is dynamic, |
| 48 | + * but changing it does not have an impact if the task is already running (unless the task is restarted or moves to another node). |
| 49 | + */ |
| 50 | + public static final Setting<Integer> MAX_CONCURRENT_INDICES_REINDEXED_PER_DATA_STREAM_SETTING = Setting.intSetting( |
| 51 | + "migrate.max_concurrent_indices_reindexed_per_data_stream", |
| 52 | + 1, |
| 53 | + 1, |
| 54 | + Setting.Property.Dynamic, |
| 55 | + Setting.Property.NodeScope |
| 56 | + ); |
| 57 | + private static final Logger logger = LogManager.getLogger(ReindexDataStreamPersistentTaskExecutor.class); |
42 | 58 | private static final TimeValue TASK_KEEP_ALIVE_TIME = TimeValue.timeValueDays(1); |
43 | 59 | private final Client client; |
44 | 60 | private final ClusterService clusterService; |
@@ -165,8 +181,9 @@ private void reindexIndices( |
165 | 181 | CountDownActionListener listener = new CountDownActionListener(indicesToBeReindexed.size() + 1, ActionListener.wrap(response1 -> { |
166 | 182 | completeSuccessfulPersistentTask(reindexDataStreamTask, updatedState); |
167 | 183 | }, exception -> { completeFailedPersistentTask(reindexDataStreamTask, updatedState, exception); })); |
| 184 | + final int maxConcurrentIndices = clusterService.getClusterSettings().get(MAX_CONCURRENT_INDICES_REINDEXED_PER_DATA_STREAM_SETTING); |
168 | 185 | List<Index> indicesRemaining = Collections.synchronizedList(new ArrayList<>(indicesToBeReindexed)); |
169 | | - final int maxConcurrentIndices = 1; |
| 186 | + logger.debug("Reindexing {} indices, with up to {} handled concurrently", indicesRemaining.size(), maxConcurrentIndices); |
170 | 187 | for (int i = 0; i < maxConcurrentIndices; i++) { |
171 | 188 | maybeProcessNextIndex(indicesRemaining, reindexDataStreamTask, reindexClient, sourceDataStream, listener, parentTaskId); |
172 | 189 | } |
|
0 commit comments