AmatyaAvadhanula commented on code in PR #13476:
URL: https://github.com/apache/druid/pull/13476#discussion_r1097047980
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/BaseRestorableTaskRunner.java:
##########
@@ -173,24 +188,55 @@ public Collection<TaskRunnerWorkItem> getKnownTasks()
@GuardedBy("tasks")
protected void saveRunningTasks()
{
- final File restoreFile = getRestoreFile();
- final List<String> theTasks = new ArrayList<>();
+ final Map<File, List<String>> theTasks = new HashMap<>();
for (TaskRunnerWorkItem forkingTaskRunnerWorkItem : tasks.values()) {
- theTasks.add(forkingTaskRunnerWorkItem.getTaskId());
+ final String taskId = forkingTaskRunnerWorkItem.getTaskId();
+ final File restoreFile = getRestoreFile(taskId);
+ theTasks.computeIfAbsent(restoreFile, k -> new ArrayList<>())
+ .add(taskId);
}
- try {
- Files.createParentDirs(restoreFile);
- jsonMapper.writeValue(restoreFile, new TaskRestoreInfo(theTasks));
+ for (Map.Entry<File, List<String>> entry : theTasks.entrySet()) {
+ final File restoreFile = entry.getKey();
+ final TaskRestoreInfo taskRestoreInfo = new
TaskRestoreInfo(entry.getValue());
+ try {
+ Files.createParentDirs(restoreFile);
+ jsonMapper.writeValue(restoreFile, taskRestoreInfo);
+ LOG.debug("Save restore file at [%s] for tasks [%s]",
+ restoreFile.getAbsoluteFile(),
Arrays.toString(theTasks.get(restoreFile).toArray()));
+ }
+ catch (Exception e) {
+ LOG.warn(e, "Failed to save tasks to restore file[%s]. Skipping this
save.", restoreFile);
+ }
}
- catch (Exception e) {
- LOG.warn(e, "Failed to save tasks to restore file[%s]. Skipping this
save.", restoreFile);
+ }
+
+ @Override
+ public void stop()
+ {
+ if (!taskConfig.isRestoreTasksOnRestart()) {
+ return;
+ }
+
+ for (File baseDir : dirTracker.getBaseTaskDirs()) {
+ File restoreFile = new File(baseDir, TASK_RESTORE_FILENAME);
+ if (restoreFile.exists()) {
+ try {
+ TaskRestoreInfo taskRestoreInfo = jsonMapper.readValue(restoreFile,
TaskRestoreInfo.class);
+ for (final String taskId : taskRestoreInfo.getRunningTasks()) {
+ LOG.info("Saving task[%s] at path[%s] for restore", taskId,
baseDir);
Review Comment:
Changed it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]