Config.cpp 78.1 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 {

C
Cai Yudong 已提交
40
constexpr int64_t GB = 1UL << 30;
41

42
static const std::unordered_map<std::string, std::string> milvus_config_version_map({{"0.6.0", "0.1"},
J
Jin Hai 已提交
43 44
                                                                                     {"0.7.0", "0.2"},
                                                                                     {"0.7.1", "0.2"}});
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
/////////////////////////////////////////////////////////////
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 已提交
81
Config&
82 83 84
Config::GetInstance() {
    static Config config_inst;
    return config_inst;
G
groot 已提交
85 86
}

S
starlord 已提交
87
Status
S
starlord 已提交
88
Config::LoadConfigFile(const std::string& filename) {
89
    if (filename.empty()) {
90
        return Status(SERVER_UNEXPECTED_ERROR, "No specified config file");
G
groot 已提交
91
    }
92 93 94 95 96

    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 已提交
97 98
    }

S
shengjh 已提交
99 100 101 102
    ConfigMgr* mgr = YamlConfigMgr::GetInstance();
    Status s = mgr->LoadConfigFile(filename);
    if (!s.ok()) {
        return s;
G
groot 已提交
103 104
    }

105 106 107
    // store config file path
    config_file_ = filename;

S
starlord 已提交
108
    return Status::OK();
G
groot 已提交
109 110
}

Y
yudong.cai 已提交
111 112
Status
Config::ValidateConfig() {
113
    std::string config_version;
C
Cai Yudong 已提交
114
    CONFIG_CHECK(GetConfigVersion(config_version));
115

Y
yudong.cai 已提交
116 117
    /* server config */
    std::string server_addr;
C
Cai Yudong 已提交
118
    CONFIG_CHECK(GetServerConfigAddress(server_addr));
Y
yudong.cai 已提交
119 120

    std::string server_port;
C
Cai Yudong 已提交
121
    CONFIG_CHECK(GetServerConfigPort(server_port));
Y
yudong.cai 已提交
122 123

    std::string server_mode;
C
Cai Yudong 已提交
124
    CONFIG_CHECK(GetServerConfigDeployMode(server_mode));
Y
yudong.cai 已提交
125 126

    std::string server_time_zone;
C
Cai Yudong 已提交
127
    CONFIG_CHECK(GetServerConfigTimeZone(server_time_zone));
Y
yudong.cai 已提交
128

B
BossZou 已提交
129 130 131
    std::string server_web_port;
    CONFIG_CHECK(GetServerConfigWebPort(server_web_port));

Y
yudong.cai 已提交
132 133
    /* db config */
    std::string db_backend_url;
C
Cai Yudong 已提交
134
    CONFIG_CHECK(GetDBConfigBackendUrl(db_backend_url));
Y
yudong.cai 已提交
135

136
    std::string db_preload_table;
137
    CONFIG_CHECK(GetDBConfigPreloadCollection(db_preload_table));
138

Y
yudong.cai 已提交
139
    int64_t db_archive_disk_threshold;
C
Cai Yudong 已提交
140
    CONFIG_CHECK(GetDBConfigArchiveDiskThreshold(db_archive_disk_threshold));
Y
yudong.cai 已提交
141

Y
yudong.cai 已提交
142
    int64_t db_archive_days_threshold;
C
Cai Yudong 已提交
143
    CONFIG_CHECK(GetDBConfigArchiveDaysThreshold(db_archive_days_threshold));
Y
yudong.cai 已提交
144

C
Cai Yudong 已提交
145
    int64_t auto_flush_interval;
146 147
    CONFIG_CHECK(GetDBConfigAutoFlushInterval(auto_flush_interval));

C
Cai Yudong 已提交
148
    /* storage config */
149 150 151 152 153 154
    std::string storage_primary_path;
    CONFIG_CHECK(GetStorageConfigPrimaryPath(storage_primary_path));

    std::string storage_secondary_path;
    CONFIG_CHECK(GetStorageConfigSecondaryPath(storage_secondary_path));

155 156
    bool storage_s3_enable;
    CONFIG_CHECK(GetStorageConfigS3Enable(storage_s3_enable));
C
Cai Yudong 已提交
157
    // std::cout << "S3 " << (storage_s3_enable ? "ENABLED !" : "DISABLED !") << std::endl;
C
Cai Yudong 已提交
158

159 160
    std::string storage_s3_address;
    CONFIG_CHECK(GetStorageConfigS3Address(storage_s3_address));
C
Cai Yudong 已提交
161

162 163
    std::string storage_s3_port;
    CONFIG_CHECK(GetStorageConfigS3Port(storage_s3_port));
C
Cai Yudong 已提交
164

165 166
    std::string storage_s3_access_key;
    CONFIG_CHECK(GetStorageConfigS3AccessKey(storage_s3_access_key));
C
Cai Yudong 已提交
167

168 169
    std::string storage_s3_secret_key;
    CONFIG_CHECK(GetStorageConfigS3SecretKey(storage_s3_secret_key));
C
Cai Yudong 已提交
170

171 172
    std::string storage_s3_bucket;
    CONFIG_CHECK(GetStorageConfigS3Bucket(storage_s3_bucket));
Y
yudong.cai 已提交
173 174 175

    /* metric config */
    bool metric_enable_monitor;
C
Cai Yudong 已提交
176
    CONFIG_CHECK(GetMetricConfigEnableMonitor(metric_enable_monitor));
Y
yudong.cai 已提交
177

C
Cai Yudong 已提交
178 179
    std::string metric_address;
    CONFIG_CHECK(GetMetricConfigAddress(metric_address));
Y
yudong.cai 已提交
180

C
Cai Yudong 已提交
181 182
    std::string metric_port;
    CONFIG_CHECK(GetMetricConfigPort(metric_port));
Y
yudong.cai 已提交
183 184

    /* cache config */
W
wxyu 已提交
185
    int64_t cache_cpu_cache_capacity;
C
Cai Yudong 已提交
186
    CONFIG_CHECK(GetCacheConfigCpuCacheCapacity(cache_cpu_cache_capacity));
Y
yudong.cai 已提交
187

Y
yudong.cai 已提交
188
    float cache_cpu_cache_threshold;
C
Cai Yudong 已提交
189
    CONFIG_CHECK(GetCacheConfigCpuCacheThreshold(cache_cpu_cache_threshold));
Y
yudong.cai 已提交
190

191 192 193
    int64_t cache_insert_buffer_size;
    CONFIG_CHECK(GetCacheConfigInsertBufferSize(cache_insert_buffer_size));

Y
yudong.cai 已提交
194
    bool cache_insert_data;
C
Cai Yudong 已提交
195
    CONFIG_CHECK(GetCacheConfigCacheInsertData(cache_insert_data));
Y
yudong.cai 已提交
196 197

    /* engine config */
Y
yudong.cai 已提交
198
    int64_t engine_use_blas_threshold;
C
Cai Yudong 已提交
199
    CONFIG_CHECK(GetEngineConfigUseBlasThreshold(engine_use_blas_threshold));
Y
yudong.cai 已提交
200

Y
yudong.cai 已提交
201
    int64_t engine_omp_thread_num;
C
Cai Yudong 已提交
202
    CONFIG_CHECK(GetEngineConfigOmpThreadNum(engine_omp_thread_num));
Y
yudong.cai 已提交
203

C
Cai Yudong 已提交
204 205 206
    bool engine_use_avx512;
    CONFIG_CHECK(GetEngineConfigUseAVX512(engine_use_avx512));

G
groot 已提交
207
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
208
    int64_t engine_gpu_search_threshold;
C
Cai Yudong 已提交
209 210
    CONFIG_CHECK(GetEngineConfigGpuSearchThreshold(engine_gpu_search_threshold));
#endif
W
wxyu 已提交
211

Y
yudong.cai 已提交
212
    /* gpu resource config */
C
Cai Yudong 已提交
213
#ifdef MILVUS_GPU_VERSION
214
    bool gpu_resource_enable;
C
Cai Yudong 已提交
215
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
216
    std::cout << "GPU resources " << (gpu_resource_enable ? "ENABLED !" : "DISABLED !") << std::endl;
C
Cai Yudong 已提交
217

218 219
    if (gpu_resource_enable) {
        int64_t resource_cache_capacity;
C
Cai Yudong 已提交
220
        CONFIG_CHECK(GetGpuResourceConfigCacheCapacity(resource_cache_capacity));
Y
yudong.cai 已提交
221

222
        float resource_cache_threshold;
C
Cai Yudong 已提交
223
        CONFIG_CHECK(GetGpuResourceConfigCacheThreshold(resource_cache_threshold));
Y
yudong.cai 已提交
224

225
        std::vector<int64_t> search_resources;
C
Cai Yudong 已提交
226
        CONFIG_CHECK(GetGpuResourceConfigSearchResources(search_resources));
227

228
        std::vector<int64_t> index_build_resources;
C
Cai Yudong 已提交
229
        CONFIG_CHECK(GetGpuResourceConfigBuildIndexResources(index_build_resources));
S
starlord 已提交
230
    }
Y
yudong.cai 已提交
231
#endif
Y
yudong.cai 已提交
232

Z
Zhiru Zhu 已提交
233 234
    /* tracing config */
    std::string tracing_config_path;
C
Cai Yudong 已提交
235
    CONFIG_CHECK(GetTracingConfigJsonConfigPath(tracing_config_path));
Z
Zhiru Zhu 已提交
236

237 238 239 240 241 242 243
    /* wal config */
    bool enable;
    CONFIG_CHECK(GetWalConfigEnable(enable));

    bool recovery_error_ignore;
    CONFIG_CHECK(GetWalConfigRecoveryErrorIgnore(recovery_error_ignore));

C
Cai Yudong 已提交
244
    int64_t buffer_size;
245 246 247 248 249
    CONFIG_CHECK(GetWalConfigBufferSize(buffer_size));

    std::string wal_path;
    CONFIG_CHECK(GetWalConfigWalPath(wal_path));

Y
yudong.cai 已提交
250 251 252
    return Status::OK();
}

Y
yudong.cai 已提交
253 254 255
Status
Config::ResetDefaultConfig() {
    /* server config */
C
Cai Yudong 已提交
256 257 258 259
    CONFIG_CHECK(SetServerConfigAddress(CONFIG_SERVER_ADDRESS_DEFAULT));
    CONFIG_CHECK(SetServerConfigPort(CONFIG_SERVER_PORT_DEFAULT));
    CONFIG_CHECK(SetServerConfigDeployMode(CONFIG_SERVER_DEPLOY_MODE_DEFAULT));
    CONFIG_CHECK(SetServerConfigTimeZone(CONFIG_SERVER_TIME_ZONE_DEFAULT));
B
BossZou 已提交
260
    CONFIG_CHECK(SetServerConfigWebPort(CONFIG_SERVER_WEB_PORT_DEFAULT));
Y
yudong.cai 已提交
261 262

    /* db config */
C
Cai Yudong 已提交
263
    CONFIG_CHECK(SetDBConfigBackendUrl(CONFIG_DB_BACKEND_URL_DEFAULT));
264
    CONFIG_CHECK(SetDBConfigPreloadCollection(CONFIG_DB_PRELOAD_TABLE_DEFAULT));
C
Cai Yudong 已提交
265 266
    CONFIG_CHECK(SetDBConfigArchiveDiskThreshold(CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT));
    CONFIG_CHECK(SetDBConfigArchiveDaysThreshold(CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT));
267
    CONFIG_CHECK(SetDBConfigAutoFlushInterval(CONFIG_DB_AUTO_FLUSH_INTERVAL_DEFAULT));
C
Cai Yudong 已提交
268 269

    /* storage config */
270 271
    CONFIG_CHECK(SetStorageConfigPrimaryPath(CONFIG_STORAGE_PRIMARY_PATH_DEFAULT));
    CONFIG_CHECK(SetStorageConfigSecondaryPath(CONFIG_STORAGE_SECONDARY_PATH_DEFAULT));
272 273 274 275 276 277
    CONFIG_CHECK(SetStorageConfigS3Enable(CONFIG_STORAGE_S3_ENABLE_DEFAULT));
    CONFIG_CHECK(SetStorageConfigS3Address(CONFIG_STORAGE_S3_ADDRESS_DEFAULT));
    CONFIG_CHECK(SetStorageConfigS3Port(CONFIG_STORAGE_S3_PORT_DEFAULT));
    CONFIG_CHECK(SetStorageConfigS3AccessKey(CONFIG_STORAGE_S3_ACCESS_KEY_DEFAULT));
    CONFIG_CHECK(SetStorageConfigS3SecretKey(CONFIG_STORAGE_S3_SECRET_KEY_DEFAULT));
    CONFIG_CHECK(SetStorageConfigS3Bucket(CONFIG_STORAGE_S3_BUCKET_DEFAULT));
Y
yudong.cai 已提交
278 279

    /* metric config */
C
Cai Yudong 已提交
280
    CONFIG_CHECK(SetMetricConfigEnableMonitor(CONFIG_METRIC_ENABLE_MONITOR_DEFAULT));
C
Cai Yudong 已提交
281 282
    CONFIG_CHECK(SetMetricConfigAddress(CONFIG_METRIC_ADDRESS_DEFAULT));
    CONFIG_CHECK(SetMetricConfigPort(CONFIG_METRIC_PORT_DEFAULT));
Y
yudong.cai 已提交
283 284

    /* cache config */
C
Cai Yudong 已提交
285 286
    CONFIG_CHECK(SetCacheConfigCpuCacheCapacity(CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT));
    CONFIG_CHECK(SetCacheConfigCpuCacheThreshold(CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT));
287
    CONFIG_CHECK(SetCacheConfigInsertBufferSize(CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT));
C
Cai Yudong 已提交
288
    CONFIG_CHECK(SetCacheConfigCacheInsertData(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT));
Y
yudong.cai 已提交
289

Y
yudong.cai 已提交
290
    /* engine config */
C
Cai Yudong 已提交
291 292
    CONFIG_CHECK(SetEngineConfigUseBlasThreshold(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT));
    CONFIG_CHECK(SetEngineConfigOmpThreadNum(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT));
C
Cai Yudong 已提交
293
    CONFIG_CHECK(SetEngineConfigUseAVX512(CONFIG_ENGINE_USE_AVX512_DEFAULT));
J
Jin Hai 已提交
294 295 296 297 298 299

    /* wal config */
    CONFIG_CHECK(SetWalConfigEnable(CONFIG_WAL_ENABLE_DEFAULT));
    CONFIG_CHECK(SetWalConfigRecoveryErrorIgnore(CONFIG_WAL_RECOVERY_ERROR_IGNORE_DEFAULT));
    CONFIG_CHECK(SetWalConfigBufferSize(CONFIG_WAL_BUFFER_SIZE_DEFAULT));
    CONFIG_CHECK(SetWalConfigWalPath(CONFIG_WAL_WAL_PATH_DEFAULT));
G
groot 已提交
300
#ifdef MILVUS_GPU_VERSION
C
Cai Yudong 已提交
301 302
    CONFIG_CHECK(SetEngineConfigGpuSearchThreshold(CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT));
#endif
Z
Zhiru Zhu 已提交
303

C
Cai Yudong 已提交
304 305 306 307 308 309 310
    /* gpu resource config */
#ifdef MILVUS_GPU_VERSION
    CONFIG_CHECK(SetGpuResourceConfigEnable(CONFIG_GPU_RESOURCE_ENABLE_DEFAULT));
    CONFIG_CHECK(SetGpuResourceConfigCacheCapacity(CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT));
    CONFIG_CHECK(SetGpuResourceConfigCacheThreshold(CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT));
    CONFIG_CHECK(SetGpuResourceConfigSearchResources(CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT));
    CONFIG_CHECK(SetGpuResourceConfigBuildIndexResources(CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT));
Y
yudong.cai 已提交
311
#endif
312

Y
yudong.cai 已提交
313 314 315
    return Status::OK();
}

Y
yudong.cai 已提交
316
void
317
Config::GetConfigJsonStr(std::string& result, int64_t indent) {
318
    nlohmann::json config_json(config_map_);
319
    result = config_json.dump(indent);
Y
yudong.cai 已提交
320 321
}

C
Cai Yudong 已提交
322
Status
323
Config::GetConfigCli(std::string& value, const std::string& parent_key, const std::string& child_key) {
C
Cai Yudong 已提交
324 325 326 327 328 329 330 331 332
    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) {
333 334
    std::string invalid_node_str = "Config node invalid: " + parent_key + CONFIG_NODE_DELIMITER + child_key;

C
Cai Yudong 已提交
335
    if (!ConfigNodeValid(parent_key, child_key)) {
336
        return Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
337
    }
338
    auto status = Status::OK();
C
Cai Yudong 已提交
339
    if (parent_key == CONFIG_SERVER) {
340 341 342 343 344 345 346 347 348 349
        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);
350 351
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
352
        }
C
Cai Yudong 已提交
353
    } else if (parent_key == CONFIG_DB) {
354 355
        if (child_key == CONFIG_DB_BACKEND_URL) {
            status = SetDBConfigBackendUrl(value);
356
        } else if (child_key == CONFIG_DB_PRELOAD_TABLE) {
357
            status = SetDBConfigPreloadCollection(value);
358 359
        } else if (child_key == CONFIG_DB_AUTO_FLUSH_INTERVAL) {
            status = SetDBConfigAutoFlushInterval(value);
360 361
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
362
        }
C
Cai Yudong 已提交
363
    } else if (parent_key == CONFIG_STORAGE) {
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
        if (child_key == CONFIG_STORAGE_PRIMARY_PATH) {
            status = SetStorageConfigPrimaryPath(value);
        } else if (child_key == CONFIG_STORAGE_SECONDARY_PATH) {
            status = SetStorageConfigSecondaryPath(value);
        } 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);
380 381
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
382
        }
C
Cai Yudong 已提交
383
    } else if (parent_key == CONFIG_METRIC) {
384 385 386 387 388 389
        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);
390 391
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
392
        }
C
Cai Yudong 已提交
393 394
    } else if (parent_key == CONFIG_CACHE) {
        if (child_key == CONFIG_CACHE_CPU_CACHE_CAPACITY) {
395
            status = SetCacheConfigCpuCacheCapacity(value);
C
Cai Yudong 已提交
396
        } else if (child_key == CONFIG_CACHE_CPU_CACHE_THRESHOLD) {
397
            status = SetCacheConfigCpuCacheThreshold(value);
C
Cai Yudong 已提交
398
        } else if (child_key == CONFIG_CACHE_CACHE_INSERT_DATA) {
399
            status = SetCacheConfigCacheInsertData(value);
400
        } else if (child_key == CONFIG_CACHE_INSERT_BUFFER_SIZE) {
401
            status = SetCacheConfigInsertBufferSize(value);
402 403
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
404 405 406
        }
    } else if (parent_key == CONFIG_ENGINE) {
        if (child_key == CONFIG_ENGINE_USE_BLAS_THRESHOLD) {
407
            status = SetEngineConfigUseBlasThreshold(value);
C
Cai Yudong 已提交
408
        } else if (child_key == CONFIG_ENGINE_OMP_THREAD_NUM) {
409
            status = SetEngineConfigOmpThreadNum(value);
C
Cai Yudong 已提交
410 411
        } else if (child_key == CONFIG_ENGINE_USE_AVX512) {
            status = SetEngineConfigUseAVX512(value);
C
Cai Yudong 已提交
412 413
#ifdef MILVUS_GPU_VERSION
        } else if (child_key == CONFIG_ENGINE_GPU_SEARCH_THRESHOLD) {
414
            status = SetEngineConfigGpuSearchThreshold(value);
C
Cai Yudong 已提交
415
#endif
416 417
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
418 419 420 421
        }
#ifdef MILVUS_GPU_VERSION
    } else if (parent_key == CONFIG_GPU_RESOURCE) {
        if (child_key == CONFIG_GPU_RESOURCE_ENABLE) {
422
            status = SetGpuResourceConfigEnable(value);
C
Cai Yudong 已提交
423
        } else if (child_key == CONFIG_GPU_RESOURCE_CACHE_CAPACITY) {
424
            status = SetGpuResourceConfigCacheCapacity(value);
C
Cai Yudong 已提交
425
        } else if (child_key == CONFIG_GPU_RESOURCE_CACHE_THRESHOLD) {
426
            status = SetGpuResourceConfigCacheThreshold(value);
C
Cai Yudong 已提交
427
        } else if (child_key == CONFIG_GPU_RESOURCE_SEARCH_RESOURCES) {
428
            status = SetGpuResourceConfigSearchResources(value);
C
Cai Yudong 已提交
429
        } else if (child_key == CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES) {
430
            status = SetGpuResourceConfigBuildIndexResources(value);
431 432
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
C
Cai Yudong 已提交
433 434 435
        }
#endif
    } else if (parent_key == CONFIG_TRACING) {
436 437 438 439 440
        if (child_key == CONFIG_TRACING_JSON_CONFIG_PATH) {
            status = SetTracingConfigJsonConfigPath(value);
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
        }
J
Jin Hai 已提交
441 442 443 444 445 446 447 448 449
    } 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);
450 451
        } else {
            status = Status(SERVER_UNEXPECTED_ERROR, invalid_node_str);
J
Jin Hai 已提交
452
        }
453 454 455 456
    }

    if (status.ok()) {
        status = UpdateFileConfigFromMem(parent_key, child_key);
457 458
        if (status.ok() &&
            !(parent_key == CONFIG_CACHE || parent_key == CONFIG_ENGINE || parent_key == CONFIG_GPU_RESOURCE)) {
459 460
            restart_required_ = true;
        }
C
Cai Yudong 已提交
461
    }
462 463

    return status;
C
Cai Yudong 已提交
464 465
}

466
//////////////////////////////////////////////////////////////
C
Cai Yudong 已提交
467
Status
468
Config::ProcessConfigCli(std::string& result, const std::string& cmd) {
C
Cai Yudong 已提交
469 470 471
    std::vector<std::string> tokens;
    std::vector<std::string> nodes;
    server::StringHelpFunctions::SplitStringByDelimeter(cmd, " ", tokens);
472
    if (tokens[0] == "get_config") {
C
Cai Yudong 已提交
473 474 475
        if (tokens.size() != 2) {
            return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd);
        }
476 477 478 479 480 481 482 483 484
        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 已提交
485
        }
486
    } else if (tokens[0] == "set_config") {
C
Cai Yudong 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499
        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);
    }
}

500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
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();
516
    auto duration_in_ms = std::chrono::duration_cast<std::chrono::nanoseconds>(time_now.time_since_epoch());
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
    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;
    if (child_key == CONFIG_CACHE_CACHE_INSERT_DATA || child_key == CONFIG_STORAGE_S3_ENABLE ||
554 555 556 557 558 559 560 561
        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;
        status = StringHelpFunctions::ConvertToBoolean(value, ok);
        if (!status.ok()) {
            return status;
        }
        value_str = ok ? "true" : "false";
562 563 564 565 566
    } 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) {
567
            std::transform(s.begin(), s.end(), s.begin(), ::tolower);
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
            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 已提交
663
////////////////////////////////////////////////////////////////////////////////
664 665
Status
Config::CheckConfigVersion(const std::string& value) {
666 667 668 669 670 671 672
    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);
            SERVER_LOG_ERROR << msg;
Y
yudong.cai 已提交
673
            return Status(SERVER_INVALID_ARGUMENT, msg);
674
        }
675 676 677 678
    }
    return Status::OK();
}

C
Cai Yudong 已提交
679
/* server config */
S
starlord 已提交
680
Status
S
starlord 已提交
681
Config::CheckServerConfigAddress(const std::string& value) {
S
shengjh 已提交
682 683 684 685
    auto exist_error = !ValidationUtil::ValidateIpAddress(value).ok();
    fiu_do_on("check_config_address_fail", exist_error = true);

    if (exist_error) {
S
starlord 已提交
686 687
        std::string msg =
            "Invalid server IP address: " + value + ". Possible reason: server_config.address is invalid.";
688
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
689
    }
Y
yudong.cai 已提交
690 691
    return Status::OK();
}
Z
zhiru 已提交
692

Y
yudong.cai 已提交
693
Status
S
starlord 已提交
694
Config::CheckServerConfigPort(const std::string& value) {
S
shengjh 已提交
695 696 697 698
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_port_fail", exist_error = true);

    if (exist_error) {
S
starlord 已提交
699
        std::string msg = "Invalid server port: " + value + ". Possible reason: server_config.port is not a number.";
700
        return Status(SERVER_INVALID_ARGUMENT, msg);
701
    } else {
Y
yudong.cai 已提交
702
        int32_t port = std::stoi(value);
703
        if (!(port > 1024 && port < 65535)) {
S
starlord 已提交
704
            std::string msg = "Invalid server port: " + value +
C
Cai Yudong 已提交
705
                              ". Possible reason: server_config.port is not in range (1024, 65535).";
706
            return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
707 708
        }
    }
Y
yudong.cai 已提交
709 710
    return Status::OK();
}
Z
zhiru 已提交
711

Y
yudong.cai 已提交
712
Status
S
starlord 已提交
713
Config::CheckServerConfigDeployMode(const std::string& value) {
S
shengjh 已提交
714 715 716 717
    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 已提交
718
    if (value != "single" && value != "cluster_readonly" && value != "cluster_writable") {
Y
yudong.cai 已提交
719
        return Status(SERVER_INVALID_ARGUMENT,
Z
Zhiru Zhu 已提交
720
                      "server_config.deploy_mode is not one of single, cluster_readonly, and cluster_writable.");
721
    }
Y
yudong.cai 已提交
722 723
    return Status::OK();
}
724

Y
yudong.cai 已提交
725
Status
S
starlord 已提交
726
Config::CheckServerConfigTimeZone(const std::string& value) {
S
shengjh 已提交
727 728 729
    fiu_return_on("check_config_time_zone_fail",
                  Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value));

Y
yudong.cai 已提交
730
    if (value.length() <= 3) {
S
starlord 已提交
731
        return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
732
    } else {
Y
yudong.cai 已提交
733
        if (value.substr(0, 3) != "UTC") {
S
starlord 已提交
734
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
735 736
        } else {
            try {
Y
yudong.cai 已提交
737
                stoi(value.substr(3));
738
            } catch (...) {
S
starlord 已提交
739
                return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
740
            }
741 742
        }
    }
Y
yudong.cai 已提交
743
    return Status::OK();
Z
zhiru 已提交
744 745
}

B
BossZou 已提交
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
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 {
        int32_t port = std::stoi(value);
        if (!(port > 1024 && port < 65535)) {
            std::string msg = "Invalid web server port: " + value +
                              ". Possible reason: server_config.web_port is not in range [1025, 65534].";
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
    }
    return Status::OK();
}

C
Cai Yudong 已提交
763
/* DB config */
Y
yudong.cai 已提交
764
Status
S
starlord 已提交
765
Config::CheckDBConfigBackendUrl(const std::string& value) {
S
shengjh 已提交
766 767 768 769
    auto exist_error = !ValidationUtil::ValidateDbURI(value).ok();
    fiu_do_on("check_config_backend_url_fail", exist_error = true);

    if (exist_error) {
770
        std::string msg =
S
starlord 已提交
771
            "Invalid backend url: " + value + ". Possible reason: db_config.db_backend_url is invalid. " +
772
            "The correct format should be like sqlite://:@:/ or mysql://root:123456@127.0.0.1:3306/milvus.";
773
        return Status(SERVER_INVALID_ARGUMENT, "invalid db_backend_url: " + value);
Z
zhiru 已提交
774
    }
Y
yudong.cai 已提交
775 776
    return Status::OK();
}
Z
zhiru 已提交
777

778
Status
779
Config::CheckDBConfigPreloadCollection(const std::string& value) {
780 781
    fiu_return_on("check_config_preload_table_fail", Status(SERVER_INVALID_ARGUMENT, ""));

782 783 784 785 786 787
    if (value.empty() || value == "*") {
        return Status::OK();
    }

    std::vector<std::string> tables;
    StringHelpFunctions::SplitStringByDelimeter(value, ",", tables);
788 789 790

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

J
Jin Hai 已提交
791 792 793
    for (auto& collection : tables) {
        if (!ValidationUtil::ValidateCollectionName(collection).ok()) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid collection name: " + collection);
794 795
        }
        bool exist = false;
796
        auto status = DBWrapper::DB()->HasNativeCollection(collection, exist);
797
        if (!(status.ok() && exist)) {
J
Jin Hai 已提交
798
            return Status(SERVER_TABLE_NOT_EXIST, "Collection " + collection + " not exist");
799
        }
J
Jin Hai 已提交
800
        table_set.insert(collection);
801 802 803 804 805
    }

    if (table_set.size() != tables.size()) {
        std::string msg =
            "Invalid preload tables. "
J
Jin Hai 已提交
806
            "Possible reason: db_config.preload_table contains duplicate collection.";
807
        return Status(SERVER_INVALID_ARGUMENT, msg);
808 809 810 811 812
    }

    return Status::OK();
}

Y
yudong.cai 已提交
813
Status
S
starlord 已提交
814
Config::CheckDBConfigArchiveDiskThreshold(const std::string& value) {
S
shengjh 已提交
815 816 817 818
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_archive_disk_threshold_fail", exist_error = true);

    if (exist_error) {
819
        std::string msg = "Invalid archive disk threshold: " + value +
S
starlord 已提交
820
                          ". Possible reason: db_config.archive_disk_threshold is invalid.";
821
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
822
    }
Y
yudong.cai 已提交
823 824
    return Status::OK();
}
Z
zhiru 已提交
825

Y
yudong.cai 已提交
826
Status
S
starlord 已提交
827
Config::CheckDBConfigArchiveDaysThreshold(const std::string& value) {
S
shengjh 已提交
828 829 830 831
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_archive_days_threshold_fail", exist_error = true);

    if (exist_error) {
832
        std::string msg = "Invalid archive days threshold: " + value +
833
                          ". Possible reason: db_config.archive_days_threshold is invalid.";
834
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
835
    }
Y
yudong.cai 已提交
836 837
    return Status::OK();
}
Z
zhiru 已提交
838

839 840
Status
Config::CheckDBConfigAutoFlushInterval(const std::string& value) {
841 842 843 844
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_auto_flush_interval_fail", exist_error = true);

    if (exist_error) {
845
        std::string msg = "Invalid db configuration auto_flush_interval: " + value +
846
                          ". Possible reason: db.auto_flush_interval is not a natural number.";
847 848 849 850 851 852
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }

    return Status::OK();
}

C
Cai Yudong 已提交
853
/* storage config */
854 855
Status
Config::CheckStorageConfigPrimaryPath(const std::string& value) {
S
shengjh 已提交
856
    fiu_return_on("check_config_primary_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
857 858 859
    if (value.empty()) {
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.db_path is empty.");
    }
860 861

    return ValidationUtil::ValidateStoragePath(value);
862 863 864 865
}

Status
Config::CheckStorageConfigSecondaryPath(const std::string& value) {
S
shengjh 已提交
866
    fiu_return_on("check_config_secondary_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890

    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");
    }

891 892 893
    return Status::OK();
}

C
Cai Yudong 已提交
894
Status
895
Config::CheckStorageConfigS3Enable(const std::string& value) {
C
Cai Yudong 已提交
896 897
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
        std::string msg =
898
            "Invalid storage config: " + value + ". Possible reason: storage_config.s3_enable is not a boolean.";
C
Cai Yudong 已提交
899 900 901 902 903 904
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
905
Config::CheckStorageConfigS3Address(const std::string& value) {
C
Cai Yudong 已提交
906
    if (!ValidationUtil::ValidateIpAddress(value).ok()) {
907
        std::string msg = "Invalid s3 address: " + value + ". Possible reason: storage_config.s3_address is invalid.";
C
Cai Yudong 已提交
908 909 910 911 912 913
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
914
Config::CheckStorageConfigS3Port(const std::string& value) {
C
Cai Yudong 已提交
915
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
916
        std::string msg = "Invalid s3 port: " + value + ". Possible reason: storage_config.s3_port is not a number.";
C
Cai Yudong 已提交
917 918 919 920
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
        int32_t port = std::stoi(value);
        if (!(port > 1024 && port < 65535)) {
921 922
            std::string msg = "Invalid s3 port: " + value +
                              ". Possible reason: storage_config.s3_port is not in range (1024, 65535).";
C
Cai Yudong 已提交
923 924 925 926 927 928 929
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
    }
    return Status::OK();
}

Status
930
Config::CheckStorageConfigS3AccessKey(const std::string& value) {
C
Cai Yudong 已提交
931
    if (value.empty()) {
932
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_access_key is empty.");
C
Cai Yudong 已提交
933 934 935 936 937
    }
    return Status::OK();
}

Status
938
Config::CheckStorageConfigS3SecretKey(const std::string& value) {
C
Cai Yudong 已提交
939
    if (value.empty()) {
940
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_secret_key is empty.");
C
Cai Yudong 已提交
941 942 943 944 945
    }
    return Status::OK();
}

Status
946
Config::CheckStorageConfigS3Bucket(const std::string& value) {
C
Cai Yudong 已提交
947
    if (value.empty()) {
948
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_bucket is empty.");
C
Cai Yudong 已提交
949 950 951 952 953
    }
    return Status::OK();
}

/* metric config */
S
starlord 已提交
954
Status
S
starlord 已提交
955
Config::CheckMetricConfigEnableMonitor(const std::string& value) {
S
shengjh 已提交
956 957 958 959
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_config_enable_monitor_fail", exist_error = true);

    if (exist_error) {
960
        std::string msg =
S
starlord 已提交
961
            "Invalid metric config: " + value + ". Possible reason: metric_config.enable_monitor is not a boolean.";
962
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
963
    }
Y
yudong.cai 已提交
964 965
    return Status::OK();
}
Z
zhiru 已提交
966

Y
yudong.cai 已提交
967
Status
C
Cai Yudong 已提交
968
Config::CheckMetricConfigAddress(const std::string& value) {
969
    if (!ValidationUtil::ValidateIpAddress(value).ok()) {
C
Cai Yudong 已提交
970 971
        std::string msg = "Invalid metric ip: " + value + ". Possible reason: metric_config.ip is invalid.";
        return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config ip: " + value);
972 973 974 975
    }
    return Status::OK();
}

Y
yudong.cai 已提交
976
Status
C
Cai Yudong 已提交
977
Config::CheckMetricConfigPort(const std::string& value) {
Y
yudong.cai 已提交
978
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
C
Cai Yudong 已提交
979
        std::string msg = "Invalid metric port: " + value + ". Possible reason: metric_config.port is not a number.";
C
Cai Yudong 已提交
980 981 982 983
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
        int32_t port = std::stoi(value);
        if (!(port > 1024 && port < 65535)) {
C
Cai Yudong 已提交
984 985
            std::string msg = "Invalid metric port: " + value +
                              ". Possible reason: metric_config.port is not in range (1024, 65535).";
C
Cai Yudong 已提交
986 987
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
Z
zhiru 已提交
988
    }
Y
yudong.cai 已提交
989
    return Status::OK();
Z
zhiru 已提交
990 991
}

C
Cai Yudong 已提交
992
/* cache config */
S
starlord 已提交
993
Status
S
starlord 已提交
994
Config::CheckCacheConfigCpuCacheCapacity(const std::string& value) {
S
shengjh 已提交
995 996
    fiu_return_on("check_config_cpu_cache_capacity_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
997
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
998
        std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
999
                          ". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
1000
        return Status(SERVER_INVALID_ARGUMENT, msg);
1001
    } else {
Y
yudong.cai 已提交
1002
        int64_t cpu_cache_capacity = std::stoll(value) * GB;
1003 1004
        if (cpu_cache_capacity <= 0) {
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1005
                              ". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
1006 1007 1008
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }

S
starlord 已提交
1009
        uint64_t total_mem = 0, free_mem = 0;
Z
zhiru 已提交
1010
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
1011 1012
        if (static_cast<uint64_t>(cpu_cache_capacity) >= total_mem) {
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1013
                              ". Possible reason: cache_config.cpu_cache_capacity exceeds system memory.";
1014
            return Status(SERVER_INVALID_ARGUMENT, msg);
1015
        } else if (static_cast<double>(cpu_cache_capacity) > static_cast<double>(total_mem * 0.9)) {
1016
            std::cerr << "WARNING: cpu cache capacity value is too big" << std::endl;
Z
zhiru 已提交
1017
        }
1018

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

Y
yudong.cai 已提交
1022
        int64_t insert_buffer_size = buffer_value * GB;
S
shengjh 已提交
1023
        fiu_do_on("Config.CheckCacheConfigCpuCacheCapacity.large_insert_buffer", insert_buffer_size = total_mem + 1);
Y
yudong.cai 已提交
1024
        if (insert_buffer_size + cpu_cache_capacity >= total_mem) {
1025
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1026
                              ". Possible reason: sum of cache_config.cpu_cache_capacity and "
1027
                              "cache_config.insert_buffer_size exceeds system memory.";
1028
            return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1029 1030
        }
    }
Y
yudong.cai 已提交
1031 1032
    return Status::OK();
}
Z
zhiru 已提交
1033

Y
yudong.cai 已提交
1034
Status
S
starlord 已提交
1035
Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) {
S
shengjh 已提交
1036 1037
    fiu_return_on("check_config_cpu_cache_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1038
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
1039
        std::string msg = "Invalid cpu cache threshold: " + value +
S
starlord 已提交
1040
                          ". Possible reason: cache_config.cpu_cache_threshold is not in range (0.0, 1.0].";
1041
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1042
    } else {
Y
yudong.cai 已提交
1043 1044
        float cpu_cache_threshold = std::stof(value);
        if (cpu_cache_threshold <= 0.0 || cpu_cache_threshold >= 1.0) {
1045
            std::string msg = "Invalid cpu cache threshold: " + value +
S
starlord 已提交
1046
                              ". Possible reason: cache_config.cpu_cache_threshold is not in range (0.0, 1.0].";
1047
            return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1048
        }
1049
    }
Y
yudong.cai 已提交
1050 1051
    return Status::OK();
}
1052

1053 1054
Status
Config::CheckCacheConfigInsertBufferSize(const std::string& value) {
S
shengjh 已提交
1055
    fiu_return_on("check_config_insert_buffer_size_fail", Status(SERVER_INVALID_ARGUMENT, ""));
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
    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);
        }

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

1071 1072
        uint64_t total_mem = 0, free_mem = 0;
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
T
Tinkerrr 已提交
1073
        if (buffer_size + cache_size >= total_mem) {
1074 1075 1076 1077 1078 1079 1080 1081
            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 已提交
1082
Status
S
starlord 已提交
1083
Config::CheckCacheConfigCacheInsertData(const std::string& value) {
S
shengjh 已提交
1084 1085
    fiu_return_on("check_config_cache_insert_data_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1086
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
1087
        std::string msg = "Invalid cache insert data option: " + value +
S
starlord 已提交
1088
                          ". Possible reason: cache_config.cache_insert_data is not a boolean.";
1089
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1090 1091
    }
    return Status::OK();
Z
zhiru 已提交
1092 1093
}

C
Cai Yudong 已提交
1094
/* engine config */
S
starlord 已提交
1095
Status
S
starlord 已提交
1096
Config::CheckEngineConfigUseBlasThreshold(const std::string& value) {
S
shengjh 已提交
1097 1098
    fiu_return_on("check_config_use_blas_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1099
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1100
        std::string msg = "Invalid use blas threshold: " + value +
S
starlord 已提交
1101
                          ". Possible reason: engine_config.use_blas_threshold is not a positive integer.";
1102
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1103
    }
Y
yudong.cai 已提交
1104 1105
    return Status::OK();
}
Z
zhiru 已提交
1106

Y
yudong.cai 已提交
1107
Status
S
starlord 已提交
1108
Config::CheckEngineConfigOmpThreadNum(const std::string& value) {
S
shengjh 已提交
1109 1110
    fiu_return_on("check_config_omp_thread_num_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1111
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1112
        std::string msg = "Invalid omp thread num: " + value +
S
starlord 已提交
1113
                          ". Possible reason: engine_config.omp_thread_num is not a positive integer.";
1114
        return Status(SERVER_INVALID_ARGUMENT, msg);
S
starlord 已提交
1115 1116
    }

Y
yudong.cai 已提交
1117 1118
    int64_t omp_thread = std::stoll(value);
    int64_t sys_thread_cnt = 8;
S
starlord 已提交
1119
    CommonUtil::GetSystemAvailableThreads(sys_thread_cnt);
Y
yudong.cai 已提交
1120
    if (omp_thread > sys_thread_cnt) {
1121
        std::string msg = "Invalid omp thread num: " + value +
S
starlord 已提交
1122
                          ". Possible reason: engine_config.omp_thread_num exceeds system cpu cores.";
1123
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1124
    }
Y
yudong.cai 已提交
1125
    return Status::OK();
Z
zhiru 已提交
1126 1127
}

C
Cai Yudong 已提交
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
Status
Config::CheckEngineConfigUseAVX512(const std::string& value) {
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
        std::string msg =
            "Invalid engine config: " + value + ". Possible reason: engine_config.use_avx512 is not a boolean.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

G
groot 已提交
1138
#ifdef MILVUS_GPU_VERSION
B
BossZou 已提交
1139

W
wxyu 已提交
1140
Status
1141
Config::CheckEngineConfigGpuSearchThreshold(const std::string& value) {
S
shengjh 已提交
1142 1143
    fiu_return_on("check_config_gpu_search_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

W
wxyu 已提交
1144
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1145 1146
        std::string msg = "Invalid gpu search threshold: " + value +
                          ". Possible reason: engine_config.gpu_search_threshold is not a positive integer.";
W
wxyu 已提交
1147 1148 1149 1150 1151
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

C
Cai Yudong 已提交
1152
/* gpu resource config */
S
starlord 已提交
1153
Status
1154
Config::CheckGpuResourceConfigEnable(const std::string& value) {
S
shengjh 已提交
1155 1156
    fiu_return_on("check_config_gpu_resource_enable_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1157
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
1158 1159
        std::string msg =
            "Invalid gpu resource config: " + value + ". Possible reason: gpu_resource_config.enable is not a boolean.";
1160
        return Status(SERVER_INVALID_ARGUMENT, msg);
W
wxyu 已提交
1161
    }
Y
yudong.cai 已提交
1162 1163
    return Status::OK();
}
1164

Y
yudong.cai 已提交
1165
Status
Y
yudong.cai 已提交
1166
Config::CheckGpuResourceConfigCacheCapacity(const std::string& value) {
S
shengjh 已提交
1167 1168
    fiu_return_on("check_gpu_resource_config_cache_capacity_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1169 1170 1171
    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.";
1172
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1173
    } else {
Y
yudong.cai 已提交
1174 1175
        int64_t gpu_cache_capacity = std::stoll(value) * GB;
        std::vector<int64_t> gpu_ids;
C
Cai Yudong 已提交
1176
        CONFIG_CHECK(GetGpuResourceConfigBuildIndexResources(gpu_ids));
Y
yudong.cai 已提交
1177

Y
yudong.cai 已提交
1178
        for (int64_t gpu_id : gpu_ids) {
Y
yudong.cai 已提交
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
            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 已提交
1191
    }
Y
yudong.cai 已提交
1192 1193
    return Status::OK();
}
1194

Y
yudong.cai 已提交
1195
Status
Y
yudong.cai 已提交
1196
Config::CheckGpuResourceConfigCacheThreshold(const std::string& value) {
S
shengjh 已提交
1197 1198
    fiu_return_on("check_config_gpu_resource_cache_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
    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 已提交
1216 1217
    std::string s = value;
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
Z
Zhiru Zhu 已提交
1218

Y
yudong.cai 已提交
1219
    const std::regex pat("gpu(\\d+)");
Z
Zhiru Zhu 已提交
1220 1221
    std::smatch m;
    if (!std::regex_match(s, m, pat)) {
Y
yudong.cai 已提交
1222 1223
        std::string msg = "Invalid gpu resource: " + value +
                          ". Possible reason: gpu_resource_config is not in the format of cpux or gpux";
1224
        return Status(SERVER_INVALID_ARGUMENT, msg);
1225 1226
    }

Z
Zhiru Zhu 已提交
1227 1228 1229
    if (s.compare(0, 3, "gpu") == 0) {
        int32_t gpu_index = std::stoi(s.substr(3));
        if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
Y
yudong.cai 已提交
1230 1231
            std::string msg = "Invalid gpu resource: " + value +
                              ". Possible reason: gpu_resource_config does not match with the hardware.";
Z
Zhiru Zhu 已提交
1232 1233
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
1234
    }
Z
Zhiru Zhu 已提交
1235

1236 1237 1238 1239
    return Status::OK();
}

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

Y
yudong.cai 已提交
1243
    if (value.empty()) {
1244
        std::string msg =
Y
yudong.cai 已提交
1245 1246
            "Invalid gpu search resource. "
            "Possible reason: gpu_resource_config.search_resources is empty.";
1247
        return Status(SERVER_INVALID_ARGUMENT, msg);
1248 1249
    }

B
BossZou 已提交
1250
    std::unordered_set<std::string> value_set;
Z
Zhiru Zhu 已提交
1251
    for (auto& resource : value) {
C
Cai Yudong 已提交
1252
        CONFIG_CHECK(CheckGpuResource(resource));
B
BossZou 已提交
1253
        value_set.insert(resource);
1254
    }
B
BossZou 已提交
1255 1256 1257 1258 1259 1260 1261 1262

    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);
    }

1263 1264 1265 1266
    return Status::OK();
}

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

1270 1271
    if (value.empty()) {
        std::string msg =
Y
yudong.cai 已提交
1272 1273
            "Invalid gpu build index resource. "
            "Possible reason: gpu_resource_config.build_index_resources is empty.";
1274 1275 1276
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }

B
BossZou 已提交
1277
    std::unordered_set<std::string> value_set;
1278
    for (auto& resource : value) {
C
Cai Yudong 已提交
1279
        CONFIG_CHECK(CheckGpuResource(resource));
B
BossZou 已提交
1280 1281 1282 1283 1284 1285 1286 1287
        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 已提交
1288
    }
1289

Y
yudong.cai 已提交
1290
    return Status::OK();
G
groot 已提交
1291
}
B
BossZou 已提交
1292

G
groot 已提交
1293
#endif
1294 1295 1296 1297 1298 1299 1300
/* 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 已提交
1301

C
Cai Yudong 已提交
1302 1303 1304
/* wal config */
Status
Config::CheckWalConfigEnable(const std::string& value) {
J
Jin Hai 已提交
1305 1306 1307 1308
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_config_wal_enable_fail", exist_error = true);

    if (exist_error) {
C
Cai Yudong 已提交
1309 1310 1311 1312 1313 1314 1315 1316
        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 已提交
1317 1318 1319 1320
    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 已提交
1321 1322 1323 1324 1325 1326 1327 1328 1329
        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 已提交
1330 1331 1332 1333
    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 已提交
1334 1335 1336 1337 1338 1339 1340
        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 已提交
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
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);
}

Y
yudong.cai 已提交
1351
////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
1352
ConfigNode&
1353
Config::GetConfigRoot() {
1354
    ConfigMgr* mgr = YamlConfigMgr::GetInstance();
1355 1356 1357 1358 1359 1360
    return mgr->GetRootNode();
}

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

C
Cai Yudong 已提交
1363 1364 1365 1366 1367
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 已提交
1368
    return config_map_[parent_key].count(child_key) != 0;
C
Cai Yudong 已提交
1369 1370
}

Y
yudong.cai 已提交
1371
Status
S
starlord 已提交
1372
Config::GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value) {
Y
yudong.cai 已提交
1373
    std::lock_guard<std::mutex> lock(mutex_);
Y
yudong.cai 已提交
1374 1375 1376 1377 1378
    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 已提交
1379
    return Status(SERVER_UNEXPECTED_ERROR, "key not exist");
Y
yudong.cai 已提交
1380 1381
}

C
Cai Yudong 已提交
1382
Status
S
starlord 已提交
1383
Config::SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value) {
Y
yudong.cai 已提交
1384 1385
    std::lock_guard<std::mutex> lock(mutex_);
    config_map_[parent_key][child_key] = value;
C
Cai Yudong 已提交
1386
    return Status::OK();
Y
yudong.cai 已提交
1387 1388 1389
}

////////////////////////////////////////////////////////////////////////////////
Y
yudong.cai 已提交
1390
std::string
S
starlord 已提交
1391
Config::GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value) {
Y
yudong.cai 已提交
1392
    std::string value;
S
starlord 已提交
1393 1394 1395
    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 已提交
1396
    }
Y
yudong.cai 已提交
1397
    return value;
Y
yudong.cai 已提交
1398 1399
}

Z
Zhiru Zhu 已提交
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
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;
}

1416 1417 1418 1419 1420 1421
Status
Config::GetConfigVersion(std::string& value) {
    value = GetConfigRoot().GetValue(CONFIG_VERSION);
    return CheckConfigVersion(value);
}

1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447
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 已提交
1448
/* server config */
1449
Status
S
starlord 已提交
1450
Config::GetServerConfigAddress(std::string& value) {
S
starlord 已提交
1451
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, CONFIG_SERVER_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
1452
    return CheckServerConfigAddress(value);
1453 1454 1455
}

Status
S
starlord 已提交
1456
Config::GetServerConfigPort(std::string& value) {
S
starlord 已提交
1457
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_PORT, CONFIG_SERVER_PORT_DEFAULT);
Y
yudong.cai 已提交
1458
    return CheckServerConfigPort(value);
1459 1460 1461
}

Status
S
starlord 已提交
1462
Config::GetServerConfigDeployMode(std::string& value) {
S
starlord 已提交
1463
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, CONFIG_SERVER_DEPLOY_MODE_DEFAULT);
Y
yudong.cai 已提交
1464
    return CheckServerConfigDeployMode(value);
1465 1466 1467
}

Status
S
starlord 已提交
1468
Config::GetServerConfigTimeZone(std::string& value) {
S
starlord 已提交
1469
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, CONFIG_SERVER_TIME_ZONE_DEFAULT);
Y
yudong.cai 已提交
1470
    return CheckServerConfigTimeZone(value);
1471 1472
}

B
BossZou 已提交
1473 1474 1475 1476 1477 1478
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 已提交
1479
/* DB config */
1480
Status
S
starlord 已提交
1481
Config::GetDBConfigBackendUrl(std::string& value) {
S
starlord 已提交
1482
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_BACKEND_URL, CONFIG_DB_BACKEND_URL_DEFAULT);
Y
yudong.cai 已提交
1483
    return CheckDBConfigBackendUrl(value);
1484 1485 1486
}

Status
Y
yudong.cai 已提交
1487
Config::GetDBConfigArchiveDiskThreshold(int64_t& value) {
S
starlord 已提交
1488 1489
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1490
    CONFIG_CHECK(CheckDBConfigArchiveDiskThreshold(str));
Y
yudong.cai 已提交
1491
    value = std::stoll(str);
1492 1493 1494 1495
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1496
Config::GetDBConfigArchiveDaysThreshold(int64_t& value) {
S
starlord 已提交
1497 1498
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1499
    CONFIG_CHECK(CheckDBConfigArchiveDaysThreshold(str));
Y
yudong.cai 已提交
1500
    value = std::stoll(str);
1501 1502 1503
    return Status::OK();
}

S
starlord 已提交
1504
Status
1505
Config::GetDBConfigPreloadCollection(std::string& value) {
S
starlord 已提交
1506
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_PRELOAD_TABLE);
S
starlord 已提交
1507 1508 1509
    return Status::OK();
}

1510
Status
C
Cai Yudong 已提交
1511
Config::GetDBConfigAutoFlushInterval(int64_t& value) {
1512
    std::string str = GetConfigStr(CONFIG_DB, CONFIG_DB_AUTO_FLUSH_INTERVAL, CONFIG_DB_AUTO_FLUSH_INTERVAL_DEFAULT);
C
Cai Yudong 已提交
1513 1514
    CONFIG_CHECK(CheckDBConfigAutoFlushInterval(str));
    value = std::stoll(str);
1515 1516 1517
    return Status::OK();
}

C
Cai Yudong 已提交
1518
/* storage config */
1519 1520
Status
Config::GetStorageConfigPrimaryPath(std::string& value) {
C
Cai Yudong 已提交
1521
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_PRIMARY_PATH, CONFIG_STORAGE_PRIMARY_PATH_DEFAULT);
1522 1523 1524 1525 1526
    return CheckStorageConfigPrimaryPath(value);
}

Status
Config::GetStorageConfigSecondaryPath(std::string& value) {
C
Cai Yudong 已提交
1527
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_SECONDARY_PATH, CONFIG_STORAGE_SECONDARY_PATH_DEFAULT);
1528 1529 1530
    return CheckStorageConfigSecondaryPath(value);
}

C
Cai Yudong 已提交
1531
Status
1532 1533 1534
Config::GetStorageConfigS3Enable(bool& value) {
    std::string str = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ENABLE, CONFIG_STORAGE_S3_ENABLE_DEFAULT);
    CONFIG_CHECK(CheckStorageConfigS3Enable(str));
Y
Yhz 已提交
1535
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
C
Cai Yudong 已提交
1536 1537 1538 1539
    return Status::OK();
}

Status
1540 1541 1542
Config::GetStorageConfigS3Address(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ADDRESS, CONFIG_STORAGE_S3_ADDRESS_DEFAULT);
    return CheckStorageConfigS3Address(value);
C
Cai Yudong 已提交
1543 1544 1545
}

Status
1546 1547 1548
Config::GetStorageConfigS3Port(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_PORT, CONFIG_STORAGE_S3_PORT_DEFAULT);
    return CheckStorageConfigS3Port(value);
C
Cai Yudong 已提交
1549 1550 1551
}

Status
1552 1553
Config::GetStorageConfigS3AccessKey(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ACCESS_KEY, CONFIG_STORAGE_S3_ACCESS_KEY_DEFAULT);
C
Cai Yudong 已提交
1554 1555 1556 1557
    return Status::OK();
}

Status
1558 1559
Config::GetStorageConfigS3SecretKey(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_SECRET_KEY, CONFIG_STORAGE_S3_SECRET_KEY_DEFAULT);
C
Cai Yudong 已提交
1560 1561 1562 1563
    return Status::OK();
}

Status
1564 1565
Config::GetStorageConfigS3Bucket(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_BUCKET, CONFIG_STORAGE_S3_BUCKET_DEFAULT);
C
Cai Yudong 已提交
1566 1567 1568 1569
    return Status::OK();
}

/* metric config */
1570
Status
S
starlord 已提交
1571
Config::GetMetricConfigEnableMonitor(bool& value) {
1572
    std::string str = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, CONFIG_METRIC_ENABLE_MONITOR_DEFAULT);
C
Cai Yudong 已提交
1573
    CONFIG_CHECK(CheckMetricConfigEnableMonitor(str));
Y
Yhz 已提交
1574
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
1575 1576 1577 1578
    return Status::OK();
}

Status
C
Cai Yudong 已提交
1579 1580
Config::GetMetricConfigAddress(std::string& value) {
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_ADDRESS, CONFIG_METRIC_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
1581
    return Status::OK();
1582 1583
}

1584
Status
C
Cai Yudong 已提交
1585 1586 1587
Config::GetMetricConfigPort(std::string& value) {
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_PORT, CONFIG_METRIC_PORT_DEFAULT);
    return CheckMetricConfigPort(value);
1588 1589
}

C
Cai Yudong 已提交
1590
/* cache config */
1591
Status
W
wxyu 已提交
1592
Config::GetCacheConfigCpuCacheCapacity(int64_t& value) {
S
starlord 已提交
1593 1594
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT);
C
Cai Yudong 已提交
1595
    CONFIG_CHECK(CheckCacheConfigCpuCacheCapacity(str));
Y
yudong.cai 已提交
1596
    value = std::stoll(str);
1597 1598 1599 1600
    return Status::OK();
}

Status
S
starlord 已提交
1601
Config::GetCacheConfigCpuCacheThreshold(float& value) {
S
starlord 已提交
1602 1603
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1604
    CONFIG_CHECK(CheckCacheConfigCpuCacheThreshold(str));
1605 1606 1607 1608
    value = std::stof(str);
    return Status::OK();
}

1609 1610 1611 1612 1613 1614 1615 1616 1617
Status
Config::GetCacheConfigInsertBufferSize(int64_t& value) {
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT);
    CONFIG_CHECK(CheckCacheConfigInsertBufferSize(str));
    value = std::stoll(str);
    return Status::OK();
}

1618
Status
S
starlord 已提交
1619
Config::GetCacheConfigCacheInsertData(bool& value) {
S
starlord 已提交
1620 1621
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
C
Cai Yudong 已提交
1622
    CONFIG_CHECK(CheckCacheConfigCacheInsertData(str));
1623 1624 1625 1626 1627
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    value = (str == "true" || str == "on" || str == "yes" || str == "1");
    return Status::OK();
}

C
Cai Yudong 已提交
1628
/* engine config */
1629
Status
Y
yudong.cai 已提交
1630
Config::GetEngineConfigUseBlasThreshold(int64_t& value) {
S
starlord 已提交
1631 1632
    std::string str =
        GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1633
    CONFIG_CHECK(CheckEngineConfigUseBlasThreshold(str));
Y
yudong.cai 已提交
1634
    value = std::stoll(str);
1635 1636 1637 1638
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1639
Config::GetEngineConfigOmpThreadNum(int64_t& value) {
1640
    std::string str = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
C
Cai Yudong 已提交
1641
    CONFIG_CHECK(CheckEngineConfigOmpThreadNum(str));
Y
yudong.cai 已提交
1642
    value = std::stoll(str);
1643 1644 1645
    return Status::OK();
}

C
Cai Yudong 已提交
1646 1647 1648 1649 1650 1651 1652 1653 1654
Status
Config::GetEngineConfigUseAVX512(bool& value) {
    std::string str = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_USE_AVX512, CONFIG_ENGINE_USE_AVX512_DEFAULT);
    CONFIG_CHECK(CheckEngineConfigUseAVX512(str));
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    value = (str == "true" || str == "on" || str == "yes" || str == "1");
    return Status::OK();
}

G
groot 已提交
1655
#ifdef MILVUS_GPU_VERSION
B
BossZou 已提交
1656

W
wxyu 已提交
1657
Status
Y
yudong.cai 已提交
1658
Config::GetEngineConfigGpuSearchThreshold(int64_t& value) {
W
wxyu 已提交
1659
    std::string str =
1660
        GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1661
    CONFIG_CHECK(CheckEngineConfigGpuSearchThreshold(str));
Y
yudong.cai 已提交
1662
    value = std::stoll(str);
W
wxyu 已提交
1663 1664
    return Status::OK();
}
S
shengjh 已提交
1665

C
Cai Yudong 已提交
1666
#endif
W
wxyu 已提交
1667

C
Cai Yudong 已提交
1668 1669
/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
S
shengjh 已提交
1670

1671
Status
1672 1673
Config::GetGpuResourceConfigEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, CONFIG_GPU_RESOURCE_ENABLE_DEFAULT);
C
Cai Yudong 已提交
1674
    CONFIG_CHECK(CheckGpuResourceConfigEnable(str));
Y
Yhz 已提交
1675
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
Y
yudong.cai 已提交
1676
    return Status::OK();
1677 1678 1679
}

Status
Y
yudong.cai 已提交
1680
Config::GetGpuResourceConfigCacheCapacity(int64_t& value) {
1681
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
1682
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
1683
    fiu_do_on("Config.GetGpuResourceConfigCacheCapacity.diable_gpu_resource", gpu_resource_enable = false);
1684 1685
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
1686 1687 1688 1689
        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 已提交
1690
    CONFIG_CHECK(CheckGpuResourceConfigCacheCapacity(str));
Y
yudong.cai 已提交
1691
    value = std::stoll(str);
W
wxyu 已提交
1692 1693 1694
    return Status::OK();
}

1695
Status
Y
yudong.cai 已提交
1696
Config::GetGpuResourceConfigCacheThreshold(float& value) {
1697
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
1698
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
1699
    fiu_do_on("Config.GetGpuResourceConfigCacheThreshold.diable_gpu_resource", gpu_resource_enable = false);
1700 1701
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
1702 1703 1704 1705
        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 已提交
1706
    CONFIG_CHECK(CheckGpuResourceConfigCacheThreshold(str));
Y
yudong.cai 已提交
1707 1708
    value = std::stof(str);
    return Status::OK();
1709 1710 1711
}

Status
Y
yudong.cai 已提交
1712
Config::GetGpuResourceConfigSearchResources(std::vector<int64_t>& value) {
1713
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
1714
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
1715
    fiu_do_on("get_gpu_config_search_resources.disable_gpu_resource_fail", gpu_resource_enable = false);
1716 1717
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
1718 1719 1720 1721 1722 1723
        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 已提交
1724
    CONFIG_CHECK(CheckGpuResourceConfigSearchResources(res_vec));
1725
    value.clear();
Y
yudong.cai 已提交
1726
    for (std::string& res : res_vec) {
Y
yudong.cai 已提交
1727
        value.push_back(std::stoll(res.substr(3)));
Y
yudong.cai 已提交
1728 1729
    }
    return Status::OK();
1730 1731 1732
}

Status
Y
yudong.cai 已提交
1733
Config::GetGpuResourceConfigBuildIndexResources(std::vector<int64_t>& value) {
1734
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
1735
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
1736
    fiu_do_on("get_gpu_config_build_index_resources.disable_gpu_resource_fail", gpu_resource_enable = false);
1737 1738
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
1739 1740
        return Status(SERVER_UNSUPPORTED_ERROR, msg);
    }
1741
    std::string str =
Y
yudong.cai 已提交
1742 1743 1744 1745
        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 已提交
1746
    CONFIG_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec));
1747
    value.clear();
Y
yudong.cai 已提交
1748
    for (std::string& res : res_vec) {
Y
yudong.cai 已提交
1749
        value.push_back(std::stoll(res.substr(3)));
Y
yudong.cai 已提交
1750
    }
1751
    return Status::OK();
Y
yudong.cai 已提交
1752
}
B
BossZou 已提交
1753

G
groot 已提交
1754
#endif
G
groot 已提交
1755

Z
Zhiru Zhu 已提交
1756 1757 1758 1759
/* tracing config */
Status
Config::GetTracingConfigJsonConfigPath(std::string& value) {
    value = GetConfigStr(CONFIG_TRACING, CONFIG_TRACING_JSON_CONFIG_PATH, "");
S
shengjh 已提交
1760
    fiu_do_on("get_config_json_config_path_fail", value = "error_config_json_path");
Z
Zhiru Zhu 已提交
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771
    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();
}

1772 1773 1774 1775
/* wal config */
Status
Config::GetWalConfigEnable(bool& wal_enable) {
    std::string str = GetConfigStr(CONFIG_WAL, CONFIG_WAL_ENABLE, CONFIG_WAL_ENABLE_DEFAULT);
C
Cai Yudong 已提交
1776
    CONFIG_CHECK(CheckWalConfigEnable(str));
Y
Yhz 已提交
1777
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, wal_enable));
1778 1779 1780 1781 1782 1783 1784
    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 已提交
1785
    CONFIG_CHECK(CheckWalConfigRecoveryErrorIgnore(str));
Y
Yhz 已提交
1786
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, recovery_error_ignore));
1787 1788 1789 1790
    return Status::OK();
}

Status
C
Cai Yudong 已提交
1791
Config::GetWalConfigBufferSize(int64_t& buffer_size) {
1792
    std::string str = GetConfigStr(CONFIG_WAL, CONFIG_WAL_BUFFER_SIZE, CONFIG_WAL_BUFFER_SIZE_DEFAULT);
C
Cai Yudong 已提交
1793 1794
    CONFIG_CHECK(CheckWalConfigBufferSize(str));
    buffer_size = std::stoll(str);
1795 1796 1797 1798 1799
    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;
    }
1800 1801 1802 1803 1804
    return Status::OK();
}

Status
Config::GetWalConfigWalPath(std::string& wal_path) {
C
Cai Yudong 已提交
1805
    wal_path = GetConfigStr(CONFIG_WAL, CONFIG_WAL_WAL_PATH, CONFIG_WAL_WAL_PATH_DEFAULT);
J
Jin Hai 已提交
1806
    CONFIG_CHECK(CheckWalConfigWalPath(wal_path));
1807 1808 1809
    return Status::OK();
}

1810 1811 1812 1813 1814 1815
Status
Config::GetServerRestartRequired(bool& required) {
    required = restart_required_;
    return Status::OK();
}

Y
yudong.cai 已提交
1816 1817 1818
///////////////////////////////////////////////////////////////////////////////
/* server config */
Status
S
starlord 已提交
1819
Config::SetServerConfigAddress(const std::string& value) {
C
Cai Yudong 已提交
1820 1821
    CONFIG_CHECK(CheckServerConfigAddress(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
Y
yudong.cai 已提交
1822 1823 1824
}

Status
S
starlord 已提交
1825
Config::SetServerConfigPort(const std::string& value) {
C
Cai Yudong 已提交
1826 1827
    CONFIG_CHECK(CheckServerConfigPort(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value);
Y
yudong.cai 已提交
1828 1829 1830
}

Status
S
starlord 已提交
1831
Config::SetServerConfigDeployMode(const std::string& value) {
C
Cai Yudong 已提交
1832 1833
    CONFIG_CHECK(CheckServerConfigDeployMode(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, value);
Y
yudong.cai 已提交
1834 1835 1836
}

Status
S
starlord 已提交
1837
Config::SetServerConfigTimeZone(const std::string& value) {
C
Cai Yudong 已提交
1838 1839
    CONFIG_CHECK(CheckServerConfigTimeZone(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
Y
yudong.cai 已提交
1840 1841
}

B
BossZou 已提交
1842 1843 1844 1845 1846 1847
Status
Config::SetServerConfigWebPort(const std::string& value) {
    CONFIG_CHECK(CheckServerConfigWebPort(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_WEB_PORT, value);
}

Y
yudong.cai 已提交
1848 1849
/* db config */
Status
S
starlord 已提交
1850
Config::SetDBConfigBackendUrl(const std::string& value) {
C
Cai Yudong 已提交
1851 1852
    CONFIG_CHECK(CheckDBConfigBackendUrl(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value);
Y
yudong.cai 已提交
1853 1854
}

1855
Status
1856 1857
Config::SetDBConfigPreloadCollection(const std::string& value) {
    CONFIG_CHECK(CheckDBConfigPreloadCollection(value));
1858 1859
    std::string cor_value = value == "*" ? "\'*\'" : value;
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRELOAD_TABLE, cor_value);
1860 1861
}

Y
yudong.cai 已提交
1862
Status
S
starlord 已提交
1863
Config::SetDBConfigArchiveDiskThreshold(const std::string& value) {
C
Cai Yudong 已提交
1864 1865
    CONFIG_CHECK(CheckDBConfigArchiveDiskThreshold(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value);
Y
yudong.cai 已提交
1866 1867 1868
}

Status
S
starlord 已提交
1869
Config::SetDBConfigArchiveDaysThreshold(const std::string& value) {
C
Cai Yudong 已提交
1870 1871
    CONFIG_CHECK(CheckDBConfigArchiveDaysThreshold(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value);
Y
yudong.cai 已提交
1872 1873
}

1874 1875 1876 1877 1878 1879
Status
Config::SetDBConfigAutoFlushInterval(const std::string& value) {
    CONFIG_CHECK(CheckDBConfigAutoFlushInterval(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_AUTO_FLUSH_INTERVAL, value);
}

C
Cai Yudong 已提交
1880
/* storage config */
1881 1882 1883
Status
Config::SetStorageConfigPrimaryPath(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigPrimaryPath(value));
C
Cai Yudong 已提交
1884
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_PRIMARY_PATH, value);
1885 1886 1887 1888 1889
}

Status
Config::SetStorageConfigSecondaryPath(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigSecondaryPath(value));
C
Cai Yudong 已提交
1890
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_SECONDARY_PATH, value);
1891 1892
}

C
Cai Yudong 已提交
1893
Status
1894 1895 1896
Config::SetStorageConfigS3Enable(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Enable(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ENABLE, value);
C
Cai Yudong 已提交
1897 1898 1899
}

Status
1900 1901 1902
Config::SetStorageConfigS3Address(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Address(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ADDRESS, value);
C
Cai Yudong 已提交
1903 1904 1905
}

Status
1906 1907 1908
Config::SetStorageConfigS3Port(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Port(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_PORT, value);
C
Cai Yudong 已提交
1909 1910 1911
}

Status
1912 1913 1914
Config::SetStorageConfigS3AccessKey(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3AccessKey(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ACCESS_KEY, value);
C
Cai Yudong 已提交
1915 1916 1917
}

Status
1918 1919 1920
Config::SetStorageConfigS3SecretKey(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3SecretKey(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_SECRET_KEY, value);
C
Cai Yudong 已提交
1921 1922 1923
}

Status
1924 1925 1926
Config::SetStorageConfigS3Bucket(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Bucket(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_BUCKET, value);
Y
yudong.cai 已提交
1927 1928 1929 1930
}

/* metric config */
Status
S
starlord 已提交
1931
Config::SetMetricConfigEnableMonitor(const std::string& value) {
C
Cai Yudong 已提交
1932 1933
    CONFIG_CHECK(CheckMetricConfigEnableMonitor(value));
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, value);
Y
yudong.cai 已提交
1934 1935 1936
}

Status
C
Cai Yudong 已提交
1937 1938 1939
Config::SetMetricConfigAddress(const std::string& value) {
    CONFIG_CHECK(CheckMetricConfigAddress(value));
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ADDRESS, value);
1940 1941
}

Y
yudong.cai 已提交
1942
Status
C
Cai Yudong 已提交
1943 1944 1945
Config::SetMetricConfigPort(const std::string& value) {
    CONFIG_CHECK(CheckMetricConfigPort(value));
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_PORT, value);
Y
yudong.cai 已提交
1946 1947 1948 1949
}

/* cache config */
Status
S
starlord 已提交
1950
Config::SetCacheConfigCpuCacheCapacity(const std::string& value) {
C
Cai Yudong 已提交
1951
    CONFIG_CHECK(CheckCacheConfigCpuCacheCapacity(value));
C
Cai Yudong 已提交
1952
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value));
1953
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value);
Y
yudong.cai 已提交
1954 1955 1956
}

Status
S
starlord 已提交
1957
Config::SetCacheConfigCpuCacheThreshold(const std::string& value) {
C
Cai Yudong 已提交
1958 1959
    CONFIG_CHECK(CheckCacheConfigCpuCacheThreshold(value));
    return SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, value);
Y
yudong.cai 已提交
1960 1961
}

1962 1963 1964
Status
Config::SetCacheConfigInsertBufferSize(const std::string& value) {
    CONFIG_CHECK(CheckCacheConfigInsertBufferSize(value));
C
Cai Yudong 已提交
1965
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, value));
1966
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, value);
1967 1968
}

Y
yudong.cai 已提交
1969
Status
S
starlord 已提交
1970
Config::SetCacheConfigCacheInsertData(const std::string& value) {
C
Cai Yudong 已提交
1971
    CONFIG_CHECK(CheckCacheConfigCacheInsertData(value));
C
Cai Yudong 已提交
1972
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value));
1973
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value);
Y
yudong.cai 已提交
1974 1975 1976 1977
}

/* engine config */
Status
S
starlord 已提交
1978
Config::SetEngineConfigUseBlasThreshold(const std::string& value) {
C
Cai Yudong 已提交
1979
    CONFIG_CHECK(CheckEngineConfigUseBlasThreshold(value));
C
Cai Yudong 已提交
1980
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value));
1981
    return ExecCallBacks(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value);
Y
yudong.cai 已提交
1982 1983 1984
}

Status
S
starlord 已提交
1985
Config::SetEngineConfigOmpThreadNum(const std::string& value) {
C
Cai Yudong 已提交
1986 1987
    CONFIG_CHECK(CheckEngineConfigOmpThreadNum(value));
    return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, value);
Y
yudong.cai 已提交
1988 1989
}

C
Cai Yudong 已提交
1990 1991 1992 1993 1994 1995
Status
Config::SetEngineConfigUseAVX512(const std::string& value) {
    CONFIG_CHECK(CheckEngineConfigUseAVX512(value));
    return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_AVX512, value);
}

1996 1997 1998 1999 2000 2001 2002
/* tracing config */
Status
Config::SetTracingConfigJsonConfigPath(const std::string& value) {
    CONFIG_CHECK(CheckTracingConfigJsonConfigPath(value));
    return SetConfigValueInMem(CONFIG_TRACING, CONFIG_TRACING_JSON_CONFIG_PATH, value);
}

J
Jin Hai 已提交
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012
/* wal config */
Status
Config::SetWalConfigEnable(const std::string& value) {
    CONFIG_CHECK(CheckWalConfigEnable(value));
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_ENABLE, value);
}

Status
Config::SetWalConfigRecoveryErrorIgnore(const std::string& value) {
    CONFIG_CHECK(CheckWalConfigRecoveryErrorIgnore(value));
2013
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_RECOVERY_ERROR_IGNORE, value);
J
Jin Hai 已提交
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
}

Status
Config::SetWalConfigBufferSize(const std::string& value) {
    CONFIG_CHECK(CheckWalConfigBufferSize(value));
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_BUFFER_SIZE, value);
}

Status
Config::SetWalConfigWalPath(const std::string& value) {
    CONFIG_CHECK(CheckWalConfigWalPath(value));
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_WAL_PATH, value);
}

G
groot 已提交
2028
#ifdef MILVUS_GPU_VERSION
W
wxyu 已提交
2029
Status
2030
Config::SetEngineConfigGpuSearchThreshold(const std::string& value) {
C
Cai Yudong 已提交
2031
    CONFIG_CHECK(CheckEngineConfigGpuSearchThreshold(value));
C
Cai Yudong 已提交
2032
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value));
2033
    return ExecCallBacks(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value);
W
wxyu 已提交
2034
}
C
Cai Yudong 已提交
2035
#endif
W
wxyu 已提交
2036

C
Cai Yudong 已提交
2037 2038
/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
S
shengjh 已提交
2039

Y
yudong.cai 已提交
2040
Status
2041
Config::SetGpuResourceConfigEnable(const std::string& value) {
C
Cai Yudong 已提交
2042
    CONFIG_CHECK(CheckGpuResourceConfigEnable(value));
C
Cai Yudong 已提交
2043
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value));
2044
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value);
Z
Zhiru Zhu 已提交
2045 2046 2047
}

Status
Y
yudong.cai 已提交
2048
Config::SetGpuResourceConfigCacheCapacity(const std::string& value) {
C
Cai Yudong 已提交
2049
    CONFIG_CHECK(CheckGpuResourceConfigCacheCapacity(value));
C
Cai Yudong 已提交
2050
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value));
2051
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value);
Y
yudong.cai 已提交
2052
}
Z
Zhiru Zhu 已提交
2053

Y
yudong.cai 已提交
2054 2055
Status
Config::SetGpuResourceConfigCacheThreshold(const std::string& value) {
C
Cai Yudong 已提交
2056 2057
    CONFIG_CHECK(CheckGpuResourceConfigCacheThreshold(value));
    return SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD, value);
Y
yudong.cai 已提交
2058 2059
}

2060
Status
Y
yudong.cai 已提交
2061
Config::SetGpuResourceConfigSearchResources(const std::string& value) {
2062
    std::vector<std::string> res_vec;
Y
yudong.cai 已提交
2063
    server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
C
Cai Yudong 已提交
2064
    CONFIG_CHECK(CheckGpuResourceConfigSearchResources(res_vec));
C
Cai Yudong 已提交
2065
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value));
2066
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value);
2067 2068
}

Y
yudong.cai 已提交
2069 2070 2071 2072
Status
Config::SetGpuResourceConfigBuildIndexResources(const std::string& value) {
    std::vector<std::string> res_vec;
    server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
C
Cai Yudong 已提交
2073
    CONFIG_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec));
C
Cai Yudong 已提交
2074
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value));
2075
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value);
C
Cai Yudong 已提交
2076
}
S
shengjh 已提交
2077

G
groot 已提交
2078
#endif
2079

S
starlord 已提交
2080 2081
}  // namespace server
}  // namespace milvus