Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

1816: getNextTask will get wrong task if DO_WHILE task is embed in FORK or DECISION #1823

Merged
merged 3 commits into from
Oct 14, 2020

Conversation

alex-fu
Copy link
Contributor

@alex-fu alex-fu commented Aug 6, 2020

Patch for #1816 .

What I changed

If the last inner task of DO_WHILE was completed and call getNextTask() in decide(), I return the DO_WHILE task (In current code, it will return the next task of DO_WHILE).
And then, in DeciderService.getNextTask(), I check if the DO_WHILE task already exists in the workflow's tasks. If it exists, just ignore it.

@codecov
Copy link

codecov bot commented Aug 6, 2020

Codecov Report

Merging #1823 into dev will decrease coverage by 41.33%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff              @@
##                dev    #1823       +/-   ##
=============================================
- Coverage     65.07%   23.74%   -41.34%     
- Complexity     3897     4054      +157     
=============================================
  Files           301      372       +71     
  Lines         18483    79077    +60594     
  Branches       1684    12643    +10959     
=============================================
+ Hits          12028    18777     +6749     
- Misses         5626    58356    +52730     
- Partials        829     1944     +1115     
Impacted Files Coverage Δ Complexity Δ
...onductor/common/metadata/workflow/WorkflowDef.java 85.58% <100.00%> (-1.58%) 45.00 <0.00> (-2.00)
...nductor/common/metadata/workflow/WorkflowTask.java 79.36% <100.00%> (+0.08%) 98.00 <0.00> (+2.00)
...tflix/conductor/core/execution/DeciderService.java 86.93% <100.00%> (+0.14%) 127.00 <1.00> (+4.00)
...ductor/dao/cassandra/CassandraEventHandlerDAO.java 65.78% <0.00%> (-10.53%) 15.00% <0.00%> (ø%)
.../conductor/dao/cassandra/CassandraMetadataDAO.java 53.88% <0.00%> (-5.70%) 24.00% <0.00%> (-1.00%)
...netflix/conductor/contribs/queue/QueueManager.java 56.12% <0.00%> (-4.09%) 14.00% <0.00%> (-2.00%)
...uctor/core/execution/mapper/DoWhileTaskMapper.java 95.00% <0.00%> (-2.50%) 5.00% <0.00%> (-1.00%)
...oto/main/java/com/google/protobuf/DoubleValue.java 0.00% <0.00%> (ø) 0.00% <0.00%> (?%)
...roto/main/java/com/google/protobuf/BytesValue.java 0.00% <0.00%> (ø) 0.00% <0.00%> (?%)
... and 69 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4c550f...3140193. Read the comment docs.

@coveralls
Copy link

coveralls commented Aug 6, 2020

Pull Request Test Coverage Report for Build 4647

  • 9 of 9 (100.0%) changed or added relevant lines in 3 files are covered.
  • 20 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.1%) to 69.481%

Files with Coverage Reduction New Missed Lines %
common/src/main/java/com/netflix/conductor/common/metadata/workflow/WorkflowDef.java 1 97.3%
core/src/main/java/com/netflix/conductor/core/execution/mapper/DoWhileTaskMapper.java 1 97.5%
cassandra-persistence/src/main/java/com/netflix/conductor/dao/cassandra/CassandraEventHandlerDAO.java 8 68.42%
cassandra-persistence/src/main/java/com/netflix/conductor/dao/cassandra/CassandraMetadataDAO.java 10 55.44%
Totals Coverage Status
Change from base Build 4636: -0.1%
Covered Lines: 12847
Relevant Lines: 18490

💛 - Coveralls

@apanicker-nflx
Copy link
Collaborator

@alex-fu Thanks for the contribution. Can you please also add an integration test for this here. Could you also add an integration test which would handle a failure and automated retry in one of the forked branches within the do_while?

@manan164 We would appreciate it if you could help with reviewing this PR.

@@ -569,6 +569,13 @@ public WorkflowTask next(String taskReferenceName, WorkflowTask parent) {
return nextTask;
}
if (task.has(taskReferenceName)) {
if (TaskType.DO_WHILE.name().equals(task.getType())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alex-fu Since we are diverging the DECISION block by so many lines of code. We can define a separate switch case for DO_WHILE task. And move common code to one function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll move this common code to a function. But this function should be called from DECISION block and FORK block, not DO_WHILE block(since we don't allow nested DO_WHILE task).

// check if already has this DO_WHILE task, ignore it if it already exists
String nextTaskReferenceName = taskToSchedule.getTaskReferenceName();
if (workflow.getTasks().stream().anyMatch(runningTask -> runningTask.getReferenceTaskName().equals(nextTaskReferenceName))) {
return Collections.emptyList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are returning an empty list. We are making get next task to return the parent DO_WHILE task let it propagates it further to decider service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in this case the parent DO_WHILE task is already exist, so we don't need to generate again. By the way, even though we return the parent DO_WHILE task, deciderService will also exclude it in below line. tasksToBeScheduled already contains this task, and putIfAbsent will not add this task again.

nextTasks.forEach(nextTask -> tasksToBeScheduled.putIfAbsent(nextTask.getReferenceTaskName(), nextTask));

@ritu-p
Copy link
Contributor

ritu-p commented Sep 15, 2020

Hi ,
I have embedded the DO_WHILE in a decision task and I am facing a similar issue where the task outside the loop task is getting executed.Any timeline by which this PR will be merged?

@apanicker-nflx
Copy link
Collaborator

@alex-fu Are you available to continue working on this PR? Thanks

@alex-fu
Copy link
Contributor Author

alex-fu commented Sep 26, 2020

@apanicker-nflx Sorry for the late reply since I was stuck in some things last month. I'll add the integration test ASAP.

@apanicker-nflx
Copy link
Collaborator

Please rebase against dev, seems like the build failure is due to a conflict.
https://travis-ci.com/github/Netflix/conductor/builds/186799651
image

@apanicker-nflx
Copy link
Collaborator

Also, while unit tests look good, please also add an integration test for this here

@alex-fu
Copy link
Contributor Author

alex-fu commented Oct 8, 2020

@apanicker-nflx I've rebased against dev and submitted some code according to @manan164's review and some integration test, please review again.

@apanicker-nflx apanicker-nflx merged commit fc533a6 into Netflix:dev Oct 14, 2020
TwoUnderscorez pushed a commit to TwoUnderscorez/conductor that referenced this pull request Jul 23, 2021
…RK or DECISION (Netflix#1823)

* 1816: getNextTask will get wrong task if DO_WHILE task is embed in FORK or DECISION

* 1816: refactor WorkflowTask.next(); add integration test

* 1816: refine getNextTask in WorkflowDef
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants