kfaraz commented on code in PR #13172:
URL: https://github.com/apache/druid/pull/13172#discussion_r995311317
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java:
##########
@@ -108,17 +108,20 @@ public TaskLockbox(
/**
* Wipe out our current in-memory state and resync it from our bundled
{@link TaskStorage}.
+ *
+ * @return SyncResult which needs to be processed by the caller
*/
- public void syncFromStorage()
+ public SyncResult syncFromStorage()
{
giant.lock();
try {
// Load stuff from taskStorage first. If this fails, we don't want to
lose all our locks.
- final Set<String> storedActiveTasks = new HashSet<>();
Review Comment:
The previous approach is the preferred one, as it seems from the preceding
comment.
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java:
##########
@@ -858,6 +873,26 @@ public void unlockAll(Task task)
}
}
+ public void unlockUnacquiredLocks(Task task)
Review Comment:
Doesn't seem to be used anywhere.
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskMaster.java:
##########
@@ -113,7 +113,7 @@ public void becomeLeader()
log.info("By the power of Grayskull, I have the power!");
try {
- taskLockbox.syncFromStorage();
+ SyncResult syncResult = taskLockbox.syncFromStorage();
Review Comment:
This is interesting. `TaskLockbox` is synced with storage just once when we
become leader, whereas the `TaskQueue` is synced periodically?
I wonder if we shouldn't just move the invocation of
`taskLockbox.syncFromStorage()` to `TaskQueue.start()`. It would help
`TaskQueue` ensure that `TaskLockbox` is actually synced without having to rely
on something done before it was constructed.
This would also help us avoid passing the `SyncResult` around.
The only difference I see is if `taskLockbox.syncFromStorage()` throws an
exception, then currently we would fail early, while becoming leader. Whereas,
if we move the sync inside `TaskQueue`, it would fail on the lifecycle start,
which is effectively the same.
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskQueue.java:
##########
@@ -770,6 +776,17 @@ private void syncFromStorage()
addTaskInternal(task);
}
+ for (Task task : tasksToFail) {
Review Comment:
I don't think this should happen in `syncFromStorage`. Put this in a
separate method and call it after `syncFromStorage` in the lifecycle `start`
method as it needs to be done only once.
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java:
##########
@@ -183,20 +184,33 @@ public int compare(Pair<Task, TaskLock> left, Pair<Task,
TaskLock> right)
);
}
} else {
- throw new ISE(
- "Could not reacquire lock on interval[%s] version[%s] for task:
%s",
+ failedToReacquireLockTaskGroups.add(task.getGroupId());
+ log.error(
+ "Could not reacquire lock on interval[%s] version[%s] for task:
%s.",
Review Comment:
Maybe include the group name in this log line too.
And add another info log line which prints all the identified bad group
names together, i.e. the contents of `failedToReacquireTaskLockGroups` and also
the task ids that we have identified to cancel.
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskQueue.java:
##########
@@ -770,6 +776,17 @@ private void syncFromStorage()
addTaskInternal(task);
}
+ for (Task task : tasksToFail) {
+ try {
+ tasks.putIfAbsent(task.getId(), task);
Review Comment:
Why is this required? We are already synced with storage at this point. If
the task id does not exist in the `tasks` map, it doesn't exist in the metadata
store and thus doesn't hold any lock either. So we need not take further action
on it, correct?
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/SyncResult.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.overlord;
+
+import org.apache.druid.indexing.common.task.Task;
+
+import java.util.Set;
+
+/**
+ * Result of TaskLockbox#syncFromStorage()
+ * Contains tasks which need to be forcefully failed to let the overlord
become the leader
+ */
+class SyncResult
Review Comment:
Maybe rename to `TaskLockboxSyncResult`
--
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]