Config.cpp 32.0 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.

S
starlord 已提交
18
#include "server/Config.h"
G
groot 已提交
19

S
starlord 已提交
20
#include <stdlib.h>
G
groot 已提交
21 22 23
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Y
yudong.cai 已提交
24
#include <algorithm>
S
starlord 已提交
25
#include <iostream>
S
starlord 已提交
26
#include <string>
S
starlord 已提交
27
#include <vector>
G
groot 已提交
28

S
starlord 已提交
29
#include "config/ConfigMgr.h"
30 31
#include "utils/CommonUtil.h"
#include "utils/ValidationUtil.h"
G
groot 已提交
32

J
jinhai 已提交
33
namespace milvus {
G
groot 已提交
34 35
namespace server {

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

S
starlord 已提交
38
Config&
39 40 41
Config::GetInstance() {
    static Config config_inst;
    return config_inst;
G
groot 已提交
42 43
}

S
starlord 已提交
44
Status
S
starlord 已提交
45
Config::LoadConfigFile(const std::string& filename) {
46
    if (filename.empty()) {
Y
yudong.cai 已提交
47 48
        std::cerr << "ERROR: need specify config file" << std::endl;
        exit(1);
G
groot 已提交
49
    }
Y
yudong.cai 已提交
50 51
    struct stat dirStat;
    int statOK = stat(filename.c_str(), &dirStat);
G
groot 已提交
52
    if (statOK != 0) {
Y
yudong.cai 已提交
53 54
        std::cerr << "ERROR: Config file not exist: " << filename << std::endl;
        exit(1);
G
groot 已提交
55 56 57
    }

    try {
S
starlord 已提交
58
        ConfigMgr* mgr = const_cast<ConfigMgr*>(ConfigMgr::GetInstance());
S
starlord 已提交
59
        ErrorCode err = mgr->LoadConfigFile(filename);
60
        if (err != 0) {
Y
yudong.cai 已提交
61 62
            std::cerr << "Server failed to load config file: " << filename << std::endl;
            exit(1);
G
groot 已提交
63
        }
S
starlord 已提交
64
    } catch (YAML::Exception& e) {
Y
yudong.cai 已提交
65 66
        std::cerr << "Server failed to load config file: " << filename << std::endl;
        exit(1);
G
groot 已提交
67 68
    }

S
starlord 已提交
69
    return Status::OK();
G
groot 已提交
70 71
}

Y
yudong.cai 已提交
72 73 74 75 76 77 78
Status
Config::ValidateConfig() {
    Status s;

    /* server config */
    std::string server_addr;
    s = GetServerConfigAddress(server_addr);
S
starlord 已提交
79 80 81
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
82 83 84

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

    std::string server_mode;
Y
yudong.cai 已提交
90
    s = GetServerConfigDeployMode(server_mode);
S
starlord 已提交
91 92 93
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
94 95 96

    std::string server_time_zone;
    s = GetServerConfigTimeZone(server_time_zone);
S
starlord 已提交
97 98 99
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
100 101 102 103

    /* db config */
    std::string db_primary_path;
    s = GetDBConfigPrimaryPath(db_primary_path);
S
starlord 已提交
104 105 106
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
107 108 109

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

    std::string db_backend_url;
    s = GetDBConfigBackendUrl(db_backend_url);
S
starlord 已提交
116 117 118
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
119 120 121

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

    int32_t db_archive_days_threshold;
    s = GetDBConfigArchiveDaysThreshold(db_archive_days_threshold);
S
starlord 已提交
128 129 130
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
131 132 133

    int32_t db_insert_buffer_size;
    s = GetDBConfigInsertBufferSize(db_insert_buffer_size);
S
starlord 已提交
134 135 136
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
137 138 139

    int32_t db_build_index_gpu;
    s = GetDBConfigBuildIndexGPU(db_build_index_gpu);
S
starlord 已提交
140 141 142
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
143 144 145 146

    /* metric config */
    bool metric_enable_monitor;
    s = GetMetricConfigEnableMonitor(metric_enable_monitor);
S
starlord 已提交
147 148 149
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
150 151 152

    std::string metric_collector;
    s = GetMetricConfigCollector(metric_collector);
S
starlord 已提交
153 154 155
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
156 157 158

    std::string metric_prometheus_port;
    s = GetMetricConfigPrometheusPort(metric_prometheus_port);
S
starlord 已提交
159 160 161
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
162 163

    /* cache config */
W
wxyu 已提交
164
    int64_t cache_cpu_cache_capacity;
Y
yudong.cai 已提交
165
    s = GetCacheConfigCpuCacheCapacity(cache_cpu_cache_capacity);
S
starlord 已提交
166 167 168
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
169

Y
yudong.cai 已提交
170 171
    float cache_cpu_cache_threshold;
    s = GetCacheConfigCpuCacheThreshold(cache_cpu_cache_threshold);
S
starlord 已提交
172 173 174
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
175

W
wxyu 已提交
176
    int64_t cache_gpu_cache_capacity;
Y
yudong.cai 已提交
177
    s = GetCacheConfigGpuCacheCapacity(cache_gpu_cache_capacity);
S
starlord 已提交
178 179 180
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
181

Y
yudong.cai 已提交
182 183
    float cache_gpu_cache_threshold;
    s = GetCacheConfigGpuCacheThreshold(cache_gpu_cache_threshold);
S
starlord 已提交
184 185 186
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
187 188 189

    bool cache_insert_data;
    s = GetCacheConfigCacheInsertData(cache_insert_data);
S
starlord 已提交
190 191 192
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
193 194

    /* engine config */
Y
yudong.cai 已提交
195 196
    int32_t engine_use_blas_threshold;
    s = GetEngineConfigUseBlasThreshold(engine_use_blas_threshold);
S
starlord 已提交
197 198 199
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
200 201 202

    int32_t engine_omp_thread_num;
    s = GetEngineConfigOmpThreadNum(engine_omp_thread_num);
S
starlord 已提交
203 204 205
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
206 207 208 209

    /* resource config */
    std::string resource_mode;
    s = GetResourceConfigMode(resource_mode);
S
starlord 已提交
210 211 212
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
213 214 215

    std::vector<std::string> resource_pool;
    s = GetResourceConfigPool(resource_pool);
S
starlord 已提交
216 217 218
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
219 220 221 222

    return Status::OK();
}

Y
yudong.cai 已提交
223 224 225 226 227 228
Status
Config::ResetDefaultConfig() {
    Status s;

    /* server config */
    s = SetServerConfigAddress(CONFIG_SERVER_ADDRESS_DEFAULT);
S
starlord 已提交
229 230 231
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
232 233

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

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

    s = SetServerConfigTimeZone(CONFIG_SERVER_TIME_ZONE_DEFAULT);
S
starlord 已提交
244 245 246
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
247 248 249

    /* db config */
    s = SetDBConfigPrimaryPath(CONFIG_DB_PRIMARY_PATH_DEFAULT);
S
starlord 已提交
250 251 252
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
253 254

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

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

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

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

    s = SetDBConfigInsertBufferSize(CONFIG_DB_INSERT_BUFFER_SIZE_DEFAULT);
S
starlord 已提交
275 276 277
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
278 279

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

    /* metric config */
    s = SetMetricConfigEnableMonitor(CONFIG_METRIC_ENABLE_MONITOR_DEFAULT);
S
starlord 已提交
286 287 288
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
289 290

    s = SetMetricConfigCollector(CONFIG_METRIC_COLLECTOR_DEFAULT);
S
starlord 已提交
291 292 293
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
294 295

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

    /* cache config */
Y
yudong.cai 已提交
301
    s = SetCacheConfigCpuCacheCapacity(CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT);
S
starlord 已提交
302 303 304
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
305

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

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

Y
yudong.cai 已提交
316
    s = SetCacheConfigGpuCacheThreshold(CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT);
S
starlord 已提交
317 318 319
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
320 321

    s = SetCacheConfigCacheInsertData(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
S
starlord 已提交
322 323 324
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
325 326

    /* engine config */
Y
yudong.cai 已提交
327
    s = SetEngineConfigUseBlasThreshold(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
S
starlord 已提交
328 329 330
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
331 332

    s = SetEngineConfigOmpThreadNum(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
S
starlord 已提交
333 334 335
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
336 337 338

    /* resource config */
    s = SetResourceConfigMode(CONFIG_RESOURCE_MODE_DEFAULT);
S
starlord 已提交
339 340 341
    if (!s.ok()) {
        return s;
    }
Y
yudong.cai 已提交
342 343 344 345

    return Status::OK();
}

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

Y
yudong.cai 已提交
357 358 359 360 361 362 363 364 365 366 367
void
Config::PrintAll() {
    PrintConfigSection(CONFIG_SERVER);
    PrintConfigSection(CONFIG_DB);
    PrintConfigSection(CONFIG_CACHE);
    PrintConfigSection(CONFIG_METRIC);
    PrintConfigSection(CONFIG_ENGINE);
    PrintConfigSection(CONFIG_RESOURCE);
}

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

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

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

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

S
starlord 已提交
416
Status
S
starlord 已提交
417
Config::CheckDBConfigPrimaryPath(const std::string& value) {
Y
yudong.cai 已提交
418
    if (value.empty()) {
Y
yudong.cai 已提交
419
        return Status(SERVER_INVALID_ARGUMENT, "DB config primary_path empty");
Z
zhiru 已提交
420
    }
Y
yudong.cai 已提交
421 422
    return Status::OK();
}
Z
zhiru 已提交
423

Y
yudong.cai 已提交
424
Status
S
starlord 已提交
425
Config::CheckDBConfigSecondaryPath(const std::string& value) {
Y
yudong.cai 已提交
426 427 428
    return Status::OK();
}

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

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

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

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

Y
yudong.cai 已提交
468
Status
S
starlord 已提交
469
Config::CheckDBConfigBuildIndexGPU(const std::string& value) {
Y
yudong.cai 已提交
470 471
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid DB config build_index_gpu: " + value);
S
starlord 已提交
472
    } else {
Y
yudong.cai 已提交
473
        int32_t gpu_index = std::stoi(value);
S
starlord 已提交
474
        if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
Y
yudong.cai 已提交
475
            return Status(SERVER_INVALID_ARGUMENT, "Invalid DB config build_index_gpu: " + value);
S
starlord 已提交
476 477
        }
    }
Y
yudong.cai 已提交
478
    return Status::OK();
Z
zhiru 已提交
479 480
}

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

Y
yudong.cai 已提交
489
Status
S
starlord 已提交
490
Config::CheckMetricConfigCollector(const std::string& value) {
Y
yudong.cai 已提交
491 492 493 494 495 496
    if (value != "prometheus") {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config collector: " + value);
    }
    return Status::OK();
}

Y
yudong.cai 已提交
497
Status
S
starlord 已提交
498
Config::CheckMetricConfigPrometheusPort(const std::string& value) {
Y
yudong.cai 已提交
499 500
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config prometheus_port: " + value);
Z
zhiru 已提交
501
    }
Y
yudong.cai 已提交
502
    return Status::OK();
Z
zhiru 已提交
503 504
}

S
starlord 已提交
505
Status
S
starlord 已提交
506
Config::CheckCacheConfigCpuCacheCapacity(const std::string& value) {
Y
yudong.cai 已提交
507
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
Y
yudong.cai 已提交
508
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config cpu_cache_capacity: " + value);
509
    } else {
Y
yudong.cai 已提交
510
        uint64_t cpu_cache_capacity = std::stoi(value) * GB;
S
starlord 已提交
511
        uint64_t total_mem = 0, free_mem = 0;
Z
zhiru 已提交
512 513
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
        if (cpu_cache_capacity >= total_mem) {
Y
yudong.cai 已提交
514
            return Status(SERVER_INVALID_ARGUMENT, "Cache config cpu_cache_capacity exceed system memory: " + value);
S
starlord 已提交
515
        } else if (cpu_cache_capacity > static_cast<double>(total_mem * 0.9)) {
Y
yudong.cai 已提交
516
            std::cerr << "Warning: cpu_cache_capacity value is too big" << std::endl;
Z
zhiru 已提交
517
        }
518

Y
yudong.cai 已提交
519 520
        int32_t buffer_value;
        Status s = GetDBConfigInsertBufferSize(buffer_value);
S
starlord 已提交
521 522 523 524
        if (!s.ok()) {
            return s;
        }

Y
yudong.cai 已提交
525
        int64_t insert_buffer_size = buffer_value * GB;
Y
yudong.cai 已提交
526
        if (insert_buffer_size + cpu_cache_capacity >= total_mem) {
Y
yudong.cai 已提交
527
            return Status(SERVER_INVALID_ARGUMENT, "Sum of cpu_cache_capacity and buffer_size exceed system memory");
Z
zhiru 已提交
528 529
        }
    }
Y
yudong.cai 已提交
530 531
    return Status::OK();
}
Z
zhiru 已提交
532

Y
yudong.cai 已提交
533
Status
S
starlord 已提交
534
Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) {
Y
yudong.cai 已提交
535
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
Y
yudong.cai 已提交
536
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config cpu_cache_threshold: " + value);
Y
yudong.cai 已提交
537
    } else {
Y
yudong.cai 已提交
538 539 540
        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 已提交
541
        }
542
    }
Y
yudong.cai 已提交
543 544
    return Status::OK();
}
545

Y
yudong.cai 已提交
546
Status
S
starlord 已提交
547
Config::CheckCacheConfigGpuCacheCapacity(const std::string& value) {
Y
yudong.cai 已提交
548
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
Y
yudong.cai 已提交
549
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config gpu_cache_capacity: " + value);
550
    } else {
Y
yudong.cai 已提交
551 552 553
        uint64_t gpu_cache_capacity = std::stoi(value) * GB;
        int gpu_index;
        Status s = GetDBConfigBuildIndexGPU(gpu_index);
S
starlord 已提交
554 555 556 557
        if (!s.ok()) {
            return s;
        }

Z
zhiru 已提交
558
        size_t gpu_memory;
S
starlord 已提交
559
        if (!ValidationUtil::GetGpuMemory(gpu_index, gpu_memory).ok()) {
Y
yudong.cai 已提交
560 561
            return Status(SERVER_UNEXPECTED_ERROR,
                          "Fail to get GPU memory for GPU device: " + std::to_string(gpu_index));
562
        } else if (gpu_cache_capacity >= gpu_memory) {
Y
yudong.cai 已提交
563
            return Status(SERVER_INVALID_ARGUMENT,
Y
yudong.cai 已提交
564
                          "Cache config gpu_cache_capacity exceed GPU memory: " + std::to_string(gpu_memory));
S
starlord 已提交
565
        } else if (gpu_cache_capacity > (double)gpu_memory * 0.9) {
Y
yudong.cai 已提交
566
            std::cerr << "Warning: gpu_cache_capacity value is too big" << std::endl;
Z
zhiru 已提交
567 568
        }
    }
Y
yudong.cai 已提交
569 570
    return Status::OK();
}
Z
zhiru 已提交
571

Y
yudong.cai 已提交
572
Status
S
starlord 已提交
573
Config::CheckCacheConfigGpuCacheThreshold(const std::string& value) {
Y
yudong.cai 已提交
574
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
Y
yudong.cai 已提交
575
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config gpu_cache_threshold: " + value);
Y
yudong.cai 已提交
576
    } else {
Y
yudong.cai 已提交
577 578 579
        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 已提交
580
        }
Z
zhiru 已提交
581
    }
Y
yudong.cai 已提交
582 583
    return Status::OK();
}
Z
zhiru 已提交
584

Y
yudong.cai 已提交
585
Status
S
starlord 已提交
586
Config::CheckCacheConfigCacheInsertData(const std::string& value) {
Y
yudong.cai 已提交
587 588 589 590
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid cache config cache_insert_data: " + value);
    }
    return Status::OK();
Z
zhiru 已提交
591 592
}

S
starlord 已提交
593
Status
S
starlord 已提交
594
Config::CheckEngineConfigUseBlasThreshold(const std::string& value) {
Y
yudong.cai 已提交
595
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
Y
yudong.cai 已提交
596
        return Status(SERVER_INVALID_ARGUMENT, "Invalid engine config use_blas_threshold: " + value);
Z
zhiru 已提交
597
    }
