diff --git a/be/src/common/configbase.cpp b/be/src/common/configbase.cpp index 093f9173d58c4..e95450e3407bf 100644 --- a/be/src/common/configbase.cpp +++ b/be/src/common/configbase.cpp @@ -189,21 +189,19 @@ bool Field::set_value(std::string value) { return false; } StripWhiteSpace(&value); - bool flag = parse_value(value); - if (flag) { + bool success = parse_value(value); + if (success) { + _last_set_val.swap(_current_set_val); _current_set_val = value; } return flag; } -void Field::set_last_update_value() { - _last_set_val = _current_set_val; -} - -bool Field::rollback_last_value() { - bool flag = parse_value(_last_set_val); - if (flag) { - _current_set_val = _last_set_val; +bool Field::rollback() { + bool success = parse_value(_last_set_val); + if (success) { + _current_set_val.swap(_last_set_val); + _last_set_val.clear(); } return flag; } @@ -247,7 +245,6 @@ Status set_config(const std::string& field, const std::string& value) { if (!it->second->valmutable()) { return Status::NotSupported(fmt::format("'{}' is immutable", field)); } - it->second->set_last_update_value(); if (!it->second->set_value(value)) { return Status::InvalidArgument(fmt::format("Invalid value of config '{}': '{}'", field, value)); } @@ -260,7 +257,7 @@ Status rollback_config(const std::string& field) { return Status::NotFound(fmt::format("'{}' is not found in rollback", field)); } - if (!it->second->rollback_last_value()) { + if (!it->second->rollback()) { return Status::InvalidArgument(fmt::format("Invalid value of config '{}' in rollback", field)); } return Status::OK(); diff --git a/be/src/common/configbase.h b/be/src/common/configbase.h index 3454b56c69a9d..a87d7966b86da 100644 --- a/be/src/common/configbase.h +++ b/be/src/common/configbase.h @@ -142,9 +142,7 @@ class Field { bool set_value(std::string value); - bool rollback_last_value(); - - void set_last_update_value(); + bool rollback(); virtual std::string value() const = 0;