AmatyaAvadhanula commented on code in PR #13476:
URL: https://github.com/apache/druid/pull/13476#discussion_r1044027231
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/BaseRestorableTaskRunner.java:
##########
@@ -74,38 +76,42 @@ public BaseRestorableTaskRunner(
@Override
public List<Pair<Task, ListenableFuture<TaskStatus>>> restore()
{
- final File restoreFile = getRestoreFile();
- final TaskRestoreInfo taskRestoreInfo;
- if (restoreFile.exists()) {
- try {
- taskRestoreInfo = jsonMapper.readValue(restoreFile,
TaskRestoreInfo.class);
- }
- catch (Exception e) {
- LOG.error(e, "Failed to read restorable tasks from file[%s]. Skipping
restore.", restoreFile);
- return ImmutableList.of();
+ final Map<File, TaskRestoreInfo> taskRestoreInfos = new HashMap<>();
+ for (File baseDir : taskConfig.getBaseTaskDirs()) {
+ File restoreFile = new File(baseDir, TASK_RESTORE_FILENAME);
+ if (restoreFile.exists()) {
+ try {
+ taskRestoreInfos.put(baseDir, jsonMapper.readValue(restoreFile,
TaskRestoreInfo.class));
+ }
+ catch (Exception e) {
+ LOG.error(e, "Failed to read restorable tasks from file[%s].
Skipping restore.", restoreFile);
+ }
}
- } else {
- return ImmutableList.of();
}
final List<Pair<Task, ListenableFuture<TaskStatus>>> retVal = new
ArrayList<>();
- for (final String taskId : taskRestoreInfo.getRunningTasks()) {
- try {
- final File taskFile = new File(taskConfig.getTaskDir(taskId),
"task.json");
- final Task task = jsonMapper.readValue(taskFile, Task.class);
-
- if (!task.getId().equals(taskId)) {
- throw new ISE("Task[%s] restore file had wrong id[%s]", taskId,
task.getId());
+ for (Map.Entry<File, TaskRestoreInfo> entry : taskRestoreInfos.entrySet())
{
+ final File baseDir = entry.getKey();
+ final TaskRestoreInfo taskRestoreInfo = entry.getValue();
+ for (final String taskId : taskRestoreInfo.getRunningTasks()) {
+ try {
+ final File taskFile = new File(taskConfig.getTaskDir(taskId),
"task.json");
+ final Task task = jsonMapper.readValue(taskFile, Task.class);
+
+ if (!task.getId().equals(taskId)) {
+ throw new ISE("Task[%s] restore file had wrong id[%s]", taskId,
task.getId());
+ }
+
+ if (taskConfig.isRestoreTasksOnRestart() && task.canRestore()) {
+ LOG.info("Restoring task[%s].", task.getId());
+ taskConfig.addTask(taskId, baseDir);
Review Comment:
This is to ensure that TaskConfig restores the state such that a task goes
back to its original disk / base directory and not a new one
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/BaseRestorableTaskRunner.java:
##########
@@ -74,38 +76,42 @@ public BaseRestorableTaskRunner(
@Override
public List<Pair<Task, ListenableFuture<TaskStatus>>> restore()
{
- final File restoreFile = getRestoreFile();
- final TaskRestoreInfo taskRestoreInfo;
- if (restoreFile.exists()) {
- try {
- taskRestoreInfo = jsonMapper.readValue(restoreFile,
TaskRestoreInfo.class);
- }
- catch (Exception e) {
- LOG.error(e, "Failed to read restorable tasks from file[%s]. Skipping
restore.", restoreFile);
- return ImmutableList.of();
+ final Map<File, TaskRestoreInfo> taskRestoreInfos = new HashMap<>();
+ for (File baseDir : taskConfig.getBaseTaskDirs()) {
+ File restoreFile = new File(baseDir, TASK_RESTORE_FILENAME);
+ if (restoreFile.exists()) {
+ try {
+ taskRestoreInfos.put(baseDir, jsonMapper.readValue(restoreFile,
TaskRestoreInfo.class));
+ }
+ catch (Exception e) {
+ LOG.error(e, "Failed to read restorable tasks from file[%s].
Skipping restore.", restoreFile);
+ }
}
- } else {
- return ImmutableList.of();
}
final List<Pair<Task, ListenableFuture<TaskStatus>>> retVal = new
ArrayList<>();
- for (final String taskId : taskRestoreInfo.getRunningTasks()) {
- try {
- final File taskFile = new File(taskConfig.getTaskDir(taskId),
"task.json");
- final Task task = jsonMapper.readValue(taskFile, Task.class);
-
- if (!task.getId().equals(taskId)) {
- throw new ISE("Task[%s] restore file had wrong id[%s]", taskId,
task.getId());
+ for (Map.Entry<File, TaskRestoreInfo> entry : taskRestoreInfos.entrySet())
{
+ final File baseDir = entry.getKey();
+ final TaskRestoreInfo taskRestoreInfo = entry.getValue();
+ for (final String taskId : taskRestoreInfo.getRunningTasks()) {
+ try {
+ final File taskFile = new File(taskConfig.getTaskDir(taskId),
"task.json");
+ final Task task = jsonMapper.readValue(taskFile, Task.class);
+
+ if (!task.getId().equals(taskId)) {
+ throw new ISE("Task[%s] restore file had wrong id[%s]", taskId,
task.getId());
+ }
+
+ if (taskConfig.isRestoreTasksOnRestart() && task.canRestore()) {
+ LOG.info("Restoring task[%s].", task.getId());
+ taskConfig.addTask(taskId, baseDir);
+ retVal.add(Pair.of(task, run(task)));
+ }
}
-
- if (taskConfig.isRestoreTasksOnRestart() && task.canRestore()) {
- LOG.info("Restoring task[%s].", task.getId());
- retVal.add(Pair.of(task, run(task)));
+ catch (Exception e) {
+ LOG.warn(e, "Failed to restore task[%s]. Trying to restore other
tasks.", taskId);
Review Comment:
Done
--
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]