-
Notifications
You must be signed in to change notification settings - Fork 120
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
[executor] multi-key conflict bug #837
Changes from all commits
106d6d9
bc8b7b0
897c043
b97c690
d682756
dda4322
aae39a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,8 @@ func (e *Executor) work() { | |
type task struct { | ||
id int | ||
f func() error | ||
// shared are the tasks that this task is using non-exclusively. | ||
shared []*task | ||
// reading are the tasks that this task is using non-exclusively. | ||
reading map[int]*task | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can have a bool flag like this would let us keep the array approach, and not adding ourselves multiple times, and is better than the map approach since we aren't doing no-ops on that action |
||
|
||
l sync.Mutex | ||
executed bool | ||
|
@@ -95,12 +95,12 @@ func (e *Executor) runTask(t *task) { | |
// to ensure we can exit. | ||
defer func() { | ||
// Notify other tasks that we are done reading them | ||
for _, rt := range t.shared { | ||
for _, rt := range t.reading { | ||
rt.l.Lock() | ||
delete(rt.readers, t.id) | ||
rt.l.Unlock() | ||
} | ||
t.shared = nil | ||
t.reading = nil | ||
|
||
// Nodify blocked tasks that they can execute | ||
t.l.Lock() | ||
|
@@ -145,9 +145,9 @@ func (e *Executor) Run(keys state.Keys, f func() error) { | |
id := e.tasks | ||
e.tasks++ | ||
t := &task{ | ||
id: id, | ||
f: f, | ||
shared: []*task{}, | ||
id: id, | ||
f: f, | ||
reading: make(map[int]*task), | ||
|
||
blocked: make(map[int]*task), | ||
readers: make(map[int]*task), | ||
|
@@ -170,16 +170,23 @@ func (e *Executor) Run(keys state.Keys, f func() error) { | |
if v == state.Read { | ||
// If we don't need exclusive access to a key, just mark | ||
// that we are reading it and that we are a reader of it. | ||
t.shared = append(t.shared, lt) | ||
// | ||
// We use a map for [reading] because a single task can have | ||
// different keys that are all just readers of another task. | ||
t.reading[lt.id] = lt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should note clearly the scenario for why we use a map here (i.e. that a single task can have different keys that are all just readers of another task) |
||
lt.readers[id] = t | ||
} else { | ||
// If we do need exclusive access to a key, we need to | ||
// mark ourselves blocked on all readers ahead of us. | ||
// | ||
// If a task is a reader, that means it is not executed yet | ||
// and can't mark itself as executed until all [shared] are | ||
// and can't mark itself as executed until all [reading] are | ||
// cleared (which can't be done while we hold the lock for [lt]). | ||
for _, rt := range lt.readers { | ||
// Don't block on ourself if we already marked ourself as a reader | ||
if rt.id == id { | ||
continue | ||
} | ||
rt.l.Lock() | ||
rt.blocked[id] = t | ||
rt.l.Unlock() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should align
shared/readers
...they no longer sound like opposite ends of a single relationship.