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

Rename transactionv2 to transaction #1424

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions glusterd2/commands/peers/peer-rpc-svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/gluster/glusterd2/glusterd2/peer"
"github.com/gluster/glusterd2/glusterd2/servers/peerrpc"
"github.com/gluster/glusterd2/glusterd2/store"
"github.com/gluster/glusterd2/glusterd2/transactionv2"
"github.com/gluster/glusterd2/glusterd2/transactionv2/cleanuphandler"
"github.com/gluster/glusterd2/glusterd2/transaction"
"github.com/gluster/glusterd2/glusterd2/transaction/cleanuphandler"
"github.com/gluster/glusterd2/glusterd2/volume"
"github.com/gluster/glusterd2/pkg/utils"

Expand Down
3 changes: 1 addition & 2 deletions glusterd2/commands/volumes/volume-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/gluster/glusterd2/glusterd2/gdctx"
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/glusterd2/transaction"
transactionv2 "github.com/gluster/glusterd2/glusterd2/transactionv2"
"github.com/gluster/glusterd2/glusterd2/volume"
"github.com/gluster/glusterd2/pkg/api"
gderrors "github.com/gluster/glusterd2/pkg/errors"
Expand Down Expand Up @@ -199,7 +198,7 @@ func CreateVolume(ctx context.Context, req api.VolCreateReq) (status int, err er
return http.StatusBadRequest, err
}

