Config.cpp 98.4 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
2
//
3 4
// Licensed 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
J
jinhai 已提交
5
//
6 7 8 9 10
// 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.
J
jinhai 已提交
11

G
groot 已提交
12
#include <sys/stat.h>
13
#include <unistd.h>
T
Tinkerrr 已提交
14

Y
yudong.cai 已提交
15
#include <algorithm>
16
#include <chrono>
17
#include <fstream>
S
starlord 已提交
18
#include <iostream>
19
#include <regex>
S
starlord 已提交
20
#include <string>
21
#include <thread>
22
#include <unordered_map>
B
BossZou 已提交
23
#include <unordered_set>
S
starlord 已提交
24
#include <vector>
G
groot 已提交
25

26 27
#include <fiu-local.h>

28
#include "config/Config.h"
29
#include "config/YamlConfigMgr.h"
30
#include "server/DBWrapper.h"
31
#include "thirdparty/nlohmann/json.hpp"
32
#include "utils/CommonUtil.h"
33
#include "utils/Log.h"
Z
Zhiru Zhu 已提交
34
#include "utils/StringHelpFunctions.h"
35
#include "utils/ValidationUtil.h"
G
groot 已提交
36

J
jinhai 已提交
37
namespace milvus {
G
groot 已提交
38 39
namespace server {

40 41 42 43 44 45 46 47 48 49 50 51 52
const char* CONFIG_NODE_DELIMITER = ".";
const char* CONFIG_VERSION = "version";

/* server config */
const char* CONFIG_SERVER = "server_config";
const char* CONFIG_SERVER_ADDRESS = "address";
const char* CONFIG_SERVER_ADDRESS_DEFAULT = "127.0.0.1";
const char* CONFIG_SERVER_PORT = "port";
const char* CONFIG_SERVER_PORT_DEFAULT = "19530";
const char* CONFIG_SERVER_DEPLOY_MODE = "deploy_mode";
const char* CONFIG_SERVER_DEPLOY_MODE_DEFAULT = "single";
const char* CONFIG_SERVER_TIME_ZONE = "time_zone";
const char* CONFIG_SERVER_TIME_ZONE_DEFAULT = "UTC+8";
53 54
const char* CONFIG_SERVER_WEB_ENABLE = "web_enable";
const char* CONFIG_SERVER_WEB_ENABLE_DEFAULT = "true";
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
const char* CONFIG_SERVER_WEB_PORT = "web_port";
const char* CONFIG_SERVER_WEB_PORT_DEFAULT = "19121";

/* db config */
const char* CONFIG_DB = "db_config";
const char* CONFIG_DB_BACKEND_URL = "backend_url";
const char* CONFIG_DB_BACKEND_URL_DEFAULT = "sqlite://:@:/";
const char* CONFIG_DB_ARCHIVE_DISK_THRESHOLD = "archive_disk_threshold";
const char* CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT = "0";
const char* CONFIG_DB_ARCHIVE_DAYS_THRESHOLD = "archive_days_threshold";
const char* CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT = "0";
const char* CONFIG_DB_PRELOAD_COLLECTION = "preload_collection";
const char* CONFIG_DB_PRELOAD_COLLECTION_DEFAULT = "";
const char* CONFIG_DB_AUTO_FLUSH_INTERVAL = "auto_flush_interval";
const char* CONFIG_DB_AUTO_FLUSH_INTERVAL_DEFAULT = "1";

/* storage config */
const char* CONFIG_STORAGE = "storage_config";
const char* CONFIG_STORAGE_PRIMARY_PATH = "primary_path";
const char* CONFIG_STORAGE_PRIMARY_PATH_DEFAULT = "/tmp/milvus";
const char* CONFIG_STORAGE_SECONDARY_PATH = "secondary_path";
const char* CONFIG_STORAGE_SECONDARY_PATH_DEFAULT = "";
G
groot 已提交
77 78
const char* CONFIG_STORAGE_FILE_CLEANUP_TIMEOUT = "file_cleanup_timeout";
const char* CONFIG_STORAGE_FILE_CLEANUP_TIMEOUT_DEFAULT = "10";
C
Cai Yudong 已提交
79 80 81 82 83 84 85 86 87 88 89 90
// const char* CONFIG_STORAGE_S3_ENABLE = "s3_enable";
// const char* CONFIG_STORAGE_S3_ENABLE_DEFAULT = "false";
// const char* CONFIG_STORAGE_S3_ADDRESS = "s3_address";
// const char* CONFIG_STORAGE_S3_ADDRESS_DEFAULT = "127.0.0.1";
// const char* CONFIG_STORAGE_S3_PORT = "s3_port";
// const char* CONFIG_STORAGE_S3_PORT_DEFAULT = "9000";
// const char* CONFIG_STORAGE_S3_ACCESS_KEY = "s3_access_key";
// const char* CONFIG_STORAGE_S3_ACCESS_KEY_DEFAULT = "minioadmin";
// const char* CONFIG_STORAGE_S3_SECRET_KEY = "s3_secret_key";
// const char* CONFIG_STORAGE_S3_SECRET_KEY_DEFAULT = "minioadmin";
// const char* CONFIG_STORAGE_S3_BUCKET = "s3_bucket";
// const char* CONFIG_STORAGE_S3_BUCKET_DEFAULT = "milvus-bucket";
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

/* cache config */
const char* CONFIG_CACHE = "cache_config";
const char* CONFIG_CACHE_CPU_CACHE_CAPACITY = "cpu_cache_capacity";
const char* CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT = "4";
const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD = "cpu_cache_threshold";
const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT = "0.7";
const char* CONFIG_CACHE_INSERT_BUFFER_SIZE = "insert_buffer_size";
const char* CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT = "1";
const char* CONFIG_CACHE_CACHE_INSERT_DATA = "cache_insert_data";
const char* CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT = "false";

/* metric config */
const char* CONFIG_METRIC = "metric_config";
const char* CONFIG_METRIC_ENABLE_MONITOR = "enable_monitor";
const char* CONFIG_METRIC_ENABLE_MONITOR_DEFAULT = "false";
const char* CONFIG_METRIC_ADDRESS = "address";
const char* CONFIG_METRIC_ADDRESS_DEFAULT = "127.0.0.1";
const char* CONFIG_METRIC_PORT = "port";
const char* CONFIG_METRIC_PORT_DEFAULT = "9091";
111

112 113 114 115 116 117
/* engine config */
const char* CONFIG_ENGINE = "engine_config";
const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD = "use_blas_threshold";
const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT = "1100";
const char* CONFIG_ENGINE_OMP_THREAD_NUM = "omp_thread_num";
const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT = "0";
F
feisiyicl 已提交
118 119
const char* CONFIG_ENGINE_SIMD_TYPE = "simd_type";
const char* CONFIG_ENGINE_SIMD_TYPE_DEFAULT = "auto";
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD = "gpu_search_threshold";
const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT = "1000";

/* gpu resource config */
const char* CONFIG_GPU_RESOURCE = "gpu_resource_config";
const char* CONFIG_GPU_RESOURCE_ENABLE = "enable";
#ifdef MILVUS_GPU_VERSION
const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "true";
#else
const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "false";
#endif
const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY = "cache_capacity";
const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT = "1";
const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD = "cache_threshold";
const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT = "0.7";
const char* CONFIG_GPU_RESOURCE_DELIMITER = ",";
const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES = "search_resources";
const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT = "gpu0";
const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES = "build_index_resources";
const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT = "gpu0";

/* tracing config */
const char* CONFIG_TRACING = "tracing_config";
const char* CONFIG_TRACING_JSON_CONFIG_PATH = "json_config_path";

/* wal config */
const char* CONFIG_WAL = "wal_config";
const char* CONFIG_WAL_ENABLE = "enable";
const char* CONFIG_WAL_ENABLE_DEFAULT = "true";
const char* CONFIG_WAL_RECOVERY_ERROR_IGNORE = "recovery_error_ignore";
const char* CONFIG_WAL_RECOVERY_ERROR_IGNORE_DEFAULT = "true";
const char* CONFIG_WAL_BUFFER_SIZE = "buffer_size";
const char* CONFIG_WAL_BUFFER_SIZE_DEFAULT = "256";
const int64_t CONFIG_WAL_BUFFER_SIZE_MAX = 4096;
const int64_t CONFIG_WAL_BUFFER_SIZE_MIN = 64;
const char* CONFIG_WAL_WAL_PATH = "wal_path";
const char* CONFIG_WAL_WAL_PATH_DEFAULT = "/tmp/milvus/wal";

W
Wang XiangYu 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
/* logs config */
const char* CONFIG_LOGS = "logs";
const char* CONFIG_LOGS_TRACE_ENABLE = "trace.enable";
const char* CONFIG_LOGS_TRACE_ENABLE_DEFAULT = "true";
const char* CONFIG_LOGS_DEBUG_ENABLE = "debug.enable";
const char* CONFIG_LOGS_DEBUG_ENABLE_DEFAULT = "true";
const char* CONFIG_LOGS_INFO_ENABLE = "info.enable";
const char* CONFIG_LOGS_INFO_ENABLE_DEFAULT = "true";
const char* CONFIG_LOGS_WARNING_ENABLE = "warning.enable";
const char* CONFIG_LOGS_WARNING_ENABLE_DEFAULT = "true";
const char* CONFIG_LOGS_ERROR_ENABLE = "error.enable";
const char* CONFIG_LOGS_ERROR_ENABLE_DEFAULT = "true";
const char* CONFIG_LOGS_FATAL_ENABLE = "fatal.enable";
const char* CONFIG_LOGS_FATAL_ENABLE_DEFAULT = "true";
const char* CONFIG_LOGS_PATH = "path";
const char* CONFIG_LOGS_PATH_DEFAULT = "/tmp/milvus/logs";
W
Wang XiangYu 已提交
174 175 176 177 178 179 180 181
const char* CONFIG_LOGS_MAX_LOG_FILE_SIZE = "max_log_file_size";
const char* CONFIG_LOGS_MAX_LOG_FILE_SIZE_DEFAULT = "256";
const int64_t CONFIG_LOGS_MAX_LOG_FILE_SIZE_MAX = 512;
const int64_t CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN = 64;
const char* CONFIG_LOGS_DELETE_EXCEEDS = "delete_exceeds";
const char* CONFIG_LOGS_DELETE_EXCEEDS_DEFAULT = "10";
const int64_t CONFIG_LOGS_DELETE_EXCEEDS_MAX = 4096;
const int64_t CONFIG_LOGS_DELETE_EXCEEDS_MIN = 1;
W
Wang XiangYu 已提交
182

183
constexpr int64_t GB = 1UL << 30;
J
Jin Hai 已提交
184 185 186
constexpr int32_t PORT_NUMBER_MIN = 1024;
constexpr int32_t PORT_NUMBER_MAX = 65535;

187 188
static const std::unordered_map<std::string, std::string> milvus_config_version_map(
    {{"0.6.0", "0.1"}, {"0.7.0", "0.2"}, {"0.7.1", "0.2"}, {"0.8.0", "0.3"}});
189

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/////////////////////////////////////////////////////////////
Config::Config() {
    auto empty_map = std::unordered_map<std::string, ConfigCallBackF>();

    // cache config
    std::string node_cpu_cache_capacity = std::string(CONFIG_CACHE) + "." + CONFIG_CACHE_CPU_CACHE_CAPACITY;
    config_callback_[node_cpu_cache_capacity] = empty_map;

    std::string node_insert_buffer_size = std::string(CONFIG_CACHE) + "." + CONFIG_CACHE_INSERT_BUFFER_SIZE;
    config_callback_[node_insert_buffer_size] = empty_map;

    std::string node_cache_insert_data = std::string(CONFIG_CACHE) + "." + CONFIG_CACHE_CACHE_INSERT_DATA;
    config_callback_[node_cache_insert_data] = empty_map;

    // engine config
    std::string node_blas_threshold = std::string(CONFIG_ENGINE) + "." + CONFIG_ENGINE_USE_BLAS_THRESHOLD;
    config_callback_[node_blas_threshold] = empty_map;

    // gpu resources config
    std::string node_gpu_search_threshold = std::string(CONFIG_ENGINE) + "." + CONFIG_ENGINE_GPU_SEARCH_THRESHOLD;
    config_callback_[node_gpu_search_threshold] = empty_map;

    std::string node_gpu_enable = std::string(CONFIG_GPU_RESOURCE) + "." + CONFIG_GPU_RESOURCE_ENABLE;
    config_callback_[node_gpu_enable] = empty_map;

    std::string node_gpu_cache_capacity = std::string(CONFIG_GPU_RESOURCE) + "." + CONFIG_GPU_RESOURCE_CACHE_CAPACITY;
    config_callback_[node_gpu_cache_capacity] = empty_map;

    std::string node_gpu_search_res = std::string(CONFIG_GPU_RESOURCE) + "." + CONFIG_GPU_RESOURCE_SEARCH_RESOURCES;
    config_callback_[node_gpu_search_res] = empty_map;

    std::string node_gpu_build_res = std::string(CONFIG_GPU_RESOURCE) + "." + CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES;
    config_callback_[node_gpu_build_res] = empty_map;
}

S
starlord 已提交
225
Config&
226 227 228
Config::GetInstance() {
    static Config config_inst;
    return config_inst;
G
groot 已提交
229 230
}

S
starlord 已提交
231
Status
S
starlord 已提交
232
Config::LoadConfigFile(const std::string& filename) {
233
    if (filename.empty()) {
234
        return Status(SERVER_UNEXPECTED_ERROR, "No specified config file");
G
groot 已提交
235
    }
236 237 238 239 240

    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 已提交
241 242
    }

S
shengjh 已提交
243
    ConfigMgr* mgr = YamlConfigMgr::GetInstance();
C
Cai Yudong 已提交
244
    STATUS_CHECK(mgr->LoadConfigFile(filename));
G
groot 已提交
245

246 247 248
    // store config file path
    config_file_ = filename;

S
starlord 已提交
249
    return Status::OK();
G
groot 已提交
250 251
}

Y
yudong.cai 已提交
252 253
Status
Config::ValidateConfig() {
254
    std::string config_version;
C
Cai Yudong 已提交
255
    STATUS_CHECK(GetConfigVersion(config_version));
256

Y
yudong.cai 已提交
257 258
    /* server config */
    std::string server_addr;
C
Cai Yudong 已提交
259
    STATUS_CHECK(GetServerConfigAddress(server_addr));
Y
yudong.cai 已提交
260 261

    std::string server_port;
C
Cai Yudong 已提交
262
    STATUS_CHECK(GetServerConfigPort(server_port));
Y
yudong.cai 已提交
263 264

    std::string server_mode;
C
Cai Yudong 已提交
265
    STATUS_CHECK(GetServerConfigDeployMode(server_mode));
Y
yudong.cai 已提交
266 267

    std::string server_time_zone;
C
Cai Yudong 已提交
268
    STATUS_CHECK(GetServerConfigTimeZone(server_time_zone));
Y
yudong.cai 已提交
269

270
    bool server_web_enable;
C
Cai Yudong 已提交
271
    STATUS_CHECK(GetServerConfigWebEnable(server_web_enable));
272

B
BossZou 已提交
273
    std::string server_web_port;
C
Cai Yudong 已提交
274
    STATUS_CHECK(GetServerConfigWebPort(server_web_port));
B
BossZou 已提交
275

Y
yudong.cai 已提交
276 277
    /* db config */
    std::string db_backend_url;
C
Cai Yudong 已提交
278
    STATUS_CHECK(GetDBConfigBackendUrl(db_backend_url));
Y
yudong.cai 已提交
279

280
    std::string db_preload_collection;
C
Cai Yudong 已提交
281
    STATUS_CHECK(GetDBConfigPreloadCollection(db_preload_collection));
282

Y
yudong.cai 已提交
283
    int64_t db_archive_disk_threshold;
C
Cai Yudong 已提交
284
    STATUS_CHECK(GetDBConfigArchiveDiskThreshold(db_archive_disk_threshold));
Y
yudong.cai 已提交
285

Y
yudong.cai 已提交
286
    int64_t db_archive_days_threshold;
C
Cai Yudong 已提交
287
    STATUS_CHECK(GetDBConfigArchiveDaysThreshold(db_archive_days_threshold));
Y
yudong.cai 已提交
288

C
Cai Yudong 已提交
289
    int64_t auto_flush_interval;
C
Cai Yudong 已提交
290
    STATUS_CHECK(GetDBConfigAutoFlushInterval(auto_flush_interval));
291

C
Cai Yudong 已提交
292
    /* storage config */
293
    std::string storage_primary_path;
C
Cai Yudong 已提交
294
    STATUS_CHECK(GetStorageConfigPrimaryPath(storage_primary_path));
295 296

    std::string storage_secondary_path;
C
Cai Yudong 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
    STATUS_CHECK(GetStorageConfigSecondaryPath(storage_secondary_path));

    // bool storage_s3_enable;
    // STATUS_CHECK(GetStorageConfigS3Enable(storage_s3_enable));
    // // std::cout << "S3 " << (storage_s3_enable ? "ENABLED !" : "DISABLED !") << std::endl;
    //
    // std::string storage_s3_address;
    // STATUS_CHECK(GetStorageConfigS3Address(storage_s3_address));
    //
    // std::string storage_s3_port;
    // STATUS_CHECK(GetStorageConfigS3Port(storage_s3_port));
    //
    // std::string storage_s3_access_key;
    // STATUS_CHECK(GetStorageConfigS3AccessKey(storage_s3_access_key));
    //
    // std::string storage_s3_secret_key;
    // STATUS_CHECK(GetStorageConfigS3SecretKey(storage_s3_secret_key));
    //
    // std::string storage_s3_bucket;
    // STATUS_CHECK(GetStorageConfigS3Bucket(storage_s3_bucket));
Y
yudong.cai 已提交
317 318 319

    /* metric config */
    bool metric_enable_monitor;
C
Cai Yudong 已提交
320
    STATUS_CHECK(GetMetricConfigEnableMonitor(metric_enable_monitor));
Y
yudong.cai 已提交
321

C
Cai Yudong 已提交
322
    std::string metric_address;
C
Cai Yudong 已提交
323
    STATUS_CHECK(GetMetricConfigAddress(metric_address));
Y
yudong.cai 已提交
324

C
Cai Yudong 已提交
325
    std::string metric_port;
C
Cai Yudong 已提交
326
    STATUS_CHECK(GetMetricConfigPort(metric_port));
Y
yudong.cai 已提交
327 328

    /* cache config */
W
wxyu 已提交
329
    int64_t cache_cpu_cache_capacity;
C
Cai Yudong 已提交
330
    STATUS_CHECK(GetCacheConfigCpuCacheCapacity(cache_cpu_cache_capacity));
Y
yudong.cai 已提交
331

Y
yudong.cai 已提交
332
    float cache_cpu_cache_threshold;
C
Cai Yudong 已提交
333
    STATUS_CHECK(GetCacheConfigCpuCacheThreshold(cache_cpu_cache_threshold));
Y
yudong.cai 已提交
334

335
    int64_t cache_insert_buffer_size;
C
Cai Yudong 已提交
336
    STATUS_CHECK(GetCacheConfigInsertBufferSize(cache_insert_buffer_size));
337

Y
yudong.cai 已提交
338
    bool cache_insert_data;
C
Cai Yudong 已提交
339
    STATUS_CHECK(GetCacheConfigCacheInsertData(cache_insert_data));
Y
yudong.cai 已提交
340 341

    /* engine config */
Y
yudong.cai 已提交
342
    int64_t engine_use_blas_threshold;
C
Cai Yudong 已提交
343
    STATUS_CHECK(GetEngineConfigUseBlasThreshold(engine_use_blas_threshold));
Y
yudong.cai 已提交
344

Y
yudong.cai 已提交
345
    int64_t engine_omp_thread_num;
C
Cai Yudong 已提交
346
    STATUS_CHECK(GetEngineConfigOmpThreadNum(engine_omp_thread_num));
Y
yudong.cai 已提交
347

F
feisiyicl 已提交
348
    std::string engine_simd_type;
C
Cai Yudong 已提交
349
    STATUS_CHECK(GetEngineConfigSimdType(engine_simd_type));
C
Cai Yudong 已提交
350

G
groot 已提交
351
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
352
    int64_t engine_gpu_search_threshold;
C
Cai Yudong 已提交
353
    STATUS_CHECK(GetEngineConfigGpuSearchThreshold(engine_gpu_search_threshold));
C
Cai Yudong 已提交
354
#endif
W
wxyu 已提交
355

Y
yudong.cai 已提交
356
    /* gpu resource config */
C
Cai Yudong 已提交
357
#ifdef MILVUS_GPU_VERSION
358
    bool gpu_resource_enable;
C
Cai Yudong 已提交
359
    STATUS_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
360
    std::cout << "GPU resources " << (gpu_resource_enable ? "ENABLED !" : "DISABLED !") << std::endl;
C
Cai Yudong 已提交
361

362 363
    if (gpu_resource_enable) {
        int64_t resource_cache_capacity;
C
Cai Yudong 已提交
364
        STATUS_CHECK(GetGpuResourceConfigCacheCapacity(resource_cache_capacity));
Y
yudong.cai 已提交
365

366
        float resource_cache_threshold;
C
Cai Yudong 已提交
367
        STATUS_CHECK(GetGpuResourceConfigCacheThreshold(resource_cache_threshold));
Y
yudong.cai 已提交
368

369
        std::vector<int64_t> search_resources;
C
Cai Yudong 已提交
370
        STATUS_CHECK(GetGpuResourceConfigSearchResources(search_resources));
371

372
        std::vector<int64_t> index_build_resources;
C
Cai Yudong 已提交
373
        STATUS_CHECK(GetGpuResourceConfigBuildIndexResources(index_build_resources));
S
starlord 已提交
374
    }
Y
yudong.cai 已提交
375
#endif
Y
yudong.cai 已提交
376

Z
Zhiru Zhu 已提交
377 378
    /* tracing config */
    std::string tracing_config_path;
C
Cai Yudong 已提交
379
    STATUS_CHECK(GetTracingConfigJsonConfigPath(tracing_config_path));
Z
Zhiru Zhu 已提交
380

381 382
    /* wal config */
    bool enable;
C
Cai Yudong 已提交
383
    STATUS_CHECK(GetWalConfigEnable(enable));
384 385

    bool recovery_error_ignore;
C
Cai Yudong 已提交
386
    STATUS_CHECK(GetWalConfigRecoveryErrorIgnore(recovery_error_ignore));
387

C
Cai Yudong 已提交
388
    int64_t buffer_size;
C
Cai Yudong 已提交
389
    STATUS_CHECK(GetWalConfigBufferSize(buffer_size));
390 391

    std::string wal_path;
C
Cai Yudong 已提交
392
    STATUS_CHECK(GetWalConfigWalPath(wal_path));
393

W
Wang XiangYu 已提交
394 395
    /* logs config */
    bool trace_enable;
C
Cai Yudong 已提交
396
    STATUS_CHECK(GetLogsTraceEnable(trace_enable));
W
Wang XiangYu 已提交
397 398

    bool debug_enable;
C
Cai Yudong 已提交
399
    STATUS_CHECK(GetLogsDebugEnable(trace_enable));
W
Wang XiangYu 已提交
400 401

    bool info_enable;
C
Cai Yudong 已提交
402
    STATUS_CHECK(GetLogsInfoEnable(trace_enable));
W
Wang XiangYu 已提交
403 404

    bool warning_enable;
C
Cai Yudong 已提交
405
    STATUS_CHECK(GetLogsWarningEnable(trace_enable));
W
Wang XiangYu 已提交
406 407

    bool error_enable;
C
Cai Yudong 已提交
408
    STATUS_CHECK(GetLogsErrorEnable(trace_enable));
W
Wang XiangYu 已提交
409 410

    bool fatal_enable;
C
Cai Yudong 已提交
411
    STATUS_CHECK(GetLogsFatalEnable(trace_enable));
W
Wang XiangYu 已提交
412 413

    std::string logs_path;
C
Cai Yudong 已提交
414
    STATUS_CHECK(GetLogsPath(logs_path));
W
Wang XiangYu 已提交
415

W
Wang XiangYu 已提交
416
    int64_t logs_max_log_file_size;
C
Cai Yudong 已提交
417
    STATUS_CHECK(GetLogsMaxLogFileSize(logs_max_log_file_size));
W
Wang XiangYu 已提交
418 419

    int64_t delete_exceeds;
C
Cai Yudong 已提交
420
    STATUS_CHECK(GetLogsDeleteExceeds(delete_exceeds));
W
Wang XiangYu 已提交
421

Y
yudong.cai 已提交
422 423 424
    return Status::OK();
}

Y
yudong.cai 已提交
425 426 427
Status
Config::ResetDefaultConfig() {
    /* server config */
C
Cai Yudong 已提交
428 429 430 431 432 433
    STATUS_CHECK(SetServerConfigAddress(CONFIG_SERVER_ADDRESS_DEFAULT));
    STATUS_CHECK(SetServerConfigPort(CONFIG_SERVER_PORT_DEFAULT));
    STATUS_CHECK(SetServerConfigDeployMode(CONFIG_SERVER_DEPLOY_MODE_DEFAULT));
    STATUS_CHECK(SetServerConfigTimeZone(CONFIG_SERVER_TIME_ZONE_DEFAULT));
    STATUS_CHECK(SetServerConfigWebEnable(CONFIG_SERVER_WEB_ENABLE_DEFAULT));
    STATUS_CHECK(SetServerConfigWebPort(CONFIG_SERVER_WEB_PORT_DEFAULT));
Y
yudong.cai 已提交
434 435

    /* db config */
C
Cai Yudong 已提交
436 437 438 439 440
    STATUS_CHECK(SetDBConfigBackendUrl(CONFIG_DB_BACKEND_URL_DEFAULT));
    STATUS_CHECK(SetDBConfigPreloadCollection(CONFIG_DB_PRELOAD_COLLECTION_DEFAULT));
    STATUS_CHECK(SetDBConfigArchiveDiskThreshold(CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT));
    STATUS_CHECK(SetDBConfigArchiveDaysThreshold(CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT));
    STATUS_CHECK(SetDBConfigAutoFlushInterval(CONFIG_DB_AUTO_FLUSH_INTERVAL_DEFAULT));
C
Cai Yudong 已提交
441 442

    /* storage config */
C
Cai Yudong 已提交
443 444 445 446 447 448 449 450 451
    STATUS_CHECK(SetStorageConfigPrimaryPath(CONFIG_STORAGE_PRIMARY_PATH_DEFAULT));
    STATUS_CHECK(SetStorageConfigSecondaryPath(CONFIG_STORAGE_SECONDARY_PATH_DEFAULT));
    STATUS_CHECK(SetStorageConfigFileCleanupTimeout(CONFIG_STORAGE_FILE_CLEANUP_TIMEOUT_DEFAULT));
    // STATUS_CHECK(SetStorageConfigS3Enable(CONFIG_STORAGE_S3_ENABLE_DEFAULT));
    // STATUS_CHECK(SetStorageConfigS3Address(CONFIG_STORAGE_S3_ADDRESS_DEFAULT));
    // STATUS_CHECK(SetStorageConfigS3Port(CONFIG_STORAGE_S3_PORT_DEFAULT));
    // STATUS_CHECK(SetStorageConfigS3AccessKey(CONFIG_STORAGE_S3_ACCESS_KEY_DEFAULT));
    // STATUS_CHECK(SetStorageConfigS3SecretKey(CONFIG_STORAGE_S3_SECRET_KEY_DEFAULT));
    // STATUS_CHECK(SetStorageConfigS3Bucket(CONFIG_STORAGE_S3_BUCKET_DEFAULT));
Y
yudong.cai 已提交
452 453

    /* metric config */
C
Cai Yudong 已提交
454 455 456
    STATUS_CHECK(SetMetricConfigEnableMonitor(CONFIG_METRIC_ENABLE_MONITOR_DEFAULT));
    STATUS_CHECK(SetMetricConfigAddress(CONFIG_METRIC_ADDRESS_DEFAULT));
    STATUS_CHECK(SetMetricConfigPort(CONFIG_METRIC_PORT_DEFAULT));
Y
yudong.cai 已提交
457 458

    /* cache config */
C
Cai Yudong 已提交
459 460 461 462
    STATUS_CHECK(SetCacheConfigCpuCacheCapacity(CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT));
    STATUS_CHECK(SetCacheConfigCpuCacheThreshold(CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT));
    STATUS_CHECK(SetCacheConfigInsertBufferSize(CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT));
    STATUS_CHECK(SetCacheConfigCacheInsertData(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT));
Y
yudong.cai 已提交
463

Y
yudong.cai 已提交
464
    /* engine config */
C
Cai Yudong 已提交
465 466 467
    STATUS_CHECK(SetEngineConfigUseBlasThreshold(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT));
    STATUS_CHECK(SetEngineConfigOmpThreadNum(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT));
    STATUS_CHECK(SetEngineConfigSimdType(CONFIG_ENGINE_SIMD_TYPE_DEFAULT));
G
groot 已提交
468
#ifdef MILVUS_GPU_VERSION
C
Cai Yudong 已提交
469
    STATUS_CHECK(SetEngineConfigGpuSearchThreshold(CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT));
C
Cai Yudong 已提交
470
#endif
Z
Zhiru Zhu 已提交
471

C
Cai Yudong 已提交
472 473
    /* gpu resource config */
#ifdef MILVUS_GPU_VERSION
C
Cai Yudong 已提交
474 475 476 477 478
    STATUS_CHECK(SetGpuResourceConfigEnable(CONFIG_GPU_RESOURCE_ENABLE_DEFAULT));
    STATUS_CHECK(SetGpuResourceConfigCacheCapacity(CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT));
    STATUS_CHECK(SetGpuResourceConfigCacheThreshold(CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT));
    STATUS_CHECK(SetGpuResourceConfigSearchResources(CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT));
    STATUS_CHECK(SetGpuResourceConfigBuildIndexResources(CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT));
Y
yudong.cai 已提交
479
#endif
480

C
Cai Yudong 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
    /* wal config */
    STATUS_CHECK(SetWalConfigEnable(CONFIG_WAL_ENABLE_DEFAULT));
    STATUS_CHECK(SetWalConfigRecoveryErrorIgnore(CONFIG_WAL_RECOVERY_ERROR_IGNORE_DEFAULT));
    STATUS_CHECK(SetWalConfigBufferSize(CONFIG_WAL_BUFFER_SIZE_DEFAULT));
    STATUS_CHECK(SetWalConfigWalPath(CONFIG_WAL_WAL_PATH_DEFAULT));

    /* logs config */
    STATUS_CHECK(SetLogsTraceEnable(CONFIG_LOGS_TRACE_ENABLE_DEFAULT));
    STATUS_CHECK(SetLogsDebugEnable(CONFIG_LOGS_DEBUG_ENABLE_DEFAULT));
    STATUS_CHECK(SetLogsInfoEnable(CONFIG_LOGS_INFO_ENABLE_DEFAULT));
    STATUS_CHECK(SetLogsWarningEnable(CONFIG_LOGS_WARNING_ENABLE_DEFAULT));
    STATUS_CHECK(SetLogsErrorEnable(CONFIG_LOGS_ERROR_ENABLE_DEFAULT));
    STATUS_CHECK(SetLogsFatalEnable(CONFIG_LOGS_FATAL_ENABLE_DEFAULT));
    STATUS_CHECK(SetLogsPath(CONFIG_LOGS_PATH_DEFAULT));
    STATUS_CHECK(SetLogsMaxLogFileSize(CONFIG_LOGS_MAX_LOG_FILE_SIZE_DEFAULT));
    STATUS_CHECK(SetLogsDeleteExceeds(CONFIG_LOGS_DELETE_EXCEEDS_DEFAULT));

Y
yudong.cai 已提交
498 499 500
    return Status::OK();
}

Y
yudong.cai 已提交
501
void
502
Config::GetConfigJsonStr(std::string& result, int64_t indent) {
503
    nlohmann::json config_json(config_map_);
504
    result = config_json.dump(indent);
Y
yudong.cai 已提交
505 506
}

C
Cai Yudong 已提交
507
Status
508
Config::GetConfigCli(std::string& value, const std::string& parent_key, const std::string& child_key) {
C
Cai Yudong 已提交
509 510 511 512 513 514 515 516 517
    if (!ConfigNodeValid(parent_key, child_key)) {
        std::string str = "Config node invalid: " + parent_key + CONFIG_NODE_DELIMITER + child_key;
        return Status(SERVER_UNEXPECTED_ERROR, str);
    }
    return GetConfigValueInMem(parent_key, child_key, value);
}

Status
Config::SetConfigCli(const std::string& parent_key, const std::string& child_key, const std::string& value) {
518 519
    std::string invalid_node_str = "Config node invalid: " + parent_key + CONFIG_NODE_DELIMITER + child_key;

C
Cai Yudong 已提交
520
    if (!ConfigNodeValid(parent_key, child_key)) {
521
        return Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
522
    }
523
    auto status = Status::OK();
C
Cai Yudong 已提交
524
    if (parent_key == CONFIG_SERVER) {
525 526 527 528 529 530 531 532 533 534
        if (child_key == CONFIG_SERVER_ADDRESS) {
            status = SetServerConfigAddress(value);
        } else if (child_key == CONFIG_SERVER_DEPLOY_MODE) {
            status = SetServerConfigDeployMode(value);
        } else if (child_key == CONFIG_SERVER_PORT) {
            status = SetServerConfigPort(value);
        } else if (child_key == CONFIG_SERVER_TIME_ZONE) {
            status = SetServerConfigTimeZone(value);
        } else if (child_key == CONFIG_SERVER_WEB_PORT) {
            status = SetServerConfigWebPort(value);
535 536
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
537
        }
C
Cai Yudong 已提交
538
    } else if (parent_key == CONFIG_DB) {
539 540
        if (child_key == CONFIG_DB_BACKEND_URL) {
            status = SetDBConfigBackendUrl(value);
G
groot 已提交
541
        } else if (child_key == CONFIG_DB_PRELOAD_COLLECTION) {
542
            status = SetDBConfigPreloadCollection(value);
543 544
        } else if (child_key == CONFIG_DB_AUTO_FLUSH_INTERVAL) {
            status = SetDBConfigAutoFlushInterval(value);
545 546
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
547
        }
C
Cai Yudong 已提交
548
    } else if (parent_key == CONFIG_STORAGE) {
549 550 551 552
        if (child_key == CONFIG_STORAGE_PRIMARY_PATH) {
            status = SetStorageConfigPrimaryPath(value);
        } else if (child_key == CONFIG_STORAGE_SECONDARY_PATH) {
            status = SetStorageConfigSecondaryPath(value);
C
Cai Yudong 已提交
553 554 555 556 557 558 559 560 561 562 563 564
            // } else if (child_key == CONFIG_STORAGE_S3_ENABLE) {
            //     status = SetStorageConfigS3Enable(value);
            // } else if (child_key == CONFIG_STORAGE_S3_ADDRESS) {
            //     status = SetStorageConfigS3Address(value);
            // } else if (child_key == CONFIG_STORAGE_S3_PORT) {
            //     status = SetStorageConfigS3Port(value);
            // } else if (child_key == CONFIG_STORAGE_S3_ACCESS_KEY) {
            //     status = SetStorageConfigS3AccessKey(value);
            // } else if (child_key == CONFIG_STORAGE_S3_SECRET_KEY) {
            //     status = SetStorageConfigS3SecretKey(value);
            // } else if (child_key == CONFIG_STORAGE_S3_BUCKET) {
            //     status = SetStorageConfigS3Bucket(value);
565 566
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
567
        }
C
Cai Yudong 已提交
568
    } else if (parent_key == CONFIG_METRIC) {
569 570 571 572 573 574
        if (child_key == CONFIG_METRIC_ENABLE_MONITOR) {
            status = SetMetricConfigEnableMonitor(value);
        } else if (child_key == CONFIG_METRIC_ADDRESS) {
            status = SetMetricConfigAddress(value);
        } else if (child_key == CONFIG_METRIC_PORT) {
            status = SetMetricConfigPort(value);
575 576
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
577
        }
C
Cai Yudong 已提交
578 579
    } else if (parent_key == CONFIG_CACHE) {
        if (child_key == CONFIG_CACHE_CPU_CACHE_CAPACITY) {
580
            status = SetCacheConfigCpuCacheCapacity(value);
C
Cai Yudong 已提交
581
        } else if (child_key == CONFIG_CACHE_CPU_CACHE_THRESHOLD) {
582
            status = SetCacheConfigCpuCacheThreshold(value);
C
Cai Yudong 已提交
583
        } else if (child_key == CONFIG_CACHE_CACHE_INSERT_DATA) {
584
            status = SetCacheConfigCacheInsertData(value);
585
        } else if (child_key == CONFIG_CACHE_INSERT_BUFFER_SIZE) {
586
            status = SetCacheConfigInsertBufferSize(value);
587 588
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
589 590 591
        }
    } else if (parent_key == CONFIG_ENGINE) {
        if (child_key == CONFIG_ENGINE_USE_BLAS_THRESHOLD) {
592
            status = SetEngineConfigUseBlasThreshold(value);
C
Cai Yudong 已提交
593
        } else if (child_key == CONFIG_ENGINE_OMP_THREAD_NUM) {
594
            status = SetEngineConfigOmpThreadNum(value);
F
feisiyicl 已提交
595 596
        } else if (child_key == CONFIG_ENGINE_SIMD_TYPE) {
            status = SetEngineConfigSimdType(value);
C
Cai Yudong 已提交
597 598
#ifdef MILVUS_GPU_VERSION
        } else if (child_key == CONFIG_ENGINE_GPU_SEARCH_THRESHOLD) {
599
            status = SetEngineConfigGpuSearchThreshold(value);
C
Cai Yudong 已提交
600
#endif
601 602
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
603 604 605 606
        }
#ifdef MILVUS_GPU_VERSION
    } else if (parent_key == CONFIG_GPU_RESOURCE) {
        if (child_key == CONFIG_GPU_RESOURCE_ENABLE) {
607
            status = SetGpuResourceConfigEnable(value);
C
Cai Yudong 已提交
608
        } else if (child_key == CONFIG_GPU_RESOURCE_CACHE_CAPACITY) {
609
            status = SetGpuResourceConfigCacheCapacity(value);
C
Cai Yudong 已提交
610
        } else if (child_key == CONFIG_GPU_RESOURCE_CACHE_THRESHOLD) {
611
            status = SetGpuResourceConfigCacheThreshold(value);
C
Cai Yudong 已提交
612
        } else if (child_key == CONFIG_GPU_RESOURCE_SEARCH_RESOURCES) {
613
            status = SetGpuResourceConfigSearchResources(value);
C
Cai Yudong 已提交
614
        } else if (child_key == CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES) {
615
            status = SetGpuResourceConfigBuildIndexResources(value);
616 617
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
618 619 620
        }
#endif
    } else if (parent_key == CONFIG_TRACING) {
621 622 623 624 625
        if (child_key == CONFIG_TRACING_JSON_CONFIG_PATH) {
            status = SetTracingConfigJsonConfigPath(value);
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
        }
J
Jin Hai 已提交
626 627 628 629 630 631 632 633 634
    } else if (parent_key == CONFIG_WAL) {
        if (child_key == CONFIG_WAL_ENABLE) {
            status = SetWalConfigEnable(value);
        } else if (child_key == CONFIG_WAL_RECOVERY_ERROR_IGNORE) {
            status = SetWalConfigRecoveryErrorIgnore(value);
        } else if (child_key == CONFIG_WAL_BUFFER_SIZE) {
            status = SetWalConfigBufferSize(value);
        } else if (child_key == CONFIG_WAL_WAL_PATH) {
            status = SetWalConfigWalPath(value);
635 636
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
J
Jin Hai 已提交
637
        }
638 639 640 641
    }

    if (status.ok()) {
        status = UpdateFileConfigFromMem(parent_key, child_key);
642 643
        if (status.ok() &&
            !(parent_key == CONFIG_CACHE || parent_key == CONFIG_ENGINE || parent_key == CONFIG_GPU_RESOURCE)) {
644 645
            restart_required_ = true;
        }
C
Cai Yudong 已提交
646
    }
647 648

    return status;
C
Cai Yudong 已提交
649 650
}

651
//////////////////////////////////////////////////////////////
C
Cai Yudong 已提交
652
Status
653
Config::ProcessConfigCli(std::string& result, const std::string& cmd) {
C
Cai Yudong 已提交
654 655 656
    std::vector<std::string> tokens;
    std::vector<std::string> nodes;
    server::StringHelpFunctions::SplitStringByDelimeter(cmd, " ", tokens);
657
    if (tokens[0] == "get_config") {
C
Cai Yudong 已提交
658 659 660
        if (tokens.size() != 2) {
            return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd);
        }
661 662 663 664 665 666 667 668 669
        if (tokens[1] == "*") {
            GetConfigJsonStr(result);
            return Status::OK();
        } else {
            server::StringHelpFunctions::SplitStringByDelimeter(tokens[1], CONFIG_NODE_DELIMITER, nodes);
            if (nodes.size() != 2) {
                return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd);
            }
            return GetConfigCli(result, nodes[0], nodes[1]);
C
Cai Yudong 已提交
670
        }
671
    } else if (tokens[0] == "set_config") {
C
Cai Yudong 已提交
672 673 674 675 676 677 678 679 680 681 682 683 684
        if (tokens.size() != 3) {
            return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd);
        }
        server::StringHelpFunctions::SplitStringByDelimeter(tokens[1], CONFIG_NODE_DELIMITER, nodes);
        if (nodes.size() != 2) {
            return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd);
        }
        return SetConfigCli(nodes[0], nodes[1], tokens[2]);
    } else {
        return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd);
    }
}

685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
Status
Config::GenUniqueIdentityID(const std::string& identity, std::string& uid) {
    std::vector<std::string> elements;
    elements.push_back(identity);

    // get current process id
    int64_t pid = getpid();
    elements.push_back(std::to_string(pid));

    // get current thread id
    std::stringstream ss;
    ss << std::this_thread::get_id();
    elements.push_back(ss.str());

    // get current timestamp
    auto time_now = std::chrono::system_clock::now();
701
    auto duration_in_ms = std::chrono::duration_cast<std::chrono::nanoseconds>(time_now.time_since_epoch());
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
    elements.push_back(std::to_string(duration_in_ms.count()));

    StringHelpFunctions::MergeStringWithDelimeter(elements, "-", uid);

    return Status::OK();
}

Status
Config::UpdateFileConfigFromMem(const std::string& parent_key, const std::string& child_key) {
    if (access(config_file_.c_str(), F_OK | R_OK) != 0) {
        return Status(SERVER_UNEXPECTED_ERROR, "Cannot find configure file: " + config_file_);
    }

    // Store original configure file
    std::string ori_file = config_file_ + ".ori";
    if (access(ori_file.c_str(), F_OK) != 0) {
        std::fstream fin(config_file_, std::ios::in);
        std::ofstream fout(ori_file);

        if (!fin.is_open() || !fout.is_open()) {
            return Status(SERVER_UNEXPECTED_ERROR, "Cannot open conf file. Store original conf file failed");
        }
        fout << fin.rdbuf();
        fout.flush();
        fout.close();
        fin.close();
    }

    std::string value;
    auto status = GetConfigValueInMem(parent_key, child_key, value);
    if (!status.ok()) {
        return status;
    }

    // convert value string to standard string stored in yaml file
    std::string value_str;
C
Cai Yudong 已提交
738 739
    if (child_key == CONFIG_CACHE_CACHE_INSERT_DATA ||
        // child_key == CONFIG_STORAGE_S3_ENABLE ||
740 741 742
        child_key == CONFIG_METRIC_ENABLE_MONITOR || child_key == CONFIG_GPU_RESOURCE_ENABLE ||
        child_key == CONFIG_WAL_ENABLE || child_key == CONFIG_WAL_RECOVERY_ERROR_IGNORE) {
        bool ok = false;
C
Cai Yudong 已提交
743
        STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(value, ok));
744
        value_str = ok ? "true" : "false";
745 746 747 748 749
    } else if (child_key == CONFIG_GPU_RESOURCE_SEARCH_RESOURCES ||
               child_key == CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES) {
        std::vector<std::string> vec;
        StringHelpFunctions::SplitStringByDelimeter(value, ",", vec);
        for (auto& s : vec) {
750
            std::transform(s.begin(), s.end(), s.begin(), ::tolower);
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
            value_str += "\n    - " + s;
        }
    } else {
        value_str = value;
    }

    std::fstream conf_fin(config_file_, std::ios::in);
    if (!conf_fin.is_open()) {
        return Status(SERVER_UNEXPECTED_ERROR, "Cannot open conf file: " + config_file_);
    }

    bool parent_key_read = false;
    std::string conf_str, line;
    while (getline(conf_fin, line)) {
        if (!parent_key_read) {
            conf_str += line + "\n";
            if (!(line.empty() || line.find_first_of('#') == 0 || line.find(parent_key) == std::string::npos))
                parent_key_read = true;
            continue;
        }

        if (line.find_first_of('#') == 0) {
            status = Status(SERVER_UNEXPECTED_ERROR, "Cannot find child key: " + child_key);
            break;
        }

        if (line.find(child_key) != std::string::npos) {
            // may loss comments here, need to extract comments from line
            conf_str += "  " + child_key + ": " + value_str + "\n";
            break;
        }

        conf_str += line + "\n";
    }

    // values of gpu resources are sequences, need to remove old here
    if (child_key == CONFIG_GPU_RESOURCE_SEARCH_RESOURCES || child_key == CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES) {
        while (getline(conf_fin, line)) {
            if (line.find("- gpu") != std::string::npos)
                continue;

            conf_str += line + "\n";
            if (!line.empty() && line.size() > 2 && isalnum(line.at(2))) {
                break;
            }
        }
    }

    if (status.ok()) {
        while (getline(conf_fin, line)) {
            conf_str += line + "\n";
        }
        conf_fin.close();

        std::fstream fout(config_file_, std::ios::out | std::ios::trunc);
        fout << conf_str;
        fout.flush();
        fout.close();
    }

    return status;
}

Status
Config::RegisterCallBack(const std::string& node, const std::string& sub_node, const std::string& key,
                         ConfigCallBackF& cb) {
    std::string cb_node = node + "." + sub_node;
    if (config_callback_.find(cb_node) == config_callback_.end()) {
        return Status(SERVER_UNEXPECTED_ERROR, cb_node + " is not supported changed in mem");
    }

    auto& callback_map = config_callback_.at(cb_node);
    callback_map[key] = cb;

    return Status::OK();
}

Status
Config::CancelCallBack(const std::string& node, const std::string& sub_node, const std::string& key) {
    if (config_callback_.empty() || key.empty()) {
        return Status::OK();
    }

    std::string cb_node = node + "." + sub_node;
    if (config_callback_.find(cb_node) == config_callback_.end()) {
        return Status(SERVER_UNEXPECTED_ERROR, cb_node + " cannot found in callback map");
    }

    auto& cb_map = config_callback_.at(cb_node);
    cb_map.erase(key);

    return Status::OK();
}

Y
yudong.cai 已提交
845
////////////////////////////////////////////////////////////////////////////////
846 847
Status
Config::CheckConfigVersion(const std::string& value) {
848 849 850 851 852 853
    if (milvus_config_version_map.find(MILVUS_VERSION) != milvus_config_version_map.end()) {
        bool exist_error = milvus_config_version_map.at(MILVUS_VERSION) != value;
        fiu_do_on("check_config_version_fail", exist_error = true);
        if (exist_error) {
            std::string msg = "Invalid config version: " + value +
                              ". Expected config version: " + milvus_config_version_map.at(MILVUS_VERSION);
854
            LOG_SERVER_ERROR_ << msg;
Y
yudong.cai 已提交
855
            return Status(SERVER_INVALID_ARGUMENT, msg);
856
        }
857 858 859 860
    }
    return Status::OK();
}

C
Cai Yudong 已提交
861
/* server config */
S
starlord 已提交
862
Status
S
starlord 已提交
863
Config::CheckServerConfigAddress(const std::string& value) {
S
shengjh 已提交
864 865 866 867
    auto exist_error = !ValidationUtil::ValidateIpAddress(value).ok();
    fiu_do_on("check_config_address_fail", exist_error = true);

    if (exist_error) {
S
starlord 已提交
868 869
        std::string msg =
            "Invalid server IP address: " + value + ". Possible reason: server_config.address is invalid.";
870
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
871
    }
Y
yudong.cai 已提交
872 873
    return Status::OK();
}
Z
zhiru 已提交
874

Y
yudong.cai 已提交
875
Status
S
starlord 已提交
876
Config::CheckServerConfigPort(const std::string& value) {
S
shengjh 已提交
877 878 879 880
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_port_fail", exist_error = true);

    if (exist_error) {
S
starlord 已提交
881
        std::string msg = "Invalid server port: " + value + ". Possible reason: server_config.port is not a number.";
882
        return Status(SERVER_INVALID_ARGUMENT, msg);
883
    } else {
J
Jin Hai 已提交
884 885 886 887 888 889 890 891 892
        try {
            int32_t port = std::stoi(value);
            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
                std::string msg = "Invalid server port: " + value +
                                  ". Possible reason: server_config.port is not in range (1024, 65535).";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.port: " + value);
Z
zhiru 已提交
893 894
        }
    }
Y
yudong.cai 已提交
895 896
    return Status::OK();
}
Z
zhiru 已提交
897

Y
yudong.cai 已提交
898
Status
S
starlord 已提交
899
Config::CheckServerConfigDeployMode(const std::string& value) {
S
shengjh 已提交
900 901 902 903
    fiu_return_on("check_config_deploy_mode_fail",
                  Status(SERVER_INVALID_ARGUMENT,
                         "server_config.deploy_mode is not one of single, cluster_readonly, and cluster_writable."));

S
starlord 已提交
904
    if (value != "single" && value != "cluster_readonly" && value != "cluster_writable") {
Y
yudong.cai 已提交
905
        return Status(SERVER_INVALID_ARGUMENT,
Z
Zhiru Zhu 已提交
906
                      "server_config.deploy_mode is not one of single, cluster_readonly, and cluster_writable.");
907
    }
Y
yudong.cai 已提交
908 909
    return Status::OK();
}
910

Y
yudong.cai 已提交
911
Status
S
starlord 已提交
912
Config::CheckServerConfigTimeZone(const std::string& value) {
S
shengjh 已提交
913 914 915
    fiu_return_on("check_config_time_zone_fail",
                  Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value));

Y
yudong.cai 已提交
916
    if (value.length() <= 3) {
S
starlord 已提交
917
        return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
918
    } else {
Y
yudong.cai 已提交
919
        if (value.substr(0, 3) != "UTC") {
S
starlord 已提交
920
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
921
        } else {
J
Jin Hai 已提交
922
            if (!ValidationUtil::IsNumber(value.substr(4))) {
S
starlord 已提交
923
                return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
924
            }
925 926
        }
    }
Y
yudong.cai 已提交
927
    return Status::OK();
Z
zhiru 已提交
928 929
}

930 931 932 933 934
Status
Config::CheckServerConfigWebEnable(const std::string& value) {
    return ValidationUtil::ValidateStringIsBool(value);
}

B
BossZou 已提交
935 936 937 938 939 940 941
Status
Config::CheckServerConfigWebPort(const std::string& value) {
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        std::string msg =
            "Invalid web server port: " + value + ". Possible reason: server_config.web_port is not a number.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
J
Jin Hai 已提交
942 943 944 945 946 947 948 949 950
        try {
            int32_t port = std::stoi(value);
            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
                std::string msg = "Invalid web server port: " + value +
                                  ". Possible reason: server_config.web_port is not in range (1024, 65535).";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.web_port: " + value);
B
BossZou 已提交
951 952 953 954 955
        }
    }
    return Status::OK();
}

C
Cai Yudong 已提交
956
/* DB config */
Y
yudong.cai 已提交
957
Status
S
starlord 已提交
958
Config::CheckDBConfigBackendUrl(const std::string& value) {
S
shengjh 已提交
959 960 961 962
    auto exist_error = !ValidationUtil::ValidateDbURI(value).ok();
    fiu_do_on("check_config_backend_url_fail", exist_error = true);

    if (exist_error) {
963
        std::string msg =
S
starlord 已提交
964
            "Invalid backend url: " + value + ". Possible reason: db_config.db_backend_url is invalid. " +
965
            "The correct format should be like sqlite://:@:/ or mysql://root:123456@127.0.0.1:3306/milvus.";
966
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
967
    }
Y
yudong.cai 已提交
968 969
    return Status::OK();
}
Z
zhiru 已提交
970

971
Status
972
Config::CheckDBConfigPreloadCollection(const std::string& value) {
973
    fiu_return_on("check_config_preload_collection_fail", Status(SERVER_INVALID_ARGUMENT, ""));
974

975 976 977 978 979 980
    if (value.empty() || value == "*") {
        return Status::OK();
    }

    std::vector<std::string> tables;
    StringHelpFunctions::SplitStringByDelimeter(value, ",", tables);
981 982 983

    std::unordered_set<std::string> table_set;

J
Jin Hai 已提交
984 985 986
    for (auto& collection : tables) {
        if (!ValidationUtil::ValidateCollectionName(collection).ok()) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid collection name: " + collection);
987 988
        }
        bool exist = false;
989
        auto status = DBWrapper::DB()->HasNativeCollection(collection, exist);
990
        if (!(status.ok() && exist)) {
G
groot 已提交
991
            return Status(SERVER_COLLECTION_NOT_EXIST, "Collection " + collection + " not exist");
992
        }
J
Jin Hai 已提交
993
        table_set.insert(collection);
994 995 996 997 998
    }

    if (table_set.size() != tables.size()) {
        std::string msg =
            "Invalid preload tables. "
999
            "Possible reason: db_config.preload_collection contains duplicate collection.";
1000
        return Status(SERVER_INVALID_ARGUMENT, msg);
1001 1002 1003 1004 1005
    }

    return Status::OK();
}

Y
yudong.cai 已提交
1006
Status
S
starlord 已提交
1007
Config::CheckDBConfigArchiveDiskThreshold(const std::string& value) {
S
shengjh 已提交
1008 1009 1010 1011
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_archive_disk_threshold_fail", exist_error = true);

    if (exist_error) {
1012
        std::string msg = "Invalid archive disk threshold: " + value +
S
starlord 已提交
1013
                          ". Possible reason: db_config.archive_disk_threshold is invalid.";
1014
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1015
    }
Y
yudong.cai 已提交
1016 1017
    return Status::OK();
}
Z
zhiru 已提交
1018

Y
yudong.cai 已提交
1019
Status
S
starlord 已提交
1020
Config::CheckDBConfigArchiveDaysThreshold(const std::string& value) {
S
shengjh 已提交
1021 1022 1023 1024
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_archive_days_threshold_fail", exist_error = true);

    if (exist_error) {
1025
        std::string msg = "Invalid archive days threshold: " + value +
1026
                          ". Possible reason: db_config.archive_days_threshold is invalid.";
1027
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1028
    }
Y
yudong.cai 已提交
1029 1030
    return Status::OK();
}
Z
zhiru 已提交
1031

1032 1033
Status
Config::CheckDBConfigAutoFlushInterval(const std::string& value) {
1034 1035 1036 1037
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_auto_flush_interval_fail", exist_error = true);

    if (exist_error) {
1038
        std::string msg = "Invalid db configuration auto_flush_interval: " + value +
1039
                          ". Possible reason: db.auto_flush_interval is not a natural number.";
1040 1041 1042 1043 1044 1045
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }

    return Status::OK();
}

C
Cai Yudong 已提交
1046
/* storage config */
1047 1048
Status
Config::CheckStorageConfigPrimaryPath(const std::string& value) {
S
shengjh 已提交
1049
    fiu_return_on("check_config_primary_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
1050 1051 1052
    if (value.empty()) {
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.db_path is empty.");
    }
1053 1054

    return ValidationUtil::ValidateStoragePath(value);
1055 1056 1057 1058
}

Status
Config::CheckStorageConfigSecondaryPath(const std::string& value) {
S
shengjh 已提交
1059
    fiu_return_on("check_config_secondary_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083

    auto status = Status::OK();

    if (value.empty()) {
        return status;
    }

    std::vector<std::string> vec;
    StringHelpFunctions::SplitStringByDelimeter(value, ",", vec);
    std::unordered_set<std::string> path_set;
    for (auto& path : vec) {
        StringHelpFunctions::TrimStringBlank(path);
        status = ValidationUtil::ValidateStoragePath(path);
        if (!status.ok()) {
            return status;
        }

        path_set.insert(path);
    }

    if (path_set.size() != vec.size()) {
        return Status(SERVER_INVALID_ARGUMENT, "Path value is duplicated");
    }

1084 1085 1086
    return Status::OK();
}

G
groot 已提交
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
Status
Config::CheckStorageConfigFileCleanupTimeout(const std::string& value) {
    auto status = Status::OK();

    if (value.empty()) {
        return status;
    }

    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        std::string msg = "Invalid file cleanup timeout: " + value +
                          ". Possible reason: storage_config.file_cleanup_timeout is not a positive integer.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
        const int64_t min = 0, max = 3600;
        int64_t file_cleanup_timeout = std::stoll(value);
        if (file_cleanup_timeout < min || file_cleanup_timeout > max) {
            std::string msg = "Invalid file cleanup timeout: " + value +
                              ". Possible reason: storage_config.file_cleanup_timeout is not in range [" +
                              std::to_string(min) + ", " + std::to_string(max) + "].";
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
    }

    return Status::OK();
}

C
Cai Yudong 已提交
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
// Status
// Config::CheckStorageConfigS3Enable(const std::string& value) {
//    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
//        std::string msg =
//            "Invalid storage config: " + value + ". Possible reason: storage_config.s3_enable is not a boolean.";
//        return Status(SERVER_INVALID_ARGUMENT, msg);
//    }
//    return Status::OK();
// }
//
// Status
// Config::CheckStorageConfigS3Address(const std::string& value) {
//    if (!ValidationUtil::ValidateIpAddress(value).ok()) {
//        std::string msg = "Invalid s3 address: " + value + ". Possible reason: storage_config.s3_address is invalid.";
//        return Status(SERVER_INVALID_ARGUMENT, msg);
//    }
//    return Status::OK();
// }
//
// Status
// Config::CheckStorageConfigS3Port(const std::string& value) {
//    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
//        std::string msg = "Invalid s3 port: " + value + ". Possible reason: storage_config.s3_port is not a number.";
//        return Status(SERVER_INVALID_ARGUMENT, msg);
//    } else {
//        try {
//            int32_t port = std::stoi(value);
//            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
//                std::string msg = "Invalid s3 port: " + value +
//                                  ". Possible reason: storage_config.s3_port is not in range (1024, 65535).";
//                return Status(SERVER_INVALID_ARGUMENT, msg);
//            }
//        } catch (...) {
//            return Status(SERVER_INVALID_ARGUMENT, "Invalid storage_config.s3_port: " + value);
//        }
//    }
//    return Status::OK();
// }
//
// Status
// Config::CheckStorageConfigS3AccessKey(const std::string& value) {
//    if (value.empty()) {
//        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_access_key is empty.");
//    }
//    return Status::OK();
// }
//
// Status
// Config::CheckStorageConfigS3SecretKey(const std::string& value) {
//    if (value.empty()) {
//        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_secret_key is empty.");
//    }
//    return Status::OK();
// }
//
// Status
// Config::CheckStorageConfigS3Bucket(const std::string& value) {
//    if (value.empty()) {
//        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_bucket is empty.");
//    }
//    return Status::OK();
// }
C
Cai Yudong 已提交
1175 1176

/* metric config */
S
starlord 已提交
1177
Status
S
starlord 已提交
1178
Config::CheckMetricConfigEnableMonitor(const std::string& value) {
S
shengjh 已提交
1179 1180 1181 1182
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_config_enable_monitor_fail", exist_error = true);

    if (exist_error) {
1183
        std::string msg =
S
starlord 已提交
1184
            "Invalid metric config: " + value + ". Possible reason: metric_config.enable_monitor is not a boolean.";
1185
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1186
    }
Y
yudong.cai 已提交
1187 1188
    return Status::OK();
}
Z
zhiru 已提交
1189

Y
yudong.cai 已提交
1190
Status
C
Cai Yudong 已提交
1191
Config::CheckMetricConfigAddress(const std::string& value) {
1192
    if (!ValidationUtil::ValidateIpAddress(value).ok()) {
C
Cai Yudong 已提交
1193
        std::string msg = "Invalid metric ip: " + value + ". Possible reason: metric_config.ip is invalid.";
1194
        return Status(SERVER_INVALID_ARGUMENT, msg);
1195 1196 1197 1198
    }
    return Status::OK();
}

Y
yudong.cai 已提交
1199
Status
C
Cai Yudong 已提交
1200
Config::CheckMetricConfigPort(const std::string& value) {
Y
yudong.cai 已提交
1201
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
C
Cai Yudong 已提交
1202
        std::string msg = "Invalid metric port: " + value + ". Possible reason: metric_config.port is not a number.";
C
Cai Yudong 已提交
1203 1204
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
J
Jin Hai 已提交
1205 1206 1207 1208 1209 1210 1211 1212 1213
        try {
            int32_t port = std::stoi(value);
            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
                std::string msg = "Invalid metric port: " + value +
                                  ". Possible reason: metric_config.port is not in range (1024, 65535).";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid metric_config.port: " + value);
C
Cai Yudong 已提交
1214
        }
Z
zhiru 已提交
1215
    }
Y
yudong.cai 已提交
1216
    return Status::OK();
Z
zhiru 已提交
1217 1218
}

C
Cai Yudong 已提交
1219
/* cache config */
S
starlord 已提交
1220
Status
S
starlord 已提交
1221
Config::CheckCacheConfigCpuCacheCapacity(const std::string& value) {
S
shengjh 已提交
1222 1223
    fiu_return_on("check_config_cpu_cache_capacity_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1224
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1225
        std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1226
                          ". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
1227
        return Status(SERVER_INVALID_ARGUMENT, msg);
1228
    } else {
Y
yudong.cai 已提交
1229
        int64_t cpu_cache_capacity = std::stoll(value) * GB;
1230 1231
        if (cpu_cache_capacity <= 0) {
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1232
                              ". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
1233 1234 1235
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }

S
starlord 已提交
1236
        uint64_t total_mem = 0, free_mem = 0;
Z
zhiru 已提交
1237
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
1238 1239
        if (static_cast<uint64_t>(cpu_cache_capacity) >= total_mem) {
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1240
                              ". Possible reason: cache_config.cpu_cache_capacity exceeds system memory.";
1241
            return Status(SERVER_INVALID_ARGUMENT, msg);
1242
        } else if (static_cast<double>(cpu_cache_capacity) > static_cast<double>(total_mem * 0.9)) {
1243
            std::cerr << "WARNING: cpu cache capacity value is too big" << std::endl;
Z
zhiru 已提交
1244
        }
1245

1246
        std::string str = GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, "0");
T
Tinkerrr 已提交
1247
        int64_t buffer_value = std::stoll(str);
S
starlord 已提交
1248

Y
yudong.cai 已提交
1249
        int64_t insert_buffer_size = buffer_value * GB;
S
shengjh 已提交
1250
        fiu_do_on("Config.CheckCacheConfigCpuCacheCapacity.large_insert_buffer", insert_buffer_size = total_mem + 1);
Y
yudong.cai 已提交
1251
        if (insert_buffer_size + cpu_cache_capacity >= total_mem) {
1252
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1253
                              ". Possible reason: sum of cache_config.cpu_cache_capacity and "
1254
                              "cache_config.insert_buffer_size exceeds system memory.";
1255
            return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1256 1257
        }
    }
Y
yudong.cai 已提交
1258 1259
    return Status::OK();
}
Z
zhiru 已提交
1260

Y
yudong.cai 已提交
1261
Status
S
starlord 已提交
1262
Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) {
S
shengjh 已提交
1263 1264
    fiu_return_on("check_config_cpu_cache_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1265
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
1266
        std::string msg = "Invalid cpu cache threshold: " + value +
S
starlord 已提交
1267
                          ". Possible reason: cache_config.cpu_cache_threshold is not in range (0.0, 1.0].";
1268
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1269
    } else {
Y
yudong.cai 已提交
1270 1271
        float cpu_cache_threshold = std::stof(value);
        if (cpu_cache_threshold <= 0.0 || cpu_cache_threshold >= 1.0) {
1272
            std::string msg = "Invalid cpu cache threshold: " + value +
S
starlord 已提交
1273
                              ". Possible reason: cache_config.cpu_cache_threshold is not in range (0.0, 1.0].";
1274
            return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1275
        }
1276
    }
Y
yudong.cai 已提交
1277 1278
    return Status::OK();
}
1279

1280 1281
Status
Config::CheckCacheConfigInsertBufferSize(const std::string& value) {
S
shengjh 已提交
1282
    fiu_return_on("check_config_insert_buffer_size_fail", Status(SERVER_INVALID_ARGUMENT, ""));
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        std::string msg = "Invalid insert buffer size: " + value +
                          ". Possible reason: cache_config.insert_buffer_size is not a positive integer.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
        int64_t buffer_size = std::stoll(value) * GB;
        if (buffer_size <= 0) {
            std::string msg = "Invalid insert buffer size: " + value +
                              ". Possible reason: cache_config.insert_buffer_size is not a positive integer.";
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }

1295 1296
        std::string str = GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, "0");
        int64_t cache_size = std::stoll(str) * GB;
T
Tinkerrr 已提交
1297

1298 1299
        uint64_t total_mem = 0, free_mem = 0;
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
T
Tinkerrr 已提交
1300
        if (buffer_size + cache_size >= total_mem) {
1301 1302 1303 1304 1305 1306 1307 1308
            std::string msg = "Invalid insert buffer size: " + value +
                              ". Possible reason: cache_config.insert_buffer_size exceeds system memory.";
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
    }
    return Status::OK();
}

Y
yudong.cai 已提交
1309
Status
S
starlord 已提交
1310
Config::CheckCacheConfigCacheInsertData(const std::string& value) {
S
shengjh 已提交
1311 1312
    fiu_return_on("check_config_cache_insert_data_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1313
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
1314
        std::string msg = "Invalid cache insert data option: " + value +
S
starlord 已提交
1315
                          ". Possible reason: cache_config.cache_insert_data is not a boolean.";
1316
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1317 1318
    }
    return Status::OK();
Z
zhiru 已提交
1319 1320
}

C
Cai Yudong 已提交
1321
/* engine config */
S
starlord 已提交
1322
Status
S
starlord 已提交
1323
Config::CheckEngineConfigUseBlasThreshold(const std::string& value) {
S
shengjh 已提交
1324 1325
    fiu_return_on("check_config_use_blas_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1326
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1327
        std::string msg = "Invalid use blas threshold: " + value +
S
starlord 已提交
1328
                          ". Possible reason: engine_config.use_blas_threshold is not a positive integer.";
1329
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1330
    }
Y
yudong.cai 已提交
1331 1332
    return Status::OK();
}
Z
zhiru 已提交
1333

Y
yudong.cai 已提交
1334
Status
S
starlord 已提交
1335
Config::CheckEngineConfigOmpThreadNum(const std::string& value) {
S
shengjh 已提交
1336 1337
    fiu_return_on("check_config_omp_thread_num_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1338
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1339
        std::string msg = "Invalid omp thread num: " + value +
S
starlord 已提交
1340
                          ". Possible reason: engine_config.omp_thread_num is not a positive integer.";
1341
        return Status(SERVER_INVALID_ARGUMENT, msg);
S
starlord 已提交
1342 1343
    }

Y
yudong.cai 已提交
1344 1345
    int64_t omp_thread = std::stoll(value);
    int64_t sys_thread_cnt = 8;
S
starlord 已提交
1346
    CommonUtil::GetSystemAvailableThreads(sys_thread_cnt);
Y
yudong.cai 已提交
1347
    if (omp_thread > sys_thread_cnt) {
1348
        std::string msg = "Invalid omp thread num: " + value +
S
starlord 已提交
1349
                          ". Possible reason: engine_config.omp_thread_num exceeds system cpu cores.";
1350
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1351
    }
Y
yudong.cai 已提交
1352
    return Status::OK();
Z
zhiru 已提交
1353 1354
}

C
Cai Yudong 已提交
1355
Status
F
feisiyicl 已提交
1356 1357 1358 1359 1360 1361
Config::CheckEngineConfigSimdType(const std::string& value) {
    fiu_return_on("check_config_simd_type_fail",
                  Status(SERVER_INVALID_ARGUMENT, "engine_config.simd_type is not one of avx512, avx2, sse and auto."));

    if (value != "avx512" && value != "avx2" && value != "sse" && value != "auto") {
        return Status(SERVER_INVALID_ARGUMENT, "engine_config.simd_type is not one of avx512, avx2, sse and auto.");
C
Cai Yudong 已提交
1362 1363 1364 1365
    }
    return Status::OK();
}

G
groot 已提交
1366
#ifdef MILVUS_GPU_VERSION
B
BossZou 已提交
1367

W
wxyu 已提交
1368
Status
1369
Config::CheckEngineConfigGpuSearchThreshold(const std::string& value) {
S
shengjh 已提交
1370 1371
    fiu_return_on("check_config_gpu_search_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

W
wxyu 已提交
1372
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1373 1374
        std::string msg = "Invalid gpu search threshold: " + value +
                          ". Possible reason: engine_config.gpu_search_threshold is not a positive integer.";
W
wxyu 已提交
1375 1376 1377 1378 1379
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

C
Cai Yudong 已提交
1380
/* gpu resource config */
S
starlord 已提交
1381
Status
1382
Config::CheckGpuResourceConfigEnable(const std::string& value) {
S
shengjh 已提交
1383 1384
    fiu_return_on("check_config_gpu_resource_enable_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1385
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
1386 1387
        std::string msg =
            "Invalid gpu resource config: " + value + ". Possible reason: gpu_resource_config.enable is not a boolean.";
1388
        return Status(SERVER_INVALID_ARGUMENT, msg);
W
wxyu 已提交
1389
    }
Y
yudong.cai 已提交
1390 1391
    return Status::OK();
}
1392

Y
yudong.cai 已提交
1393
Status
Y
yudong.cai 已提交
1394
Config::CheckGpuResourceConfigCacheCapacity(const std::string& value) {
S
shengjh 已提交
1395 1396
    fiu_return_on("check_gpu_resource_config_cache_capacity_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1397 1398 1399
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        std::string msg = "Invalid gpu cache capacity: " + value +
                          ". Possible reason: gpu_resource_config.cache_capacity is not a positive integer.";
1400
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1401
    } else {
Y
yudong.cai 已提交
1402 1403
        int64_t gpu_cache_capacity = std::stoll(value) * GB;
        std::vector<int64_t> gpu_ids;
C
Cai Yudong 已提交
1404
        STATUS_CHECK(GetGpuResourceConfigBuildIndexResources(gpu_ids));
Y
yudong.cai 已提交
1405

Y
yudong.cai 已提交
1406
        for (int64_t gpu_id : gpu_ids) {
Y
yudong.cai 已提交
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418
            size_t gpu_memory;
            if (!ValidationUtil::GetGpuMemory(gpu_id, gpu_memory).ok()) {
                std::string msg = "Fail to get GPU memory for GPU device: " + std::to_string(gpu_id);
                return Status(SERVER_UNEXPECTED_ERROR, msg);
            } else if (gpu_cache_capacity >= gpu_memory) {
                std::string msg = "Invalid gpu cache capacity: " + value +
                                  ". Possible reason: gpu_resource_config.cache_capacity exceeds GPU memory.";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            } else if (gpu_cache_capacity > (double)gpu_memory * 0.9) {
                std::cerr << "Warning: gpu cache capacity value is too big" << std::endl;
            }
        }
W
wxyu 已提交
1419
    }
Y
yudong.cai 已提交
1420 1421
    return Status::OK();
}
1422

Y
yudong.cai 已提交
1423
Status
Y
yudong.cai 已提交
1424
Config::CheckGpuResourceConfigCacheThreshold(const std::string& value) {
S
shengjh 已提交
1425 1426
    fiu_return_on("check_config_gpu_resource_cache_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
        std::string msg = "Invalid gpu cache threshold: " + value +
                          ". Possible reason: gpu_resource_config.cache_threshold is not in range (0.0, 1.0].";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
        float gpu_cache_threshold = std::stof(value);
        if (gpu_cache_threshold <= 0.0 || gpu_cache_threshold >= 1.0) {
            std::string msg = "Invalid gpu cache threshold: " + value +
                              ". Possible reason: gpu_resource_config.cache_threshold is not in range (0.0, 1.0].";
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
    }
    return Status::OK();
}

Status
CheckGpuResource(const std::string& value) {
Y
youny626 已提交
1444 1445
    std::string s = value;
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
Z
Zhiru Zhu 已提交
1446

Y
yudong.cai 已提交
1447
    const std::regex pat("gpu(\\d+)");
Z
Zhiru Zhu 已提交
1448 1449
    std::smatch m;
    if (!std::regex_match(s, m, pat)) {
Y
yudong.cai 已提交
1450 1451
        std::string msg = "Invalid gpu resource: " + value +
                          ". Possible reason: gpu_resource_config is not in the format of cpux or gpux";
1452
        return Status(SERVER_INVALID_ARGUMENT, msg);
1453 1454
    }

Z
Zhiru Zhu 已提交
1455
    if (s.compare(0, 3, "gpu") == 0) {
J
Jin Hai 已提交
1456 1457 1458 1459 1460 1461 1462 1463 1464
        try {
            int32_t gpu_index = std::stoi(s.substr(3));
            if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
                std::string msg = "Invalid gpu resource: " + value +
                                  ". Possible reason: gpu_resource_config does not match with the hardware.";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid gpu_resource_config: " + value);
Z
Zhiru Zhu 已提交
1465
        }
1466
    }
Z
Zhiru Zhu 已提交
1467

1468 1469 1470 1471
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1472
Config::CheckGpuResourceConfigSearchResources(const std::vector<std::string>& value) {
S
shengjh 已提交
1473 1474
    fiu_return_on("check_gpu_resource_config_search_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1475
    if (value.empty()) {
1476
        std::string msg =
Y
yudong.cai 已提交
1477 1478
            "Invalid gpu search resource. "
            "Possible reason: gpu_resource_config.search_resources is empty.";
1479
        return Status(SERVER_INVALID_ARGUMENT, msg);
1480 1481
    }

B
BossZou 已提交
1482
    std::unordered_set<std::string> value_set;
Z
Zhiru Zhu 已提交
1483
    for (auto& resource : value) {
C
Cai Yudong 已提交
1484
        STATUS_CHECK(CheckGpuResource(resource));
B
BossZou 已提交
1485
        value_set.insert(resource);
1486
    }
B
BossZou 已提交
1487 1488 1489 1490 1491 1492 1493 1494

    if (value_set.size() != value.size()) {
        std::string msg =
            "Invalid gpu build search resource. "
            "Possible reason: gpu_resource_config.gpu_search_resources contains duplicate resources.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }

1495 1496 1497 1498
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1499
Config::CheckGpuResourceConfigBuildIndexResources(const std::vector<std::string>& value) {
S
shengjh 已提交
1500 1501
    fiu_return_on("check_gpu_resource_config_build_index_fail", Status(SERVER_INVALID_ARGUMENT, ""));

1502 1503
    if (value.empty()) {
        std::string msg =
Y
yudong.cai 已提交
1504 1505
            "Invalid gpu build index resource. "
            "Possible reason: gpu_resource_config.build_index_resources is empty.";
1506 1507 1508
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }

B
BossZou 已提交
1509
    std::unordered_set<std::string> value_set;
1510
    for (auto& resource : value) {
C
Cai Yudong 已提交
1511
        STATUS_CHECK(CheckGpuResource(resource));
B
BossZou 已提交
1512 1513 1514 1515 1516 1517 1518 1519
        value_set.insert(resource);
    }

    if (value_set.size() != value.size()) {
        std::string msg =
            "Invalid gpu build index resource. "
            "Possible reason: gpu_resource_config.build_index_resources contains duplicate resources.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
G
groot 已提交
1520
    }
1521

Y
yudong.cai 已提交
1522
    return Status::OK();
G
groot 已提交
1523
}
B
BossZou 已提交
1524

G
groot 已提交
1525
#endif
G
groot 已提交
1526

1527 1528 1529 1530 1531 1532 1533
/* tracing config */
Status
Config::CheckTracingConfigJsonConfigPath(const std::string& value) {
    std::string msg = "Invalid wal config: " + value +
                      ". Possible reason: tracing_config.json_config_path is not supported to configure.";
    return Status(SERVER_INVALID_ARGUMENT, msg);
}
G
groot 已提交
1534

C
Cai Yudong 已提交
1535 1536 1537
/* wal config */
Status
Config::CheckWalConfigEnable(const std::string& value) {
J
Jin Hai 已提交
1538 1539 1540 1541
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_config_wal_enable_fail", exist_error = true);

    if (exist_error) {
C
Cai Yudong 已提交
1542 1543 1544 1545 1546 1547 1548 1549
        std::string msg = "Invalid wal config: " + value + ". Possible reason: wal_config.enable is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckWalConfigRecoveryErrorIgnore(const std::string& value) {
J
Jin Hai 已提交
1550 1551 1552 1553
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_config_wal_recovery_error_ignore_fail", exist_error = true);

    if (exist_error) {
C
Cai Yudong 已提交
1554 1555 1556 1557 1558 1559 1560 1561 1562
        std::string msg =
            "Invalid wal config: " + value + ". Possible reason: wal_config.recovery_error_ignore is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckWalConfigBufferSize(const std::string& value) {
J
Jin Hai 已提交
1563 1564 1565 1566
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_wal_buffer_size_fail", exist_error = true);

    if (exist_error) {
C
Cai Yudong 已提交
1567 1568 1569 1570 1571 1572 1573
        std::string msg = "Invalid wal buffer size: " + value +
                          ". Possible reason: wal_config.buffer_size is not a positive integer.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

J
Jin Hai 已提交
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
Status
Config::CheckWalConfigWalPath(const std::string& value) {
    fiu_return_on("check_wal_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
    if (value.empty()) {
        return Status(SERVER_INVALID_ARGUMENT, "wal_config.wal_path is empty!");
    }

    return ValidationUtil::ValidateStoragePath(value);
}

W
Wang XiangYu 已提交
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666
/* logs config */
Status
Config::CheckLogsTraceEnable(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_logs_trace_enable_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid logs config: " + value + ". Possible reason: logs.trace.enable is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckLogsDebugEnable(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_logs_debug_enable_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid logs config: " + value + ". Possible reason: logs.debug.enable is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckLogsInfoEnable(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_logs_info_enable_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid logs config: " + value + ". Possible reason: logs.info.enable is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckLogsWarningEnable(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_logs_warning_enable_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid logs config: " + value + ". Possible reason: logs.warning.enable is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckLogsErrorEnable(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_logs_error_enable_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid logs config: " + value + ". Possible reason: logs.error.enable is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckLogsFatalEnable(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_logs_fatal_enable_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid logs config: " + value + ". Possible reason: logs.fatal.enable is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckLogsPath(const std::string& value) {
    fiu_return_on("check_logs_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
    if (value.empty()) {
        return Status(SERVER_INVALID_ARGUMENT, "logs.path is empty!");
    }

    return ValidationUtil::ValidateStoragePath(value);
}

W
Wang XiangYu 已提交
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
Status
Config::CheckLogsMaxLogFileSize(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_logs_max_log_file_size_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid max_log_file_size: " + value +
                          ". Possible reason: logs.max_log_file_size is not a positive integer.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
Config::CheckLogsDeleteExceeds(const std::string& value) {
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_logs_delete_exceeds_fail", exist_error = true);

    if (exist_error) {
        std::string msg = "Invalid max_log_file_size: " + value +
                          ". Possible reason: logs.max_log_file_size is not a positive integer.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Y
yudong.cai 已提交
1693
////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
1694
ConfigNode&
1695
Config::GetConfigRoot() {
1696
    ConfigMgr* mgr = YamlConfigMgr::GetInstance();
1697 1698 1699 1700 1701 1702
    return mgr->GetRootNode();
}

ConfigNode&
Config::GetConfigNode(const std::string& name) {
    return GetConfigRoot().GetChild(name);
G
groot 已提交
1703 1704
}

C
Cai Yudong 已提交
1705 1706 1707 1708 1709
bool
Config::ConfigNodeValid(const std::string& parent_key, const std::string& child_key) {
    if (config_map_.find(parent_key) == config_map_.end()) {
        return false;
    }
S
shengjh 已提交
1710
    return config_map_[parent_key].count(child_key) != 0;
C
Cai Yudong 已提交
1711 1712
}

Y
yudong.cai 已提交
1713
Status
S
starlord 已提交
1714
Config::GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value) {
Y
yudong.cai 已提交
1715
    std::lock_guard<std::mutex> lock(mutex_);
Y
yudong.cai 已提交
1716 1717 1718 1719 1720
    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 已提交
1721
    return Status(SERVER_UNEXPECTED_ERROR, "key not exist");
Y
yudong.cai 已提交
1722 1723
}

C
Cai Yudong 已提交
1724
Status
S
starlord 已提交
1725
Config::SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value) {
Y
yudong.cai 已提交
1726 1727
    std::lock_guard<std::mutex> lock(mutex_);
    config_map_[parent_key][child_key] = value;
C
Cai Yudong 已提交
1728
    return Status::OK();
Y
yudong.cai 已提交
1729 1730 1731
}

////////////////////////////////////////////////////////////////////////////////
Y
yudong.cai 已提交
1732
std::string
S
starlord 已提交
1733
Config::GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value) {
Y
yudong.cai 已提交
1734
    std::string value;
S
starlord 已提交
1735 1736 1737
    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 已提交
1738
    }
Y
yudong.cai 已提交
1739
    return value;
Y
yudong.cai 已提交
1740 1741
}

Z
Zhiru Zhu 已提交
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
std::string
Config::GetConfigSequenceStr(const std::string& parent_key, const std::string& child_key, const std::string& delim,
                             const std::string& default_value) {
    std::string value;
    if (!GetConfigValueInMem(parent_key, child_key, value).ok()) {
        std::vector<std::string> sequence = GetConfigNode(parent_key).GetSequence(child_key);
        if (sequence.empty()) {
            value = default_value;
        } else {
            server::StringHelpFunctions::MergeStringWithDelimeter(sequence, delim, value);
        }
        SetConfigValueInMem(parent_key, child_key, value);
    }
    return value;
}

1758 1759 1760 1761 1762 1763
Status
Config::GetConfigVersion(std::string& value) {
    value = GetConfigRoot().GetValue(CONFIG_VERSION);
    return CheckConfigVersion(value);
}

1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
Status
Config::ExecCallBacks(const std::string& node, const std::string& sub_node, const std::string& value) {
    auto status = Status::OK();

    if (config_callback_.empty()) {
        return Status(SERVER_UNEXPECTED_ERROR, "Callback map is empty. Cannot take effect in-service");
    }

    std::string cb_node = node + "." + sub_node;
    if (config_callback_.find(cb_node) == config_callback_.end()) {
        return Status(SERVER_UNEXPECTED_ERROR,
                      "Cannot find " + cb_node + " in callback map, cannot take effect in-service");
    }

    auto& cb_map = config_callback_.at(cb_node);
    for (auto& cb_kv : cb_map) {
        auto& cd = cb_kv.second;
        status = cd(value);
        if (!status.ok()) {
            break;
        }
    }

    return status;
}

C
Cai Yudong 已提交
1790
/* server config */
1791
Status
S
starlord 已提交
1792
Config::GetServerConfigAddress(std::string& value) {
S
starlord 已提交
1793
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, CONFIG_SERVER_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
1794
    return CheckServerConfigAddress(value);
1795 1796 1797
}

Status
S
starlord 已提交
1798
Config::GetServerConfigPort(std::string& value) {
S
starlord 已提交
1799
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_PORT, CONFIG_SERVER_PORT_DEFAULT);
Y
yudong.cai 已提交
1800
    return CheckServerConfigPort(value);
1801 1802 1803
}

Status
S
starlord 已提交
1804
Config::GetServerConfigDeployMode(std::string& value) {
S
starlord 已提交
1805
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, CONFIG_SERVER_DEPLOY_MODE_DEFAULT);
Y
yudong.cai 已提交
1806
    return CheckServerConfigDeployMode(value);
1807 1808 1809
}

Status
S
starlord 已提交
1810
Config::GetServerConfigTimeZone(std::string& value) {
S
starlord 已提交
1811
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, CONFIG_SERVER_TIME_ZONE_DEFAULT);
Y
yudong.cai 已提交
1812
    return CheckServerConfigTimeZone(value);
1813 1814
}

1815 1816 1817
Status
Config::GetServerConfigWebEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_WEB_ENABLE, CONFIG_SERVER_WEB_ENABLE_DEFAULT);
C
Cai Yudong 已提交
1818
    STATUS_CHECK(CheckServerConfigWebEnable(str));
1819 1820 1821
    return StringHelpFunctions::ConvertToBoolean(str, value);
}

B
BossZou 已提交
1822 1823 1824 1825 1826 1827
Status
Config::GetServerConfigWebPort(std::string& value) {
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_WEB_PORT, CONFIG_SERVER_WEB_PORT_DEFAULT);
    return CheckServerConfigWebPort(value);
}

C
Cai Yudong 已提交
1828
/* DB config */
1829
Status
S
starlord 已提交
1830
Config::GetDBConfigBackendUrl(std::string& value) {
S
starlord 已提交
1831
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_BACKEND_URL, CONFIG_DB_BACKEND_URL_DEFAULT);
Y
yudong.cai 已提交
1832
    return CheckDBConfigBackendUrl(value);
1833 1834 1835
}

Status
Y
yudong.cai 已提交
1836
Config::GetDBConfigArchiveDiskThreshold(int64_t& value) {
S
starlord 已提交
1837 1838
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1839
    STATUS_CHECK(CheckDBConfigArchiveDiskThreshold(str));
Y
yudong.cai 已提交
1840
    value = std::stoll(str);
1841 1842 1843 1844
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1845
Config::GetDBConfigArchiveDaysThreshold(int64_t& value) {
S
starlord 已提交
1846 1847
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1848
    STATUS_CHECK(CheckDBConfigArchiveDaysThreshold(str));
Y
yudong.cai 已提交
1849
    value = std::stoll(str);
1850 1851 1852
    return Status::OK();
}

S
starlord 已提交
1853
Status
1854
Config::GetDBConfigPreloadCollection(std::string& value) {
G
groot 已提交
1855
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_PRELOAD_COLLECTION);
S
starlord 已提交
1856 1857 1858
    return Status::OK();
}

1859
Status
C
Cai Yudong 已提交
1860
Config::GetDBConfigAutoFlushInterval(int64_t& value) {
1861
    std::string str = GetConfigStr(CONFIG_DB, CONFIG_DB_AUTO_FLUSH_INTERVAL, CONFIG_DB_AUTO_FLUSH_INTERVAL_DEFAULT);
C
Cai Yudong 已提交
1862
    STATUS_CHECK(CheckDBConfigAutoFlushInterval(str));
C
Cai Yudong 已提交
1863
    value = std::stoll(str);
1864 1865 1866
    return Status::OK();
}

C
Cai Yudong 已提交
1867
/* storage config */
1868 1869
Status
Config::GetStorageConfigPrimaryPath(std::string& value) {
C
Cai Yudong 已提交
1870
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_PRIMARY_PATH, CONFIG_STORAGE_PRIMARY_PATH_DEFAULT);
1871 1872 1873 1874 1875
    return CheckStorageConfigPrimaryPath(value);
}

Status
Config::GetStorageConfigSecondaryPath(std::string& value) {
C
Cai Yudong 已提交
1876
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_SECONDARY_PATH, CONFIG_STORAGE_SECONDARY_PATH_DEFAULT);
1877 1878 1879
    return CheckStorageConfigSecondaryPath(value);
}

G
groot 已提交
1880 1881 1882 1883
Status
Config::GetStorageConfigFileCleanupTimeup(int64_t& value) {
    std::string str =
        GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_FILE_CLEANUP_TIMEOUT, CONFIG_STORAGE_FILE_CLEANUP_TIMEOUT_DEFAULT);
C
Cai Yudong 已提交
1884
    STATUS_CHECK(CheckStorageConfigFileCleanupTimeout(str));
G
groot 已提交
1885 1886 1887 1888
    value = std::stoll(str);
    return Status::OK();
}

C
Cai Yudong 已提交
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
// Status
// Config::GetStorageConfigS3Enable(bool& value) {
//    std::string str = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ENABLE, CONFIG_STORAGE_S3_ENABLE_DEFAULT);
//    STATUS_CHECK(CheckStorageConfigS3Enable(str));
//    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
//    return Status::OK();
// }
//
// Status
// Config::GetStorageConfigS3Address(std::string& value) {
//    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ADDRESS, CONFIG_STORAGE_S3_ADDRESS_DEFAULT);
//    return CheckStorageConfigS3Address(value);
// }
//
// Status
// Config::GetStorageConfigS3Port(std::string& value) {
//    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_PORT, CONFIG_STORAGE_S3_PORT_DEFAULT);
//    return CheckStorageConfigS3Port(value);
// }
//
// Status
// Config::GetStorageConfigS3AccessKey(std::string& value) {
//    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ACCESS_KEY, CONFIG_STORAGE_S3_ACCESS_KEY_DEFAULT);
//    return Status::OK();
// }
//
// Status
// Config::GetStorageConfigS3SecretKey(std::string& value) {
//    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_SECRET_KEY, CONFIG_STORAGE_S3_SECRET_KEY_DEFAULT);
//    return Status::OK();
// }
//
// Status
// Config::GetStorageConfigS3Bucket(std::string& value) {
//    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_BUCKET, CONFIG_STORAGE_S3_BUCKET_DEFAULT);
//    return Status::OK();
// }
C
Cai Yudong 已提交
1926 1927

/* metric config */
1928
Status
S
starlord 已提交
1929
Config::GetMetricConfigEnableMonitor(bool& value) {
1930
    std::string str = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, CONFIG_METRIC_ENABLE_MONITOR_DEFAULT);
C
Cai Yudong 已提交
1931 1932
    STATUS_CHECK(CheckMetricConfigEnableMonitor(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
1933 1934 1935 1936
    return Status::OK();
}

Status
C
Cai Yudong 已提交
1937 1938
Config::GetMetricConfigAddress(std::string& value) {
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_ADDRESS, CONFIG_METRIC_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
1939
    return Status::OK();
1940 1941
}

1942
Status
C
Cai Yudong 已提交
1943 1944 1945
Config::GetMetricConfigPort(std::string& value) {
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_PORT, CONFIG_METRIC_PORT_DEFAULT);
    return CheckMetricConfigPort(value);
1946 1947
}

C
Cai Yudong 已提交
1948
/* cache config */
1949
Status
W
wxyu 已提交
1950
Config::GetCacheConfigCpuCacheCapacity(int64_t& value) {
S
starlord 已提交
1951 1952
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT);
C
Cai Yudong 已提交
1953
    STATUS_CHECK(CheckCacheConfigCpuCacheCapacity(str));
Y
yudong.cai 已提交
1954
    value = std::stoll(str);
1955 1956 1957 1958
    return Status::OK();
}

Status
S
starlord 已提交
1959
Config::GetCacheConfigCpuCacheThreshold(float& value) {
S
starlord 已提交
1960 1961
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1962
    STATUS_CHECK(CheckCacheConfigCpuCacheThreshold(str));
1963 1964 1965 1966
    value = std::stof(str);
    return Status::OK();
}

1967 1968 1969 1970
Status
Config::GetCacheConfigInsertBufferSize(int64_t& value) {
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT);
C
Cai Yudong 已提交
1971
    STATUS_CHECK(CheckCacheConfigInsertBufferSize(str));
1972 1973 1974 1975
    value = std::stoll(str);
    return Status::OK();
}

1976
Status
S
starlord 已提交
1977
Config::GetCacheConfigCacheInsertData(bool& value) {
S
starlord 已提交
1978 1979
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
C
Cai Yudong 已提交
1980
    STATUS_CHECK(CheckCacheConfigCacheInsertData(str));
1981 1982 1983 1984 1985
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    value = (str == "true" || str == "on" || str == "yes" || str == "1");
    return Status::OK();
}

C
Cai Yudong 已提交
1986
/* engine config */
1987
Status
Y
yudong.cai 已提交
1988
Config::GetEngineConfigUseBlasThreshold(int64_t& value) {
S
starlord 已提交
1989 1990
    std::string str =
        GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1991
    STATUS_CHECK(CheckEngineConfigUseBlasThreshold(str));
Y
yudong.cai 已提交
1992
    value = std::stoll(str);
1993 1994 1995 1996
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1997
Config::GetEngineConfigOmpThreadNum(int64_t& value) {
1998
    std::string str = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
C
Cai Yudong 已提交
1999
    STATUS_CHECK(CheckEngineConfigOmpThreadNum(str));
Y
yudong.cai 已提交
2000
    value = std::stoll(str);
2001 2002 2003
    return Status::OK();
}

C
Cai Yudong 已提交
2004
Status
F
feisiyicl 已提交
2005 2006 2007
Config::GetEngineConfigSimdType(std::string& value) {
    value = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_SIMD_TYPE, CONFIG_ENGINE_SIMD_TYPE_DEFAULT);
    return CheckEngineConfigSimdType(value);
C
Cai Yudong 已提交
2008 2009
}

G
groot 已提交
2010
#ifdef MILVUS_GPU_VERSION
W
wxyu 已提交
2011
Status
Y
yudong.cai 已提交
2012
Config::GetEngineConfigGpuSearchThreshold(int64_t& value) {
W
wxyu 已提交
2013
    std::string str =
2014
        GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
2015
    STATUS_CHECK(CheckEngineConfigGpuSearchThreshold(str));
Y
yudong.cai 已提交
2016
    value = std::stoll(str);
W
wxyu 已提交
2017 2018
    return Status::OK();
}
C
Cai Yudong 已提交
2019
#endif
W
wxyu 已提交
2020

C
Cai Yudong 已提交
2021 2022
/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
S
shengjh 已提交
2023

2024
Status
2025 2026
Config::GetGpuResourceConfigEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, CONFIG_GPU_RESOURCE_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2027 2028
    STATUS_CHECK(CheckGpuResourceConfigEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
Y
yudong.cai 已提交
2029
    return Status::OK();
2030 2031 2032
}

Status
Y
yudong.cai 已提交
2033
Config::GetGpuResourceConfigCacheCapacity(int64_t& value) {
2034
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
2035
    STATUS_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
2036
    fiu_do_on("Config.GetGpuResourceConfigCacheCapacity.diable_gpu_resource", gpu_resource_enable = false);
2037 2038
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
2039 2040 2041 2042
        return Status(SERVER_UNSUPPORTED_ERROR, msg);
    }
    std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY,
                                   CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT);
C
Cai Yudong 已提交
2043
    STATUS_CHECK(CheckGpuResourceConfigCacheCapacity(str));
Y
yudong.cai 已提交
2044
    value = std::stoll(str);
W
wxyu 已提交
2045 2046 2047
    return Status::OK();
}

2048
Status
Y
yudong.cai 已提交
2049
Config::GetGpuResourceConfigCacheThreshold(float& value) {
2050
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
2051
    STATUS_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
2052
    fiu_do_on("Config.GetGpuResourceConfigCacheThreshold.diable_gpu_resource", gpu_resource_enable = false);
2053 2054
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
2055 2056 2057 2058
        return Status(SERVER_UNSUPPORTED_ERROR, msg);
    }
    std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD,
                                   CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
2059
    STATUS_CHECK(CheckGpuResourceConfigCacheThreshold(str));
Y
yudong.cai 已提交
2060 2061
    value = std::stof(str);
    return Status::OK();
2062 2063 2064
}

Status
Y
yudong.cai 已提交
2065
Config::GetGpuResourceConfigSearchResources(std::vector<int64_t>& value) {
2066
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
2067
    STATUS_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
2068
    fiu_do_on("get_gpu_config_search_resources.disable_gpu_resource_fail", gpu_resource_enable = false);
2069 2070
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
2071 2072 2073 2074 2075 2076
        return Status(SERVER_UNSUPPORTED_ERROR, msg);
    }
    std::string str = GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES,
                                           CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT);
    std::vector<std::string> res_vec;
    server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
C
Cai Yudong 已提交
2077
    STATUS_CHECK(CheckGpuResourceConfigSearchResources(res_vec));
2078
    value.clear();
Y
yudong.cai 已提交
2079
    for (std::string& res : res_vec) {
Y
yudong.cai 已提交
2080
        value.push_back(std::stoll(res.substr(3)));
Y
yudong.cai 已提交
2081 2082
    }
    return Status::OK();
2083 2084 2085
}

Status
Y
yudong.cai 已提交
2086
Config::GetGpuResourceConfigBuildIndexResources(std::vector<int64_t>& value) {
2087
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
2088
    STATUS_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
2089
    fiu_do_on("get_gpu_config_build_index_resources.disable_gpu_resource_fail", gpu_resource_enable = false);
2090 2091
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
2092 2093
        return Status(SERVER_UNSUPPORTED_ERROR, msg);
    }
2094
    std::string str =
Y
yudong.cai 已提交
2095 2096 2097 2098
        GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES,
                             CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT);
    std::vector<std::string> res_vec;
    server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
C
Cai Yudong 已提交
2099
    STATUS_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec));
2100
    value.clear();
Y
yudong.cai 已提交
2101
    for (std::string& res : res_vec) {
Y
yudong.cai 已提交
2102
        value.push_back(std::stoll(res.substr(3)));
Y
yudong.cai 已提交
2103
    }
2104
    return Status::OK();
Y
yudong.cai 已提交
2105
}
B
BossZou 已提交
2106

G
groot 已提交
2107
#endif
G
groot 已提交
2108

Z
Zhiru Zhu 已提交
2109 2110 2111 2112
/* tracing config */
Status
Config::GetTracingConfigJsonConfigPath(std::string& value) {
    value = GetConfigStr(CONFIG_TRACING, CONFIG_TRACING_JSON_CONFIG_PATH, "");
S
shengjh 已提交
2113
    fiu_do_on("get_config_json_config_path_fail", value = "error_config_json_path");
Z
Zhiru Zhu 已提交
2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124
    if (!value.empty()) {
        std::ifstream tracer_config(value);
        Status s = tracer_config.good() ? Status::OK()
                                        : Status(SERVER_INVALID_ARGUMENT, "Failed to open tracer config file " + value +
                                                                              ": " + std::strerror(errno));
        tracer_config.close();
        return s;
    }
    return Status::OK();
}

2125 2126 2127 2128
/* wal config */
Status
Config::GetWalConfigEnable(bool& wal_enable) {
    std::string str = GetConfigStr(CONFIG_WAL, CONFIG_WAL_ENABLE, CONFIG_WAL_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2129 2130
    STATUS_CHECK(CheckWalConfigEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, wal_enable));
2131 2132 2133 2134 2135 2136 2137
    return Status::OK();
}

Status
Config::GetWalConfigRecoveryErrorIgnore(bool& recovery_error_ignore) {
    std::string str =
        GetConfigStr(CONFIG_WAL, CONFIG_WAL_RECOVERY_ERROR_IGNORE, CONFIG_WAL_RECOVERY_ERROR_IGNORE_DEFAULT);
C
Cai Yudong 已提交
2138 2139
    STATUS_CHECK(CheckWalConfigRecoveryErrorIgnore(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, recovery_error_ignore));
2140 2141 2142 2143
    return Status::OK();
}

Status
C
Cai Yudong 已提交
2144
Config::GetWalConfigBufferSize(int64_t& buffer_size) {
2145
    std::string str = GetConfigStr(CONFIG_WAL, CONFIG_WAL_BUFFER_SIZE, CONFIG_WAL_BUFFER_SIZE_DEFAULT);
C
Cai Yudong 已提交
2146
    STATUS_CHECK(CheckWalConfigBufferSize(str));
C
Cai Yudong 已提交
2147
    buffer_size = std::stoll(str);
2148 2149 2150 2151 2152
    if (buffer_size > CONFIG_WAL_BUFFER_SIZE_MAX) {
        buffer_size = CONFIG_WAL_BUFFER_SIZE_MAX;
    } else if (buffer_size < CONFIG_WAL_BUFFER_SIZE_MIN) {
        buffer_size = CONFIG_WAL_BUFFER_SIZE_MIN;
    }
2153 2154 2155 2156 2157
    return Status::OK();
}

Status
Config::GetWalConfigWalPath(std::string& wal_path) {
C
Cai Yudong 已提交
2158
    wal_path = GetConfigStr(CONFIG_WAL, CONFIG_WAL_WAL_PATH, CONFIG_WAL_WAL_PATH_DEFAULT);
C
Cai Yudong 已提交
2159
    STATUS_CHECK(CheckWalConfigWalPath(wal_path));
2160 2161 2162
    return Status::OK();
}

W
Wang XiangYu 已提交
2163 2164 2165 2166
/* logs config */
Status
Config::GetLogsTraceEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_TRACE_ENABLE, CONFIG_LOGS_TRACE_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2167 2168
    STATUS_CHECK(CheckLogsTraceEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
W
Wang XiangYu 已提交
2169 2170 2171 2172 2173 2174
    return Status::OK();
}

Status
Config::GetLogsDebugEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_DEBUG_ENABLE, CONFIG_LOGS_DEBUG_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2175 2176
    STATUS_CHECK(CheckLogsDebugEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
W
Wang XiangYu 已提交
2177 2178 2179 2180 2181 2182
    return Status::OK();
}

Status
Config::GetLogsInfoEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_INFO_ENABLE, CONFIG_LOGS_INFO_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2183 2184
    STATUS_CHECK(CheckLogsInfoEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
W
Wang XiangYu 已提交
2185 2186 2187 2188 2189 2190
    return Status::OK();
}

Status
Config::GetLogsWarningEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_WARNING_ENABLE, CONFIG_LOGS_WARNING_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2191 2192
    STATUS_CHECK(CheckLogsWarningEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
W
Wang XiangYu 已提交
2193 2194 2195 2196 2197 2198
    return Status::OK();
}

Status
Config::GetLogsErrorEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_ERROR_ENABLE, CONFIG_LOGS_ERROR_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2199 2200
    STATUS_CHECK(CheckLogsErrorEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
W
Wang XiangYu 已提交
2201 2202 2203 2204 2205 2206
    return Status::OK();
}

Status
Config::GetLogsFatalEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_FATAL_ENABLE, CONFIG_LOGS_FATAL_ENABLE_DEFAULT);
C
Cai Yudong 已提交
2207 2208
    STATUS_CHECK(CheckLogsFatalEnable(str));
    STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
W
Wang XiangYu 已提交
2209 2210 2211 2212 2213 2214
    return Status::OK();
}

Status
Config::GetLogsPath(std::string& value) {
    value = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_PATH, CONFIG_LOGS_PATH_DEFAULT);
C
Cai Yudong 已提交
2215
    STATUS_CHECK(CheckLogsPath(value));
W
Wang XiangYu 已提交
2216 2217 2218 2219 2220 2221
    return Status::OK();
}

Status
Config::GetLogsMaxLogFileSize(int64_t& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_MAX_LOG_FILE_SIZE, CONFIG_LOGS_MAX_LOG_FILE_SIZE_DEFAULT);
C
Cai Yudong 已提交
2222
    STATUS_CHECK(CheckLogsMaxLogFileSize(str));
W
Wang XiangYu 已提交
2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237
    value = std::stoll(str);
    if (value == 0) {
        // OFF
    } else if (value > CONFIG_LOGS_MAX_LOG_FILE_SIZE_MAX) {
        value = CONFIG_LOGS_MAX_LOG_FILE_SIZE_MAX;
    } else if (value < CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN) {
        value = CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN;
    }

    return Status::OK();
}

Status
Config::GetLogsDeleteExceeds(int64_t& value) {
    std::string str = GetConfigStr(CONFIG_LOGS, CONFIG_LOGS_DELETE_EXCEEDS, CONFIG_LOGS_DELETE_EXCEEDS_DEFAULT);
C
Cai Yudong 已提交
2238
    STATUS_CHECK(CheckLogsDeleteExceeds(str));
W
Wang XiangYu 已提交
2239 2240 2241 2242 2243 2244 2245 2246 2247
    value = std::stoll(str);
    if (value == 0) {
        // OFF
    } else if (value > CONFIG_LOGS_DELETE_EXCEEDS_MAX) {
        value = CONFIG_LOGS_DELETE_EXCEEDS_MAX;
    } else if (value < CONFIG_LOGS_DELETE_EXCEEDS_MIN) {
        value = CONFIG_LOGS_DELETE_EXCEEDS_MIN;
    }

W
Wang XiangYu 已提交
2248 2249 2250
    return Status::OK();
}

2251 2252 2253 2254 2255 2256
Status
Config::GetServerRestartRequired(bool& required) {
    required = restart_required_;
    return Status::OK();
}

Y
yudong.cai 已提交
2257 2258 2259
///////////////////////////////////////////////////////////////////////////////
/* server config */
Status
S
starlord 已提交
2260
Config::SetServerConfigAddress(const std::string& value) {
C
Cai Yudong 已提交
2261
    STATUS_CHECK(CheckServerConfigAddress(value));
C
Cai Yudong 已提交
2262
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
Y
yudong.cai 已提交
2263 2264 2265
}

Status
S
starlord 已提交
2266
Config::SetServerConfigPort(const std::string& value) {
C
Cai Yudong 已提交
2267
    STATUS_CHECK(CheckServerConfigPort(value));
C
Cai Yudong 已提交
2268
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value);
Y
yudong.cai 已提交
2269 2270 2271
}

Status
S
starlord 已提交
2272
Config::SetServerConfigDeployMode(const std::string& value) {
C
Cai Yudong 已提交
2273
    STATUS_CHECK(CheckServerConfigDeployMode(value));
C
Cai Yudong 已提交
2274
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, value);
Y
yudong.cai 已提交
2275 2276 2277
}

Status
S
starlord 已提交
2278
Config::SetServerConfigTimeZone(const std::string& value) {
C
Cai Yudong 已提交
2279
    STATUS_CHECK(CheckServerConfigTimeZone(value));
C
Cai Yudong 已提交
2280
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
Y
yudong.cai 已提交
2281 2282
}

2283 2284
Status
Config::SetServerConfigWebEnable(const std::string& value) {
C
Cai Yudong 已提交
2285
    STATUS_CHECK(CheckServerConfigWebEnable(value));
2286 2287 2288
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_WEB_ENABLE, value);
}

B
BossZou 已提交
2289 2290
Status
Config::SetServerConfigWebPort(const std::string& value) {
C
Cai Yudong 已提交
2291
    STATUS_CHECK(CheckServerConfigWebPort(value));
B
BossZou 已提交
2292 2293 2294
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_WEB_PORT, value);
}

Y
yudong.cai 已提交
2295 2296
/* db config */
Status
S
starlord 已提交
2297
Config::SetDBConfigBackendUrl(const std::string& value) {
C
Cai Yudong 已提交
2298
    STATUS_CHECK(CheckDBConfigBackendUrl(value));
C
Cai Yudong 已提交
2299
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value);
Y
yudong.cai 已提交
2300 2301
}

2302
Status
2303
Config::SetDBConfigPreloadCollection(const std::string& value) {
C
Cai Yudong 已提交
2304
    STATUS_CHECK(CheckDBConfigPreloadCollection(value));
2305
    std::string cor_value = value == "*" ? "\'*\'" : value;
G
groot 已提交
2306
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRELOAD_COLLECTION, cor_value);
2307 2308
}

Y
yudong.cai 已提交
2309
Status
S
starlord 已提交
2310
Config::SetDBConfigArchiveDiskThreshold(const std::string& value) {
C
Cai Yudong 已提交
2311
    STATUS_CHECK(CheckDBConfigArchiveDiskThreshold(value));
C
Cai Yudong 已提交
2312
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value);
Y
yudong.cai 已提交
2313 2314 2315
}

Status
S
starlord 已提交
2316
Config::SetDBConfigArchiveDaysThreshold(const std::string& value) {
C
Cai Yudong 已提交
2317
    STATUS_CHECK(CheckDBConfigArchiveDaysThreshold(value));
C
Cai Yudong 已提交
2318
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value);
Y
yudong.cai 已提交
2319 2320
}

2321 2322
Status
Config::SetDBConfigAutoFlushInterval(const std::string& value) {
C
Cai Yudong 已提交
2323
    STATUS_CHECK(CheckDBConfigAutoFlushInterval(value));
2324 2325 2326
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_AUTO_FLUSH_INTERVAL, value);
}

C
Cai Yudong 已提交
2327
/* storage config */
2328 2329
Status
Config::SetStorageConfigPrimaryPath(const std::string& value) {
C
Cai Yudong 已提交
2330
    STATUS_CHECK(CheckStorageConfigPrimaryPath(value));
C
Cai Yudong 已提交
2331
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_PRIMARY_PATH, value);
2332 2333 2334 2335
}

Status
Config::SetStorageConfigSecondaryPath(const std::string& value) {
C
Cai Yudong 已提交
2336
    STATUS_CHECK(CheckStorageConfigSecondaryPath(value));
C
Cai Yudong 已提交
2337
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_SECONDARY_PATH, value);
2338 2339
}

G
groot 已提交
2340 2341
Status
Config::SetStorageConfigFileCleanupTimeout(const std::string& value) {
C
Cai Yudong 已提交
2342
    STATUS_CHECK(CheckStorageConfigFileCleanupTimeout(value));
G
groot 已提交
2343 2344 2345
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_FILE_CLEANUP_TIMEOUT, value);
}

C
Cai Yudong 已提交
2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380
// Status
// Config::SetStorageConfigS3Enable(const std::string& value) {
//    STATUS_CHECK(CheckStorageConfigS3Enable(value));
//    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ENABLE, value);
// }
//
// Status
// Config::SetStorageConfigS3Address(const std::string& value) {
//    STATUS_CHECK(CheckStorageConfigS3Address(value));
//    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ADDRESS, value);
// }
//
// Status
// Config::SetStorageConfigS3Port(const std::string& value) {
//    STATUS_CHECK(CheckStorageConfigS3Port(value));
//    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_PORT, value);
// }
//
// Status
// Config::SetStorageConfigS3AccessKey(const std::string& value) {
//    STATUS_CHECK(CheckStorageConfigS3AccessKey(value));
//    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ACCESS_KEY, value);
// }
//
// Status
// Config::SetStorageConfigS3SecretKey(const std::string& value) {
//    STATUS_CHECK(CheckStorageConfigS3SecretKey(value));
//    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_SECRET_KEY, value);
// }
//
// Status
// Config::SetStorageConfigS3Bucket(const std::string& value) {
//    STATUS_CHECK(CheckStorageConfigS3Bucket(value));
//    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_BUCKET, value);
// }
Y
yudong.cai 已提交
2381 2382 2383

/* metric config */
Status
S
starlord 已提交
2384
Config::SetMetricConfigEnableMonitor(const std::string& value) {
C
Cai Yudong 已提交
2385
    STATUS_CHECK(CheckMetricConfigEnableMonitor(value));
C
Cai Yudong 已提交
2386
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, value);
Y
yudong.cai 已提交
2387 2388 2389
}

Status
C
Cai Yudong 已提交
2390
Config::SetMetricConfigAddress(const std::string& value) {
C
Cai Yudong 已提交
2391
    STATUS_CHECK(CheckMetricConfigAddress(value));
C
Cai Yudong 已提交
2392
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ADDRESS, value);
2393 2394
}

Y
yudong.cai 已提交
2395
Status
C
Cai Yudong 已提交
2396
Config::SetMetricConfigPort(const std::string& value) {
C
Cai Yudong 已提交
2397
    STATUS_CHECK(CheckMetricConfigPort(value));
C
Cai Yudong 已提交
2398
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_PORT, value);
Y
yudong.cai 已提交
2399 2400 2401 2402
}

/* cache config */
Status
S
starlord 已提交
2403
Config::SetCacheConfigCpuCacheCapacity(const std::string& value) {
C
Cai Yudong 已提交
2404 2405
    STATUS_CHECK(CheckCacheConfigCpuCacheCapacity(value));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value));
2406
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value);
Y
yudong.cai 已提交
2407 2408 2409
}

Status
S
starlord 已提交
2410
Config::SetCacheConfigCpuCacheThreshold(const std::string& value) {
C
Cai Yudong 已提交
2411
    STATUS_CHECK(CheckCacheConfigCpuCacheThreshold(value));
C
Cai Yudong 已提交
2412
    return SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, value);
Y
yudong.cai 已提交
2413 2414
}

2415 2416
Status
Config::SetCacheConfigInsertBufferSize(const std::string& value) {
C
Cai Yudong 已提交
2417 2418
    STATUS_CHECK(CheckCacheConfigInsertBufferSize(value));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, value));
2419
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, value);
2420 2421
}

Y
yudong.cai 已提交
2422
Status
S
starlord 已提交
2423
Config::SetCacheConfigCacheInsertData(const std::string& value) {
C
Cai Yudong 已提交
2424 2425
    STATUS_CHECK(CheckCacheConfigCacheInsertData(value));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value));
2426
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value);
Y
yudong.cai 已提交
2427 2428 2429 2430
}

/* engine config */
Status
S
starlord 已提交
2431
Config::SetEngineConfigUseBlasThreshold(const std::string& value) {
C
Cai Yudong 已提交
2432 2433
    STATUS_CHECK(CheckEngineConfigUseBlasThreshold(value));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value));
2434
    return ExecCallBacks(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value);
Y
yudong.cai 已提交
2435 2436 2437
}

Status
S
starlord 已提交
2438
Config::SetEngineConfigOmpThreadNum(const std::string& value) {
C
Cai Yudong 已提交
2439
    STATUS_CHECK(CheckEngineConfigOmpThreadNum(value));
C
Cai Yudong 已提交
2440
    return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, value);
Y
yudong.cai 已提交
2441 2442
}

C
Cai Yudong 已提交
2443
Status
F
feisiyicl 已提交
2444
Config::SetEngineConfigSimdType(const std::string& value) {
C
Cai Yudong 已提交
2445
    STATUS_CHECK(CheckEngineConfigSimdType(value));
F
feisiyicl 已提交
2446
    return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_SIMD_TYPE, value);
C
Cai Yudong 已提交
2447 2448
}

C
Cai Yudong 已提交
2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498
#ifdef MILVUS_GPU_VERSION
Status
Config::SetEngineConfigGpuSearchThreshold(const std::string& value) {
    STATUS_CHECK(CheckEngineConfigGpuSearchThreshold(value));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value));
    return ExecCallBacks(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value);
}
#endif

/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
Status
Config::SetGpuResourceConfigEnable(const std::string& value) {
    STATUS_CHECK(CheckGpuResourceConfigEnable(value));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value));
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value);
}

Status
Config::SetGpuResourceConfigCacheCapacity(const std::string& value) {
    STATUS_CHECK(CheckGpuResourceConfigCacheCapacity(value));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value));
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value);
}

Status
Config::SetGpuResourceConfigCacheThreshold(const std::string& value) {
    STATUS_CHECK(CheckGpuResourceConfigCacheThreshold(value));
    return SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD, value);
}

Status
Config::SetGpuResourceConfigSearchResources(const std::string& value) {
    std::vector<std::string> res_vec;
    server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
    STATUS_CHECK(CheckGpuResourceConfigSearchResources(res_vec));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value));
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value);
}

Status
Config::SetGpuResourceConfigBuildIndexResources(const std::string& value) {
    std::vector<std::string> res_vec;
    server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
    STATUS_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec));
    STATUS_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value));
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value);
}
#endif

2499 2500 2501
/* tracing config */
Status
Config::SetTracingConfigJsonConfigPath(const std::string& value) {
C
Cai Yudong 已提交
2502
    STATUS_CHECK(CheckTracingConfigJsonConfigPath(value));
2503 2504 2505
    return SetConfigValueInMem(CONFIG_TRACING, CONFIG_TRACING_JSON_CONFIG_PATH, value);
}

J
Jin Hai 已提交
2506 2507 2508
/* wal config */
Status
Config::SetWalConfigEnable(const std::string& value) {
C
Cai Yudong 已提交
2509
    STATUS_CHECK(CheckWalConfigEnable(value));
J
Jin Hai 已提交
2510 2511 2512 2513 2514
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_ENABLE, value);
}

Status
Config::SetWalConfigRecoveryErrorIgnore(const std::string& value) {
C
Cai Yudong 已提交
2515
    STATUS_CHECK(CheckWalConfigRecoveryErrorIgnore(value));
2516
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_RECOVERY_ERROR_IGNORE, value);
J
Jin Hai 已提交
2517 2518 2519 2520
}

Status
Config::SetWalConfigBufferSize(const std::string& value) {
C
Cai Yudong 已提交
2521
    STATUS_CHECK(CheckWalConfigBufferSize(value));
J
Jin Hai 已提交
2522 2523 2524 2525 2526
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_BUFFER_SIZE, value);
}

Status
Config::SetWalConfigWalPath(const std::string& value) {
C
Cai Yudong 已提交
2527
    STATUS_CHECK(CheckWalConfigWalPath(value));
J
Jin Hai 已提交
2528 2529 2530
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_WAL_PATH, value);
}

W
Wang XiangYu 已提交
2531 2532 2533
/* logs config */
Status
Config::SetLogsTraceEnable(const std::string& value) {
C
Cai Yudong 已提交
2534
    STATUS_CHECK(CheckLogsTraceEnable(value));
W
Wang XiangYu 已提交
2535 2536 2537 2538 2539
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_TRACE_ENABLE, value);
}

Status
Config::SetLogsDebugEnable(const std::string& value) {
C
Cai Yudong 已提交
2540
    STATUS_CHECK(CheckLogsDebugEnable(value));
W
Wang XiangYu 已提交
2541 2542 2543 2544 2545
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_DEBUG_ENABLE, value);
}

Status
Config::SetLogsInfoEnable(const std::string& value) {
C
Cai Yudong 已提交
2546
    STATUS_CHECK(CheckLogsInfoEnable(value));
W
Wang XiangYu 已提交
2547 2548 2549 2550 2551
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_INFO_ENABLE, value);
}

Status
Config::SetLogsWarningEnable(const std::string& value) {
C
Cai Yudong 已提交
2552
    STATUS_CHECK(CheckLogsWarningEnable(value));
W
Wang XiangYu 已提交
2553 2554 2555 2556 2557
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_WARNING_ENABLE, value);
}

Status
Config::SetLogsErrorEnable(const std::string& value) {
C
Cai Yudong 已提交
2558
    STATUS_CHECK(CheckLogsErrorEnable(value));
W
Wang XiangYu 已提交
2559 2560 2561 2562 2563
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_ERROR_ENABLE, value);
}

Status
Config::SetLogsFatalEnable(const std::string& value) {
C
Cai Yudong 已提交
2564
    STATUS_CHECK(CheckLogsFatalEnable(value));
W
Wang XiangYu 已提交
2565 2566 2567 2568 2569
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_FATAL_ENABLE, value);
}

Status
Config::SetLogsPath(const std::string& value) {
C
Cai Yudong 已提交
2570
    STATUS_CHECK(CheckLogsPath(value));
W
Wang XiangYu 已提交
2571 2572 2573
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_PATH, value);
}

W
Wang XiangYu 已提交
2574 2575
Status
Config::SetLogsMaxLogFileSize(const std::string& value) {
C
Cai Yudong 已提交
2576
    STATUS_CHECK(CheckLogsMaxLogFileSize(value));
W
Wang XiangYu 已提交
2577 2578 2579 2580 2581
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_MAX_LOG_FILE_SIZE, value);
}

Status
Config::SetLogsDeleteExceeds(const std::string& value) {
C
Cai Yudong 已提交
2582
    STATUS_CHECK(CheckLogsDeleteExceeds(value));
W
Wang XiangYu 已提交
2583 2584 2585
    return SetConfigValueInMem(CONFIG_LOGS, CONFIG_LOGS_DELETE_EXCEEDS, value);
}

S
starlord 已提交
2586 2587
}  // namespace server
}  // namespace milvus