Skip to content

Commit 33da807

Browse files
committed
Make StartReindexJobAction a non-master action
TransportStartReindexJobAction is currently a master action. Reindexing only needs access to the cluster state to perform some validations. Prior to persistent reindexing we used a normal data node to perform these validations. There is not reason that these validations need a perfectly update to date view of the cluster state. The commit changes the action to be a normal transport action. Relates to elastic#42612.
1 parent 7be5875 commit 33da807

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportStartReindexJobAction.java

+12-29
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,14 @@
2828
import org.elasticsearch.action.index.IndexRequest;
2929
import org.elasticsearch.action.index.IndexResponse;
3030
import org.elasticsearch.action.support.ActionFilters;
31-
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
31+
import org.elasticsearch.action.support.HandledTransportAction;
3232
import org.elasticsearch.client.Client;
3333
import org.elasticsearch.client.OriginSettingClient;
3434
import org.elasticsearch.cluster.ClusterState;
35-
import org.elasticsearch.cluster.block.ClusterBlockException;
36-
import org.elasticsearch.cluster.block.ClusterBlockLevel;
3735
import org.elasticsearch.cluster.metadata.IndexMetaData;
38-
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
3936
import org.elasticsearch.cluster.service.ClusterService;
4037
import org.elasticsearch.common.UUIDs;
4138
import org.elasticsearch.common.inject.Inject;
42-
import org.elasticsearch.common.io.stream.StreamInput;
4339
import org.elasticsearch.common.settings.Settings;
4440
import org.elasticsearch.common.xcontent.ToXContent;
4541
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -56,35 +52,26 @@
5652

5753
import static org.elasticsearch.index.reindex.ReindexTask.REINDEX_ORIGIN;
5854

59-
public class TransportStartReindexJobAction
60-
extends TransportMasterNodeAction<StartReindexJobAction.Request, StartReindexJobAction.Response> {
55+
public class TransportStartReindexJobAction extends HandledTransportAction<StartReindexJobAction.Request, StartReindexJobAction.Response> {
6156

57+
private final ThreadPool threadPool;
58+
private final ClusterService clusterService;
6259
private final PersistentTasksService persistentTasksService;
6360
private final Client taskClient;
6461

6562
@Inject
6663
public TransportStartReindexJobAction(TransportService transportService, ThreadPool threadPool,
67-
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
68-
ClusterService clusterService, PersistentTasksService persistentTasksService, Client client) {
69-
super(StartReindexJobAction.NAME, transportService, clusterService, threadPool, actionFilters, StartReindexJobAction.Request::new,
70-
indexNameExpressionResolver);
64+
ActionFilters actionFilters, ClusterService clusterService,
65+
PersistentTasksService persistentTasksService, Client client) {
66+
super(StartReindexJobAction.NAME, transportService, actionFilters, StartReindexJobAction.Request::new);
67+
this.threadPool = threadPool;
68+
this.clusterService = clusterService;
7169
this.persistentTasksService = persistentTasksService;
7270
this.taskClient = new OriginSettingClient(client, REINDEX_ORIGIN);
7371
}
7472

7573
@Override
76-
protected String executor() {
77-
return ThreadPool.Names.SAME;
78-
}
79-
80-
@Override
81-
protected StartReindexJobAction.Response read(StreamInput in) throws IOException {
82-
return new StartReindexJobAction.Response(in);
83-
}
84-
85-
@Override
86-
protected void masterOperation(Task task, StartReindexJobAction.Request request, ClusterState state,
87-
ActionListener<StartReindexJobAction.Response> listener) {
74+
protected void doExecute(Task task, StartReindexJobAction.Request request, ActionListener<StartReindexJobAction.Response> listener) {
8875
// TODO: If the connection is lost to the master, this action might be retried creating two tasks.
8976
// Eventually prevent this (perhaps by pre-generating UUID).
9077
String generatedId = UUIDs.randomBase64UUID();
@@ -93,7 +80,8 @@ protected void masterOperation(Task task, StartReindexJobAction.Request request,
9380
boolean storeTaskResult = request.getWaitForCompletion() == false;
9481
ReindexJob job = new ReindexJob(storeTaskResult, threadPool.getThreadContext().getHeaders());
9582

96-
boolean reindexIndexExists = state.routingTable().hasIndex(ReindexTask.REINDEX_INDEX);
83+
ClusterState clusterState = clusterService.state();
84+
boolean reindexIndexExists = clusterState.routingTable().hasIndex(ReindexTask.REINDEX_INDEX);
9785

9886
createReindexTaskDoc(generatedId, request.getReindexRequest(), reindexIndexExists, new ActionListener<>() {
9987
@Override
@@ -162,11 +150,6 @@ public void onFailure(Exception e) {
162150
});
163151
}
164152

165-
@Override
166-
protected ClusterBlockException checkBlock(StartReindexJobAction.Request request, ClusterState state) {
167-
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
168-
}
169-
170153
private void createReindexTaskDoc(String taskId, ReindexRequest reindexRequest, boolean indexExists, ActionListener<Void> listener) {
171154
if (indexExists) {
172155
IndexRequest indexRequest = new IndexRequest(ReindexTask.REINDEX_INDEX).id(taskId).opType(DocWriteRequest.OpType.CREATE);

0 commit comments

Comments
 (0)