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

Commit

Permalink
added comments to volgen structs and snapshot related fixes
Browse files Browse the repository at this point in the history
Brick volfiles generation added during Snapshot activate and
volfiles delete added during snapshot deactivate.

Also fixed client volfile regeneration of snapshot volume during
snapshot restore undo.

Signed-off-by: Aravinda VK <avishwan@redhat.com>
  • Loading branch information
aravindavk authored and Atin Mukherjee committed Nov 9, 2018
1 parent 1fe0df5 commit 367de6f
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 155 deletions.
5 changes: 2 additions & 3 deletions doc/endpoints.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glusterd2/commands/snapshot/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func storeSnapinfo(c transaction.TxnCtx, key string) error {

if err := snapshot.AddOrUpdateSnapFunc(&snapinfo); err != nil {
c.Logger().WithError(err).WithField(
"snapshot", volinfo.Name).Debug("storeSnapshot: failed to store snapshot info")
"snapshot", volinfo.Name).Error("storeSnapshot: failed to store snapshot info")
return err
}

Expand Down
32 changes: 15 additions & 17 deletions glusterd2/commands/snapshot/snapshot-activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ func activateSnapshot(c transaction.TxnCtx) error {
}

// Generate local Bricks Volfiles
for _, b := range vol.GetLocalBricks() {
volfileID := brick.GetVolfileID(vol.Name, b.Path)
err := volgen.BrickVolfileToFile(vol, volfileID, "brick", b.PeerID.String(), b.Path)
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volfile": volfileID,
}).Error("failed to generate volfile")
return err
}
err = volgen.GenerateBricksVolfiles(vol, vol.GetLocalBricks())
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volume": vol.Name,
}).Error("failed to generate brick volfiles")
return err
}

err = snapshot.ActivateDeactivateFunc(&snapinfo, brickinfos, activate, c.Logger())
Expand All @@ -72,15 +69,16 @@ func rollbackActivateSnapshot(c transaction.TxnCtx) error {
}

// Remove the local Bricks Volfiles
for _, b := range vol.GetLocalBricks() {
volfileID := brick.GetVolfileID(vol.Name, b.Path)
err := volgen.DeleteFile(volfileID)
if err != nil {
c.Logger().WithError(err).WithField("volfile", volfileID).Error("failed to delete volfile")
}
err := volgen.DeleteBricksVolfiles(vol.GetLocalBricks())
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volume": vol.Name,
}).Error("failed to delete brick volfiles")
return err
}

err := snapshot.ActivateDeactivateFunc(&snapinfo, brickinfos, activate, c.Logger())
err = snapshot.ActivateDeactivateFunc(&snapinfo, brickinfos, activate, c.Logger())

return err

Expand Down
7 changes: 4 additions & 3 deletions glusterd2/commands/snapshot/snapshot-clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func undoStoreSnapshotClone(c transaction.TxnCtx) error {
if err := volgen.DeleteVolfiles(vol.VolfileID); err != nil {
c.Logger().WithError(err).
WithField("volume", vol.Name).
Warn("failed to delete volfiles of volume")
Error("failed to delete volfiles of volume")
return err
}
return nil
}
Expand All @@ -64,13 +65,13 @@ func storeSnapshotClone(c transaction.TxnCtx) error {
}
if err := volume.AddOrUpdateVolumeFunc(&vol); err != nil {
c.Logger().WithError(err).WithField(
"volume", vol.Name).Debug("storeVolume: failed to store Volinfo")
"volume", vol.Name).Error("storeVolume: failed to store Volinfo")
return err
}

if err := volgen.VolumeVolfileToStore(&vol, vol.Name, "client"); err != nil {
c.Logger().WithError(err).WithField(
"volume", vol.Name).Debug("generateVolfiles: failed to generate volfiles")
"volume", vol.Name).Error("generateVolfiles: failed to generate volfiles")
return err
}

Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/snapshot/snapshot-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func undoStoreSnapshotOnCreate(c transaction.TxnCtx) error {
if err := volgen.DeleteVolfiles(snapInfo.SnapVolinfo.VolfileID); err != nil {
c.Logger().WithError(err).
WithField("snapshot", snapshot.GetStorePath(&snapInfo)).
Warn("failed to delete volfiles of snapshot")
Error("failed to delete volfiles of snapshot")
return err
}

Expand Down Expand Up @@ -242,7 +242,7 @@ func storeSnapshotCreate(c transaction.TxnCtx) error {
}
if err := volgen.VolumeVolfileToStore(volinfo, volinfo.VolfileID, "client"); err != nil {
c.Logger().WithError(err).WithField(
"volume", volinfo.Name).Debug("generateVolfiles: failed to generate volfiles")
"volume", volinfo.Name).Error("generateVolfiles: failed to generate volfiles")
return err
}

Expand Down
22 changes: 21 additions & 1 deletion glusterd2/commands/snapshot/snapshot-deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/glusterd2/snapshot"
"github.com/gluster/glusterd2/glusterd2/transaction"
"github.com/gluster/glusterd2/glusterd2/volgen"
"github.com/gluster/glusterd2/glusterd2/volume"
"github.com/gluster/glusterd2/pkg/api"
"github.com/gluster/glusterd2/pkg/errors"
Expand Down Expand Up @@ -38,6 +39,15 @@ func deactivateSnapshot(c transaction.TxnCtx) error {
return err
}

err = volgen.DeleteBricksVolfiles(vol.GetLocalBricks())
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volume": vol.Name,
}).Error("failed to delete brick volfiles")
return err
}

//TODO Stop other process of snapshot volume
//Yet to implement a generic way in glusterd2

Expand Down Expand Up @@ -69,13 +79,23 @@ func rollbackDeactivateSnapshot(c transaction.TxnCtx) error {
if err := c.Get("oldsnapinfo", &snapinfo); err != nil {
return err
}
vol := &snapinfo.SnapVolinfo

if err := c.GetNodeResult(gdctx.MyUUID, "brickListToOperate", &brickinfos); err != nil {
log.WithError(err).Error("failed to set request in transaction context")
return err
}

err := snapshot.ActivateDeactivateFunc(&snapinfo, brickinfos, activate, c.Logger())
err := volgen.GenerateBricksVolfiles(vol, vol.GetLocalBricks())
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volume": vol.Name,
}).Error("failed to generate brick volfiles")
return err
}

err = snapshot.ActivateDeactivateFunc(&snapinfo, brickinfos, activate, c.Logger())

return err

Expand Down
9 changes: 8 additions & 1 deletion glusterd2/commands/snapshot/snapshot-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func snapshotBrickDelete(errCh chan error, wg *sync.WaitGroup, snapVol volume.Vo
}
mountRoot := strings.TrimSuffix(b.Path, b.MountInfo.BrickDirSuffix)
os.RemoveAll(mountRoot)

volfileID := brick.GetVolfileID(snapVol.Name, b.Path)
if err := volgen.DeleteFile(volfileID); err != nil {
errCh <- err
}

errCh <- nil
return
}
Expand Down Expand Up @@ -88,7 +94,8 @@ func snapshotDeleteStore(c transaction.TxnCtx) error {
if err := volgen.DeleteVolfiles(snapinfo.SnapVolinfo.VolfileID); err != nil {
c.Logger().WithError(err).
WithField("snapshot", snapshot.GetStorePath(&snapinfo)).
Warn("failed to delete volfiles of snapshot")
Error("failed to delete volfiles of snapshot")
return err
}

return nil
Expand Down
50 changes: 46 additions & 4 deletions glusterd2/commands/snapshot/snapshot-restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func undoSnapStore(c transaction.TxnCtx) error {
return err
}

// Regenerate the volfile of original volume
err := volgen.VolumeVolfileToStore(&volinfo, volinfo.Name, "client")
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
Expand All @@ -118,7 +119,25 @@ func undoSnapStore(c transaction.TxnCtx) error {
return err
}

if err := volume.AddOrUpdateVolumeFunc(&volinfo); err != nil {
// Regenerate the Volfile of snapshot Volume
err = volgen.VolumeVolfileToStore(&snapInfo.SnapVolinfo, snapInfo.SnapVolinfo.Name, "client")
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "client",
"volfile": snapInfo.SnapVolinfo.Name,
}).Error("failed to generate snapshot volfile and save to store")
return err
}

// Generate brick Volfiles if Snapshot was started earlier
if snapInfo.SnapVolinfo.State == volume.VolStarted {
err = volgen.GenerateBricksVolfiles(&snapInfo.SnapVolinfo, snapInfo.SnapVolinfo.GetLocalBricks())
if err != nil {
return err
}
}

if err = volume.AddOrUpdateVolumeFunc(&volinfo); err != nil {
c.Logger().WithError(err).WithField(
"volume", volinfo.Name).Debug("failed to store volume info")
return err
Expand Down Expand Up @@ -260,20 +279,43 @@ func storeSnapRestore(c transaction.TxnCtx) error {

newVolinfo := createRestoreVolinfo(snapInfo, vol)

// Volfile of restored volume
err = volgen.VolumeVolfileToStore(&newVolinfo, newVolinfo.Name, "client")
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "client",
"volfile": newVolinfo.Name,
}).Error("failed to generate volfile and save to store")
return err
}

if err := volume.AddOrUpdateVolumeFunc(&newVolinfo); err != nil {
c.Logger().WithError(err).WithField(
"volume", newVolinfo.Name).Debug("failed to store volume info")
"volume", newVolinfo.Name).Error("failed to store volume info")
return err
}

if err := snapshot.DeleteSnapshot(snapInfo); err != nil {
c.Logger().WithError(err).WithField(
"snapshot", snapVol.Name).Debug("failed to delete snap from store")
"snapshot", snapVol.Name).Error("failed to delete snap from store")
return err
}
if err := volgen.DeleteVolfiles(snapInfo.SnapVolinfo.VolfileID); err != nil {
if err := volgen.DeleteVolfiles(snapVol.VolfileID); err != nil {
c.Logger().WithError(err).
WithField("snapshot", snapshot.GetStorePath(snapInfo)).
Warn("failed to delete volfiles of snapshot")
return err
}

// Delete Snapshot Brick volfiles if Snapvol was in started state
if snapVol.State == volume.VolStarted {
if err := volgen.DeleteBricksVolfiles(snapVol.GetLocalBricks()); err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volume": snapVol.Name,
}).Error("failed to delete brick volfiles")
return err
}
}

return nil
Expand Down
42 changes: 18 additions & 24 deletions glusterd2/commands/volumes/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func storeVolInfo(c transaction.TxnCtx, key string) error {
var volinfo volume.Volinfo
if err := c.Get(key, &volinfo); err != nil {
c.Logger().WithError(err).WithField(
"key", "volinfo").Debug("Failed to get key from store")
"key", "volinfo").Debug("failed to get key from store")
return err
}
err := volgen.VolumeVolfileToStore(&volinfo, volinfo.Name, "client")
Expand Down Expand Up @@ -359,44 +359,38 @@ func isActionStepRequired(opt map[string]string, volinfo *volume.Volinfo) bool {
return false
}

func deleteBrickVolfiles(c transaction.TxnCtx) error {
func txnDeleteBrickVolfiles(c transaction.TxnCtx) error {
var volinfo volume.Volinfo
if err := c.Get("volinfo", &volinfo); err != nil {
c.Logger().WithError(err).WithField(
"key", "volinfo").Error("Failed to get key from store")
"key", "volinfo").Error("failed to get key from store")
return err
}

for _, b := range volinfo.GetLocalBricks() {
volfileID := brick.GetVolfileID(volinfo.Name, b.Path)
err := volgen.DeleteFile(volfileID)
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"volume": volinfo.Name,
"filename": volfileID,
}).Error("failed to delete brick volfile")
return err
}
err := volgen.DeleteBricksVolfiles(volinfo.GetLocalBricks())
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volume": volinfo.Name,
}).Error("failed to delete brick volfile")
return err
}
return nil
}

func generateBrickVolfiles(c transaction.TxnCtx) error {
func txnGenerateBrickVolfiles(c transaction.TxnCtx) error {
var volinfo volume.Volinfo
if err := c.Get("volinfo", &volinfo); err != nil {
return err
}

for _, b := range volinfo.GetLocalBricks() {
volfileID := brick.GetVolfileID(volinfo.Name, b.Path)
err := volgen.BrickVolfileToFile(&volinfo, volfileID, "brick", b.PeerID.String(), b.Path)
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volfile": volfileID,
}).Error("failed to generate volfile")
return err
}
err := volgen.GenerateBricksVolfiles(&volinfo, volinfo.GetLocalBricks())
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "brick",
"volume": volinfo.Name,
}).Error("failed to generate volfile")
return err
}
return nil
}
8 changes: 2 additions & 6 deletions glusterd2/commands/volumes/volume-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func deleteVolume(c transaction.TxnCtx) error {
if err := volgen.DeleteVolfiles(volinfo.Name); err != nil {
c.Logger().WithError(err).
WithField("volume", volinfo.Name).
Warn("failed to delete volfiles of volume")
Error("failed to delete volfiles of volume")
return err
}

return nil
Expand All @@ -40,7 +41,6 @@ func deleteVolume(c transaction.TxnCtx) error {
func registerVolDeleteStepFuncs() {
transaction.RegisterStepFunc(deleteVolume, "vol-delete.Store")
transaction.RegisterStepFunc(txnCleanBricks, "vol-delete.CleanBricks")
transaction.RegisterStepFunc(deleteBrickVolfiles, "vol-delete.DeleteBrickVolfiles")
}

func volumeDeleteHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -90,10 +90,6 @@ func volumeDeleteHandler(w http.ResponseWriter, r *http.Request) {
DoFunc: "vol-delete.Store",
Nodes: []uuid.UUID{gdctx.MyUUID},
},
{
DoFunc: "vol-delete.DeleteBrickVolfiles",
Nodes: volinfo.Nodes(),
},
}

if err := txn.Ctx.Set("volinfo", volinfo); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/volumes/volume-option.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func registerVolOptionStepFuncs() {
{"vol-option.UpdateVolinfo", storeVolume},
{"vol-option.UpdateVolinfo.Undo", undoStoreVolume},
{"vol-option.NotifyVolfileChange", notifyVolfileChange},
{"vol-option.GenerateBrickVolfiles", generateBrickVolfiles},
{"vol-option.GenerateBrickvolfiles.Undo", deleteBrickVolfiles},
{"vol-option.GenerateBrickVolfiles", txnGenerateBrickVolfiles},
{"vol-option.GenerateBrickvolfiles.Undo", txnDeleteBrickVolfiles},
}
for _, sf := range sfs {
transaction.RegisterStepFunc(sf.sf, sf.name)
Expand Down
Loading

0 comments on commit 367de6f

Please sign in to comment.