Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
transaction: restore logs of txn lock
Browse files Browse the repository at this point in the history
Signed-off-by: Oshank Kumar <okumar@redhat.com>
  • Loading branch information
Oshank Kumar committed Nov 21, 2018
1 parent 23653b8 commit cc26978
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions glusterd2/transaction/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions glusterd2/transactionv2/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit cc26978

Please sign in to comment.