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:
authorSami Hiltunen <shiltunen@gitlab.com>2021-05-18 20:11:47 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-09-02 08:23:40 +0300
commitb5f6c05f13528ed90323113a3406fa29f2e7726c (patch)
tree06bb4c0e9285820d0b1a54b8fb41c0ee03775079
parent682fe7a7688035b91dbed30e74c477ede6581325 (diff)
Implement DidCommitAnySubtransaction on Transaction
This commit implements DidCommitAnySubtransaction method on Transaction. The method returns whether the transaction committed at least one subtransaction which would indicate that some changes were made on the nodes. This is used later to check whether the primary replica was actually modified. (cherry picked from commit d9891a8527dba2191cae964e4bd18d4889071e9a)
-rw-r--r--internal/praefect/coordinator_test.go9
-rw-r--r--internal/praefect/transactions/transaction.go24
2 files changed, 31 insertions, 2 deletions
diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go
index fdb4b543d..f9812fe3e 100644
--- a/internal/praefect/coordinator_test.go
+++ b/internal/praefect/coordinator_test.go
@@ -1539,8 +1539,9 @@ func TestCoordinator_grpcErrorHandling(t *testing.T) {
}
type mockTransaction struct {
- nodeStates map[string]transactions.VoteResult
- subtransactions int
+ nodeStates map[string]transactions.VoteResult
+ subtransactions int
+ didCommitAnySubtransaction bool
}
func (t mockTransaction) ID() uint64 {
@@ -1551,6 +1552,10 @@ func (t mockTransaction) CountSubtransactions() int {
return t.subtransactions
}
+func (t mockTransaction) DidCommitAnySubtransaction() bool {
+ return t.didCommitAnySubtransaction
+}
+
func (t mockTransaction) State() (map[string]transactions.VoteResult, error) {
return t.nodeStates, nil
}
diff --git a/internal/praefect/transactions/transaction.go b/internal/praefect/transactions/transaction.go
index 90d8f6bf9..840710d29 100644
--- a/internal/praefect/transactions/transaction.go
+++ b/internal/praefect/transactions/transaction.go
@@ -57,6 +57,8 @@ type Transaction interface {
CountSubtransactions() int
// State returns the state of each voter part of the transaction.
State() (map[string]VoteResult, error)
+ // DidCommitAnySubtransaction returns whether the transaction committed at least one subtransaction.
+ DidCommitAnySubtransaction() bool
}
// transaction is a session where a set of voters votes on one or more
@@ -184,6 +186,28 @@ func (t *transaction) CountSubtransactions() int {
return len(t.subtransactions)
}
+// DidCommitSubtransaction returns whether the transaction committed at least one subtransaction.
+func (t *transaction) DidCommitAnySubtransaction() bool {
+ t.lock.Lock()
+ defer t.lock.Unlock()
+
+ if len(t.subtransactions) == 0 {
+ return false
+ }
+
+ // We only need to check the first subtransaction. If it failed, there would
+ // be no further subtransactions.
+ for _, result := range t.subtransactions[0].state() {
+ // It's sufficient to find a single commit in the subtransaction
+ // to say it was committed.
+ if result == VoteCommitted {
+ return true
+ }
+ }
+
+ return false
+}
+
// getOrCreateSubtransaction gets an ongoing subtransaction on which the given
// node hasn't yet voted on or creates a new one if the node has succeeded on
// all subtransactions. In case the node has failed on any of the