Skip to content

Commit 1b1b246

Browse files
wyxxxcatYour Name
authored andcommitted
[chore](http) Merge ms and recycler http skeleton (#61502)
### What problem does this PR solve? Problem Summary: Meta service and recycler maintained duplicated HTTP parsing, routing, and config handling logic, which made it harder to reuse handlers and keep versioned endpoints consistent. This change extracts the shared HTTP helper layer into `cloud/src/common/ http_helper.*`, introduces role-based handler registration for MetaService and Recycler, reuses common config show/update helpers, and adds versioned cluster HTTP test coverage. If you want to expand the interface version ``` {"add_cluster", {.handler = [](void* s, brpc::Controller* c) { return process_alter_cluster((MS*)s, c); }, .versioned_handlers = {{"v2", [](void* s, brpc::Controller* c) { return process_alter_cluster_v2((MS*)s, c); }}}, .role = HttpRole::META_SERVICE}}, ```
1 parent 3105e9d commit 1b1b246

10 files changed

Lines changed: 1721 additions & 1121 deletions

File tree

cloud/src/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(COMMON_FILES
1010
logging.cpp
1111
bvars.cpp
1212
encryption_util.cpp
13+
http_helper.cpp
1314
metric.cpp
1415
kms.cpp
1516
network_util.cpp

cloud/src/common/configbase.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// under the License.
1717

1818
#include <fmt/core.h>
19+
#include <rapidjson/document.h>
20+
#include <rapidjson/stringbuffer.h>
21+
#include <rapidjson/writer.h>
1922

2023
#include <algorithm>
2124
#include <cerrno>
@@ -462,4 +465,58 @@ std::pair<bool, std::string> set_config(std::unordered_map<std::string, std::str
462465
std::shared_mutex* get_mutable_string_config_lock() {
463466
return &mutable_string_config_lock;
464467
}
468+
469+
std::string show_config(const std::string& conf_name) {
470+
if (full_conf_map == nullptr) {
471+
return "";
472+
}
473+
474+
rapidjson::Document doc;
475+
doc.SetArray();
476+
auto& allocator = doc.GetAllocator();
477+
for (auto& [name, field] : *Register::_s_field_map) {
478+
if (!conf_name.empty() && name != conf_name) {
479+
continue;
480+
}
481+
auto it = full_conf_map->find(name);
482+
std::string value = (it != full_conf_map->end()) ? it->second : "";
483+
484+
rapidjson::Value item(rapidjson::kArrayType);
485+
item.PushBack(rapidjson::Value(name.data(), name.size(), allocator), allocator);
486+
item.PushBack(rapidjson::Value(field.type, allocator), allocator);
487+
item.PushBack(rapidjson::Value(value.data(), value.size(), allocator), allocator);
488+
item.PushBack(field.valmutable, allocator);
489+
doc.PushBack(item, allocator);
490+
}
491+
492+
rapidjson::StringBuffer sb;
493+
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
494+
doc.Accept(writer);
495+
return sb.GetString();
496+
}
497+
498+
std::pair<bool, std::string> update_config(const std::string& configs, bool persist,
499+
const std::string& custom_conf_path) {
500+
if (configs.empty()) {
501+
return {false, "query param `configs` should not be empty"};
502+
}
503+
504+
std::unordered_map<std::string, std::string> conf_map;
505+
std::istringstream ss(configs);
506+
std::string conf;
507+
while (std::getline(ss, conf, ',')) {
508+
auto pos = conf.find('=');
509+
if (pos == std::string::npos) {
510+
return {false, fmt::format("config {} is invalid", conf)};
511+
}
512+
std::string key = conf.substr(0, pos);
513+
std::string val = conf.substr(pos + 1);
514+
trim(key);
515+
trim(val);
516+
conf_map.emplace(std::move(key), std::move(val));
517+
}
518+
519+
return set_config(std::move(conf_map), persist, custom_conf_path);
520+
}
521+
465522
} // namespace doris::cloud::config

cloud/src/common/configbase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,9 @@ std::pair<bool, std::string> set_config(std::unordered_map<std::string, std::str
181181

182182
std::shared_mutex* get_mutable_string_config_lock();
183183

184+
std::string show_config(const std::string& conf_name);
185+
186+
std::pair<bool, std::string> update_config(const std::string& configs, bool persist,
187+
const std::string& custom_conf_path);
188+
184189
} // namespace doris::cloud::config

0 commit comments

Comments
 (0)