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

Commit

Permalink
transaction: Replace Cleanup with Done
Browse files Browse the repository at this point in the history
  • Loading branch information
kshlm committed May 28, 2018
1 parent 2ff4f66 commit 0d145ce
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion glusterd2/commands/peers/editpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func editPeer(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()
lock, unlock, err := transaction.CreateLockSteps(peerID)
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/bricks-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func volumeBricksStatusHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()
txn.Steps = []*transaction.Step{
{
DoFunc: "bricks-status.Check",
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/volume-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func volumeCreateHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

lock, unlock, err := transaction.CreateLockSteps(req.Name)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/volume-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func volumeDeleteHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

txn.Steps = []*transaction.Step{
{
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/volume-expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func volumeExpandHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

nodes, err := req.Nodes()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/volume-option.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func volumeOptionsHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

allNodes, err := peer.GetPeerIDs()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/volume-start.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func volumeStartHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

txn.Steps = []*transaction.Step{
{
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/volume-statedump.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func volumeStatedumpHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

txn.Steps = []*transaction.Step{
{
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/commands/volumes/volume-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func volumeStopHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

txn.Steps = []*transaction.Step{
{
Expand Down
11 changes: 3 additions & 8 deletions glusterd2/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func NewTxn(ctx context.Context) *Txn {
}).WithPrefix(prefix)

t.Ctx.Logger().Debug("new transaction created")
expTxn.Add("initiated_txn_in_progress", 1)
return t
}

Expand All @@ -71,20 +72,15 @@ func NewTxnWithLocks(ctx context.Context, lockIDs ...string) *Txn {
return t
}

// Cleanup cleans the leftovers after a transaction ends
func (t *Txn) Cleanup() {
store.Store.Delete(context.TODO(), t.Ctx.Prefix(), clientv3.WithPrefix())
expTxn.Add("initiated_txn_in_progress", -1)
}

// Done releases any obtained locks and cleans up the transaction namespace
// Done must be called after a transaction ends
func (t *Txn) Done() {
// Release obtained locks
for _, locker := range t.locks {
locker.Unlock(context.Background())
}
t.Cleanup()
store.Store.Delete(context.TODO(), t.Ctx.Prefix(), clientv3.WithPrefix())
expTxn.Add("initiated_txn_in_progress", -1)
}

func (t *Txn) checkAlive() error {
Expand Down Expand Up @@ -115,7 +111,6 @@ func (t *Txn) Do() error {
}

t.Ctx.Logger().Debug("Starting transaction")
expTxn.Add("initiated_txn_in_progress", 1)

for i, s := range t.Steps {
if s.Skip {
Expand Down
8 changes: 4 additions & 4 deletions plugins/bitrot/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func bitrotEnableHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which starts bitd and scrubber on all nodes.
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

if err := txn.Ctx.Set("volinfo", volinfo); err != nil {
logger.WithError(err).Error("failed to set volinfo in transaction context")
Expand Down Expand Up @@ -140,7 +140,7 @@ func bitrotDisableHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which stop bitd and scrubber on all nodes.
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

if err := txn.Ctx.Set("volinfo", volinfo); err != nil {
logger.WithError(err).Error("failed to set volinfo in transaction context")
Expand Down Expand Up @@ -221,7 +221,7 @@ func bitrotScrubOndemandHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which starts scrubber on demand.
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

//Lock on Volume Name
lock, unlock, err := transaction.CreateLockSteps(volName)
Expand Down Expand Up @@ -288,7 +288,7 @@ func bitrotScrubStatusHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which gets scrubber status.
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

//Lock on Volume Name
lock, unlock, err := transaction.CreateLockSteps(volName)
Expand Down
2 changes: 1 addition & 1 deletion plugins/device/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

txn.Nodes = []uuid.UUID{peerInfo.ID}
txn.Steps = []*transaction.Step{
Expand Down
16 changes: 8 additions & 8 deletions plugins/georeplication/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func georepCreateHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which updates the Geo-rep session
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

// Lock on Master Volume name
lock, unlock, err := transaction.CreateLockSteps(geoSession.MasterVol)
Expand Down Expand Up @@ -292,7 +292,7 @@ func georepActionHandler(w http.ResponseWriter, r *http.Request, action actionTy
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

lock, unlock, err := transaction.CreateLockSteps(geoSession.MasterVol)
if err != nil {
Expand Down Expand Up @@ -424,7 +424,7 @@ func georepDeleteHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

lock, unlock, err := transaction.CreateLockSteps(geoSession.MasterVol)
if err != nil {
Expand Down Expand Up @@ -514,7 +514,7 @@ func georepStatusHandler(w http.ResponseWriter, r *http.Request) {

// Status Transaction
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

txn.Nodes = vol.Nodes()
txn.Steps = []*transaction.Step{
Expand Down Expand Up @@ -785,7 +785,7 @@ func georepConfigSetHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()
// TODO: change the lock key
lock, unlock, err := transaction.CreateLockSteps(geoSession.MasterVol)
if err != nil {
Expand Down Expand Up @@ -927,7 +927,7 @@ func georepConfigResetHandler(w http.ResponseWriter, r *http.Request) {
}

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()
// TODO: change the lock key
lock, unlock, err := transaction.CreateLockSteps(geoSession.MasterVol)
if err != nil {
Expand Down Expand Up @@ -1024,7 +1024,7 @@ func georepSSHKeyGenerateHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which updates the Geo-rep session
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

// Lock on Master Volume name
lock, unlock, err := transaction.CreateLockSteps(volname)
Expand Down Expand Up @@ -1120,7 +1120,7 @@ func georepSSHKeyPushHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which updates the Geo-rep session
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

// Lock on Master Volume name
lock, unlock, err := transaction.CreateLockSteps(volname)
Expand Down
4 changes: 2 additions & 2 deletions plugins/glustershd/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func glustershEnableHandler(w http.ResponseWriter, r *http.Request) {

// Transaction which starts self heal daemon on all nodes with atleast one brick.
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

//Lock on Volume Name
lock, unlock, err := transaction.CreateLockSteps(volname)
Expand Down Expand Up @@ -140,7 +140,7 @@ func glustershDisableHandler(w http.ResponseWriter, r *http.Request) {
// Transaction which checks if all replicate volumes are stopped before
// stopping the self-heal daemon.
txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

// Lock on volume name.
lock, unlock, err := transaction.CreateLockSteps(volname)
Expand Down
2 changes: 1 addition & 1 deletion plugins/quota/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func quotaEnableHandler(w http.ResponseWriter, r *http.Request) {
vol.Options[quotaEnabledKey] = "on"

txn := transaction.NewTxn(ctx)
defer txn.Cleanup()
defer txn.Done()

if err := txn.Ctx.Set("volinfo", vol); err != nil {
logger.WithError(err).Error("failed to set volinfo in transaction context")
Expand Down

0 comments on commit 0d145ce

Please sign in to comment.