Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): Same workflow nodes are not executing parallel even semaphore locks available #6418

Merged
merged 4 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(controller): Same workflow nodes are not executing parallel in se…
…maphore

Signed-off-by: Saravanan Balasubramanian <[email protected]>
  • Loading branch information
sarabala1979 committed Jul 24, 2021
commit 17a40d6b2ca4e5797ef491e484cc3daabc996110
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,6 @@ func (woc *wfOperationCtx) executeTemplate(ctx context.Context, nodeName string,
} else {
woc.log.Infof("Node %s acquired synchronization lock", nodeName)
if node != nil {
node.Message = ""
node = woc.markNodeWaitingForLock(node.Name, "")
}
}
Expand Down Expand Up @@ -2196,6 +2195,7 @@ func (woc *wfOperationCtx) markNodeWaitingForLock(nodeName string, lockName stri
if lockName == "" {
// If we are no longer waiting for a lock, nil out the sync status
node.SynchronizationStatus = nil
node.Message = ""
} else {
node.SynchronizationStatus.Waiting = lockName
}
Expand Down
16 changes: 15 additions & 1 deletion workflow/sync/semaphore.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ func (s *PrioritySemaphore) acquire(holderKey string) bool {
return false
}

func isSameWorkflowNodeKeys(first, second string) bool {
firstItems := strings.Split(first, "/")
secondItems := strings.Split(second, "/")
if len(firstItems) != len(secondItems){
return false
}
if len(firstItems) == 3 {
return firstItems[1] == secondItems[1]
}
return false
}

func (s *PrioritySemaphore) tryAcquire(holderKey string) (bool, string) {
s.lock.Lock()
defer s.lock.Unlock()
Expand All @@ -165,7 +177,8 @@ func (s *PrioritySemaphore) tryAcquire(holderKey string) (bool, string) {
if s.pending.Len() > 0 {
item := s.pending.peek()
nextKey = fmt.Sprintf("%v", item.key)
if holderKey != nextKey {
if holderKey != nextKey && !isSameWorkflowNodeKeys(holderKey, nextKey){
s.log.Debugf("key is not in front of queue. %s - %s", holderKey, nextKey)
// Enqueue the front workflow if lock is available
if len(s.lockHolder) < s.limit {
s.nextWorkflow(nextKey)
Expand All @@ -175,6 +188,7 @@ func (s *PrioritySemaphore) tryAcquire(holderKey string) (bool, string) {
}

if s.acquire(holderKey) {
s.log.Debugf("Current semaphore Holders. %v", s.lockHolder)
s.pending.pop()
s.log.Infof("%s acquired by %s ", s.name, nextKey)
return true, ""
Expand Down