Y
yudong.cai 已提交
598 599
    return Status::OK();
}
Z
zhiru 已提交
600

Y
yudong.cai 已提交
601
Status
S
starlord 已提交
602
Config::CheckEngineConfigOmpThreadNum(const std::string& value) {
Y
yudong.cai 已提交
603 604
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid engine config omp_thread_num: " + value);
S
starlord 已提交
605 606 607 608 609 610 611
    }

    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 已提交
612
    }
Y
yudong.cai 已提交
613
    return Status::OK();
Z
zhiru 已提交
614 615
}

S
starlord 已提交
616
Status
S
starlord 已提交
617
Config::CheckResourceConfigMode(const std::string& value) {
Y
yudong.cai 已提交
618 619
    if (value != "simple") {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid resource config mode: " + value);
W
wxyu 已提交
620
    }
Y
yudong.cai 已提交
621 622
    return Status::OK();
}
623

Y
yudong.cai 已提交
624
Status
S
starlord 已提交
625
Config::CheckResourceConfigPool(const std::vector<std::string>& value) {
Y
yudong.cai 已提交
626 627
    if (value.empty()) {
        return Status(SERVER_INVALID_ARGUMENT, "Invalid resource config pool");
G
groot 已提交
628
    }
Y
yudong.cai 已提交
629
    return Status::OK();
G
groot 已提交
630 631
}

