Config.cpp 32.5 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

G
groot 已提交
18
#include <sys/stat.h>
Y
yudong.cai 已提交
19
#include <algorithm>
S
starlord 已提交
20
#include <iostream>
21
#include <regex>
S
starlord 已提交
22
#include <string>
S
starlord 已提交
23
#include <vector>
G
groot 已提交
24

25 26
#include "config/YamlConfigMgr.h"
#include "server/Config.h"
27 28
#include "utils/CommonUtil.h"
#include "utils/ValidationUtil.h"
G
groot 已提交
29

J
jinhai 已提交
30
namespace milvus {
G
groot 已提交
31 32
namespace server {

Y
yudong.cai 已提交
33
constexpr uint64_t GB = 1UL << 30;
34

S
starlord 已提交
35
Config&
36 37 38
Config::GetInstance() {
    static Config config_inst;
    return config_inst;
G
groot 已提交
39 40
}

S
starlord 已提交
41
Status
S
starlord 已提交
42
Config::LoadConfigFile(const std::string& filename) {
43
    if (filename.empty()) {
44
        return Status(SERVER_UNEXPECTED_ERROR, "No specified config file");
G
groot 已提交
45
    }
46 47 48 49 50

    struct stat file_stat;
    if (stat(filename.c_str(), &file_stat) != 0) {
        std::string str = "Config file not exist: " + filename;
        return Status(SERVER_FILE_NOT_FOUND, str);
G
groot 已提交
51 52 53
    }

    try {
54 55 56 57
        ConfigMgr* mgr = YamlConfigMgr::GetInstance();
        Status s = mgr->LoadConfigFile(filename);
        if (!s.ok()) {
            return s;
G
groot 已提交
58
        }
S
starlord 已提交
59
    } catch (YAML::Exception& e) {
60 61
        std::string str = "Exception occurs when loading config file: " + filename;
        return Status(SERVER_UNEXPECTED_ERROR, str);
G
groot 已提交
62 63
    }

S
starlord 已提交
64
    return Status::OK();
G
groot 已提交
65 66
}

Y
yudong.cai 已提交
67 68 69 70 71 72 73
Status
Config::ValidateConfig() {
    Status s;

    /* server config */
    std::string server_addr;
    s = GetServerConfigAddress(server_addr);
S
starlord 已提交
74 75 76
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
77 78 79

    std::string server_port;
    s = GetServerConfigPort(server_port);
S
starlord 已提交
80 81 82
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
83 84

    std::string server_mode;
Y
yudong.cai 已提交
85
    s = GetServerConfigDeployMode(server_mode);
S
starlord 已提交
86 87 88
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
89 90 91

    std::string server_time_zone;
    s = GetServerConfigTimeZone(server_time_zone);
S
starlord 已提交
92 93 94
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
95 96 97 98

    /* db config */
    std::string db_primary_path;
    s = GetDBConfigPrimaryPath(db_primary_path);
S
starlord 已提交
99 100 101
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
102 103 104

    std::string db_secondary_path;
    s = GetDBConfigSecondaryPath(db_secondary_path);
S
starlord 已提交
105 106 107
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
108 109 110

    std::string db_backend_url;
    s = GetDBConfigBackendUrl(db_backend_url);
S
starlord 已提交
111 112 113
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
114 115 116

    int32_t db_archive_disk_threshold;
    s = GetDBConfigArchiveDiskThreshold(db_archive_disk_threshold);
S
starlord 已提交
117 118 119
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
120 121 122

    int32_t db_archive_days_threshold;
    s = GetDBConfigArchiveDaysThreshold(db_archive_days_threshold);
S
starlord 已提交
123 124 125
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
126 127 128

    int32_t db_insert_buffer_size;
    s = GetDBConfigInsertBufferSize(db_insert_buffer_size);
S
starlord 已提交
129 130 131
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
132 133 134 135

    /* metric config */
    bool metric_enable_monitor;
    s = GetMetricConfigEnableMonitor(metric_enable_monitor);
S
starlord 已提交
136 137 138
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
139 140 141

    std::string metric_collector;
    s = GetMetricConfigCollector(metric_collector);
S
starlord 已提交
142 143 144
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
145 146 147

    std::string metric_prometheus_port;
    s = GetMetricConfigPrometheusPort(metric_prometheus_port);
S
starlord 已提交
148 149 150
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
151 152

    /* cache config */
W
wxyu 已提交
153
    int64_t cache_cpu_cache_capacity;
Y
yudong.cai 已提交
154
    s = GetCacheConfigCpuCacheCapacity(cache_cpu_cache_capacity);
S
starlord 已提交
155 156 157
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
158

Y
yudong.cai 已提交
159 160
    float cache_cpu_cache_threshold;
    s = GetCacheConfigCpuCacheThreshold(cache_cpu_cache_threshold);
S
starlord 已提交
161 162 163
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
164

W
wxyu 已提交
165
    int64_t cache_gpu_cache_capacity;
Y
yudong.cai 已提交
166
    s = GetCacheConfigGpuCacheCapacity(cache_gpu_cache_capacity);
S
starlord 已提交
167 168 169
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
170

Y
yudong.cai 已提交
171 172
    float cache_gpu_cache_threshold;
    s = GetCacheConfigGpuCacheThreshold(cache_gpu_cache_threshold);
S
starlord 已提交
173 174 175
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
176 177 178

    bool cache_insert_data;
    s = GetCacheConfigCacheInsertData(cache_insert_data);
S
starlord 已提交
179 180 181
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
182 183

    /* engine config */
Y
yudong.cai 已提交
184 185
    int32_t engine_use_blas_threshold;
    s = GetEngineConfigUseBlasThreshold(engine_use_blas_threshold);
S
starlord 已提交
186 187 188
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
189 190 191

    int32_t engine_omp_thread_num;
    s = GetEngineConfigOmpThreadNum(engine_omp_thread_num);
S
starlord 已提交
192 193 194
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
195 196 197 198

    /* resource config */
    std::string resource_mode;
    s = GetResourceConfigMode(resource_mode);
S
starlord 已提交
199 200 201
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
202

203 204 205 206 207 208 209 210
    std::vector<std::string> search_resources;
    s = GetResourceConfigSearchResources(search_resources);
    if (!s.ok()) {
        return s;
    }

    int32_t resource_index_build_device;
    s = GetResourceConfigIndexBuildDevice(resource_index_build_device);
S
starlord 已提交
211 212 213
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
214 215 216 217

    return Status::OK();
}

Y
yudong.cai 已提交
218 219 220 221 222 223
Status
Config::ResetDefaultConfig() {
    Status s;

    /* server config */
    s = SetServerConfigAddress(CONFIG_SERVER_ADDRESS_DEFAULT);
S
starlord 已提交
224 225 226
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
227 228

    s = SetServerConfigPort(CONFIG_SERVER_PORT_DEFAULT);
S
starlord 已提交
229 230 231
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
232 233

    s = SetServerConfigDeployMode(CONFIG_SERVER_DEPLOY_MODE_DEFAULT);
S
starlord 已提交
234 235 236
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
237 238

    s = SetServerConfigTimeZone(CONFIG_SERVER_TIME_ZONE_DEFAULT);
S
starlord 已提交
239 240 241
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
242 243 244

    /* db config */
    s = SetDBConfigPrimaryPath(CONFIG_DB_PRIMARY_PATH_DEFAULT);
S
starlord 已提交
245 246 247
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
248 249

    s = SetDBConfigSecondaryPath(CONFIG_DB_SECONDARY_PATH_DEFAULT);
S
starlord 已提交
250 251 252
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
253 254

    s = SetDBConfigBackendUrl(CONFIG_DB_BACKEND_URL_DEFAULT);
S
starlord 已提交
255 256 257
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
258 259

    s = SetDBConfigArchiveDiskThreshold(CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT);
S
starlord 已提交
260 261 262
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
263 264

    s = SetDBConfigArchiveDaysThreshold(CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT);
S
starlord 已提交
265 266 267
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
268 269

    s = SetDBConfigInsertBufferSize(CONFIG_DB_INSERT_BUFFER_SIZE_DEFAULT);
S
starlord 已提交
270 271 272
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
273 274 275

    /* metric config */
    s = SetMetricConfigEnableMonitor(CONFIG_METRIC_ENABLE_MONITOR_DEFAULT);
S
starlord 已提交
276 277 278
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
279 280

    s = SetMetricConfigCollector(CONFIG_METRIC_COLLECTOR_DEFAULT);
S
starlord 已提交
281 282 283
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
284 285

    s = SetMetricConfigPrometheusPort(CONFIG_METRIC_PROMETHEUS_PORT_DEFAULT);
S
starlord 已提交
286 287 288
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
289 290

    /* cache config */
Y
yudong.cai 已提交
291
    s = SetCacheConfigCpuCacheCapacity(CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT);
S
starlord 已提交
292 293 294
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
295

Y
yudong.cai 已提交
296
    s = SetCacheConfigCpuCacheThreshold(CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT);
S
starlord 已提交
297 298 299
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
300

Y
yudong.cai 已提交
301
    s = SetCacheConfigGpuCacheCapacity(CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT);
S
starlord 已提交
302 303 304
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
305

Y
yudong.cai 已提交
306
    s = SetCacheConfigGpuCacheThreshold(CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT);
S
starlord 已提交
307 308 309
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
310 311

    s = SetCacheConfigCacheInsertData(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
S
starlord 已提交
312 313 314
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
315 316

    /* engine config */
Y
yudong.cai 已提交
317
    s = SetEngineConfigUseBlasThreshold(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
S
starlord 已提交
318 319 320
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
321 322

    s = SetEngineConfigOmpThreadNum(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
S
starlord 已提交
323 324 325
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
326 327 328

    /* resource config */
    s = SetResourceConfigMode(CONFIG_RESOURCE_MODE_DEFAULT);
S
starlord 已提交
329 330 331
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
332

333 334 335 336 337
    s = SetResourceConfigIndexBuildDevice(CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT);
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
338 339 340
    return Status::OK();
}

Y
yudong.cai 已提交
341
void
S
starlord 已提交
342
Config::PrintConfigSection(const std::string& config_node_name) {
Y
yudong.cai 已提交
343 344 345
    std::cout << std::endl;
    std::cout << config_node_name << ":" << std::endl;
    if (config_map_.find(config_node_name) != config_map_.end()) {
S
starlord 已提交
346
        for (auto item : config_map_[config_node_name]) {
Y
yudong.cai 已提交
347 348
            std::cout << item.first << ": " << item.second << std::endl;
        }
Z
zhiru 已提交
349 350 351
    }
}

Y
yudong.cai 已提交
352 353 354 355 356 357 358 359 360 361 362
void
Config::PrintAll() {
    PrintConfigSection(CONFIG_SERVER);
    PrintConfigSection(CONFIG_DB);
    PrintConfigSection(CONFIG_CACHE);
    PrintConfigSection(CONFIG_METRIC);
    PrintConfigSection(CONFIG_ENGINE);
    PrintConfigSection(CONFIG_RESOURCE);
}

////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
363
Status
S
starlord 已提交
364
Config::CheckServerConfigAddress(const std::string& value) {
Y
yudong.cai 已提交
365 366
    if (!ValidationUtil::ValidateIpAddress(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid server config address: " + value);
Z
zhiru 已提交
367
    }
Y
yudong.cai 已提交
368 369
    return Status::OK();
}
Z
zhiru 已提交
370

Y
yudong.cai 已提交
371
Status
S
starlord 已提交
372
Config::CheckServerConfigPort(const std::string& value) {
Y
yudong.cai 已提交
373 374
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid server config port: " + value);
375
    } else {
Y
yudong.cai 已提交
376
        int32_t port = std::stoi(value);
377
        if (!(port > 1024 && port < 65535)) {
Y
yudong.cai 已提交
378
            return Status(SERVER_INVALID_ARGUMENT, "Server config port out of range (1024, 65535): " + value);
Z
zhiru 已提交
379 380
        }
    }
Y
yudong.cai 已提交
381 382
    return Status::OK();
}
Z
zhiru 已提交
383

Y
yudong.cai 已提交
384
Status
S
starlord 已提交
385 386
Config::CheckServerConfigDeployMode(const std::string& value) {
    if (value != "single" && value != "cluster_readonly" && value != "cluster_writable") {
Y
yudong.cai 已提交
387 388
        return Status(SERVER_INVALID_ARGUMENT,
                      "Invalid server config mode [single, cluster_readonly, cluster_writable]: " + value);
389
    }
Y
yudong.cai 已提交
390 391
    return Status::OK();
}
392

Y
yudong.cai 已提交
393
Status
S
starlord 已提交
394
Config::CheckServerConfigTimeZone(const std::string& value) {
Y
yudong.cai 已提交
395 396
    if (value.length() <= 3) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid server config time_zone: " + value);
397
    } else {
Y
yudong.cai 已提交
398 399
        if (value.substr(0, 3) != "UTC") {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server config time_zone: " + value);
400 401
        } else {
            try {
Y
yudong.cai 已提交
402
                stoi(value.substr(3));
403
            } catch (...) {
Y
yudong.cai 已提交
404
                return Status(SERVER_INVALID_ARGUMENT, "Invalid server config time_zone: " + value);
405
            }
406 407
        }
    }
Y
yudong.cai 已提交
408
    return Status::OK();
Z
zhiru 已提交
409 410
}

S
starlord 已提交
411
Status
S
starlord 已提交
412
Config::CheckDBConfigPrimaryPath(const std::string& value) {
Y
yudong.cai 已提交
413
    if (value.empty()) {
Y
yudong.cai 已提交
414
        return Status(SERVER_INVALID_ARGUMENT, "DB config primary_path empty");
Z
zhiru 已提交
415
    }
Y
yudong.cai 已提交
416 417
    return Status::OK();
}
Z
zhiru 已提交
418

Y
yudong.cai 已提交
419
Status
S
starlord 已提交
420
Config::CheckDBConfigSecondaryPath(const std::string& value) {
Y
yudong.cai 已提交
421 422 423
    return Status::OK();
}

Y
yudong.cai 已提交
424
Status
S
starlord 已提交
425
Config::CheckDBConfigBackendUrl(const std::string& value) {
Y
yudong.cai 已提交
426 427
    if (!ValidationUtil::ValidateDbURI(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid DB config backend_url: " + value);
Z
zhiru 已提交
428
    }
Y
yudong.cai 已提交
429 430
    return Status::OK();
}
Z
zhiru 已提交
431

Y
yudong.cai 已提交
432
Status
S
starlord 已提交
433
Config::CheckDBConfigArchiveDiskThreshold(const std::string& value) {
Y
yudong.cai 已提交
434 435
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid DB config archive_disk_threshold: " + value);
Z
zhiru 已提交
436
    }
Y
yudong.cai 已提交
437 438
    return Status::OK();
}
Z
zhiru 已提交
439

Y
yudong.cai 已提交
440
Status
S
starlord 已提交
441
Config::CheckDBConfigArchiveDaysThreshold(const std::string& value) {
Y
yudong.cai 已提交
442 443
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid DB config archive_days_threshold: " + value);
Z
zhiru 已提交
444
    }
Y
yudong.cai 已提交
445 446
    return Status::OK();
}
Z
zhiru 已提交
447

Y
yudong.cai 已提交
448
Status
S
starlord 已提交
449
Config::CheckDBConfigInsertBufferSize(const std::string& value) {
Y
yudong.cai 已提交
450
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
Y
yudong.cai 已提交
451
        return Status(SERVER_INVALID_ARGUMENT, "Invalid DB config insert_buffer_size: " + value);
452
    } else {
Y
yudong.cai 已提交
453
        int64_t buffer_size = std::stoi(value) * GB;
S
starlord 已提交
454
        uint64_t total_mem = 0, free_mem = 0;
Z
zhiru 已提交
455
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
Y
yudong.cai 已提交
456
        if (buffer_size >= total_mem) {
Y
yudong.cai 已提交
457
            return Status(SERVER_INVALID_ARGUMENT, "DB config insert_buffer_size exceed system memory: " + value);
Z
zhiru 已提交
458 459
        }
    }
Y
yudong.cai 已提交
460 461
    return Status::OK();
}
Z
zhiru 已提交
462

S
starlord 已提交
463
Status
S
starlord 已提交
464
Config::CheckMetricConfigEnableMonitor(const std::string& value) {
Y
yudong.cai 已提交
465 466
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config auto_bootup: " + value);
Z
zhiru 已提交
467
    }
Y
yudong.cai 已提交
468 469
    return Status::OK();
}
Z
zhiru 已提交
470

Y
yudong.cai 已提交
471
Status
S
starlord 已提交
472
Config::CheckMetricConfigCollector(const std::string& value) {
Y
yudong.cai 已提交
473 474 475 476 477 478
    if (value != "prometheus") {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config collector: " + value);
    }
    return Status::OK();
}

Y
yudong.cai 已提交
479
Status
S
starlord 已提交
480
Config::CheckMetricConfigPrometheusPort(const std::string& value) {
Y
yudong.cai 已提交
481 482
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config prometheus_port: " + value);
Z
zhiru 已提交
483
    }
Y
yudong.cai 已提交
484
    return Status::OK();
Z
zhiru 已提交
485 486
}

