jtuglu1 commented on code in PR #18851: URL: https://github.com/apache/druid/pull/18851#discussion_r2647266881
########## indexing-service/src/main/java/org/apache/druid/indexing/overlord/hrtr/HttpRemoteTaskRunner.java: ########## @@ -466,60 +377,82 @@ private boolean runTaskOnWorker( // because that is attached by TaskQueue to task result future. So, this method must not be called with "statusLock" // held. See https://github.com/apache/druid/issues/6201 private void taskComplete( - HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem, - WorkerHolder workerHolder, + String taskId, + String workerHost, TaskStatus taskStatus ) { - Preconditions.checkState(!Thread.holdsLock(statusLock), "Current thread must not hold statusLock."); - Preconditions.checkNotNull(taskRunnerWorkItem, "taskRunnerWorkItem"); - Preconditions.checkNotNull(taskStatus, "taskStatus"); - if (workerHolder != null) { - log.info( - "Worker[%s] completed task[%s] with status[%s]", - workerHolder.getWorker().getHost(), - taskStatus.getId(), - taskStatus.getStatusCode() - ); - // Worker is done with this task - workerHolder.setLastCompletedTaskTime(DateTimes.nowUtc()); - } + Preconditions.checkState(!Thread.holdsLock(workerStateLock), "Current thread must not hold workerStateLock."); + Preconditions.checkState(!Thread.holdsLock(taskStateLock), "Current thread must not hold taskStateLock."); - if (taskRunnerWorkItem.getResult().isDone()) { - // This is not the first complete event. - try { - TaskState lastKnownState = taskRunnerWorkItem.getResult().get().getStatusCode(); - if (taskStatus.getStatusCode() != lastKnownState) { - log.warn( - "The state of the new task complete event is different from its last known state. " - + "New state[%s], last known state[%s]", - taskStatus.getStatusCode(), - lastKnownState - ); + AtomicBoolean taskCompleted = new AtomicBoolean(false); + + tasks.compute( + taskId, + (key, taskEntry) -> { + Preconditions.checkState(taskEntry != null, "Expected task[%s] to exist", taskId); + if (taskEntry.getResult().isDone()) { + // This is not the first complete event. + try { + TaskState lastKnownState = taskEntry.getResult().get().getStatusCode(); + if (taskStatus.getStatusCode() != lastKnownState) { + log.warn( + "The state of the new task complete event is different from its last known state. " + + "New state[%s], last known state[%s]", + taskStatus.getStatusCode(), + lastKnownState + ); + } + } + catch (InterruptedException e) { + log.warn(e, "Interrupted while getting the last known task status."); + Thread.currentThread().interrupt(); + } + catch (ExecutionException e) { + // This case should not really happen. + log.warn(e, "Failed to get the last known task status. Ignoring this failure."); + } + } else { + // Notify interested parties + taskEntry.setResult(taskStatus); + taskCompleted.set(true); + } + + return taskEntry; } - } - catch (InterruptedException e) { - log.warn(e, "Interrupted while getting the last known task status."); - Thread.currentThread().interrupt(); - } - catch (ExecutionException e) { - // This case should not really happen. - log.warn(e, "Failed to get the last known task status. Ignoring this failure."); - } - } else { - // Notify interested parties - taskRunnerWorkItem.setResult(taskStatus); - TaskRunnerUtils.notifyStatusChanged(listeners, taskStatus.getId(), taskStatus); + ); - // Update success/failure counters, Blacklist node if there are too many failures. - if (workerHolder != null) { - blacklistWorkerIfNeeded(taskStatus, workerHolder); + if (workerHost != null) { + synchronized (workerStateLock) { + workers.compute( + workerHost, + (key, workerHolder) -> { + if (workerHolder != null) { + log.info( + "Worker[%s] completed task[%s] with status[%s]", + workerHolder.getWorker().getHost(), + taskStatus.getId(), + taskStatus.getStatusCode() + ); Review Comment: While I think that would help moderately with performance, since we're using key-based locking it's not likely to help that much. I can do it, but also nice way (in the logs) to validate that nothing else was modifying this simulatenously. -- 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]
