Skip to content

Commit

Permalink
[BugFix] The update_config interface still returns success after the …
Browse files Browse the repository at this point in the history
…dynamic parameter setup fails. (backport #50821) (#52661)

Co-authored-by: zhanghe <[email protected]>
  • Loading branch information
mergify[bot] and zhangheihei authored Nov 6, 2024
1 parent 264ef9d commit 153c725
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 64 deletions.
28 changes: 27 additions & 1 deletion be/src/common/configbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,21 @@ bool Field::set_value(std::string value) {
return false;
}
StripWhiteSpace(&value);
return parse_value(value);
bool success = parse_value(value);
if (success) {
_last_set_val.swap(_current_set_val);
_current_set_val = value;
}
return success;
}

bool Field::rollback() {
bool success = parse_value(_last_set_val);
if (success) {
_current_set_val.swap(_last_set_val);
_last_set_val.clear();
}
return success;
}

// Init conf fields.
Expand Down Expand Up @@ -237,6 +251,18 @@ Status set_config(const std::string& field, const std::string& value) {
return Status::OK();
}

Status rollback_config(const std::string& field) {
auto it = Field::fields().find(field);
if (it == Field::fields().end()) {
return Status::NotFound(fmt::format("'{}' is not found in rollback", field));
}

if (!it->second->rollback()) {
return Status::InvalidArgument(fmt::format("Invalid value of config '{}' in rollback", field));
}
return Status::OK();
}

std::vector<ConfigInfo> list_configs() {
std::vector<ConfigInfo> infos;
for (const auto& [name, field] : Field::fields()) {
Expand Down
6 changes: 6 additions & 0 deletions be/src/common/configbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class Field {

bool set_value(std::string value);

bool rollback();

virtual std::string value() const = 0;

static void clear_fields() { _s_field_map.clear(); }
Expand All @@ -160,6 +162,8 @@ class Field {
void* _storage;
const char* _defval;
bool _valmutable;
std::string _last_set_val;
std::string _current_set_val;
};

template <typename T, typename = void>
Expand Down Expand Up @@ -325,6 +329,8 @@ bool init(std::istream& input);

Status set_config(const std::string& field, const std::string& value);

Status rollback_config(const std::string& field);

std::vector<ConfigInfo> list_configs();

void TEST_clear_configs();
Expand Down
Loading

0 comments on commit 153c725

Please sign in to comment.