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

Rebalance missing validation and code refactor #986

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

rishubhjain
Copy link
Contributor

Issue: #428

@rishubhjain
Copy link
Contributor Author

rishubhjain commented Jul 10, 2018

Remaining :

  1. CLI
  2. E2E
  3. TODOs.

Will update the PR with the remaining sections.

Copy link
Member

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update endpoints.md file

Pattern: "/volumes/{volname}/rebalance/start",
Version: 1,
RequestType: utils.GetTypeString((*rebalanceapi.StartReq)(nil)),
ResponseType: utils.GetTypeString((*uuid.UUID)(nil)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of giving an ID to the user, send it as a JSON struct or send RebalStatus or RebalInfo to user,

type RebalanceStartResp struct{
ID string 
}

rebalinfo := createRebalanceInfo(volname, &req)
if rebalinfo == nil {
logger.WithError(err).Error("failed to create Rebalance info")
rebalInfo, err := GetRebalanceInfo(volname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you missing error handling here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I want the error to be not nil

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when we get err !=nil don't we need to stop proceeding further
and return the error to the user

}

rebalInfo = createRebalanceInfo(volname, &req)
if rebalInfo == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: in what scenario createRebalanceInfo will return nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this scenario won't happen, but I have kept the error handling in case of future use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is for future use, this check will become redundant now. then we need to comment the code or remove it

if err != nil {
logger.WithError(err).Error("failed to set rebalance info in transaction context")
logger.WithError(err).WithField("key", "rinfo").Error("failed to set rebalance info in transaction context")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about logging as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already answered in your PR

@@ -162,14 +171,14 @@ func rebalanceStopHandler(w http.ResponseWriter, r *http.Request) {
return
}

rebalinfo, err := GetRebalanceInfo(volname)
rebalInfo, err := GetRebalanceInfo(volname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question:
do we need to return ErrRebalanceNotStarted error if get from store fails?

@@ -162,14 +171,14 @@ func rebalanceStopHandler(w http.ResponseWriter, r *http.Request) {
return
}

rebalinfo, err := GetRebalanceInfo(volname)
rebalInfo, err := GetRebalanceInfo(volname)
if err != nil {
restutils.SendHTTPError(r.Context(), w, http.StatusBadRequest, ErrRebalanceNotStarted)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as ctx is already defined as ctx := r.Context() ,send ctx instead of r.Context() to restutils.SendHTTPError

@@ -188,34 +197,33 @@ func rebalanceStopHandler(w http.ResponseWriter, r *http.Request) {

err = txn.Ctx.Set("volname", volname)
if err != nil {
logger.WithError(err).Error("failed to set volname in transaction context")
logger.WithError(err).WithField("key", "volname").Error("failed to set volname in transaction context")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same WithField question for logging in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered

rebalinfo.Volname = volname
rebalinfo.State = rebalanceapi.Stopped
rebalinfo.Cmd = rebalanceapi.CmdStop
rebalInfo.Volname = volname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question:

do we need to assign rebalInfo.Volname = volname as Volname already assigned during rebalance start?

@Madhu-1
Copy link
Member

Madhu-1 commented Jul 11, 2018

@rishubhjain please add a TODO for UNDO functions in txn steps for rebalance start and stop.

)

var rebalanceCmd = &cobra.Command{
Use: "volume rebalance",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where ever its required place add Long command to give more information about this CLI command to users

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

volname := cmd.Flags().Args()[0]
var err error
if flagRebalanceStartCmdForce && flagRebalanceStartCmdFixLayout {
err := errors.New("Conflicting options found")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use above declared err variable here, start error with small case

if err != nil {
if verbose {
log.WithError(err.Error()).WithFields(log.Fields{
"volume": volname,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question:
do we need to convert err.Error() error to string before logging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err.Error() itself is a string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.WithError does not expect input as string, you need to pass error to it

rebalinfo := createRebalanceInfo(volname, &req)
if rebalinfo == nil {
logger.WithError(err).Error("failed to create Rebalance info")
rebalInfo, err := GetRebalanceInfo(volname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when we get err !=nil don't we need to stop proceeding further
and return the error to the user

}

rebalInfo = createRebalanceInfo(volname, &req)
if rebalInfo == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is for future use, this check will become redundant now. then we need to comment the code or remove it

@@ -118,25 +127,16 @@ func rebalanceStartHandler(w http.ResponseWriter, r *http.Request) {
* rebalance process is one per node per volume.
* Need to handle scenarios where process is started in
* few nodes and failed in few others */
logger.WithFields(log.Fields{
"error": err.Error(),
logger.WithError(err).WithFields(log.Fields{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use WithField if you have only one field to log

restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err.Error())
return
}

err = txn.Do()
if err != nil {
logger.WithFields(log.Fields{
"error": err.Error(),
logger.WithError(err).WithFields(log.Fields{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use WithField to log if you have only one field to log

return
}

err = txn.Do()
if err != nil {
logger.WithFields(log.Fields{
"error": err.Error(),
logger.WithError(err).WithFields(log.Fields{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here log with WithField

req := rebalanceapi.StartReq{
Option: option,
}
url := fmt.Sprintf("/v1/volumes/%s/rebalance/start", volname)
Copy link
Member

@Madhu-1 Madhu-1 Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing import fmt package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Option: option,
}
url := fmt.Sprintf("/v1/volumes/%s/rebalance/start", volname)
return c.post(url, req, http.StatusOK, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, where are you importing HTTP package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rishubhjain rishubhjain force-pushed the rebalance branch 2 times, most recently from d6308da to 109d636 Compare July 12, 2018 11:36
func init() {

// Rebalance Start
rebalanceStartCmd.Flags().BoolVar(&flagRebalanceStartCmdForce, "force", false, "Force")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of the flags can be a little bit more elaborate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I am following the trend set by volumestart, will update both of them with more description in the next PR

const (
helpRebalanceCmd = "Gluster Rebalance"
helpRebalanceStartCmd = "Start rebalance session for gluster volume"
helpRebalanceStatusCmd = "Status of rebalance seesion"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: typo (seesion)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use rebalance operation instead of rebalance session.

@@ -44,14 +44,18 @@ func rebalanceStartHandler(w http.ResponseWriter, r *http.Request) {
return
}

rebalinfo := createRebalanceInfo(volname, &req)
if rebalinfo == nil {
logger.WithError(err).Error("failed to create Rebalance info")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this require to log the volume name as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO : Its easier to debug if the resource name is provided with error/debug message

)

err := ctx.Get("rinfo", &rebalinfo)
err := ctx.Get("rinfo", &rebalInfo)
if err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebalance info would be more consistent across err messages.

@atinmu
Copy link
Contributor

atinmu commented Jul 20, 2018 via email

@rishubhjain
Copy link
Contributor Author

retest this please

@@ -81,14 +79,16 @@ WebhookTest | POST | /events/webhook/test | [Webhook](https://godoc.org/github.c
WebhookDelete | DELETE | /events/webhook | [WebhookDel](https://godoc.org/github.com/gluster/glusterd2/pkg/api#WebhookDel) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
WebhookList | GET | /events/webhook | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [WebhookList](https://godoc.org/github.com/gluster/glusterd2/pkg/api#WebhookList)
EventsList | GET | /events | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [Event](https://godoc.org/github.com/gluster/glusterd2/pkg/api#Event)
SelfHealInfo | GET | /volumes/{name}/{opts}/heal-info | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [BrickHealInfo](https://godoc.org/github.com/gluster/glusterd2/pkg/api#BrickHealInfo)
SelfHealInfo2 | GET | /volumes/{name}/heal-info | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [BrickHealInfo](https://godoc.org/github.com/gluster/glusterd2/pkg/api#BrickHealInfo)
SelfHealInfo | GET | /volumes/{volname}/{opts}/heal-info | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [BrickHealInfo](https://godoc.org/github.com/gluster/glusterd2/pkg/api#BrickHealInfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be regenerated

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants