Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-07-08 16:05:39 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-07-09 14:53:28 +0300
commitef6392fd86ffdc9066f2448b3db67bd50fbc9888 (patch)
tree5e09f589ad9cdcf29f7db73d7dbd0852968faba4
parentc12022da6d1c65bebd303786a7abcf04ee7d67b3 (diff)
transactions: Simplify computation of voter state
In order to determine the voter state in a transaction, we iterate through all subtransactions and soak up the result in there. But given that subtransactions are always created with all voters of the transaction, we know that on each iteration, we'll override all results of the preceding subtransaction anyway. Ultimately, we thus end up with the state as recorded by the last subtransaction, and it's clear that the iteration is pointless. Simplify the code to just take the state of the last subtransaction.
-rw-r--r--internal/praefect/transactions/transaction.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/internal/praefect/transactions/transaction.go b/internal/praefect/transactions/transaction.go
index 2476c0b31..784531404 100644
--- a/internal/praefect/transactions/transaction.go
+++ b/internal/praefect/transactions/transaction.go
@@ -166,12 +166,12 @@ func (t *transaction) State() (map[string]VoteResult, error) {
return results, nil
}
- // Collect all subtransactions. As they are ordered by reverse recency, we can simply
- // overwrite our own results.
- for _, subtransaction := range t.subtransactions {
- for voter, result := range subtransaction.state() {
- results[voter] = result
- }
+ // Collect voter results. Given that all subtransactions are created with all voters
+ // registered in the transaction, we can simply take results from the last subtransaction.
+ // Any nodes which didn't yet cast a vote in the last transaction will be in the default
+ // undecided state.
+ for voter, result := range t.subtransactions[len(t.subtransactions)-1].state() {
+ results[voter] = result
}
return results, nil