PragmaTwice commented on code in PR #2347:
URL: https://github.com/apache/kvrocks/pull/2347#discussion_r1623229293
##########
src/config/config.cc:
##########
@@ -885,11 +885,20 @@ Status Config::Set(Server *srv, std::string key, const
std::string &value) {
if (!s.IsOK()) return s.Prefixed("invalid value");
}
+ auto origin_value = field->ToString();
auto s = field->Set(value);
if (!s.IsOK()) return s.Prefixed("failed to set new value");
if (field->callback) {
- return field->callback(srv, key, value);
+ s = field->callback(srv, key, value);
+ if (!s.IsOK()) {
+ // rollback the value if the callback failed
+ auto set_status = field->Set(origin_value);
+ if (!set_status.IsOK()) {
+ return set_status.Prefixed("failed to rollback the value");
+ }
Review Comment:
I think maybe `Set` has other side effects, sohere the rollback is a little
dangerous.
e.g. there's a `x++` in `callback`, it will be triggered twice here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]