From af446fe6d301a7a80ef1cbe14b2b7950330b05e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Wed, 17 May 2023 11:33:14 +0200 Subject: [PATCH 1/2] Make `task.isTeeTask()` the first test in `TaskUpdateManager#running2Finalized2Completed` --- CHANGELOG.md | 1 + .../iexec/core/task/update/TaskUpdateManager.java | 13 +++++++------ .../core/task/update/TaskUpdateManagerTest.java | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 877610dd..7ba34d12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) - Refactor unnotified detectors to avoid code duplication. (#580) - Use `==` or `!=` operators to test the equality of enums. (#584) +- Make `task.isTeeTask()` the first test in `TaskUpdateManager#running2Finalized2Completed` to avoid unnecessary calls to the database. (#585) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) - Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574) diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index bf818527..94089428 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -330,7 +330,12 @@ void running2ConsensusReached(Task task) { void running2Finalized2Completed(Task task) { boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING; final String chainTaskId = task.getChainTaskId(); - final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); + + if (!task.isTeeTask()) { + log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible" + + " [chainTaskId:{}]", chainTaskId); + return; + } if (!isTaskInRunningStatus) { log.error("Can't transition task to `Finalized` or `Completed` when task is not `Running` " + @@ -338,17 +343,13 @@ void running2Finalized2Completed(Task task) { return; } + final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); if (oReplicatesList.isEmpty()) { log.error("Can't transition task to `Finalized` or `Completed` when no replicatesList exists" + " [chainTaskId:{}]", chainTaskId); return; } - if (!task.isTeeTask()) { - log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible" - + " [chainTaskId:{}]", chainTaskId); - return; - } final ReplicatesList replicates = oReplicatesList.get(); final int nbReplicatesWithContributeAndFinalizeStatus = replicates.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE); diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index 8aef17a4..eb82b0c7 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -688,6 +688,7 @@ void shouldUpdateFromInitializedOrRunning2ContributionTimeout() { void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { Task task = getStubTask(maxExecutionTime); task.changeStatus(INITIALIZED); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); taskUpdateManager.running2Finalized2Completed(task); assertThat(task.getCurrentStatus()).isEqualTo(INITIALIZED); @@ -697,6 +698,7 @@ void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { void shouldNotUpdateRunning2Finalized2CompletedWhenNoReplicates() { Task task = getStubTask(maxExecutionTime); task.changeStatus(RUNNING); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.empty()); From 3760cb30353eb177019551628de0a695d9b8850c Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 17 May 2023 12:26:02 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md Co-authored-by: Maxence Cornaton <87655102+mcornaton@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba34d12..9372368d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ All notable changes to this project will be documented in this file. - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) - Refactor unnotified detectors to avoid code duplication. (#580) - Use `==` or `!=` operators to test the equality of enums. (#584) -- Make `task.isTeeTask()` the first test in `TaskUpdateManager#running2Finalized2Completed` to avoid unnecessary calls to the database. (#585) +- Rearrange checks order to avoid call to database. (#585) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) - Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574)