S
starlord 已提交
487
Status
S
starlord 已提交
488
Config::CheckCacheConfigCpuCacheCapacity(const std::string& value) {
Y
yudong.cai 已提交
489
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
Y
yudong.cai 已提交
490
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config cpu_cache_capacity: " + value);
491
    } else {
Y
yudong.cai 已提交
492
        uint64_t cpu_cache_capacity = std::stoi(value) * GB;
S
starlord 已提交
493
        uint64_t total_mem = 0, free_mem = 0;
Z
zhiru 已提交
494 495
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
        if (cpu_cache_capacity >= total_mem) {
Y
yudong.cai 已提交
496
            return Status(SERVER_INVALID_ARGUMENT, "Cache config cpu_cache_capacity exceed system memory: " + value);
S
starlord 已提交
497
        } else if (cpu_cache_capacity > static_cast<double>(total_mem * 0.9)) {
Y
yudong.cai 已提交
498
            std::cerr << "Warning: cpu_cache_capacity value is too big" << std::endl;
Z
zhiru 已提交
499
        }
500

Y
yudong.cai 已提交
501 502
        int32_t buffer_value;
        Status s = GetDBConfigInsertBufferSize(buffer_value);
S
starlord 已提交
503 504 505 506
        if (!s.ok()) {
            return s;
        }

Y
yudong.cai 已提交
507
        int64_t insert_buffer_size = buffer_value * GB;
Y
yudong.cai 已提交
508
        if (insert_buffer_size + cpu_cache_capacity >= total_mem) {
Y
yudong.cai 已提交
509
            return Status(SERVER_INVALID_ARGUMENT, "Sum of cpu_cache_capacity and buffer_size exceed system memory");
Z
zhiru 已提交
510 511
        }
    }
Y
yudong.cai 已提交
512 513
    return Status::OK();
}
Z
zhiru 已提交
514

Y
yudong.cai 已提交
515
Status
S
starlord 已提交
516
Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) {
Y
yudong.cai 已提交
517
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
Y
yudong.cai 已提交
518
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config cpu_cache_threshold: " + value);
Y
yudong.cai 已提交
519
    } else {
Y
yudong.cai 已提交
520 521 522
        float cpu_cache_threshold = std::stof(value);
        if (cpu_cache_threshold <= 0.0 || cpu_cache_threshold >= 1.0) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config cpu_cache_threshold: " + value);
Y
yudong.cai 已提交
523
        }
524
    }
Y
yudong.cai 已提交
525 526
    return Status::OK();
}
527

Y
yudong.cai 已提交
528
Status
S
starlord 已提交
529
Config::CheckCacheConfigGpuCacheCapacity(const std::string& value) {
Y
yudong.cai 已提交
530
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
Y
yudong.cai 已提交
531
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config gpu_cache_capacity: " + value);
532
    } else {
Y
yudong.cai 已提交
533 534
        uint64_t gpu_cache_capacity = std::stoi(value) * GB;
        int gpu_index;
535
        Status s = GetResourceConfigIndexBuildDevice(gpu_index);
S
starlord 已提交
536 537 538 539
        if (!s.ok()) {
            return s;
        }

Z
zhiru 已提交
540
        size_t gpu_memory;
S
starlord 已提交
541
        if (!ValidationUtil::GetGpuMemory(gpu_index, gpu_memory).ok()) {
Y
yudong.cai 已提交
542 543
            return Status(SERVER_UNEXPECTED_ERROR,
                          "Fail to get GPU memory for GPU device: " + std::to_string(gpu_index));
544
        } else if (gpu_cache_capacity >= gpu_memory) {
Y
yudong.cai 已提交
545
            return Status(SERVER_INVALID_ARGUMENT,
Y
yudong.cai 已提交
546
                          "Cache config gpu_cache_capacity exceed GPU memory: " + std::to_string(gpu_memory));
S
starlord 已提交
547
        } else if (gpu_cache_capacity > (double)gpu_memory * 0.9) {
Y
yudong.cai 已提交
548
            std::cerr << "Warning: gpu_cache_capacity value is too big" << std::endl;
Z
zhiru 已提交
549 550
        }
    }