Y
yudong.cai 已提交
632
////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
633 634 635 636
ConfigNode&
Config::GetConfigNode(const std::string& name) {
    ConfigMgr* mgr = ConfigMgr::GetInstance();
    ConfigNode& root_node = mgr->GetRootNode();
G
groot 已提交
637
    return root_node.GetChild(name);
G
groot 已提交
638 639
}

Y
yudong.cai 已提交
640
Status
S
starlord 已提交
641
Config::GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value) {
Y
yudong.cai 已提交
642
    std::lock_guard<std::mutex> lock(mutex_);
Y
yudong.cai 已提交
643 644 645 646 647
    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 已提交
648
    return Status(SERVER_UNEXPECTED_ERROR, "key not exist");
Y
yudong.cai 已提交
649 650
}

Y
yudong.cai 已提交
651
void
S
starlord 已提交
652
Config::SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value) {
Y
yudong.cai 已提交
653 654 655 656 657
    std::lock_guard<std::mutex> lock(mutex_);
    config_map_[parent_key][child_key] = value;
}

////////////////////////////////////////////////////////////////////////////////
Y
yudong.cai 已提交
658
std::string
S
starlord 已提交
659
Config::GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value) {
Y
yudong.cai 已提交
660
    std::string value;
S
starlord 已提交
661 662 663
    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 已提交
664
    }
Y
yudong.cai 已提交
665
    return value;
Y
yudong.cai 已提交
666 667
}

668
Status
S
starlord 已提交
669
Config::GetServerConfigAddress(std::string& value) {
S
starlord 已提交
670
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, CONFIG_SERVER_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
671
    return CheckServerConfigAddress(value);
672 673 674
}

Status
S
starlord 已提交
675
Config::GetServerConfigPort(std::string& value) {
S
starlord 已提交
676
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_PORT, CONFIG_SERVER_PORT_DEFAULT);
Y
yudong.cai 已提交
677
    return CheckServerConfigPort(value);
678 679 680
}

Status
S
starlord 已提交
681
Config::GetServerConfigDeployMode(std::string& value) {
S
starlord 已提交
682
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, CONFIG_SERVER_DEPLOY_MODE_DEFAULT);
Y
yudong.cai 已提交
683
    return CheckServerConfigDeployMode(value);
684 685 686
}

Status
S
starlord 已提交
687
Config::GetServerConfigTimeZone(std::string& value) {
S
starlord 已提交
688
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, CONFIG_SERVER_TIME_ZONE_DEFAULT);
Y
yudong.cai 已提交
689
    return CheckServerConfigTimeZone(value);
690 691 692
}

Status
S
starlord 已提交
693
Config::GetDBConfigPrimaryPath(std::string& value) {
S
starlord 已提交
694
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_PRIMARY_PATH, CONFIG_DB_PRIMARY_PATH_DEFAULT);
Y
yudong.cai 已提交
695
    return CheckDBConfigPrimaryPath(value);
696 697 698
}

Status
S
starlord 已提交
699
Config::GetDBConfigSecondaryPath(std::string& value) {
S
starlord 已提交
700
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_SECONDARY_PATH, CONFIG_DB_SECONDARY_PATH_DEFAULT);
Y
yudong.cai 已提交
701
    return Status::OK();
702 703 704
}

Status
S
starlord 已提交
705
Config::GetDBConfigBackendUrl(std::string& value) {
S
starlord 已提交
706
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_BACKEND_URL, CONFIG_DB_BACKEND_URL_DEFAULT);
Y
yudong.cai 已提交
707
    return CheckDBConfigBackendUrl(value);
708 709 710
}

Status
S
starlord 已提交
711
Config::GetDBConfigArchiveDiskThreshold(int32_t& value) {
S
starlord 已提交
712 713
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT);
Y
yudong.cai 已提交
714
    Status s = CheckDBConfigArchiveDiskThreshold(str);
S
starlord 已提交
715 716 717 718
    if (!s.ok()) {
        return s;
    }

719 720 721 722 723
    value = std::stoi(str);
    return Status::OK();
}

Status
S
starlord 已提交
724
Config::GetDBConfigArchiveDaysThreshold(int32_t& value) {
S
starlord 已提交
725 726
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT);
Y
yudong.cai 已提交
727
    Status s = CheckDBConfigArchiveDaysThreshold(str);
S
starlord 已提交
728 729 730 731
    if (!s.ok()) {
        return s;
    }

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

Status
S
starlord 已提交
737
Config::GetDBConfigInsertBufferSize(int32_t& value) {
738
    std::string str = GetConfigStr(CONFIG_DB, CONFIG_DB_INSERT_BUFFER_SIZE, CONFIG_DB_INSERT_BUFFER_SIZE_DEFAULT);
Y
yudong.cai 已提交
739
    Status s = CheckDBConfigInsertBufferSize(str);
S
starlord 已提交
740 741 742 743
    if (!s.ok()) {
        return s;
    }

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

Status
S
starlord 已提交
749
Config::GetDBConfigBuildIndexGPU(int32_t& value) {
750
    std::string str = GetConfigStr(CONFIG_DB, CONFIG_DB_BUILD_INDEX_GPU, CONFIG_DB_BUILD_INDEX_GPU_DEFAULT);
Y
yudong.cai 已提交
751
    Status s = CheckDBConfigBuildIndexGPU(str);
S
starlord 已提交
752 753 754 755
    if (!s.ok()) {
        return s;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Status
S
starlord 已提交
889
Config::GetResourceConfigPool(std::vector<std::string>& value) {
890 891
    ConfigNode resource_config = GetConfigNode(CONFIG_RESOURCE);
    value = resource_config.GetSequence(CONFIG_RESOURCE_POOL);
Y
yudong.cai 已提交
892
    return CheckResourceConfigPool(value);
Y
yudong.cai 已提交
893
}
G
groot 已提交
894

Y
yudong.cai 已提交
895 896 897
///////////////////////////////////////////////////////////////////////////////
/* server config */
Status
S
starlord 已提交
898
Config::SetServerConfigAddress(const std::string& value) {
Y
yudong.cai 已提交
899
    Status s = CheckServerConfigAddress(value);
S
starlord 已提交
900 901 902 903
    if (!s.ok()) {
        return s;
    }

Y
yudong.cai 已提交
904 905 906 907 908
    SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
    return Status::OK();
}

Status
S
starlord 已提交
909
Config::SetServerConfigPort(const std::string& value) {
Y
yudong.cai 已提交
910
    Status s = CheckServerConfigPort(value);
S
starlord 已提交
911 912 913 914
    if (!s.ok()) {
        return s;
    }

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

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

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

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

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

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

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

Status
S
starlord 已提交
954
Config::SetDBConfigSecondaryPath(const std::string& value) {
Y
yudong.cai 已提交
955
    Status s = CheckDBConfigSecondaryPath(value);
S
starlord 已提交
956 957 958 959
    if (!s.ok()) {
        return s;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

S
starlord 已提交
1144 1145
}  // namespace server
}  // namespace milvus