From 0d145ced9c733daa9aea8b9005975323348913c3 Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Mon, 28 May 2018 12:46:18 +0530 Subject: [PATCH] transaction: Replace Cleanup with Done --- glusterd2/commands/peers/editpeer.go | 2 +- glusterd2/commands/volumes/bricks-status.go | 2 +- glusterd2/commands/volumes/volume-create.go | 2 +- glusterd2/commands/volumes/volume-delete.go | 2 +- glusterd2/commands/volumes/volume-expand.go | 2 +- glusterd2/commands/volumes/volume-option.go | 2 +- glusterd2/commands/volumes/volume-start.go | 2 +- glusterd2/commands/volumes/volume-statedump.go | 2 +- glusterd2/commands/volumes/volume-stop.go | 2 +- glusterd2/transaction/transaction.go | 11 +++-------- plugins/bitrot/rest.go | 8 ++++---- plugins/device/rest.go | 2 +- plugins/georeplication/rest.go | 16 ++++++++-------- plugins/glustershd/rest.go | 4 ++-- plugins/quota/rest.go | 2 +- 15 files changed, 28 insertions(+), 33 deletions(-) diff --git a/glusterd2/commands/peers/editpeer.go b/glusterd2/commands/peers/editpeer.go index 37203bb02..25263e447 100644 --- a/glusterd2/commands/peers/editpeer.go +++ b/glusterd2/commands/peers/editpeer.go @@ -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) diff --git a/glusterd2/commands/volumes/bricks-status.go b/glusterd2/commands/volumes/bricks-status.go index 62294670f..2047b7d46 100644 --- a/glusterd2/commands/volumes/bricks-status.go +++ b/glusterd2/commands/volumes/bricks-status.go @@ -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", diff --git a/glusterd2/commands/volumes/volume-create.go b/glusterd2/commands/volumes/volume-create.go index d9955737d..1de0fbb45 100644 --- a/glusterd2/commands/volumes/volume-create.go +++ b/glusterd2/commands/volumes/volume-create.go @@ -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 { diff --git a/glusterd2/commands/volumes/volume-delete.go b/glusterd2/commands/volumes/volume-delete.go index 06b35f38e..f80792ac9 100644 --- a/glusterd2/commands/volumes/volume-delete.go +++ b/glusterd2/commands/volumes/volume-delete.go @@ -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{ { diff --git a/glusterd2/commands/volumes/volume-expand.go b/glusterd2/commands/volumes/volume-expand.go index e8a190253..91d61d1b2 100644 --- a/glusterd2/commands/volumes/volume-expand.go +++ b/glusterd2/commands/volumes/volume-expand.go @@ -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 { diff --git a/glusterd2/commands/volumes/volume-option.go b/glusterd2/commands/volumes/volume-option.go index 9088869ab..247c01640 100644 --- a/glusterd2/commands/volumes/volume-option.go +++ b/glusterd2/commands/volumes/volume-option.go @@ -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 { diff --git a/glusterd2/commands/volumes/volume-start.go b/glusterd2/commands/volumes/volume-start.go index c13aca2eb..262089e70 100644 --- a/glusterd2/commands/volumes/volume-start.go +++ b/glusterd2/commands/volumes/volume-start.go @@ -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{ { diff --git a/glusterd2/commands/volumes/volume-statedump.go b/glusterd2/commands/volumes/volume-statedump.go index c32cea0e3..84ed76c0d 100644 --- a/glusterd2/commands/volumes/volume-statedump.go +++ b/glusterd2/commands/volumes/volume-statedump.go @@ -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{ { diff --git a/glusterd2/commands/volumes/volume-stop.go b/glusterd2/commands/volumes/volume-stop.go index 4809209c7..221a9932f 100644 --- a/glusterd2/commands/volumes/volume-stop.go +++ b/glusterd2/commands/volumes/volume-stop.go @@ -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{ { diff --git a/glusterd2/transaction/transaction.go b/glusterd2/transaction/transaction.go index 1aa6b4b6f..4b011b5b3 100644 --- a/glusterd2/transaction/transaction.go +++ b/glusterd2/transaction/transaction.go @@ -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 } @@ -71,12 +72,6 @@ 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() { @@ -84,7 +79,8 @@ func (t *Txn) Done() { 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 { @@ -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 { diff --git a/plugins/bitrot/rest.go b/plugins/bitrot/rest.go index 958dbb78d..0b0fffb09 100644 --- a/plugins/bitrot/rest.go +++ b/plugins/bitrot/rest.go @@ -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") @@ -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") @@ -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) @@ -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) diff --git a/plugins/device/rest.go b/plugins/device/rest.go index 310d7ed44..d84f28ad0 100644 --- a/plugins/device/rest.go +++ b/plugins/device/rest.go @@ -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{ diff --git a/plugins/georeplication/rest.go b/plugins/georeplication/rest.go index 18f86fbbd..0b3b6446b 100644 --- a/plugins/georeplication/rest.go +++ b/plugins/georeplication/rest.go @@ -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) @@ -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 { @@ -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 { @@ -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{ @@ -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 { @@ -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 { @@ -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) @@ -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) diff --git a/plugins/glustershd/rest.go b/plugins/glustershd/rest.go index a62f46ed6..5c05deec3 100644 --- a/plugins/glustershd/rest.go +++ b/plugins/glustershd/rest.go @@ -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) @@ -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) diff --git a/plugins/quota/rest.go b/plugins/quota/rest.go index 87d8a4262..f34ae3d45 100644 --- a/plugins/quota/rest.go +++ b/plugins/quota/rest.go @@ -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")