Updates #456: Add Volume Reset Rest API#545
Conversation
|
WIP PR, wasn't getting time to work on it. |
aravindavk
left a comment
There was a problem hiding this comment.
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.
glusterd2/volgen/volgen.go
Outdated
| } | ||
|
|
||
| // DeleteClientVoloption deletes the client vol option | ||
| func DeleteClientVoloption(vol *volume.Volinfo) error { |
There was a problem hiding this comment.
@aravindavk worked on the suggested changes. PR is ready for review.
thanks :)
|
There's one more catch which I highlighted in one of our stand up calls.
Take a look at the volopt flags like VOLOPT_FLAG_FORCE ,
VOLOPT_FLAG_NEVER_RESET . We need to have special handling for those
options and hence a force option in reset API is also required.
…On Thu, Feb 1, 2018 at 2:46 PM, Aravinda VK ***@***.***> wrote:
***@***.**** requested changes on this pull request.
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.
------------------------------
In glusterd2/volgen/volgen.go
<#545 (comment)>:
> @@ -80,6 +80,21 @@ func DeleteClientVolfile(vol *volume.Volinfo) error {
return nil
}
+// DeleteClientVoloption deletes the client vol option
+func DeleteClientVoloption(vol *volume.Volinfo) error {
Not required with volgen2
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#545 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGp7mKlXZsHAVRpovac0N9agFW-8TWIcks5tQYDTgaJpZM4R0g1K>
.
|
aa6f4f9 to
80b3c08
Compare
|
@devyanikota Checking back on the progress on this PR. Could you update with the status? |
5b91287 to
4ddbbd5
Compare
0d0eed4 to
8ec85c2
Compare
| "github.com/pborman/uuid" | ||
| ) | ||
|
|
||
| func registerVolResetStepFuncs() { |
There was a problem hiding this comment.
Not required, same name can be used as used in other places
| unlock, | ||
| } | ||
|
|
||
| for k, v := range req.Options { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
why delete from txn.Ctx? should be deleted from volinfo.Options
| } | ||
| } | ||
| } | ||
| defer txn.Cleanup() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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
},
glusterd2/volume/store-utils.go
Outdated
| return e | ||
| } | ||
|
|
||
| // //DeleteVolOption passes the option name to store to delete the option key |
| return | ||
| } | ||
|
|
||
| var req api.VolOptionReq |
There was a problem hiding this comment.
This is different from Volume Set. Value will not be sent in request.
type VolOptionResetReq struct {
Options []string json:"options"
Force bool json:"force"
}
|
@devyanikota @aravindavk Has all the comments been addressed? Can we try to get this PR in by end of this week? |
b0bd68d to
73071bf
Compare
| success := false | ||
| for _, k := range req.Options { | ||
| if _, ok := volinfo.Options[k]; ok { | ||
| if !volinfo.Options[k].VOLOPT_FLAG_NEVER_RESET { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Same as above, expose function as IsForceRequired in options.go
|
@devyanikota any blockers for this patch? |
6a4a6ab to
3ed9871
Compare
|
retest this please |
| } | ||
| // Check if an option was reset, else return. | ||
| if !success { | ||
| return |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Http error required. return after the error
|
|
||
| txn := transaction.NewTxn(ctx) | ||
| // Delete the option after checking for volopt flags | ||
| success := false |
There was a problem hiding this comment.
variable name "success" is very confusing here
| } | ||
| } | ||
| } else { | ||
| logger.WithError(err).Error("Option %s trying to reset is not set or invalid option", k) |
| } else { | ||
| logger.WithError(err).Error("Option %s needs a force flag to be set", k) | ||
| } | ||
| } |
There was a problem hiding this comment.
else is required here. Valid case, add else {delete(volinfo.Options, k)}
| } | ||
|
|
||
| // Reset the Options with new values | ||
| for key, value := range req.Options { |
There was a problem hiding this comment.
This step is not required. reseted options already removed above.
glusterd2/volume/store-utils.go
Outdated
| return e | ||
| } | ||
|
|
||
| // //DeleteVolOption passes the option name to store to delete the option key |
| txn.Steps = []*transaction.Step{ | ||
| lock, | ||
| { | ||
| DoFunc: "vol-reset.Store", |
There was a problem hiding this comment.
Reuse the name from other files for "storeVolume", and remove register function
| Nodes: []uuid.UUID{gdctx.MyUUID}, | ||
| }, | ||
| { | ||
| DoFunc: "vol-reset.NotifyVolfileChange", |
d692b48 to
b466f3a
Compare
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) |
There was a problem hiding this comment.
missing return after this line
|
|
||
| txn := transaction.NewTxn(ctx) | ||
| // Delete the option after checking for volopt flags | ||
| op_reset := false |
| 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) |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
| restutils.SendHTTPError(ctx, w, http.StatusBadRequest, errMsg) | ||
| return | ||
| } | ||
| } else { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
missing return after this line
| } | ||
| // Check if an option was reset, else return. | ||
| if !op_reset { | ||
| restutils.SendHTTPResponse(ctx, w, http.StatusOK, nil) |
There was a problem hiding this comment.
send volinfo.Options instead of nil as in the last line.
|
retest this please |
5e55d53 to
e50cf11
Compare
Signed-off-by: Devyani Kota <devyanikota@gmail.com>
Volume reset replaces the existing value of an option key with
the new value.
Signed-off-by: Devyani Kota devyanikota@gmail.com