Y
yudong.cai 已提交
551 552
    return Status::OK();
}
Z
zhiru 已提交
553

Y
yudong.cai 已提交
554
Status
S
starlord 已提交
555
Config::CheckCacheConfigGpuCacheThreshold(const std::string& value) {
Y
yudong.cai 已提交
556
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
Y
yudong.cai 已提交
557
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config gpu_cache_threshold: " + value);
Y
yudong.cai 已提交
558
    } else {
Y
yudong.cai 已提交
559 560 561
        float gpu_cache_threshold = std::stof(value);
        if (gpu_cache_threshold <= 0.0 || gpu_cache_threshold >= 1.0) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config gpu_cache_threshold: " + value);
Y
yudong.cai 已提交
562
        }
Z
zhiru 已提交
563
    }
Y
yudong.cai 已提交
564 565
    return Status::OK();
}
Z
zhiru 已提交
566

Y
yudong.cai 已提交
567
Status
S
starlord 已提交
568
Config::CheckCacheConfigCacheInsertData(const std::string& value) {
Y
yudong.cai 已提交
569 570 571 572
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config cache_insert_data: " + value);
    }
    return Status::OK();
Z
zhiru 已提交
573 574
}

S
starlord 已提交
575
Status
S
starlord 已提交
576
Config::CheckEngineConfigUseBlasThreshold(const std::string& value) {
Y
yudong.cai 已提交
577
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
Y
yudong.cai 已提交
578
        return Status(SERVER_INVALID_ARGUMENT, "Invalid engine config use_blas_threshold: " + value);
Z
zhiru 已提交
579
    }
