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

Commit

Permalink
log with reqid and transaction id in
Browse files Browse the repository at this point in the history
daemon framework

Signed-off-by: Madhu Rajanna <[email protected]>
  • Loading branch information
Madhu-1 authored and prashanthpai committed Jun 15, 2018
1 parent 9dda1d5 commit 8955492
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 63 deletions.
8 changes: 4 additions & 4 deletions glusterd2/brick/glusterfsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ func errorContainsErrno(err error, errno syscall.Errno) bool {
// These functions are used in vol-create, vol-expand and vol-shrink (TBD)

//StartBrick starts glusterfsd process
func (b Brickinfo) StartBrick() error {
func (b Brickinfo) StartBrick(logger log.FieldLogger) error {

brickDaemon, err := NewGlusterfsd(b)
if err != nil {
return err
}

for i := 0; i < BrickStartMaxRetries; i++ {
err = daemon.Start(brickDaemon, true)
err = daemon.Start(brickDaemon, true, logger)
if err != nil {
if errorContainsErrno(err, syscall.EADDRINUSE) || errorContainsErrno(err, anotherEADDRINUSE) {
// Retry iff brick failed to start because of port being in use.
Expand Down Expand Up @@ -238,13 +238,13 @@ func (b Brickinfo) TerminateBrick() error {
}

//StopBrick will stop glusterfsd process
func (b Brickinfo) StopBrick() error {
func (b Brickinfo) StopBrick(logger log.FieldLogger) error {

brickDaemon, err := NewGlusterfsd(b)
if err != nil {
return err
}
return daemon.Stop(brickDaemon, true)
return daemon.Stop(brickDaemon, true, logger)
}

//CreateBrickSizeInfo parses size information for response
Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/snapshot/snapshot-activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func activateSnapshot(c transaction.TxnCtx) error {
return err
}

err = snapshot.ActivateDeactivateFunc(snapinfo, brickinfos, activate)
err = snapshot.ActivateDeactivateFunc(snapinfo, brickinfos, activate, c.Logger())
if err != nil {
return err
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func rollbackActivateSnapshot(c transaction.TxnCtx) error {
return err
}

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

return err

Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/snapshot/snapshot-deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func deactivateSnapshot(c transaction.TxnCtx) error {
return err
}

err = snapshot.ActivateDeactivateFunc(snapinfo, brickinfos, activate)
err = snapshot.ActivateDeactivateFunc(snapinfo, brickinfos, activate, c.Logger())
if err != nil {
return err
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func rollbackDeactivateSnapshot(c transaction.TxnCtx) error {
return err
}

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

return err

Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/volumes/volume-expand-txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func startBricksOnExpand(c transaction.TxnCtx) error {
"brick": b.String(),
}).Info("Starting brick")

if err := b.StartBrick(); err != nil {
if err := b.StartBrick(c.Logger()); err != nil {
return err
}
}
Expand All @@ -129,7 +129,7 @@ func undoStartBricksOnExpand(c transaction.TxnCtx) error {
"brick": b.String(),
}).Info("volume expand failed, stopping brick")

if err := b.StopBrick(); err != nil {
if err := b.StopBrick(c.Logger()); err != nil {
c.Logger().WithFields(log.Fields{
"error": err,
"volume": b.VolumeName,
Expand Down
5 changes: 3 additions & 2 deletions glusterd2/commands/volumes/volume-option.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/gorilla/mux"
"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
)

func optionSetValidate(c transaction.TxnCtx) error {
Expand Down Expand Up @@ -90,7 +91,7 @@ func xlatorAction(c transaction.TxnCtx, txnOp txnOpType) error {
return err
}

var fn func(*volume.Volinfo, string, string) error
var fn func(*volume.Volinfo, string, string, log.FieldLogger) error
for k, v := range req.Options {
_, xl, key, err := options.SplitKey(k)
if err != nil {
Expand All @@ -106,7 +107,7 @@ func xlatorAction(c transaction.TxnCtx, txnOp txnOpType) error {
} else {
fn = xltr.Actor.Undo
}
if err := fn(&volinfo, key, v); err != nil {
if err := fn(&volinfo, key, v, c.Logger()); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/volumes/volume-start.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func startAllBricks(c transaction.TxnCtx) error {
"brick": b.String(),
}).Info("Starting brick")

if err := b.StartBrick(); err != nil {
if err := b.StartBrick(c.Logger()); err != nil {
if err == errors.ErrProcessAlreadyRunning {
continue
}
Expand All @@ -53,7 +53,7 @@ func stopAllBricks(c transaction.TxnCtx) error {
"brick": b.String(),
}).Info("volume start failed, stopping brick")

if err := b.StopBrick(); err != nil {
if err := b.StopBrick(c.Logger()); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/volumes/volume-statedump.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func takeStatedump(c transaction.TxnCtx) error {
if err != nil {
return err
}
if err := daemon.Signal(d, unix.SIGUSR1); err != nil {
if err := daemon.Signal(d, unix.SIGUSR1, c.Logger()); err != nil {
// only log, don't error out
c.Logger().WithError(err).WithField(
"daemon", d.ID()).Error("Failed to take statedump for daemon")
Expand All @@ -72,7 +72,7 @@ func takeStatedump(c transaction.TxnCtx) error {
if err != nil {
return err
}
if err := daemon.Signal(d, unix.SIGUSR1); err != nil {
if err := daemon.Signal(d, unix.SIGUSR1, c.Logger()); err != nil {
// only log, don't error out
c.Logger().WithError(err).WithField(
"daemon", d.ID()).Error("Failed to take statedump for daemon")
Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/volumes/volume-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func stopBricks(c transaction.TxnCtx) error {
if err != nil {
c.Logger().WithError(err).WithField(
"brick", b.String()).Error("failed to connect to brick, sending SIGTERM")
daemon.Stop(brickDaemon, false)
daemon.Stop(brickDaemon, false, c.Logger())
continue
}

Expand All @@ -50,7 +50,7 @@ func stopBricks(c transaction.TxnCtx) error {
if err != nil || rsp.OpRet != 0 {
c.Logger().WithError(err).WithField(
"brick", b.String()).Error("failed to send terminate RPC, sending SIGTERM")
daemon.Stop(brickDaemon, false)
daemon.Stop(brickDaemon, false, c.Logger())
continue
}

Expand Down
30 changes: 15 additions & 15 deletions glusterd2/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ type Daemon interface {
// is already running, errors.ErrProcessAlreadyRunning is returned.
// When wait == true, this function can be used to spawn short term processes
// which will be waited on for completion before this function returns.
func Start(d Daemon, wait bool) error {
func Start(d Daemon, wait bool, logger log.FieldLogger) error {

log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"path": d.Path(),
"args": strings.Join(d.Args(), " "),
Expand Down Expand Up @@ -81,7 +81,7 @@ func Start(d Daemon, wait bool) error {
if wait == true {
// Wait for the child to exit
errStatus := cmd.Wait()
log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"pid": cmd.Process.Pid,
"status": errStatus,
}).Debug("Child exited")
Expand All @@ -97,15 +97,15 @@ func Start(d Daemon, wait bool) error {
// daemon tell glusterd2 that it's up and ready.
pid, err = ReadPidFromFile(d.PidFile())
if err != nil {
log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"pidfile": d.PidFile(),
"error": err.Error(),
}).Error("Could not read pidfile")
events.Broadcast(newEvent(d, daemonStartFailed, 0))
return err
}

log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"pid": pid,
}).Debug("Started daemon successfully")
Expand All @@ -116,7 +116,7 @@ func Start(d Daemon, wait bool) error {
// exit status. This should not let it be a zombie.
go func() {
err := cmd.Wait()
log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"pid": cmd.Process.Pid,
"status": err,
Expand All @@ -126,7 +126,7 @@ func Start(d Daemon, wait bool) error {

// Save daemon information in the store so it can be restarted
if err := saveDaemon(d); err != nil {
log.WithField("name", d.Name()).WithError(err).Warn("failed to save daemon information into store, daemon may not be restarted on GlusterD restart")
logger.WithField("name", d.Name()).WithError(err).Warn("failed to save daemon information into store, daemon may not be restarted on GlusterD restart")
}

return nil
Expand All @@ -136,7 +136,7 @@ func Start(d Daemon, wait bool) error {
// terminate the process gracefully or forcefully.
// When force == false, a SIGTERM signal is sent to the daemon.
// When force == true, a SIGKILL signal is sent to the daemon.
func Stop(d Daemon, force bool) error {
func Stop(d Daemon, force bool, logger log.FieldLogger) error {

// It is assumed that the process d has written to pidfile
pid, err := ReadPidFromFile(d.PidFile())
Expand All @@ -149,7 +149,7 @@ func Stop(d Daemon, force bool) error {
return err
}

log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"pid": pid,
}).Debug("Stopping daemon.")
Expand All @@ -165,7 +165,7 @@ func Stop(d Daemon, force bool) error {
_ = os.Remove(d.PidFile())

if err != nil {
log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"pid": pid,
}).Error("Stopping daemon failed.")
Expand All @@ -175,7 +175,7 @@ func Stop(d Daemon, force bool) error {
}

if err := DelDaemon(d); err != nil {
log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"pid": pid,
}).WithError(err).Warn("failed to delete daemon from store, it may be restarted on GlusterD restart")
Expand All @@ -197,7 +197,7 @@ func StartAllDaemons() {
}

for _, d := range ds {
if err := Start(d, true); err != nil {
if err := Start(d, true, log.StandardLogger()); err != nil {
log.WithField("name", d.Name()).WithError(err).Warn("failed to start daemon")
}
}
Expand All @@ -206,7 +206,7 @@ func StartAllDaemons() {

// Signal function reads the PID from path returned by PidFile() and
// sends the signal to that PID
func Signal(d Daemon, sig syscall.Signal) error {
func Signal(d Daemon, sig syscall.Signal, logger log.FieldLogger) error {

// It is assumed that the process d has written to pidfile
pid, err := ReadPidFromFile(d.PidFile())
Expand All @@ -219,15 +219,15 @@ func Signal(d Daemon, sig syscall.Signal) error {
return err
}

log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"pid": pid,
"signal": sig,
}).Debug("Signal to daemon.")

err = process.Signal(sig)
if err != nil {
log.WithFields(log.Fields{
logger.WithFields(log.Fields{
"name": d.Name(),
"pid": pid,
"signal": sig,
Expand Down
1 change: 0 additions & 1 deletion glusterd2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
)

func main() {

if err := gdctx.SetHostnameAndIP(); err != nil {
log.WithError(err).Fatal("Failed to get and set hostname or IP")
}
Expand Down
6 changes: 3 additions & 3 deletions glusterd2/snapshot/snapshot-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func MountSnapBrickDirectory(vol *volume.Volinfo, brickinfo *brick.Brickinfo) er
}

//ActivateDeactivateFunc uses to activate and deactivate
func ActivateDeactivateFunc(snapinfo *Snapinfo, b []brick.Brickinfo, activate bool) error {
func ActivateDeactivateFunc(snapinfo *Snapinfo, b []brick.Brickinfo, activate bool, logger log.FieldLogger) error {
volinfo := &snapinfo.SnapVolinfo
switch volinfo.State == volume.VolStarted {
case true:
Expand All @@ -96,14 +96,14 @@ func ActivateDeactivateFunc(snapinfo *Snapinfo, b []brick.Brickinfo, activate bo
if err := MountSnapBrickDirectory(volinfo, &b[i]); err != nil {
return err
}
if err := b[i].StartBrick(); err != nil {
if err := b[i].StartBrick(logger); err != nil {
return err
}

} else {
var err error
if err = b[i].TerminateBrick(); err != nil {
if err = b[i].StopBrick(); err != nil {
if err = b[i].StopBrick(logger); err != nil {
return err
}
}
Expand Down
10 changes: 6 additions & 4 deletions glusterd2/xlator/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package xlator

import (
"github.com/gluster/glusterd2/glusterd2/volume"

log "github.com/sirupsen/logrus"
)

var optionActors = make(map[string]OptionActor)
Expand All @@ -12,11 +14,11 @@ var optionActors = make(map[string]OptionActor)
// have the xlator/feature specific logic executed during volume set. An example
// of such logic is the task of starting and stopping daemon.
type OptionActor interface {
// Do function takes volinfo, option key, option value.
Do(*volume.Volinfo, string, string) error
// Undo function takes volinfo, option key, option value. The returned
// Do function takes volinfo, option key, option value, logger.
Do(*volume.Volinfo, string, string, log.FieldLogger) error
// Undo function takes volinfo, option key, option value and logger. The returned
// error is currently ignored.
Undo(*volume.Volinfo, string, string) error
Undo(*volume.Volinfo, string, string, log.FieldLogger) error
}

// RegisterOptionActor registers a xlator's type implementing OptionActor
Expand Down
Loading

0 comments on commit 8955492

Please sign in to comment.