Skip to content

Commit 64ca066

Browse files
add custom config path
1 parent 3b665ef commit 64ca066

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

cloud/src/common/config.h

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ CONF_Int32(log_verbose_level, "5");
5454
// Only works when starting Cloud with --console.
5555
CONF_Bool(enable_file_logger, "true");
5656

57+
// Custom conf path is default the same as conf path, and configs will be append to it.
58+
// Otherwise, will a new custom conf file will be created.
59+
CONF_String(custom_conf_path, "./conf/doris_cloud.conf");
60+
5761
// recycler config
5862
CONF_mInt64(recycle_interval_seconds, "3600");
5963
CONF_mInt64(retention_seconds, "259200"); // 72h, global retention time

cloud/src/common/configbase.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
namespace doris::cloud::config {
3434

35-
std::string g_conf_path {};
36-
3735
std::map<std::string, Register::Field>* Register::_s_field_map = nullptr;
3836
std::map<std::string, std::function<bool()>>* RegisterConfValidator::_s_field_validator = nullptr;
3937
std::map<std::string, std::string>* full_conf_map = nullptr;
@@ -412,26 +410,35 @@ bool do_set_config(const Register::Field& feild, const std::string& value, bool
412410
return false;
413411
}
414412

415-
bool set_config(const std::string& field, const std::string& value, bool need_persist) {
413+
bool set_config(const std::string& field, const std::string& value, bool need_persist,
414+
const std::string& custom_conf_path) {
416415
auto it = Register::_s_field_map->find(field);
417416
if (it == Register::_s_field_map->end()) {
418417
return false;
419418
}
420419
if (!it->second.valmutable) {
421420
return false;
422421
}
422+
423423
Properties props;
424-
if (!do_set_config(it->second, value, need_persist, props)) {
425-
std::cerr << "not supported to modify: " << field << "=" << value << std::endl;
426-
return false;
427-
}
424+
auto set_conf_func = [&]() {
425+
if (!do_set_config(it->second, value, need_persist, props)) {
426+
std::cerr << "not supported to modify: " << field << "=" << value << std::endl;
427+
return false;
428+
}
429+
return true;
430+
};
428431

429432
if (need_persist) {
430433
// lock to make sure only one thread can modify the be_custom.conf
431434
std::lock_guard<std::mutex> l(conf_persist_lock);
432-
return props.dump(config::g_conf_path.data());
435+
if (!set_conf_func()) {
436+
return false;
437+
}
438+
return props.dump(custom_conf_path);
433439
}
434-
return true;
440+
441+
return set_conf_func();
435442
}
436443

437444
} // namespace doris::cloud::config

cloud/src/common/configbase.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
namespace doris::cloud::config {
2828

29-
extern std::string g_conf_path;
30-
3129
class Register {
3230
public:
3331
struct Field {
@@ -172,5 +170,6 @@ extern std::map<std::string, std::string>* full_conf_map;
172170
bool init(const char* conf_file, bool fill_conf_map = false, bool must_exist = true,
173171
bool set_to_default = true);
174172

175-
bool set_config(const std::string& field, const std::string& value, bool need_persist = false);
173+
bool set_config(const std::string& field, const std::string& value, bool need_persist,
174+
const std::string& custom_conf_path);
176175
} // namespace doris::cloud::config

cloud/src/main.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,15 @@ int main(int argc, char** argv) {
194194
return -1;
195195
}
196196

197-
config::g_conf_path = args.get<std::string>(ARG_CONF);
198-
if (!config::init(config::g_conf_path.data(), true)) {
199-
std::cerr << "failed to init config file, conf=" << config::g_conf_path << std::endl;
197+
auto conf_file = args.get<std::string>(ARG_CONF);
198+
if (!config::init(conf_file.c_str(), true)) {
199+
std::cerr << "failed to init config file, conf=" << conf_file << std::endl;
200+
return -1;
201+
}
202+
if (!std::filesystem::equivalent(conf_file, config::custom_conf_path) &&
203+
!config::init(config::custom_conf_path.c_str(), false)) {
204+
std::cerr << "failed to init custom config file, conf=" << config::custom_conf_path
205+
<< std::endl;
200206
return -1;
201207
}
202208

cloud/src/meta-service/meta_service_http.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ static HttpResponse process_update_config(MetaServiceImpl* service, brpc::Contro
468468
}
469469
trim(conf_pair[0]);
470470
trim(conf_pair[1]);
471-
if (!config::set_config(conf_pair[0], conf_pair[1], persist)) {
471+
if (!config::set_config(conf_pair[0], conf_pair[1], persist, config::custom_conf_path)) {
472472
return http_json_reply(MetaServiceCode::INVALID_ARGUMENT,
473473
fmt::format("set {}={} failed", conf_pair[0], conf_pair[1]));
474474
}

cloud/test/meta_service_http_test.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1663,15 +1663,16 @@ TEST(MetaServiceHttpTest, UpdateConfig) {
16631663
ASSERT_EQ(config::recycle_interval_seconds, 3601);
16641664
}
16651665
{
1666-
config::g_conf_path = "./doris_cloud.conf";
1666+
auto original_conf_path = config::custom_conf_path;
1667+
config::custom_conf_path = "./doris_cloud.conf";
16671668
auto [status_code, content] = ctx.query<std::string>(
16681669
"update_config",
16691670
"configs=recycle_interval_seconds=3659,retention_seconds=259219&persist=true");
16701671
ASSERT_EQ(status_code, 200);
16711672
ASSERT_EQ(config::recycle_interval_seconds, 3659);
16721673
ASSERT_EQ(config::retention_seconds, 259219);
16731674
config::Properties props;
1674-
ASSERT_TRUE(props.load(config::g_conf_path.data(), true));
1675+
ASSERT_TRUE(props.load(config::custom_conf_path.c_str(), true));
16751676
{
16761677
bool new_val_set = false;
16771678
int64_t recycle_interval_s = 0;
@@ -1688,7 +1689,8 @@ TEST(MetaServiceHttpTest, UpdateConfig) {
16881689
ASSERT_TRUE(new_val_set);
16891690
ASSERT_EQ(retention_s, 259219);
16901691
}
1691-
std::filesystem::remove(config::g_conf_path);
1692+
std::filesystem::remove(config::custom_conf_path);
1693+
config::custom_conf_path = original_conf_path;
16921694
}
16931695
}
16941696

0 commit comments

Comments
 (0)