Y
yudong.cai 已提交
580 581
    return Status::OK();
}
Z
zhiru 已提交
582

Y
yudong.cai 已提交
583
Status
S
starlord 已提交
584
Config::CheckEngineConfigOmpThreadNum(const std::string& value) {
Y
yudong.cai 已提交
585 586
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid engine config omp_thread_num: " + value);
S
starlord 已提交
587 588 589 590 591 592 593
    }

    int32_t omp_thread = std::stoi(value);
    uint32_t sys_thread_cnt = 8;
    CommonUtil::GetSystemAvailableThreads(sys_thread_cnt);
    if (omp_thread > static_cast<int32_t>(sys_thread_cnt)) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid engine config omp_thread_num: " + value);
Z
zhiru 已提交
594
    }
Y
yudong.cai 已提交
595
    return Status::OK();
Z
zhiru 已提交
596 597
}

S
starlord 已提交
598
Status
S
starlord 已提交
599
Config::CheckResourceConfigMode(const std::string& value) {
Y
yudong.cai 已提交
600 601
    if (value != "simple") {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid resource config mode: " + value);
W
wxyu 已提交
602
    }
Y
yudong.cai 已提交
603 604
    return Status::OK();
}
605

Y
yudong.cai 已提交
606
Status
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
CheckGpuDevice(const std::string& value) {
    const std::regex pat("gpu(\\d+)");
    std::cmatch m;
    if (!std::regex_match(value.c_str(), m, pat)) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid gpu device: " + value);
    }

    int32_t gpu_index = std::stoi(value.substr(3));
    if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid gpu device: " + value);
    }
    return Status::OK();
}

Status
Config::CheckResourceConfigSearchResources(const std::vector<std::string>& value) {
Y
yudong.cai 已提交
623
    if (value.empty()) {
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
        return Status(SERVER_INVALID_ARGUMENT, "Empty resource config search_resources");
    }

    for (auto& gpu_device : value) {
        if (!CheckGpuDevice(gpu_device).ok()) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid resource config search_resources: " + gpu_device);
        }
    }
    return Status::OK();
}

Status
Config::CheckResourceConfigIndexBuildDevice(const std::string& value) {
    if (!CheckGpuDevice(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid resource config index_build_device: " + value);
G
groot 已提交
639
    }
Y
yudong.cai 已提交
640
    return Status::OK();
G
groot 已提交
641 642
}

Y
yudong.cai 已提交
643
////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
644 645
ConfigNode&
Config::GetConfigNode(const std::string& name) {
646
    ConfigMgr* mgr = YamlConfigMgr::GetInstance();
S
starlord 已提交
647
    ConfigNode& root_node = mgr->GetRootNode();
G
groot 已提交
648
    return root_node.GetChild(name);
G
groot 已提交
649 650
}

Y
yudong.cai 已提交
651
Status
S
starlord 已提交
652
Config::GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value) {
Y
yudong.cai 已提交
653
    std::lock_guard<std::mutex> lock(mutex_);
Y
yudong.cai 已提交
654 655 656 657 658
    if (config_map_.find(parent_key) != config_map_.end() &&
        config_map_[parent_key].find(child_key) != config_map_[parent_key].end()) {
        value = config_map_[parent_key][child_key];
        return Status::OK();
    }
S
starlord 已提交
659
    return Status(SERVER_UNEXPECTED_ERROR, "key not exist");
Y
yudong.cai 已提交
660 661
}

Y
yudong.cai 已提交
662
void
S
starlord 已提交
663
Config::SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value) {
Y
yudong.cai 已提交
664 665 666 667 668
    std::lock_guard<std::mutex> lock(mutex_);
    config_map_[parent_key][child_key] = value;
}

////////////////////////////////////////////////////////////////////////////////
Y
yudong.cai 已提交
669
std::string
S
starlord 已提交
670
Config::GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value) {
Y
yudong.cai 已提交
671
    std::string value;
S
starlord 已提交
672 673 674
    if (!GetConfigValueInMem(parent_key, child_key, value).ok()) {
        value = GetConfigNode(parent_key).GetValue(child_key, default_value);
        SetConfigValueInMem(parent_key, child_key, value);
Y
yudong.cai 已提交
675
    }
Y
yudong.cai 已提交
676
    return value;
Y
yudong.cai 已提交
677 678
}

679
Status
S
starlord 已提交
680
Config::GetServerConfigAddress(std::string& value) {
S
starlord 已提交
681
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, CONFIG_SERVER_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
682
    return CheckServerConfigAddress(value);
683 684 685
}

Status
S
starlord 已提交
686
Config::GetServerConfigPort(std::string& value) {
S
starlord 已提交
687
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_PORT, CONFIG_SERVER_PORT_DEFAULT);
Y
yudong.cai 已提交
688
    return CheckServerConfigPort(value);
689 690 691
}

Status
S
starlord 已提交
692
Config::GetServerConfigDeployMode(std::string& value) {
S
starlord 已提交
693
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, CONFIG_SERVER_DEPLOY_MODE_DEFAULT);
Y
yudong.cai 已提交
694
    return CheckServerConfigDeployMode(value);
695 696 697
}

Status
S
starlord 已提交
698
Config::GetServerConfigTimeZone(std::string& value) {
S
starlord 已提交
699
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, CONFIG_SERVER_TIME_ZONE_DEFAULT);
Y
yudong.cai 已提交
700
    return CheckServerConfigTimeZone(value);
701 702 703
}

Status
S
starlord 已提交
704
Config::GetDBConfigPrimaryPath(std::string& value) {
S
starlord 已提交
705
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_PRIMARY_PATH, CONFIG_DB_PRIMARY_PATH_DEFAULT);
Y
yudong.cai 已提交
706
    return CheckDBConfigPrimaryPath(value);
