From 744704d231ff89bb31b1f08413da51e193ba73d4 Mon Sep 17 00:00:00 2001 From: Oshank Kumar Date: Wed, 21 Nov 2018 16:02:16 +0530 Subject: [PATCH] transaction: restore logs of txn lock Signed-off-by: Oshank Kumar --- glusterd2/transaction/lock.go | 7 +++++++ glusterd2/transactionv2/transaction.go | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/glusterd2/transaction/lock.go b/glusterd2/transaction/lock.go index 772c51209..8f27baf09 100644 --- a/glusterd2/transaction/lock.go +++ b/glusterd2/transaction/lock.go @@ -153,11 +153,15 @@ func CreateLockFuncs(key string) (LockUnlockFunc, LockUnlockFunc) { type Locks map[string]*concurrency.Mutex func (l Locks) lock(lockID string) error { + var logger = log.WithField("lockID", lockID) + // Ensure that no prior lock exists for the given lockID in this transaction if _, ok := l[lockID]; ok { return ErrLockExists } + logger.Debug("attempting to obtain lock") + key := lockPrefix + lockID locker := concurrency.NewMutex(store.Store.Session, key) @@ -167,14 +171,17 @@ func (l Locks) lock(lockID string) error { err := locker.Lock(ctx) switch err { case nil: + logger.Debug("lock obtained") // Attach lock to the transaction l[lockID] = locker case context.DeadlineExceeded: + logger.Debug("timeout: failed to obtain lock") // Propagate this all the way back to the client as a HTTP 409 response err = ErrLockTimeout default: + logger.WithError(err).Error("failed to obtain lock") } return err diff --git a/glusterd2/transactionv2/transaction.go b/glusterd2/transactionv2/transaction.go index 93787e592..29eebb6d8 100644 --- a/glusterd2/transactionv2/transaction.go +++ b/glusterd2/transactionv2/transaction.go @@ -101,12 +101,13 @@ func (t *Txn) releaseLocks() { // Done releases any obtained locks and cleans up the transaction namespace // Done must be called after a transaction ends func (t *Txn) Done() { - if t.succeeded { - t.done() - t.releaseLocks() - GlobalTxnManager.RemoveTransaction(t.ID) - t.Ctx.Logger().Info("txn succeeded on all nodes, txn data cleaned up from store") + if !t.succeeded { + return } + t.done() + t.releaseLocks() + GlobalTxnManager.RemoveTransaction(t.ID) + t.Ctx.Logger().Info("txn succeeded on all nodes, txn data cleaned up from store") } func (t *Txn) done() {