diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-07-06 10:25:55 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-07-06 10:25:55 +0300 |
commit | 176f1f5045466d303414af70342d698a19394fb5 (patch) | |
tree | dded3e4b3d0c3033a46cea6d2a327a87709f2f2c /internal/praefect/transactions | |
parent | c08c929b340e911b5d7633aeca1b039968cf672c (diff) |
transactions: Use an RWMutex to deserialize vote collection
We're currently using a simple mutex to protect votes of a transaction.
This was fine before moving to a scheme that's allowed to commit with a
subset of nodes failing as we knew that nobody would modify votes after
the last vote was cast and thus we didn't require any locking when
collecting votes. But now, each node needs to establish whether its own
vote has succeeded, which may happen even if some votes are still
missing when a majority was established already. As a result, vote
collection is now essentially serialized.
Fix the issue by using an rwmutex instead of a simple one. This allows
us to count voting results concurrently with all the other voters.
Diffstat (limited to 'internal/praefect/transactions')
-rw-r--r-- | internal/praefect/transactions/transaction.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/internal/praefect/transactions/transaction.go b/internal/praefect/transactions/transaction.go index 40bb809c4..ba4fde803 100644 --- a/internal/praefect/transactions/transaction.go +++ b/internal/praefect/transactions/transaction.go @@ -51,7 +51,7 @@ type transaction struct { threshold uint - lock sync.Mutex + lock sync.RWMutex votersByNode map[string]*Voter voteCounts map[vote]uint } @@ -168,8 +168,8 @@ func (t *transaction) collectVotes(ctx context.Context, node string) error { break } - t.lock.Lock() - defer t.lock.Unlock() + t.lock.RLock() + defer t.lock.RUnlock() voter, ok := t.votersByNode[node] if !ok { |