707 708 709
}

Status
S
starlord 已提交
710
Config::GetDBConfigSecondaryPath(std::string& value) {
S
starlord 已提交
711
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_SECONDARY_PATH, CONFIG_DB_SECONDARY_PATH_DEFAULT);
Y
yudong.cai 已提交
712
    return Status::OK();
713 714 715
}

Status
S
starlord 已提交
716
Config::GetDBConfigBackendUrl(std::string& value) {
S
starlord 已提交
717
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_BACKEND_URL, CONFIG_DB_BACKEND_URL_DEFAULT);
Y
yudong.cai 已提交
718
    return CheckDBConfigBackendUrl(value);
719 720 721
}

Status
S
starlord 已提交
722
Config::GetDBConfigArchiveDiskThreshold(int32_t& value) {
S
starlord 已提交
723 724
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT);
Y
yudong.cai 已提交
725
    Status s = CheckDBConfigArchiveDiskThreshold(str);
S
starlord 已提交
726 727 728 729
    if (!s.ok()) {
        return s;
    }

730 731 732 733 734
    value = std::stoi(str);
    return Status::OK();
}

Status
S
starlord 已提交
735
Config::GetDBConfigArchiveDaysThreshold(int32_t& value) {
S
starlord 已提交
736 737
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT);
Y
yudong.cai 已提交
738
    Status s = CheckDBConfigArchiveDaysThreshold(str);
S
starlord 已提交
739 740 741 742
    if (!s.ok()) {
        return s;
    }

743 744 745 746 747
    value = std::stoi(str);
    return Status::OK();
}

Status
S
starlord 已提交
748
Config::GetDBConfigInsertBufferSize(int32_t& value) {
749
    std::string str = GetConfigStr(CONFIG_DB, CONFIG_DB_INSERT_BUFFER_SIZE, CONFIG_DB_INSERT_BUFFER_SIZE_DEFAULT);
Y
yudong.cai 已提交
750
    Status s = CheckDBConfigInsertBufferSize(str);
S
starlord 已提交
751 752 753 754
    if (!s.ok()) {
        return s;
    }

755 756 757 758
    value = std::stoi(str);
    return Status::OK();
}

S
starlord 已提交
759 760
Status
Config::GetDBConfigPreloadTable(std::string& value) {
S
starlord 已提交
761
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_PRELOAD_TABLE);
S
starlord 已提交
762 763 764
    return Status::OK();
}

765
Status
S
starlord 已提交
766
Config::GetMetricConfigEnableMonitor(bool& value) {
767
    std::string str = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, CONFIG_METRIC_ENABLE_MONITOR_DEFAULT);
Y
yudong.cai 已提交
768
    Status s = CheckMetricConfigEnableMonitor(str);
S
starlord 已提交
769 770 771 772
    if (!s.ok()) {
        return s;
    }

773 774 775 776 777 778
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    value = (str == "true" || str == "on" || str == "yes" || str == "1");
    return Status::OK();
}

Status
S
starlord 已提交
779
Config::GetMetricConfigCollector(std::string& value) {
S
starlord 已提交
780
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_COLLECTOR, CONFIG_METRIC_COLLECTOR_DEFAULT);
Y
yudong.cai 已提交
781
    return Status::OK();
782 783 784
}

Status
S
starlord 已提交
785
Config::GetMetricConfigPrometheusPort(std::string& value) {
S
starlord 已提交
786
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_PROMETHEUS_PORT, CONFIG_METRIC_PROMETHEUS_PORT_DEFAULT);
Y
yudong.cai 已提交
787
    return CheckMetricConfigPrometheusPort(value);
788 789 790
}

Status
W
wxyu 已提交
791
Config::GetCacheConfigCpuCacheCapacity(int64_t& value) {
S
starlord 已提交
792 793
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT);
Y
yudong.cai 已提交
794
    Status s = CheckCacheConfigCpuCacheCapacity(str);
S
starlord 已提交
795 796 797 798
    if (!s.ok()) {
        return s;
    }

799 800 801 802 803
    value = std::stoi(str);
    return Status::OK();
}

Status
S
starlord 已提交
804
Config::GetCacheConfigCpuCacheThreshold(float& value) {
S
starlord 已提交
805 806
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT);
Y
yudong.cai 已提交
807
    Status s = CheckCacheConfigCpuCacheThreshold(str);
S
starlord 已提交
808 809 810 811
    if (!s.ok()) {
        return s;
    }

812 813 814 815 816
    value = std::stof(str);
    return Status::OK();
}

Status
W
wxyu 已提交
817
Config::GetCacheConfigGpuCacheCapacity(int64_t& value) {
S
starlord 已提交
818 819
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_CAPACITY, CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT);
Y
yudong.cai 已提交
820
    Status s = CheckCacheConfigGpuCacheCapacity(str);
S
starlord 已提交
821 822 823 824
    if (!s.ok()) {
        return s;
    }

825 826 827 828 829
    value = std::stoi(str);
    return Status::OK();
}

Status
S
starlord 已提交
830
Config::GetCacheConfigGpuCacheThreshold(float& value) {
S
starlord 已提交
831 832
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_THRESHOLD, CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT);
Y
yudong.cai 已提交
833
    Status s = CheckCacheConfigGpuCacheThreshold(str);
S
starlord 已提交
834 835 836 837
    if (!s.ok()) {
        return s;
    }

838 839 840 841 842
    value = std::stof(str);
    return Status::OK();
}

