void updateTaskStatus(TaskStatus newValue) { // change to new value if old value is not changed and new value has a newer version AtomicBoolean taskMismatch = new AtomicBoolean(); taskStatus.setIf(newValue, oldValue -> { // did the task instance id change if (!isNullOrEmpty(oldValue.getTaskInstanceId()) && !oldValue.getTaskInstanceId().equals(newValue.getTaskInstanceId())) { taskMismatch.set(true); return false; } if (oldValue.getState().isDone()) { // never update if the task has reached a terminal state return false; } if (newValue.getVersion() < oldValue.getVersion()) { // don't update to an older version (same version is ok) return false; } return true; }); if (taskMismatch.get()) { // This will also set the task status to FAILED state directly. // Additionally, this will issue a DELETE for the task to the worker. // While sending the DELETE is not required, it is preferred because a task was created by the previous request. onFail.accept(new PrestoException(REMOTE_TASK_MISMATCH, format("%s (%s)", REMOTE_TASK_MISMATCH_ERROR, HostAddress.fromUri(getTaskStatus().getSelf())))); } }
void updateTaskStatus(TaskStatus newValue) { // change to new value if old value is not changed and new value has a newer version AtomicBoolean taskMismatch = new AtomicBoolean(); taskStatus.setIf(newValue, oldValue -> { // did the task instance id change if (!isNullOrEmpty(oldValue.getTaskInstanceId()) && !oldValue.getTaskInstanceId().equals(newValue.getTaskInstanceId())) { taskMismatch.set(true); return false; } if (oldValue.getState().isDone()) { // never update if the task has reached a terminal state return false; } if (newValue.getVersion() < oldValue.getVersion()) { // don't update to an older version (same version is ok) return false; } return true; }); if (taskMismatch.get()) { // This will also set the task status to FAILED state directly. // Additionally, this will issue a DELETE for the task to the worker. // While sending the DELETE is not required, it is preferred because a task was created by the previous request. onFail.accept(new PrestoException(REMOTE_TASK_MISMATCH, format("%s (%s)", REMOTE_TASK_MISMATCH_ERROR, HostAddress.fromUri(getTaskStatus().getSelf())))); } }
synchronized void updateTaskInfo(TaskInfo newValue) { boolean updated = taskInfo.setIf(newValue, oldValue -> { TaskStatus oldTaskStatus = oldValue.getTaskStatus(); TaskStatus newTaskStatus = newValue.getTaskStatus(); if (oldTaskStatus.getState().isDone()) { // never update if the task has reached a terminal state return false; } // don't update to an older version (same version is ok) return newTaskStatus.getVersion() >= oldTaskStatus.getVersion(); }); if (updated && newValue.getTaskStatus().getState().isDone()) { finalTaskInfo.compareAndSet(Optional.empty(), Optional.of(newValue)); stop(); } }
synchronized void updateTaskInfo(TaskInfo newValue) { boolean updated = taskInfo.setIf(newValue, oldValue -> { TaskStatus oldTaskStatus = oldValue.getTaskStatus(); TaskStatus newTaskStatus = newValue.getTaskStatus(); if (oldTaskStatus.getState().isDone()) { // never update if the task has reached a terminal state return false; } // don't update to an older version (same version is ok) return newTaskStatus.getVersion() >= oldTaskStatus.getVersion(); }); if (updated && newValue.getTaskStatus().getState().isDone()) { finalTaskInfo.compareAndSet(Optional.empty(), Optional.of(newValue)); stop(); } }