From d1dd4c5fb09a8b86a367b95521bc5070006ca69f Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Fri, 23 Feb 2024 10:13:07 +0800 Subject: [PATCH] 1 --- src/meta/app_env_validator.cpp | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/meta/app_env_validator.cpp b/src/meta/app_env_validator.cpp index 8f78d06bc8..458ab069f0 100644 --- a/src/meta/app_env_validator.cpp +++ b/src/meta/app_env_validator.cpp @@ -196,54 +196,54 @@ bool check_rocksdb_num_levels(const std::string &env_value, std::string &hint_me app_env_validator::EnvInfo::EnvInfo(ValueType t, std::string ld, std::string s, validator_func v) : type(t), limit_desc(std::move(ld)), sample(std::move(s)), validator(std::move(v)) { + // Set default limitation description. if (limit_desc.empty()) { switch (type) { case ValueType::kBool: limit_desc = "true | false"; break; case ValueType::kUint64: - limit_desc = ">=0"; + limit_desc = ">= 0"; + break; + case ValueType::kInt64ButOnlyNegativeOne: + limit_desc = ">= 0 or == -1"; break; case ValueType::kString: - // TODO(yingchun): break; default: CHECK_TRUE(false); __builtin_unreachable(); } } + + // Set default sample. if (sample.empty()) { switch (type) { case ValueType::kBool: sample = "true"; break; case ValueType::kString: - // TODO(yingchun): break; default: CHECK_TRUE(false); __builtin_unreachable(); } } - if (!validator) { - switch (type) { - case ValueType::kBool: - validator = [](const std::string &env_value, std::string &hint_message) { - bool result = false; - if (!dsn::buf2bool(env_value, result)) { - hint_message = - fmt::format("invalid value '{}', should be 'true' or 'false'", env_value); - return false; - } - return true; - }; - break; - default: - CHECK_TRUE(false); - __builtin_unreachable(); - } + + // Set default validator. + if (validator == nullptr && type == ValueType::kBool) { + validator = [](const std::string &env_value, std::string &hint_message) { + bool result = false; + if (!dsn::buf2bool(env_value, result)) { + hint_message = + fmt::format("invalid value '{}', should be 'true' or 'false'", env_value); + return false; + } + return true; + }; } } + bool app_env_validator::validate_app_env(const std::string &env_name, const std::string &env_value, std::string &hint_message)