Status
S
starlord 已提交
843
Config::GetCacheConfigCacheInsertData(bool& value) {
S
starlord 已提交
844 845
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
Y
yudong.cai 已提交
846
    Status s = CheckCacheConfigCacheInsertData(str);
S
starlord 已提交
847 848 849 850
    if (!s.ok()) {
        return s;
    }

851 852 853 854 855 856
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    value = (str == "true" || str == "on" || str == "yes" || str == "1");
    return Status::OK();
}

Status
S
starlord 已提交
857
Config::GetEngineConfigUseBlasThreshold(int32_t& value) {
S
starlord 已提交
858 859
    std::string str =
        GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
Y
yudong.cai 已提交
860
    Status s = CheckEngineConfigUseBlasThreshold(str);
S
starlord 已提交
861 862 863 864
    if (!s.ok()) {
        return s;
    }

865 866 867 868 869
    value = std::stoi(str);
    return Status::OK();
}

Status
S
starlord 已提交
870
Config::GetEngineConfigOmpThreadNum(int32_t& value) {
871
    std::string str = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
Y
yudong.cai 已提交
872
    Status s = CheckEngineConfigOmpThreadNum(str);
S
starlord 已提交
873 874 875 876
    if (!s.ok()) {
        return s;
    }

877 878 879 880 881
    value = std::stoi(str);
    return Status::OK();
}

Status
S
starlord 已提交
882
Config::GetResourceConfigMode(std::string& value) {
S
starlord 已提交
883
    value = GetConfigStr(CONFIG_RESOURCE, CONFIG_RESOURCE_MODE, CONFIG_RESOURCE_MODE_DEFAULT);
Y
yudong.cai 已提交
884
    return CheckResourceConfigMode(value);
885 886 887
}

Status
888
Config::GetResourceConfigSearchResources(std::vector<std::string>& value) {
889
    ConfigNode resource_config = GetConfigNode(CONFIG_RESOURCE);
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
    value = resource_config.GetSequence(CONFIG_RESOURCE_SEARCH_RESOURCES);
    return CheckResourceConfigSearchResources(value);
}

Status
Config::GetResourceConfigIndexBuildDevice(int32_t& value) {
    std::string str =
        GetConfigStr(CONFIG_RESOURCE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT);
    Status s = CheckResourceConfigIndexBuildDevice(str);
    if (!s.ok()) {
        return s;
    }

    value = std::stoi(str.substr(3));
    return Status::OK();
Y
yudong.cai 已提交
905
}
G
groot 已提交
906

Y
yudong.cai 已提交
907 908 909
///////////////////////////////////////////////////////////////////////////////
/* server config */
Status
S
starlord 已提交
910
Config::SetServerConfigAddress(const std::string& value) {
Y
yudong.cai 已提交
911
    Status s = CheckServerConfigAddress(value);
S
starlord 已提交
912 913 914 915
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
916 917 918 919 920
    SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
    return Status::OK();
}

Status
S
starlord 已提交
921
Config::SetServerConfigPort(const std::string& value) {
Y
yudong.cai 已提交
922
    Status s = CheckServerConfigPort(value);
S
starlord 已提交
923 924 925 926
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
927 928 929 930 931
    SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value);
    return Status::OK();
}

Status
S
starlord 已提交
932
Config::SetServerConfigDeployMode(const std::string& value) {
Y
yudong.cai 已提交
933
    Status s = CheckServerConfigDeployMode(value);
S
starlord 已提交
934 935 936 937
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
938
    SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, value);
Y
yudong.cai 已提交
939 940 941 942
    return Status::OK();
}

Status
S
starlord 已提交
943
Config::SetServerConfigTimeZone(const std::string& value) {
Y
yudong.cai 已提交
944
    Status s = CheckServerConfigTimeZone(value);
S
starlord 已提交
945 946 947 948
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
949 950 951 952 953 954
    SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
    return Status::OK();
}

/* db config */
Status
S
starlord 已提交
955
Config::SetDBConfigPrimaryPath(const std::string& value) {
Y
yudong.cai 已提交
956
    Status s = CheckDBConfigPrimaryPath(value);
S
starlord 已提交
957 958 959 960
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
961
    SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRIMARY_PATH, value);
Y
yudong.cai 已提交
962 963 964 965
    return Status::OK();
}

Status
S
starlord 已提交
966
Config::SetDBConfigSecondaryPath(const std::string& value) {
Y
yudong.cai 已提交
967
    Status s = CheckDBConfigSecondaryPath(value);
S
starlord 已提交
968 969 970 971
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
972
    SetConfigValueInMem(CONFIG_DB, CONFIG_DB_SECONDARY_PATH, value);
Y
yudong.cai 已提交
973 974 975 976
    return Status::OK();
}

Status
S
starlord 已提交
977
Config::SetDBConfigBackendUrl(const std::string& value) {
Y
yudong.cai 已提交
978
    Status s = CheckDBConfigBackendUrl(value);
S
starlord 已提交
979 980 981 982
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
983 984 985 986 987
    SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value);
    return Status::OK();
}

Status
S
starlord 已提交
988
Config::SetDBConfigArchiveDiskThreshold(const std::string& value) {
Y
yudong.cai 已提交
989
    Status s = CheckDBConfigArchiveDiskThreshold(value);
S
starlord 已提交
990 991 992 993
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
994 995 996 997 998
    SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value);
    return Status::OK();
}

Status
S
starlord 已提交
999
Config::SetDBConfigArchiveDaysThreshold(const std::string& value) {
Y
yudong.cai 已提交
1000
    Status s = CheckDBConfigArchiveDaysThreshold(value);
S
starlord 已提交
1001 1002 1003 1004
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1005 1006 1007 1008 1009
    SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value);
    return Status::OK();
}

Status
S
starlord 已提交
1010
Config::SetDBConfigInsertBufferSize(const std::string& value) {
Y
yudong.cai 已提交
1011
    Status s = CheckDBConfigInsertBufferSize(value);
S
starlord 已提交
1012 1013 1014 1015
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1016
    SetConfigValueInMem(CONFIG_DB, CONFIG_DB_INSERT_BUFFER_SIZE, value);
Y
yudong.cai 已提交
1017 1018 1019 1020 1021
    return Status::OK();
}

/* metric config */
Status
S
starlord 已提交
1022
Config::SetMetricConfigEnableMonitor(const std::string& value) {
Y
yudong.cai 已提交
1023
    Status s = CheckMetricConfigEnableMonitor(value);
S
starlord 已提交
1024 1025 1026 1027
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1028
    SetConfigValueInMem(CONFIG_DB, CONFIG_METRIC_ENABLE_MONITOR, value);
Y
yudong.cai 已提交
1029 1030 1031 1032
    return Status::OK();
}

Status
S
starlord 已提交
1033
Config::SetMetricConfigCollector(const std::string& value) {
Y
yudong.cai 已提交
1034
    Status s = CheckMetricConfigCollector(value);
S
starlord 已提交
1035 1036 1037 1038
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1039 1040 1041 1042 1043
    SetConfigValueInMem(CONFIG_DB, CONFIG_METRIC_COLLECTOR, value);
    return Status::OK();
}

Status
S
starlord 已提交
1044
Config::SetMetricConfigPrometheusPort(const std::string& value) {
Y
yudong.cai 已提交
1045
    Status s = CheckMetricConfigPrometheusPort(value);
S
starlord 已提交
1046 1047 1048 1049
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1050 1051 1052 1053 1054 1055
    SetConfigValueInMem(CONFIG_DB, CONFIG_METRIC_PROMETHEUS_PORT, value);
    return Status::OK();
}

/* cache config */
Status
S
starlord 已提交
1056
Config::SetCacheConfigCpuCacheCapacity(const std::string& value) {
Y
yudong.cai 已提交
1057
    Status s = CheckCacheConfigCpuCacheCapacity(value);
S
starlord 已提交
1058 1059 1060 1061
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1062
    SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_CPU_CACHE_CAPACITY, value);
Y
yudong.cai 已提交
1063 1064 1065 1066
    return Status::OK();
}

Status
S
starlord 已提交
1067
Config::SetCacheConfigCpuCacheThreshold(const std::string& value) {
Y
yudong.cai 已提交
1068
    Status s = CheckCacheConfigCpuCacheThreshold(value);
S
starlord 已提交
1069 1070 1071 1072
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1073
    SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_CPU_CACHE_THRESHOLD, value);
Y
yudong.cai 已提交
1074 1075 1076 1077
    return Status::OK();
}

Status
S
starlord 已提交
1078
Config::SetCacheConfigGpuCacheCapacity(const std::string& value) {
Y
yudong.cai 已提交
1079
    Status s = CheckCacheConfigGpuCacheCapacity(value);
S
starlord 已提交
1080 1081 1082 1083
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1084
    SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_GPU_CACHE_CAPACITY, value);
Y
yudong.cai 已提交
1085 1086 1087 1088
    return Status::OK();
}

Status
S
starlord 已提交
1089
Config::SetCacheConfigGpuCacheThreshold(const std::string& value) {
Y
yudong.cai 已提交
1090
    Status s = CheckCacheConfigGpuCacheThreshold(value);
S
starlord 已提交
1091 1092 1093 1094
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1095
    SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_GPU_CACHE_THRESHOLD, value);
Y
yudong.cai 已提交
1096 1097 1098 1099
    return Status::OK();
}

Status
S
starlord 已提交
1100
Config::SetCacheConfigCacheInsertData(const std::string& value) {
Y
yudong.cai 已提交
1101
    Status s = CheckCacheConfigCacheInsertData(value);
S
starlord 已提交
1102 1103 1104 1105
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1106 1107 1108 1109 1110 1111
    SetConfigValueInMem(CONFIG_DB, CONFIG_CACHE_CACHE_INSERT_DATA, value);
    return Status::OK();
}

/* engine config */
Status
S
starlord 已提交
1112
Config::SetEngineConfigUseBlasThreshold(const std::string& value) {
Y
yudong.cai 已提交
1113
    Status s = CheckEngineConfigUseBlasThreshold(value);
S
starlord 已提交
1114 1115 1116 1117
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1118
    SetConfigValueInMem(CONFIG_DB, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value);
Y
yudong.cai 已提交
1119 1120 1121 1122
    return Status::OK();
}

Status
S
starlord 已提交
1123
Config::SetEngineConfigOmpThreadNum(const std::string& value) {
Y
yudong.cai 已提交
1124
    Status s = CheckEngineConfigOmpThreadNum(value);
S
starlord 已提交
1125 1126 1127 1128
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1129 1130 1131 1132 1133 1134
    SetConfigValueInMem(CONFIG_DB, CONFIG_ENGINE_OMP_THREAD_NUM, value);
    return Status::OK();
}

/* resource config */
Status
S
starlord 已提交
1135
Config::SetResourceConfigMode(const std::string& value) {
Y
yudong.cai 已提交
1136
    Status s = CheckResourceConfigMode(value);
S
starlord 已提交
1137 1138 1139 1140
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
1141 1142 1143 1144
    SetConfigValueInMem(CONFIG_DB, CONFIG_RESOURCE_MODE, value);
    return Status::OK();
}

1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
Status
Config::SetResourceConfigIndexBuildDevice(const std::string& value) {
    Status s = CheckResourceConfigIndexBuildDevice(value);
    if (!s.ok()) {
        return s;
    }

    SetConfigValueInMem(CONFIG_DB, CONFIG_RESOURCE_INDEX_BUILD_DEVICE, value);
    return Status::OK();
}

S
starlord 已提交
1156 1157
}  // namespace server
}  // namespace milvus