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

Updates #456: Add Volume Reset Rest API#545

Merged
aravindavk merged 8 commits intogluster:masterfrom
devyanikota:vreset
May 9, 2018
Merged

Updates #456: Add Volume Reset Rest API#545
aravindavk merged 8 commits intogluster:masterfrom
devyanikota:vreset

Conversation

@devyanikota
Copy link
Contributor

Volume reset replaces the existing value of an option key with
the new value.

Signed-off-by: Devyani Kota devyanikota@gmail.com

@devyanikota devyanikota changed the title Updates #456: Add Volume Reset Rest API WIP: Updates #456: Add Volume Reset Rest API Jan 31, 2018
@devyanikota
Copy link
Contributor Author

WIP PR, wasn't getting time to work on it.
Haven't tested, not up for review yet.

Copy link
Member

@aravindavk aravindavk left a comment

Choose a reason for hiding this comment

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

Volume Reset logic is very simple. No validations required except checking in volinfo.Options

For example, if "changelog.changelog" is set to "on" then it will be available in volinfo.Options["changelog.changelog"]. So if Reset comes to "changelog.changelog" then just delete from volinfo.Options, storeVolume(which regenerates the volfiles) and then Notify.

If reset comes to a key which is not set, log and ignore it.(log message, Option trying to reset is not set or invalid option")

if _, ok := volinfo.Options[k]; ok {
// Delete from volinfo
}

Volfile generation is not incremental, full volfile will be regenerated. If option key is reset then it is removed from volinfo.Options so volgen will automatically add default value and generate volfile.

}

// DeleteClientVoloption deletes the client vol option
func DeleteClientVoloption(vol *volume.Volinfo) error {
Copy link
Member

Choose a reason for hiding this comment

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

Not required with volgen2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aravindavk worked on the suggested changes. PR is ready for review.
thanks :)

@atinmu
Copy link
Contributor

atinmu commented Feb 1, 2018 via email

@atinmu atinmu requested a review from prashanthpai February 6, 2018 02:27
@devyanikota devyanikota force-pushed the vreset branch 2 times, most recently from aa6f4f9 to 80b3c08 Compare February 8, 2018 18:18
@atinmu
Copy link
Contributor

atinmu commented Feb 18, 2018

@devyanikota Checking back on the progress on this PR. Could you update with the status?

@devyanikota devyanikota force-pushed the vreset branch 3 times, most recently from 5b91287 to 4ddbbd5 Compare February 26, 2018 08:12
@devyanikota devyanikota force-pushed the vreset branch 10 times, most recently from 0d0eed4 to 8ec85c2 Compare March 13, 2018 14:30
@devyanikota devyanikota changed the title WIP: Updates #456: Add Volume Reset Rest API Updates #456: Add Volume Reset Rest API Mar 14, 2018
"github.com/pborman/uuid"
)

func registerVolResetStepFuncs() {
Copy link
Member

Choose a reason for hiding this comment

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

Not required, same name can be used as used in other places

unlock,
}

for k, v := range req.Options {
Copy link
Member

Choose a reason for hiding this comment

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

why this is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is where we Re- set the options with new values?

txn := transaction.NewTxn(ctx)
for _, k := range req.Options {
if _, ok := volinfo.Options[k]; ok {
err = txn.Ctx.Delete(k)
Copy link
Member

Choose a reason for hiding this comment

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

why delete from txn.Ctx? should be deleted from volinfo.Options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack! thanks :)

}
}
}
defer txn.Cleanup()
Copy link
Member

Choose a reason for hiding this comment

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

Maintain a flag saying minimum one option reset. Return from here if no option is reset.

txn := transaction.NewTxn(ctx)
for _, k := range req.Options {
if _, ok := volinfo.Options[k]; ok {
err = txn.Ctx.Delete(k)
Copy link
Member

Choose a reason for hiding this comment

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

Before deleting from volinfo, check is required for VOLOPT_FLAG_FORCE and VOLOPT_FLAG_NEVER_RESET #545 (comment)

  • Error if VOLOPT_FLAG_NEVER_RESET is set and option is trying to reset.
  • Only allow Reset if force is used in API request in case of VOLOPT_FLAG_FORCE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aravindavk am not quite sure how to get these volopt flags' values. I intend to ask if those flags happen to be part of the volinfo or ..?
Checking glusterfs code, I found them listed as follows:

        { .key         = VKEY_FEATURES_QUOTA,
          .voltype     = "features/marker",
          .option      = "quota",
          .value       = "off",
          .type        = NO_DOC,
          .flags       = VOLOPT_FLAG_NEVER_RESET,
          .op_version  = 1
        },

return e
}

// //DeleteVolOption passes the option name to store to delete the option key
Copy link
Member

Choose a reason for hiding this comment

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

commented lines

Copy link
Member

Choose a reason for hiding this comment

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

remove commented lines

return
}

var req api.VolOptionReq
Copy link
Member

Choose a reason for hiding this comment

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

This is different from Volume Set. Value will not be sent in request.

type VolOptionResetReq struct {
Options []string json:"options"
Force bool json:"force"
}

@atinmu
Copy link
Contributor

atinmu commented Apr 5, 2018

@devyanikota @aravindavk Has all the comments been addressed? Can we try to get this PR in by end of this week?