txn, err := transactionv2.NewTxnWithLocks(ctx, req.Name)
txn, err := transaction.NewTxnWithLocks(ctx, req.Name)
if err != nil {
return restutils.ErrToStatusCode(err)
}
Expand Down
3 changes: 1 addition & 2 deletions glusterd2/commands/volumes/volume-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/gluster/glusterd2/glusterd2/gdctx"
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/glusterd2/transaction"
transactionv2 "github.com/gluster/glusterd2/glusterd2/transactionv2"
"github.com/gluster/glusterd2/glusterd2/volume"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -45,7 +44,7 @@ func volumeDeleteHandler(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(ctx, "/volumeDeleteHandler")
defer span.End()

txn, err := transactionv2.NewTxnWithLocks(ctx, volname)
txn, err := transaction.NewTxnWithLocks(ctx, volname)
if err != nil {
status, err := restutils.ErrToStatusCode(err)
restutils.SendHTTPError(ctx, w, status, err)
Expand Down
3 changes: 1 addition & 2 deletions glusterd2/commands/volumes/volume-start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/gluster/glusterd2/glusterd2/gdctx"
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/glusterd2/transaction"
transactionv2 "github.com/gluster/glusterd2/glusterd2/transactionv2"
"github.com/gluster/glusterd2/glusterd2/volgen"
"github.com/gluster/glusterd2/glusterd2/volume"
"github.com/gluster/glusterd2/pkg/api"
Expand Down Expand Up @@ -156,7 +155,7 @@ func StartVolume(ctx context.Context, volname string, req api.VolumeStartReq) (v
ctx, span := trace.StartSpan(ctx, "/volumeStartHandler")
defer span.End()

txn, err := transactionv2.NewTxnWithLocks(ctx, volname)
txn, err := transaction.NewTxnWithLocks(ctx, volname)
if err != nil {
status, err := restutils.ErrToStatusCode(err)
return nil, status, err
Expand Down
3 changes: 1 addition & 2 deletions glusterd2/commands/volumes/volume-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/gluster/glusterd2/glusterd2/gdctx"
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/glusterd2/transaction"
transactionv2 "github.com/gluster/glusterd2/glusterd2/transactionv2"
"github.com/gluster/glusterd2/glusterd2/volgen"
"github.com/gluster/glusterd2/glusterd2/volume"
"github.com/gluster/glusterd2/pkg/api"
Expand Down Expand Up @@ -124,7 +123,7 @@ func volumeStopHandler(w http.ResponseWriter, r *http.Request) {
logger := gdctx.GetReqLogger(ctx)
volname := mux.Vars(r)["volname"]

txn, err := transactionv2.NewTxnWithLocks(ctx, volname)
txn, err := transaction.NewTxnWithLocks(ctx, volname)
if err != nil {
status, err := restutils.ErrToStatusCode(err)
restutils.SendHTTPError(ctx, w, status, err)
Expand Down
4 changes: 2 additions & 2 deletions glusterd2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/gluster/glusterd2/glusterd2/pmap"
"github.com/gluster/glusterd2/glusterd2/servers"
"github.com/gluster/glusterd2/glusterd2/store"
"github.com/gluster/glusterd2/glusterd2/transactionv2"
"github.com/gluster/glusterd2/glusterd2/transactionv2/cleanuphandler"
"github.com/gluster/glusterd2/glusterd2/transaction"
"github.com/gluster/glusterd2/glusterd2/transaction/cleanuphandler"
gdutils "github.com/gluster/glusterd2/glusterd2/utils"
"github.com/gluster/glusterd2/glusterd2/volgen"
"github.com/gluster/glusterd2/glusterd2/xlator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/gluster/glusterd2/glusterd2/gdctx"
"github.com/gluster/glusterd2/glusterd2/store"
"github.com/gluster/glusterd2/glusterd2/transactionv2"
"github.com/gluster/glusterd2/glusterd2/transaction"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3/concurrency"
Expand Down
5 changes: 1 addition & 4 deletions glusterd2/transaction/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"reflect"
"time"

"github.com/gluster/glusterd2/glusterd2/store"

Expand All @@ -14,8 +13,6 @@ import (
log "github.com/sirupsen/logrus"
)

const etcdTxnTimeout = 10

// TxnCtx is used to carry contextual information across the lifetime of a transaction
type TxnCtx interface {
// Set attaches the given key with value to the context. It updates value if key exists already.
Expand Down Expand Up @@ -120,7 +117,7 @@ func (c *Tctx) Commit() error {
putOps = append(putOps, clientv3.OpPut(key, value))
}

ctx, cancel := context.WithTimeout(context.Background(), etcdTxnTimeout*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), etcdTxnTimeout)
txn, err := store.Txn(ctx).
If().
Then(putOps...).
Expand Down
62 changes: 0 additions & 62 deletions glusterd2/transaction/context_mock.go

This file was deleted.

125 changes: 0 additions & 125 deletions glusterd2/transaction/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"errors"
"time"

"github.com/gluster/glusterd2/glusterd2/gdctx"
"github.com/gluster/glusterd2/glusterd2/store"

"github.com/coreos/etcd/clientv3/concurrency"
"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
)

Expand All @@ -27,129 +25,6 @@ var (
ErrLockExists = errors.New("existing lock found for given lock ID")
)

// createLockStepFunc returns the registry IDs of StepFuncs which lock/unlock the given key.
// If existing StepFuncs are not found, new funcs are created and registered.
func createLockStepFunc(key string) (string, string, error) {
lockFuncID := key + ".Lock"
unlockFuncID := key + ".Unlock"

_, lockFuncFound := getStepFunc(lockFuncID)
_, unlockFuncFound := getStepFunc(unlockFuncID)

if lockFuncFound && unlockFuncFound {
return lockFuncID, unlockFuncID, nil
}

key = lockPrefix + key
locker := concurrency.NewMutex(store.Store.Session, key)

lockFunc := func(c TxnCtx) error {

ctx, cancel := context.WithTimeout(context.Background(), lockObtainTimeout)
defer cancel()

c.Logger().WithField("key", key).Debug("attempting to lock")
err := locker.Lock(ctx)
switch err {
case nil:
c.Logger().WithField("key", key).Debug("lock obtained")
case context.DeadlineExceeded:
// Propagate this all the way back to the client as a HTTP 409 response
c.Logger().WithField("key", key).Debug("timeout: failed to obtain lock")
err = ErrLockTimeout
}

return err
}
RegisterStepFunc(lockFunc, lockFuncID)

unlockFunc := func(c TxnCtx) error {

c.Logger().WithField("key", key).Debug("attempting to unlock")
err := locker.Unlock(context.Background())
if err == nil {
c.Logger().WithField("key", key).Debug("lock unlocked")
}

return err
}
RegisterStepFunc(unlockFunc, unlockFuncID)

return lockFuncID, unlockFuncID, nil
}

// CreateLockSteps returns a lock and an unlock Step which lock/unlock the given key
// TODO: Remove this function
func CreateLockSteps(key string) (*Step, *Step, error) {
lockFunc, unlockFunc, err := createLockStepFunc(key)
if err != nil {
return nil, nil, err
}

lockStep := &Step{DoFunc: lockFunc, UndoFunc: unlockFunc, Nodes: []uuid.UUID{gdctx.MyUUID}, Skip: false}
unlockStep := &Step{DoFunc: unlockFunc, UndoFunc: "", Nodes: []uuid.UUID{gdctx.MyUUID}, Skip: false}

return lockStep, unlockStep, nil
}

// LockUnlockFunc is signature of functions used for distributed locking
// and unlocking.
type LockUnlockFunc func(ctx context.Context) error

// CreateLockFuncs creates and returns functions for distributed lock and
// unlock. This is similar to CreateLockSteps() but returns normal functions.
// TODO: Remove this function
func CreateLockFuncs(key string) (LockUnlockFunc, LockUnlockFunc) {

key = lockPrefix + key
locker := concurrency.NewMutex(store.Store.Session, key)

// TODO: There is an opportunity for refactor here to re-use code
// between CreateLockFunc and CreateLockSteps. This variant doesn't
// have registry either.

lockFunc := func(ctx context.Context) error {
logger := gdctx.GetReqLogger(ctx)
if logger == nil {
logger = log.StandardLogger()
}

ctx, cancel := context.WithTimeout(ctx, lockObtainTimeout)
defer cancel()

logger.WithField("key", key).Debug("attempting to lock")
err := locker.Lock(ctx)
switch err {
case nil:
logger.WithField("key", key).Debug("lock obtained")
case context.DeadlineExceeded:
// Propagate this all the way back to the client as a HTTP 409 response
logger.WithField("key", key).Debug("timeout: failed to obtain lock")
err = ErrLockTimeout
}

return err
}

unlockFunc := func(ctx context.Context) error {
logger := gdctx.GetReqLogger(ctx)
if logger == nil {
logger = log.StandardLogger()
}

logger.WithField("key", key).Debug("attempting to unlock")
if err := locker.Unlock(context.Background()); err != nil {
logger.WithField("key", key).WithError(err).Error("unlock failed")
return err
}

logger.WithField("key", key).Debug("lock unlocked")
return nil
}

return lockFunc, unlockFunc
}

// Locks are the collection of cluster wide transaction lock
type Locks map[string]*concurrency.Mutex

Expand Down
Loading