Skip to content

Commit

Permalink
Merge pull request #585 from iExecBlockchainComputing/feature/refacto…
Browse files Browse the repository at this point in the history
…r-to-avoid-unnecessary-db-calls

Make `task.isTeeTask()` the first test in `TaskUpdateManager#running2…
  • Loading branch information
mcornaton authored May 17, 2023
2 parents b8b7689 + 50f887f commit 05913fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- Rearrange checks order to avoid call to database. (#585)
### Dependency Upgrades
- Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586)
- Add new `iexec-commons-poco` 2.0.0 dependency. (#571 #574 #586)
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/iexec/core/task/update/TaskUpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,26 @@ void running2ConsensusReached(Task task) {
void running2Finalized2Completed(Task task) {
boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING;
final String chainTaskId = task.getChainTaskId();
final Optional<ReplicatesList> 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` " +
" [chainTaskId:{}]", chainTaskId);
return;
}

final Optional<ReplicatesList> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());

Expand Down

0 comments on commit 05913fe

Please sign in to comment.