提交 c5d45bc4 编写于 作者: Y yudong.cai

MS-574 add config set APIs


Former-commit-id: cc5cc054ffe0297021ee55f89fa5cb3c3f42a309
上级 6937e08d
...@@ -93,7 +93,7 @@ Config::PrintAll() { ...@@ -93,7 +93,7 @@ Config::PrintAll() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Status Status
Config::CheckServerConfigAddress(std::string &value) { Config::CheckServerConfigAddress(const std::string &value) {
if (!ValidationUtil::ValidateIpAddress(value).ok()) { if (!ValidationUtil::ValidateIpAddress(value).ok()) {
return Status(SERVER_INVALID_ARGUMENT, "Invalid server config address: " + value); return Status(SERVER_INVALID_ARGUMENT, "Invalid server config address: " + value);
} }
...@@ -101,7 +101,7 @@ Config::CheckServerConfigAddress(std::string &value) { ...@@ -101,7 +101,7 @@ Config::CheckServerConfigAddress(std::string &value) {
} }
Status Status
Config::CheckServerConfigPort(std::string &value) { Config::CheckServerConfigPort(const std::string &value) {
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) { if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
return Status(SERVER_INVALID_ARGUMENT, "Invalid server config port: " + value); return Status(SERVER_INVALID_ARGUMENT, "Invalid server config port: " + value);
} else { } else {
...@@ -114,7 +114,7 @@ Config::CheckServerConfigPort(std::string &value) { ...@@ -114,7 +114,7 @@ Config::CheckServerConfigPort(std::string &value) {
} }
Status Status
Config::CheckServerConfigMode(std::string &value) { Config::CheckServerConfigMode(const std::string &value) {
if (value != "single" && value != "cluster" && value != "read_only") { if (value != "single" && value != "cluster" && value != "read_only") {
return Status(SERVER_INVALID_ARGUMENT, "Invalid server config mode [single, cluster, read_only]: " + value); return Status(SERVER_INVALID_ARGUMENT, "Invalid server config mode [single, cluster, read_only]: " + value);
} }
...@@ -122,7 +122,7 @@ Config::CheckServerConfigMode(std::string &value) { ...@@ -122,7 +122,7 @@ Config::CheckServerConfigMode(std::string &value) {
} }
Status Status
Config::CheckServerConfigTimeZone(std::string &value) { Config::CheckServerConfigTimeZone(const std::string &value) {
if (value.length() <= 3) { if (value.length() <= 3) {
return Status(SERVER_INVALID_ARGUMENT, "Invalid server config time_zone: " + value); return Status(SERVER_INVALID_ARGUMENT, "Invalid server config time_zone: " + value);
} else { } else {
...@@ -147,6 +147,11 @@ Config::CheckDBConfigPath(const std::string &value) { ...@@ -147,6 +147,11 @@ Config::CheckDBConfigPath(const std::string &value) {
return Status::OK(); return Status::OK();
} }
Status
Config::CheckDBConfigSlavePath(const std::string &value) {
return Status::OK();
}
Status Status
Config::CheckDBConfigBackendUrl(const std::string &value) { Config::CheckDBConfigBackendUrl(const std::string &value) {
if (!ValidationUtil::ValidateDbURI(value).ok()) { if (!ValidationUtil::ValidateDbURI(value).ok()) {
...@@ -207,6 +212,14 @@ Config::CheckMetricConfigAutoBootup(const std::string& value) { ...@@ -207,6 +212,14 @@ Config::CheckMetricConfigAutoBootup(const std::string& value) {
return Status::OK(); return Status::OK();
} }
Status
Config::CheckMetricConfigCollector(const std::string& value) {
if (value != "prometheus") {
return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config collector: " + value);
}
return Status::OK();
}
Status Status
Config::CheckMetricConfigPrometheusPort(const std::string& value) { Config::CheckMetricConfigPrometheusPort(const std::string& value) {
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) { if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
...@@ -347,9 +360,9 @@ Status ...@@ -347,9 +360,9 @@ Status
Config::GetConfigValueInMem(const std::string &parent_key, Config::GetConfigValueInMem(const std::string &parent_key,
const std::string &child_key, const std::string &child_key,
std::string &value) { std::string &value) {
std::lock_guard<std::mutex> lock(mutex_);
if (config_map_.find(parent_key) != config_map_.end() && if (config_map_.find(parent_key) != config_map_.end() &&
config_map_[parent_key].find(child_key) != config_map_[parent_key].end()) { config_map_[parent_key].find(child_key) != config_map_[parent_key].end()) {
std::lock_guard<std::mutex> lock(mutex_);
value = config_map_[parent_key][child_key]; value = config_map_[parent_key][child_key];
return Status::OK(); return Status::OK();
} else { } else {
...@@ -360,7 +373,7 @@ Config::GetConfigValueInMem(const std::string &parent_key, ...@@ -360,7 +373,7 @@ Config::GetConfigValueInMem(const std::string &parent_key,
void void
Config::SetConfigValueInMem(const std::string &parent_key, Config::SetConfigValueInMem(const std::string &parent_key,
const std::string &child_key, const std::string &child_key,
std::string &value) { const std::string &value) {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
config_map_[parent_key][child_key] = value; config_map_[parent_key][child_key] = value;
} }
...@@ -798,6 +811,189 @@ Config::GetResourceConfigPool(std::vector<std::string>& value) { ...@@ -798,6 +811,189 @@ Config::GetResourceConfigPool(std::vector<std::string>& value) {
return CheckResourceConfigPool(value); return CheckResourceConfigPool(value);
} }
///////////////////////////////////////////////////////////////////////////////
/* server config */
Status
Config::SetServerConfigAddress(const std::string& value) {
Status s = CheckServerConfigAddress(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
return Status::OK();
}
Status
Config::SetServerConfigPort(const std::string& value) {
Status s = CheckServerConfigPort(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value);
return Status::OK();
}
Status
Config::SetServerConfigMode(const std::string& value) {
Status s = CheckServerConfigMode(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_MODE, value);
return Status::OK();
}
Status
Config::SetServerConfigTimeZone(const std::string& value) {
Status s = CheckServerConfigTimeZone(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
return Status::OK();
}
/* db config */
Status
Config::SetDBConfigPath(const std::string& value) {
Status s = CheckDBConfigPath(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PATH, value);
return Status::OK();
}
Status
Config::SetDBConfigSlavePath(const std::string& value) {
Status s = CheckDBConfigSlavePath(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_SLAVE_PATH, value);
return Status::OK();
}
Status
Config::SetDBConfigBackendUrl(const std::string& value) {
Status s = CheckDBConfigBackendUrl(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value);
return Status::OK();
}
Status
Config::SetDBConfigArchiveDiskThreshold(const std::string& value) {
Status s = CheckDBConfigArchiveDiskThreshold(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value);
return Status::OK();
}
Status
Config::SetDBConfigArchiveDaysThreshold(const std::string& value) {
Status s = CheckDBConfigArchiveDaysThreshold(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value);
return Status::OK();
}
Status
Config::SetDBConfigBufferSize(const std::string& value) {
Status s = CheckDBConfigBufferSize(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BUFFER_SIZE, value);
return Status::OK();
}
Status
Config::SetDBConfigBuildIndexGPU(const std::string& value) {
Status s = CheckDBConfigBuildIndexGPU(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BUILD_INDEX_GPU, value);
return Status::OK();
}
/* metric config */
Status
Config::SetMetricConfigAutoBootup(const std::string& value) {
Status s = CheckMetricConfigAutoBootup(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_METRIC_AUTO_BOOTUP, value);
return Status::OK();
}
Status
Config::SetMetricConfigCollector(const std::string& value) {
Status s = CheckMetricConfigCollector(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_METRIC_COLLECTOR, value);
return Status::OK();
}
Status
Config::SetMetricConfigPrometheusPort(const std::string& value) {
Status s = CheckMetricConfigPrometheusPort(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_METRIC_PROMETHEUS_PORT, value);
return Status::OK();
}
/* cache config */
Status
Config::SetCacheConfigCpuMemCapacity(const std::string& value) {
Status s = CheckCacheConfigCpuMemCapacity(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_CPU_MEM_CAPACITY, value);
return Status::OK();
}
Status
Config::SetCacheConfigCpuMemThreshold(const std::string& value) {
Status s = CheckCacheConfigCpuMemThreshold(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_CPU_MEM_THRESHOLD, value);
return Status::OK();
}
Status
Config::SetCacheConfigGpuMemCapacity(const std::string& value) {
Status s = CheckCacheConfigGpuMemCapacity(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_GPU_MEM_CAPACITY, value);
return Status::OK();
}
Status
Config::SetCacheConfigGpuMemThreshold(const std::string& value) {
Status s = CheckCacheConfigGpuMemThreshold(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_GPU_MEM_THRESHOLD, value);
return Status::OK();
}
Status
Config::SetCacheConfigCacheInsertData(const std::string& value) {
Status s = CheckCacheConfigCacheInsertData(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_CACHE_INSERT_DATA, value);
return Status::OK();
}
/* engine config */
Status
Config::SetEngineConfigBlasThreshold(const std::string& value) {
Status s = CheckEngineConfigBlasThreshold(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_ENGINE_BLAS_THRESHOLD, value);
return Status::OK();
}
Status
Config::SetEngineConfigOmpThreadNum(const std::string& value) {
Status s = CheckEngineConfigOmpThreadNum(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_ENGINE_OMP_THREAD_NUM, value);
return Status::OK();
}
/* resource config */
Status
Config::SetResourceConfigMode(const std::string& value) {
Status s = CheckResourceConfigMode(value);
if (!s.ok()) return s;
SetConfigValueInMem(CONFIG_DB, CONFIG_RESOURCE_MODE, value);
return Status::OK();
}
} }
} }
} }
...@@ -108,16 +108,16 @@ class Config { ...@@ -108,16 +108,16 @@ class Config {
void SetConfigValueInMem(const std::string& parent_key, void SetConfigValueInMem(const std::string& parent_key,
const std::string& child_key, const std::string& child_key,
std::string& value); const std::string& value);
void PrintConfigSection(const std::string& config_node_name); void PrintConfigSection(const std::string& config_node_name);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/* server config */ /* server config */
Status CheckServerConfigAddress(std::string& value); Status CheckServerConfigAddress(const std::string& value);
Status CheckServerConfigPort(std::string& value); Status CheckServerConfigPort(const std::string& value);
Status CheckServerConfigMode(std::string& value); Status CheckServerConfigMode(const std::string& value);
Status CheckServerConfigTimeZone(std::string& value); Status CheckServerConfigTimeZone(const std::string& value);
/* db config */ /* db config */
Status CheckDBConfigPath(const std::string& value); Status CheckDBConfigPath(const std::string& value);
...@@ -130,6 +130,7 @@ class Config { ...@@ -130,6 +130,7 @@ class Config {
/* metric config */ /* metric config */
Status CheckMetricConfigAutoBootup(const std::string& value); Status CheckMetricConfigAutoBootup(const std::string& value);
Status CheckMetricConfigCollector(const std::string& value);
Status CheckMetricConfigPrometheusPort(const std::string& value); Status CheckMetricConfigPrometheusPort(const std::string& value);
/* cache config */ /* cache config */
...@@ -218,6 +219,41 @@ class Config { ...@@ -218,6 +219,41 @@ class Config {
Status GetResourceConfigMode(std::string& value); Status GetResourceConfigMode(std::string& value);
Status GetResourceConfigPool(std::vector<std::string>& value); Status GetResourceConfigPool(std::vector<std::string>& value);
public:
/* server config */
Status SetServerConfigAddress(const std::string& value);
Status SetServerConfigPort(const std::string& value);
Status SetServerConfigMode(const std::string& value);
Status SetServerConfigTimeZone(const std::string& value);
/* db config */
Status SetDBConfigPath(const std::string& value);
Status SetDBConfigSlavePath(const std::string& value);
Status SetDBConfigBackendUrl(const std::string& value);
Status SetDBConfigArchiveDiskThreshold(const std::string& value);
Status SetDBConfigArchiveDaysThreshold(const std::string& value);
Status SetDBConfigBufferSize(const std::string& value);
Status SetDBConfigBuildIndexGPU(const std::string& value);
/* metric config */
Status SetMetricConfigAutoBootup(const std::string& value);
Status SetMetricConfigCollector(const std::string& value);
Status SetMetricConfigPrometheusPort(const std::string& value);
/* cache config */
Status SetCacheConfigCpuMemCapacity(const std::string& value);
Status SetCacheConfigCpuMemThreshold(const std::string& value);
Status SetCacheConfigGpuMemCapacity(const std::string& value);
Status SetCacheConfigGpuMemThreshold(const std::string& value);
Status SetCacheConfigCacheInsertData(const std::string& value);
/* engine config */
Status SetEngineConfigBlasThreshold(const std::string& value);
Status SetEngineConfigOmpThreadNum(const std::string& value);
/* resource config */
Status SetResourceConfigMode(const std::string& value);
private: private:
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_; std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_;
std::mutex mutex_; std::mutex mutex_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册