Skip to content

Commit 281549f

Browse files
Reindex naming changes
Renamed types and action names to fit that we now call it a reindex task and not a job. Removed action and named writeable todos. Relates elastic#42612
1 parent 476eeb7 commit 281549f

15 files changed

+91
-95
lines changed

modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexJobState.java renamed to modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPersistentTaskState.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131

3232
import java.io.IOException;
3333

34-
public class ReindexJobState implements Task.Status, PersistentTaskState {
34+
public class ReindexPersistentTaskState implements Task.Status, PersistentTaskState {
3535

36-
// TODO: Name
37-
public static final String NAME = ReindexTask.NAME;
36+
public static final String NAME = "reindex_persistent_task_state";
3837

39-
public static final ConstructingObjectParser<ReindexJobState, Void> PARSER =
40-
new ConstructingObjectParser<>(NAME, a -> new ReindexJobState((String) a[0], (String) a[1]));
38+
public static final ConstructingObjectParser<ReindexPersistentTaskState, Void> PARSER =
39+
new ConstructingObjectParser<>(NAME, a -> new ReindexPersistentTaskState((String) a[0], (String) a[1]));
4140

4241
private static String EPHEMERAL_TASK_ID = "ephemeral_task_id";
4342
private static String STATUS = "status";
@@ -50,17 +49,17 @@ public class ReindexJobState implements Task.Status, PersistentTaskState {
5049
private final TaskId ephemeralTaskId;
5150
private final Status status;
5251

53-
private ReindexJobState(String ephemeralTaskId, String status) {
52+
private ReindexPersistentTaskState(String ephemeralTaskId, String status) {
5453
this(new TaskId(ephemeralTaskId), Status.valueOf(status));
5554
}
5655

57-
ReindexJobState(TaskId ephemeralTaskId, Status status) {
56+
ReindexPersistentTaskState(TaskId ephemeralTaskId, Status status) {
5857
assert status != null : "Status cannot be null";
5958
this.ephemeralTaskId = ephemeralTaskId;
6059
this.status = status;
6160
}
6261

63-
public ReindexJobState(StreamInput in) throws IOException {
62+
public ReindexPersistentTaskState(StreamInput in) throws IOException {
6463
ephemeralTaskId = TaskId.readFromStream(in);
6564
status = in.readEnum(Status.class);
6665
}
@@ -96,7 +95,7 @@ public TaskId getEphemeralTaskId() {
9695
return ephemeralTaskId;
9796
}
9897

99-
public static ReindexJobState fromXContent(XContentParser parser) {
98+
public static ReindexPersistentTaskState fromXContent(XContentParser parser) {
10099
return PARSER.apply(parser, null);
101100
}
102101

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,26 @@ public class ReindexPlugin extends Plugin implements ActionPlugin, PersistentTas
7171
new ActionHandler<>(UpdateByQueryAction.INSTANCE, TransportUpdateByQueryAction.class),
7272
new ActionHandler<>(DeleteByQueryAction.INSTANCE, TransportDeleteByQueryAction.class),
7373
new ActionHandler<>(RethrottleAction.INSTANCE, TransportRethrottleAction.class),
74-
new ActionHandler<>(StartReindexJobAction.INSTANCE, TransportStartReindexJobAction.class)
74+
new ActionHandler<>(StartReindexTaskAction.INSTANCE, TransportStartReindexTaskAction.class)
7575
);
7676
}
7777

7878
@Override
7979
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
8080
return Arrays.asList(
8181
new NamedWriteableRegistry.Entry(Task.Status.class, BulkByScrollTask.Status.NAME, BulkByScrollTask.Status::new),
82-
new NamedWriteableRegistry.Entry(PersistentTaskParams.class, ReindexJob.NAME, ReindexJob::new),
83-
new NamedWriteableRegistry.Entry(Task.Status.class, ReindexJobState.NAME, ReindexJobState::new),
84-
new NamedWriteableRegistry.Entry(PersistentTaskState.class, ReindexJobState.NAME, ReindexJobState::new));
82+
new NamedWriteableRegistry.Entry(PersistentTaskParams.class, ReindexTaskParams.NAME, ReindexTaskParams::new),
83+
new NamedWriteableRegistry.Entry(Task.Status.class, ReindexPersistentTaskState.NAME, ReindexPersistentTaskState::new),
84+
new NamedWriteableRegistry.Entry(PersistentTaskState.class, ReindexPersistentTaskState.NAME, ReindexPersistentTaskState::new));
8585
}
8686

8787
@Override
8888
public List<NamedXContentRegistry.Entry> getNamedXContent() {
8989
return Arrays.asList(
90-
new NamedXContentRegistry.Entry(PersistentTaskParams.class, new ParseField(ReindexJob.NAME), ReindexJob::fromXContent),
91-
new NamedXContentRegistry.Entry(Task.Status.class, new ParseField(ReindexJobState.NAME), ReindexJobState::fromXContent),
92-
new NamedXContentRegistry.Entry(PersistentTaskState.class, new ParseField(ReindexJobState.NAME),
93-
ReindexJobState::fromXContent));
90+
new NamedXContentRegistry.Entry(PersistentTaskParams.class, new ParseField(ReindexTaskParams.NAME), ReindexTaskParams::fromXContent),
91+
new NamedXContentRegistry.Entry(Task.Status.class, new ParseField(ReindexPersistentTaskState.NAME), ReindexPersistentTaskState::fromXContent),
92+
new NamedXContentRegistry.Entry(PersistentTaskState.class, new ParseField(ReindexPersistentTaskState.NAME),
93+
ReindexPersistentTaskState::fromXContent));
9494
}
9595

9696
@Override

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

+17-18
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public class ReindexTask extends AllocatedPersistentTask {
4747

4848
private static final Logger logger = LogManager.getLogger(ReindexTask.class);
4949

50-
// TODO: Name
51-
public static final String NAME = "reindex/job";
50+
public static final String NAME = "reindex";
5251

5352
private final NodeClient client;
5453
private final ReindexIndexClient reindexIndexClient;
@@ -59,7 +58,7 @@ public class ReindexTask extends AllocatedPersistentTask {
5958
private volatile String description;
6059
private volatile boolean assignmentConflictDetected;
6160

62-
public static class ReindexPersistentTasksExecutor extends PersistentTasksExecutor<ReindexJob> {
61+
public static class ReindexPersistentTasksExecutor extends PersistentTasksExecutor<ReindexTaskParams> {
6362

6463
private final ClusterService clusterService;
6564
private final Client client;
@@ -80,14 +79,14 @@ public static class ReindexPersistentTasksExecutor extends PersistentTasksExecut
8079
}
8180

8281
@Override
83-
protected void nodeOperation(AllocatedPersistentTask task, ReindexJob reindexJob, PersistentTaskState state) {
82+
protected void nodeOperation(AllocatedPersistentTask task, ReindexTaskParams reindexTaskParams, PersistentTaskState state) {
8483
ReindexTask reindexTask = (ReindexTask) task;
85-
reindexTask.execute(reindexJob);
84+
reindexTask.execute(reindexTaskParams);
8685
}
8786

8887
@Override
8988
protected AllocatedPersistentTask createTask(long id, String type, String action, TaskId parentTaskId,
90-
PersistentTasksCustomMetaData.PersistentTask<ReindexJob> taskInProgress,
89+
PersistentTasksCustomMetaData.PersistentTask<ReindexTaskParams> taskInProgress,
9190
Map<String, String> headers) {
9291
headers.putAll(taskInProgress.getParams().getHeaders());
9392
Reindexer reindexer = new Reindexer(clusterService, client, threadPool, scriptService, reindexSslConfig);
@@ -139,20 +138,20 @@ BulkByScrollTask getChildTask() {
139138
return childTask;
140139
}
141140

142-
private void execute(ReindexJob reindexJob) {
141+
private void execute(ReindexTaskParams reindexTaskParams) {
143142
long allocationId = getAllocationId();
144143

145144
ReindexTaskStateUpdater taskUpdater = new ReindexTaskStateUpdater(reindexIndexClient, client.threadPool(), getPersistentTaskId(),
146145
allocationId, new ActionListener<>() {
147146
@Override
148147
public void onResponse(ReindexTaskStateDoc stateDoc) {
149-
reindexDone(stateDoc, reindexJob.shouldStoreResult());
148+
reindexDone(stateDoc, reindexTaskParams.shouldStoreResult());
150149
}
151150

152151
@Override
153152
public void onFailure(Exception e) {
154153
logger.info("Reindex task failed", e);
155-
updateClusterStateToFailed(reindexJob.shouldStoreResult(), ReindexJobState.Status.DONE, e);
154+
updateClusterStateToFailed(reindexTaskParams.shouldStoreResult(), ReindexPersistentTaskState.Status.DONE, e);
156155
}
157156
}, this::handleCheckpointAssignmentConflict);
158157

@@ -166,7 +165,7 @@ public void onResponse(ReindexTaskStateDoc stateDoc) {
166165
public void onResponse(Void aVoid) {
167166
// TODO: need to store status in state so we can continue from it.
168167
transientStatus = childTask.getStatus();
169-
performReindex(reindexJob, stateDoc, taskUpdater);
168+
performReindex(reindexTaskParams, stateDoc, taskUpdater);
170169
}
171170

172171
@Override
@@ -178,7 +177,7 @@ public void onFailure(Exception e) {
178177

179178
@Override
180179
public void onFailure(Exception ex) {
181-
updateClusterStateToFailed(reindexJob.shouldStoreResult(), ReindexJobState.Status.ASSIGNMENT_FAILED, ex);
180+
updateClusterStateToFailed(reindexTaskParams.shouldStoreResult(), ReindexPersistentTaskState.Status.ASSIGNMENT_FAILED, ex);
182181
}
183182
});
184183
}
@@ -196,7 +195,7 @@ protected void onCancelled() {
196195

197196
private void reindexDone(ReindexTaskStateDoc stateDoc, boolean shouldStoreResult) {
198197
TaskManager taskManager = getTaskManager();
199-
updatePersistentTaskState(new ReindexJobState(taskId, ReindexJobState.Status.DONE), new ActionListener<>() {
198+
updatePersistentTaskState(new ReindexPersistentTaskState(taskId, ReindexPersistentTaskState.Status.DONE), new ActionListener<>() {
200199
@Override
201200
public void onResponse(PersistentTasksCustomMetaData.PersistentTask<?> persistentTask) {
202201
if (shouldStoreResult) {
@@ -226,7 +225,7 @@ public void onFailure(Exception ex) {
226225
}
227226

228227
private void sendStartedNotification(boolean shouldStoreResult) {
229-
updatePersistentTaskState(new ReindexJobState(taskId, ReindexJobState.Status.STARTED), new ActionListener<>() {
228+
updatePersistentTaskState(new ReindexPersistentTaskState(taskId, ReindexPersistentTaskState.Status.STARTED), new ActionListener<>() {
230229
@Override
231230
public void onResponse(PersistentTasksCustomMetaData.PersistentTask<?> persistentTask) {
232231
}
@@ -239,14 +238,14 @@ public void onFailure(Exception e) {
239238
});
240239
}
241240

242-
private void performReindex(ReindexJob reindexJob, ReindexTaskStateDoc stateDoc, ReindexTaskStateUpdater taskUpdater) {
241+
private void performReindex(ReindexTaskParams reindexTaskParams, ReindexTaskStateDoc stateDoc, ReindexTaskStateUpdater taskUpdater) {
243242
ReindexRequest reindexRequest = stateDoc.getReindexRequest();
244243
ScrollableHitSource.Checkpoint initialCheckpoint = stateDoc.getCheckpoint();
245244
ThreadContext threadContext = client.threadPool().getThreadContext();
246245

247246
Supplier<ThreadContext.StoredContext> context = threadContext.newRestorableContext(false);
248247
// TODO: Eventually we only want to retain security context
249-
try (ThreadContext.StoredContext ignore = stashWithHeaders(threadContext, reindexJob.getHeaders())) {
248+
try (ThreadContext.StoredContext ignore = stashWithHeaders(threadContext, reindexTaskParams.getHeaders())) {
250249
reindexer.execute(childTask, reindexRequest, new ContextPreservingActionListener<>(context, new ActionListener<>() {
251250
@Override
252251
public void onResponse(BulkByScrollResponse response) {
@@ -264,11 +263,11 @@ public void onFailure(Exception e) {
264263
}, true);
265264
}
266265
// send this after we started reindex to ensure sub-tasks are created.
267-
sendStartedNotification(reindexJob.shouldStoreResult());
266+
sendStartedNotification(reindexTaskParams.shouldStoreResult());
268267
}
269268

270-
private void updateClusterStateToFailed(boolean shouldStoreResult, ReindexJobState.Status status, Exception ex) {
271-
updatePersistentTaskState(new ReindexJobState(taskId, status), new ActionListener<>() {
269+
private void updateClusterStateToFailed(boolean shouldStoreResult, ReindexPersistentTaskState.Status status, Exception ex) {
270+
updatePersistentTaskState(new ReindexPersistentTaskState(taskId, status), new ActionListener<>() {
272271
@Override
273272
public void onResponse(PersistentTasksCustomMetaData.PersistentTask<?> persistentTask) {
274273
markEphemeralTaskFailed(shouldStoreResult, ex);

modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexJob.java renamed to modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexTaskParams.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@
3131
import java.io.IOException;
3232
import java.util.Map;
3333

34-
public class ReindexJob implements PersistentTaskParams {
34+
public class ReindexTaskParams implements PersistentTaskParams {
3535

36-
// TODO: Name
37-
public static final String NAME = ReindexTask.NAME;
36+
public static final String NAME = "reindex_task_params";
3837

3938
@SuppressWarnings("unchecked")
40-
public static final ConstructingObjectParser<ReindexJob, Void> PARSER
41-
= new ConstructingObjectParser<>(NAME, a -> new ReindexJob((Boolean) a[0], (Map<String, String>) a[1]));
39+
public static final ConstructingObjectParser<ReindexTaskParams, Void> PARSER
40+
= new ConstructingObjectParser<>(NAME, a -> new ReindexTaskParams((Boolean) a[0], (Map<String, String>) a[1]));
4241

4342
private static String STORE_RESULT = "store_result";
4443
private static String HEADERS = "headers";
@@ -51,12 +50,12 @@ public class ReindexJob implements PersistentTaskParams {
5150
private final boolean storeResult;
5251
private final Map<String, String> headers;
5352

54-
public ReindexJob(boolean storeResult, Map<String, String> headers) {
53+
public ReindexTaskParams(boolean storeResult, Map<String, String> headers) {
5554
this.storeResult = storeResult;
5655
this.headers = headers;
5756
}
5857

59-
public ReindexJob(StreamInput in) throws IOException {
58+
public ReindexTaskParams(StreamInput in) throws IOException {
6059
storeResult = in.readBoolean();
6160
headers = in.readMap(StreamInput::readString, StreamInput::readString);
6261
}
@@ -94,7 +93,7 @@ public Map<String, String> getHeaders() {
9493
return headers;
9594
}
9695

97-
public static ReindexJob fromXContent(XContentParser parser) {
96+
public static ReindexTaskParams fromXContent(XContentParser parser) {
9897
return PARSER.apply(parser, null);
9998
}
10099
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
6363
boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", true);
6464

6565
// Build the internal request
66-
StartReindexJobAction.Request internal = new StartReindexJobAction.Request(setCommonOptions(request, buildRequest(request)),
66+
StartReindexTaskAction.Request internal = new StartReindexTaskAction.Request(setCommonOptions(request, buildRequest(request)),
6767
waitForCompletion);
6868
/*
6969
* Let's try and validate before forking so the user gets some error. The
@@ -81,12 +81,12 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
8181
params.put(BulkByScrollTask.Status.INCLUDE_CREATED, Boolean.toString(true));
8282
params.put(BulkByScrollTask.Status.INCLUDE_UPDATED, Boolean.toString(true));
8383

84-
return channel -> client.execute(StartReindexJobAction.INSTANCE, internal, new ActionListener<>() {
84+
return channel -> client.execute(StartReindexTaskAction.INSTANCE, internal, new ActionListener<>() {
8585

8686
private BulkIndexByScrollResponseContentListener listener = new BulkIndexByScrollResponseContentListener(channel, params);
8787

8888
@Override
89-
public void onResponse(StartReindexJobAction.Response response) {
89+
public void onResponse(StartReindexTaskAction.Response response) {
9090
listener.onResponse(response.getReindexResponse());
9191
}
9292

@@ -96,9 +96,9 @@ public void onFailure(Exception e) {
9696
}
9797
});
9898
} else {
99-
return channel -> client.execute(StartReindexJobAction.INSTANCE, internal, new RestBuilderListener<>(channel) {
99+
return channel -> client.execute(StartReindexTaskAction.INSTANCE, internal, new RestBuilderListener<>(channel) {
100100
@Override
101-
public RestResponse buildResponse(StartReindexJobAction.Response response, XContentBuilder builder) throws Exception {
101+
public RestResponse buildResponse(StartReindexTaskAction.Response response, XContentBuilder builder) throws Exception {
102102
builder.startObject();
103103
// This is the ephemeral task-id from the first node that is assigned the task (for BWC).
104104
builder.field("task", response.getTaskId());

modules/reindex/src/main/java/org/elasticsearch/index/reindex/StartReindexJobAction.java renamed to modules/reindex/src/main/java/org/elasticsearch/index/reindex/StartReindexTaskAction.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@
3535

3636
import java.io.IOException;
3737

38-
public class StartReindexJobAction extends ActionType<StartReindexJobAction.Response> {
38+
public class StartReindexTaskAction extends ActionType<StartReindexTaskAction.Response> {
3939

40-
public static final StartReindexJobAction INSTANCE = new StartReindexJobAction();
41-
// TODO: Name
42-
public static final String NAME = "indices:data/write/start_reindex";
40+
public static final StartReindexTaskAction INSTANCE = new StartReindexTaskAction();
41+
public static final String NAME = "indices:data/write/reindex/start";
4342

44-
private StartReindexJobAction() {
43+
private StartReindexTaskAction() {
4544
super(NAME, Response::new);
4645
}
4746

0 commit comments

Comments
 (0)