Skip to content

Commit

Permalink
fix(ludicrous): Fix logical race in concurrent execution of mutations (
Browse files Browse the repository at this point in the history
…#7269)

Fix the race condition in the concurrent execution of mutations in
the ludicrous mode. The issue caused same mutation to be called
for execution twice, which resulted in double done on the watermark.
  • Loading branch information
ahsanbarkati authored Jan 13, 2021
1 parent c9e54b9 commit 594ff63
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion worker/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (e *executor) processMutationCh(ctx context.Context, ch chan *subMutation)
graph: g,
}

isDependent := false
g.Lock()
for c := range conflicts {
l, ok := g.conflicts[c]
Expand All @@ -236,6 +237,7 @@ func (e *executor) processMutationCh(ctx context.Context, ch chan *subMutation)
for _, dependent := range l {
_, ok := dependent.dependentMutations[m.sm.startTs]
if !ok {
isDependent = true
atomic.AddInt64(&m.inDeg, 1)
dependent.dependentMutations[m.sm.startTs] = m
}
Expand All @@ -246,7 +248,10 @@ func (e *executor) processMutationCh(ctx context.Context, ch chan *subMutation)
}
g.Unlock()

if atomic.LoadInt64(&m.inDeg) == 0 {
// If this mutation doesn't depend on any other mutation then process it right now.
// Otherwise, don't process it. It will be called for processing when the last mutation on
// which it depends is completed.
if !isDependent {
x.Check(e.throttle.Do())
go e.worker(m)
}
Expand Down

0 comments on commit 594ff63

Please sign in to comment.