rohangarg commented on code in PR #13476:
URL: https://github.com/apache/druid/pull/13476#discussion_r1040724937
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/config/TaskConfig.java:
##########
@@ -121,10 +122,24 @@
@JsonProperty
private final boolean encapsulatedTask;
+ @JsonProperty
+ private final String baseTaskDir;
+
+ // Use multiple base files for tasks instead of a single one
+ @JsonProperty
+ @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
Review Comment:
I think always accepting arrays is fine and would also remove any ambiguity
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/config/TaskConfig.java:
##########
@@ -191,14 +216,35 @@ public String getBaseDir()
}
@JsonProperty
- public File getBaseTaskDir()
+ public String getBaseTaskDir()
{
return baseTaskDir;
}
+ @JsonProperty
+ public List<String> getBaseTaskDirPaths()
+ {
+ return baseTaskDirPaths;
+ }
+
+ public List<File> getBaseTaskDirs()
+ {
+ return baseTaskDirs;
+ }
+
+ public synchronized File getTaskBaseDir(String taskId)
Review Comment:
this should be `getOrSelectTaskDir(String taskId)`
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/config/TaskConfig.java:
##########
@@ -191,14 +216,35 @@ public String getBaseDir()
}
@JsonProperty
- public File getBaseTaskDir()
+ public String getBaseTaskDir()
{
return baseTaskDir;
}
+ @JsonProperty
+ public List<String> getBaseTaskDirPaths()
+ {
+ return baseTaskDirPaths;
+ }
+
+ public List<File> getBaseTaskDirs()
+ {
+ return baseTaskDirs;
+ }
+
+ public synchronized File getTaskBaseDir(String taskId)
+ {
+ if (!taskToTempDirMap.containsKey(taskId)) {
+ taskToTempDirMap.put(taskId, baseTaskDirs.get(taskDirIndex));
Review Comment:
this can call `addTask` as well
##########
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()) {
Review Comment:
since this is during state building, can also log the if/else case so that
we know which files were used for restoring the state.
##########
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:
seems like `getTaskDir` would also add to the map, so this would repeat
doing that.
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/config/TaskConfig.java:
##########
@@ -292,6 +333,21 @@ public boolean isEncapsulatedTask()
return encapsulatedTask;
}
+ public synchronized void addTask(final String taskId, final File taskDir)
Review Comment:
I think this could be extracted out of `TaskConfig` object along with the
selection and removal method - can create an inner class itself in this class.
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/config/TaskConfig.java:
##########
@@ -182,6 +197,16 @@ public TaskConfig(
}
log.debug("Batch processing mode:[%s]", this.batchProcessingMode);
this.storeEmptyColumns = storeEmptyColumns == null ?
DEFAULT_STORE_EMPTY_COLUMNS : storeEmptyColumns;
+
+ this.baseTaskDir = baseTaskDir;
+ if (CollectionUtils.isNullOrEmpty(baseTaskDirPaths)) {
Review Comment:
I think it'd be better to enforce that only of `baseTaskDir` or
`baseTaskDirPaths` is present.
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/config/TaskConfig.java:
##########
@@ -191,14 +216,35 @@ public String getBaseDir()
}
@JsonProperty
- public File getBaseTaskDir()
+ public String getBaseTaskDir()
Review Comment:
can you make this as `getBaseTaskDirPath` as well with json annotation as
`baseTaskDir`? would make it consistent with the new one and easier to
understand
##########
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:
now that the there can be multiple restoration files, we should also log the
restoration file checked. also, same in the above info log
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/BaseRestorableTaskRunner.java:
##########
@@ -173,24 +179,30 @@ 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));
- }
- catch (Exception e) {
- LOG.warn(e, "Failed to save tasks to restore file[%s]. Skipping this
save.", restoreFile);
+ 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);
+ }
+ catch (Exception e) {
+ LOG.warn(e, "Failed to save tasks to restore file[%s]. Skipping this
save.", restoreFile);
Review Comment:
should also print a list of tasks that this restoreFile is supposed to be
serving
##########
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()) {
Review Comment:
if this is false, then we'd have the task in the map due to current
`getTaskDir` impl and it won't be removed. So, I think we should `remove` it if
this false
##########
indexing-service/src/test/java/org/apache/druid/indexing/common/config/TaskConfigTest.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.indexing.common.config;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.druid.java.util.common.ISE;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+
+public class TaskConfigTest
+{
+ @Test
+ public void testGetTaskBaseDir()
+ {
+ TaskConfig taskConfig = new TaskConfig(
Review Comment:
move this to a before test method
--
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]