diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-12 11:37:22 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-12 13:42:42 +0300 |
commit | 2894e8325f3f24f2cbaad1cab4393c26228dc7bd (patch) | |
tree | e806e45fe1c852416462bdadba08d3a61f545612 | |
parent | 6730c101d0be2db5155b6e2c4de689dc906337f4 (diff) |
transactions: Log transaction state when cancelling them
In order to make a transaction's outcome more visible, add a new log
message that is written when cancelling a transaction. Next to the
actual notification that it's got wrapped up, the log message will also
include the number of total nodes registered as part of the transaction,
how many committed and the number of subtransactions created. This
improves visibility and makes it a lot easier to reason about what the
actual result of a transaction is.
-rw-r--r-- | changelogs/unreleased/pks-tx-log-finished.yml | 5 | ||||
-rw-r--r-- | internal/praefect/transactions/manager.go | 19 |
2 files changed, 22 insertions, 2 deletions
diff --git a/changelogs/unreleased/pks-tx-log-finished.yml b/changelogs/unreleased/pks-tx-log-finished.yml new file mode 100644 index 000000000..93f8d4bbf --- /dev/null +++ b/changelogs/unreleased/pks-tx-log-finished.yml @@ -0,0 +1,5 @@ +--- +title: Log transaction state when cancelling them +merge_request: 2465 +author: +type: added diff --git a/internal/praefect/transactions/manager.go b/internal/praefect/transactions/manager.go index 1afc03588..c3527db16 100644 --- a/internal/praefect/transactions/manager.go +++ b/internal/praefect/transactions/manager.go @@ -6,6 +6,7 @@ import ( "encoding/binary" "encoding/hex" "errors" + "fmt" "math/rand" "sync" "time" @@ -146,11 +147,11 @@ func (mgr *Manager) RegisterTransaction(ctx context.Context, voters []Voter, thr mgr.counterMetric.WithLabelValues("registered").Add(float64(len(voters))) return transaction, func() error { - return mgr.cancelTransaction(transaction) + return mgr.cancelTransaction(ctx, transaction) }, nil } -func (mgr *Manager) cancelTransaction(transaction *Transaction) error { +func (mgr *Manager) cancelTransaction(ctx context.Context, transaction *Transaction) error { mgr.lock.Lock() defer mgr.lock.Unlock() @@ -159,6 +160,20 @@ func (mgr *Manager) cancelTransaction(transaction *Transaction) error { transaction.cancel() mgr.subtransactionsMetric.Observe(float64(transaction.CountSubtransactions())) + var committed uint64 + state := transaction.State() + for _, success := range state { + if success { + committed++ + } + } + + mgr.log(ctx).WithFields(logrus.Fields{ + "transaction_id": transaction.ID(), + "committed": fmt.Sprintf("%d/%d", committed, len(state)), + "subtransactions": transaction.CountSubtransactions(), + }).Info("transaction completed") + return nil } |