@devyanikota devyanikota force-pushed the vreset branch 2 times, most recently from b0bd68d to 73071bf Compare April 5, 2018 20:44
success := false
for _, k := range req.Options {
if _, ok := volinfo.Options[k]; ok {
if !volinfo.Options[k].VOLOPT_FLAG_NEVER_RESET {
Copy link
Member

Choose a reason for hiding this comment

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

volinfo.Options is map[string]string. This usage is wrong. You have to do xlator.FindOption(k) and then check for these flag. Expose function IsNeverReset similar to IsSettable in $SRC/glusterd2/xlator/options/options.go.

for _, k := range req.Options {
if _, ok := volinfo.Options[k]; ok {
if !volinfo.Options[k].VOLOPT_FLAG_NEVER_RESET {
if !volinfo.Options[k].VOLOPT_FLAG_FORCE {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, expose function as IsForceRequired in options.go

@aravindavk
Copy link
Member

@devyanikota any blockers for this patch?

@devyanikota devyanikota force-pushed the vreset branch 4 times, most recently from 6a4a6ab to 3ed9871 Compare May 4, 2018 10:06
@devyanikota
Copy link
Contributor Author

retest this please

}
// Check if an option was reset, else return.
if !success {
return
Copy link
Member

Choose a reason for hiding this comment

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

Returning without any http response is bad, Add success response and return

if err != nil {
logger.WithError(err)
} else if op.IsNeverReset() {
logger.WithError(err).Error("Option %s needs NEVER_RESET flag to be set", k)
Copy link
Member

Choose a reason for hiding this comment

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

Http error required here. Return from here in case of failure. Message can be like "Reserved option, can't be reset"

delete(volinfo.Options, k)
success = true
} else {
logger.WithError(err).Error("Option %s needs a force flag to be set", k)
Copy link
Member

Choose a reason for hiding this comment

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

Http error required. return after the error


txn := transaction.NewTxn(ctx)
// Delete the option after checking for volopt flags
success := false
Copy link
Member

Choose a reason for hiding this comment

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

variable name "success" is very confusing here

}
}
} else {
logger.WithError(err).Error("Option %s trying to reset is not set or invalid option", k)
Copy link
Member

Choose a reason for hiding this comment

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

http error and return

} else {
logger.WithError(err).Error("Option %s needs a force flag to be set", k)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

else is required here. Valid case, add else {delete(volinfo.Options, k)}

}

// Reset the Options with new values
for key, value := range req.Options {
Copy link
Member

Choose a reason for hiding this comment

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

This step is not required. reseted options already removed above.

return e
}

// //DeleteVolOption passes the option name to store to delete the option key
Copy link
Member

Choose a reason for hiding this comment

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

remove commented lines

txn.Steps = []*transaction.Step{
lock,
{
DoFunc: "vol-reset.Store",
Copy link
Member

Choose a reason for hiding this comment

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

Reuse the name from other files for "storeVolume", and remove register function

Nodes: []uuid.UUID{gdctx.MyUUID},
},
{
DoFunc: "vol-reset.NotifyVolfileChange",
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

@devyanikota devyanikota force-pushed the vreset branch 2 times, most recently from d692b48 to b466f3a Compare May 4, 2018 12:15
Volume reset replaces the existing value of an option key with
the new value.

Signed-off-by: Devyani Kota <devyanikota@gmail.com>
Signed-off-by: Devyani Kota <devyanikota@gmail.com>
Signed-off-by: Devyani Kota <devyanikota@gmail.com>
Signed-off-by: Devyani Kota <devyanikota@gmail.com>
Signed-off-by: Devyani Kota <devyanikota@gmail.com>
op, err := xlator.FindOption(k)
// If key exists, check for NEVER_RESET and FORCE flags
if err != nil {
restutils.SendHTTPError(ctx, http.StatusBadRequest, err)
Copy link
Member

Choose a reason for hiding this comment

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

missing return after this line


txn := transaction.NewTxn(ctx)
// Delete the option after checking for volopt flags
op_reset := false
Copy link
Member

Choose a reason for hiding this comment

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

s/o_reset/opReset

op, err := xlator.FindOption(k)
// If key exists, check for NEVER_RESET and FORCE flags
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, err)
Copy link
Member

Choose a reason for hiding this comment

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

missing return after this line

// If key exists, check for NEVER_RESET and FORCE flags
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, err)
} else if op.IsNeverReset() {
Copy link
Member

Choose a reason for hiding this comment

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

Since all these conditions contains return statement. Skip else and just use if op.IsNeverReset in new line

errMsg := "Reserved option, can't be reset"
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, errMsg)
return
} else if op.IsForceRequired() {
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

restutils.SendHTTPError(ctx, w, http.StatusBadRequest, errMsg)
return
}
} else {
Copy link
Member

Choose a reason for hiding this comment

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

skip else statement and add this in next line

}
} else {
errMsg := "Option trying to reset is not set or invalid option"
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, errMsg)
Copy link
Member

Choose a reason for hiding this comment

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

missing return after this line

}
// Check if an option was reset, else return.
if !op_reset {
restutils.SendHTTPResponse(ctx, w, 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.

send volinfo.Options instead of nil as in the last line.

@devyanikota
Copy link
Contributor Author

retest this please

@devyanikota devyanikota force-pushed the vreset branch 2 times, most recently from 5e55d53 to e50cf11 Compare May 4, 2018 13:22
Signed-off-by: Devyani Kota <devyanikota@gmail.com>
Copy link
Member

@aravindavk aravindavk left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@aravindavk aravindavk merged commit 0feaad9 into gluster:master May 9, 2018
@devyanikota devyanikota deleted the vreset branch May 9, 2018 08:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants