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

Commit

Permalink
volgen: changes for Volume operation
Browse files Browse the repository at this point in the history
Fixes: #1111 and #1190
Signed-off-by: Aravinda VK <avishwan@redhat.com>
  • Loading branch information
aravindavk authored and Atin Mukherjee committed Nov 9, 2018
1 parent e686775 commit 928e3a3
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 37 deletions.
23 changes: 14 additions & 9 deletions glusterd2/brick/glusterfsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ const (
glusterfsdBin = "glusterfsd"
)

func brickPathWithoutSlashes(brickPath string) string {
return strings.Trim(strings.Replace(brickPath, "/", "-", -1), "-")
}

// GetVolfileID returns Volfile ID of glusterfsd process
func GetVolfileID(volname string, brickPath string) string {
return volname + "." + gdctx.MyUUID.String() + "." + brickPathWithoutSlashes(brickPath)
}

// Glusterfsd type represents information about the brick daemon
type Glusterfsd struct {
// Externally consumable using methods of Glusterfsd interface
Expand Down Expand Up @@ -53,11 +62,9 @@ func (b *Glusterfsd) Args() []string {
return b.args
}

brickPathWithoutSlashes := strings.Trim(strings.Replace(b.brickinfo.Path, "/", "-", -1), "-")

logFile := path.Join(config.GetString("logdir"), "glusterfs", "bricks", fmt.Sprintf("%s.log", brickPathWithoutSlashes))
logFile := path.Join(config.GetString("logdir"), "glusterfs", "bricks", fmt.Sprintf("%s.log", brickPathWithoutSlashes(b.brickinfo.Path)))

volFileID := b.brickinfo.VolfileID + "." + gdctx.MyUUID.String() + "." + brickPathWithoutSlashes
volfileID := GetVolfileID(b.brickinfo.VolumeName, b.brickinfo.Path)

shost, sport, _ := net.SplitHostPort(config.GetString("clientaddress"))
if shost == "" {
Expand All @@ -67,7 +74,7 @@ func (b *Glusterfsd) Args() []string {
b.args = []string{}
b.args = append(b.args, "--volfile-server", shost)
b.args = append(b.args, "--volfile-server-port", sport)
b.args = append(b.args, "--volfile-id", volFileID)
b.args = append(b.args, "--volfile-id", volfileID)
b.args = append(b.args, "-p", b.PidFile())
b.args = append(b.args, "-S", b.SocketFile())
b.args = append(b.args, "--brick-name", b.brickinfo.Path)
Expand All @@ -88,8 +95,7 @@ func (b *Glusterfsd) SocketFile() string {

// First we form a key
// Example: key = peerid + brick path with '/' replaced by -
brickPathWithoutSlashes := strings.Trim(strings.Replace(b.brickinfo.Path, "/", "-", -1), "-")
key := fmt.Sprintf("%s-%s", b.brickinfo.PeerID.String(), brickPathWithoutSlashes)
key := fmt.Sprintf("%s-%s", b.brickinfo.PeerID.String(), brickPathWithoutSlashes(b.brickinfo.Path))

// Then xxhash of the above key shall be the name of socket file.
// Example: /var/run/gluster/<xxhash-hash>.socket
Expand All @@ -108,9 +114,8 @@ func (b *Glusterfsd) PidFile() string {
return b.pidfilepath
}

brickPathWithoutSlashes := strings.Trim(strings.Replace(b.brickinfo.Path, "/", "-", -1), "-")
// FIXME: The brick can no longer clean this up on clean shut down
pidfilename := fmt.Sprintf("%s-%s.pid", b.brickinfo.PeerID.String(), brickPathWithoutSlashes)
pidfilename := fmt.Sprintf("%s-%s.pid", b.brickinfo.PeerID.String(), brickPathWithoutSlashes(b.brickinfo.Path))
b.pidfilepath = path.Join(config.GetString("rundir"), pidfilename)

return b.pidfilepath
Expand Down
6 changes: 0 additions & 6 deletions glusterd2/commands/volumes/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ func (c *Command) Routes() route.Routes {
Version: 1,
RequestType: utils.GetTypeString((*api.VolStatedumpReq)(nil)),
HandlerFunc: volumeStatedumpHandler},
route.Route{
Name: "VolfilesGenerate",
Method: "POST",
Pattern: "/volfiles",
Version: 1,
HandlerFunc: volfilesGenerateHandler},
route.Route{
Name: "VolfilesGet",
Method: "GET",
Expand Down
56 changes: 50 additions & 6 deletions glusterd2/commands/volumes/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,18 @@ func storeVolInfo(c transaction.TxnCtx, key string) error {
"key", "volinfo").Debug("Failed to get key from store")
return err
}

if err := volume.AddOrUpdateVolumeFunc(&volinfo); err != nil {
c.Logger().WithError(err).WithField(
"volume", volinfo.Name).Debug("failed to store volume info")
err := volgen.VolumeVolfileToStore(&volinfo, volinfo.Name, "client")
if err != nil {
c.Logger().WithError(err).WithFields(log.Fields{
"template": "client",
"volfile": volinfo.Name,
}).Error("failed to generate volfile and save to store")
return err
}

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

Expand Down Expand Up @@ -356,3 +358,45 @@ func isActionStepRequired(opt map[string]string, volinfo *volume.Volinfo) bool {

return false
}

func deleteBrickVolfiles(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")
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
}
}
return nil
}

func generateBrickVolfiles(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
}
}
return nil
}
16 changes: 0 additions & 16 deletions glusterd2/commands/volumes/volfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ import (
"github.com/gorilla/mux"
)

func volfilesGenerateHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

err := volgen.Generate()
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "unable to generate volfiles")
return
}
volfiles, err := volgen.GetVolfiles()
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "unable to get list of volfiles")
return
}
restutils.SendHTTPResponse(ctx, w, http.StatusOK, volfiles)
}

func volfilesListHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down
5 changes: 5 additions & 0 deletions glusterd2/commands/volumes/volume-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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 @@ -89,6 +90,10 @@ 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
7 changes: 7 additions & 0 deletions glusterd2/commands/volumes/volume-option.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +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},
}
for _, sf := range sfs {
transaction.RegisterStepFunc(sf.sf, sf.name)
Expand Down Expand Up @@ -246,6 +248,11 @@ func volumeOptionsHandler(w http.ResponseWriter, r *http.Request) {
Nodes: volinfo.Nodes(),
Skip: !isActionStepRequired(req.Options, volinfo),
},
{
DoFunc: "vol-option.GenerateBrickVolfiles",
UndoFunc: "vol-option.GenerateBrickvolfiles.Undo",
Nodes: volinfo.Nodes(),
},
{
DoFunc: "vol-option.NotifyVolfileChange",
Nodes: allNodes,
Expand Down
5 changes: 5 additions & 0 deletions glusterd2/commands/volumes/volume-reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func volumeResetHandler(w http.ResponseWriter, r *http.Request) {
UndoFunc: "vol-option.UpdateVolinfo.Undo",
Nodes: []uuid.UUID{gdctx.MyUUID},
},
{
DoFunc: "vol-option.GenerateBrickVolfiles",
UndoFunc: "vol-option.GenerateBrickvolfiles.Undo",
Nodes: volinfo.Nodes(),
},
{
DoFunc: "vol-option.NotifyVolfileChange",
Nodes: allNodes,
Expand Down
11 changes: 11 additions & 0 deletions glusterd2/commands/volumes/volume-start.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func startAllBricks(c transaction.TxnCtx) error {
return err
}

err := generateBrickVolfiles(c)
if err != nil {
return err
}
for _, b := range volinfo.GetLocalBricks() {

c.Logger().WithFields(log.Fields{
Expand Down Expand Up @@ -74,6 +78,8 @@ func registerVolStartStepFuncs() {
{"vol-start.XlatorActionUndoVolumeStart", xlatorActionUndoVolumeStart},
{"vol-start.UpdateVolinfo", storeVolume},
{"vol-start.UpdateVolinfo.Undo", undoStoreVolume},
{"vol-start.GenerateBrickVolfile", generateBrickVolfiles},
{"vol-start.GenerateBrickVolfile.Undo", deleteBrickVolfiles},
}
for _, sf := range sfs {
transaction.RegisterStepFunc(sf.sf, sf.name)
Expand Down Expand Up @@ -115,6 +121,11 @@ func volumeStartHandler(w http.ResponseWriter, r *http.Request) {
}

txn.Steps = []*transaction.Step{
{
DoFunc: "vol-start.GenerateBrickVolfile",
UndoFunc: "vol-start.GenerateBrickVolfile.Undo",
Nodes: volinfo.Nodes(),
},
{
DoFunc: "vol-start.StartBricks",
UndoFunc: "vol-start.StartBricksUndo",
Expand Down
10 changes: 10 additions & 0 deletions glusterd2/volume/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func (v *Volinfo) StringMap() map[string]string {
return m
}

// StringMap returns a map[string]string representation of Subvol
func (sv *Subvol) StringMap() map[string]string {
m := make(map[string]string)

m["subvol.type"] = strings.ToLower(sv.Type.String())
m["subvol.name"] = sv.Name

return m
}

// NewBrickEntries creates the brick list
func NewBrickEntries(bricks []api.BrickReq, volName, volfileID string, volID uuid.UUID, ptype brick.ProvisionType) ([]brick.Brickinfo, error) {
var brickInfos []brick.Brickinfo
Expand Down

0 comments on commit 928e3a3

Please sign in to comment.