Config.cpp 78.0 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 43
static const std::unordered_map<std::string, std::string> milvus_config_version_map(
    {{"0.6.0", "0.1"}, {"0.7.0", "0.2"}, {"0.7.1", "0.2"}, {"0.8.0", "0.3"}});
44

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
/////////////////////////////////////////////////////////////
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 已提交
80
Config&
81 82 83
Config::GetInstance() {
    static Config config_inst;
    return config_inst;
G
groot 已提交
84 85
}

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

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

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

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

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

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

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

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

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

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

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

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

135 136
    std::string db_preload_collection;
    CONFIG_CHECK(GetDBConfigPreloadCollection(db_preload_collection));
137

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    bool recovery_error_ignore;
    CONFIG_CHECK(GetWalConfigRecoveryErrorIgnore(recovery_error_ignore));

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

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

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

Y
yudong.cai 已提交
252 253 254
Status
Config::ResetDefaultConfig() {
    /* server config */
C
Cai Yudong 已提交
255 256 257 258
    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 已提交
259
    CONFIG_CHECK(SetServerConfigWebPort(CONFIG_SERVER_WEB_PORT_DEFAULT));
Y
yudong.cai 已提交
260 261

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

    /* storage config */
269 270
    CONFIG_CHECK(SetStorageConfigPrimaryPath(CONFIG_STORAGE_PRIMARY_PATH_DEFAULT));
    CONFIG_CHECK(SetStorageConfigSecondaryPath(CONFIG_STORAGE_SECONDARY_PATH_DEFAULT));
271 272 273 274 275 276
    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 已提交
277 278

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

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

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

    /* 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 已提交
299
#ifdef MILVUS_GPU_VERSION
C
Cai Yudong 已提交
300 301
    CONFIG_CHECK(SetEngineConfigGpuSearchThreshold(CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT));
#endif
Z
Zhiru Zhu 已提交
302

C
Cai Yudong 已提交
303 304 305 306 307 308 309
    /* 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 已提交
310
#endif
311

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

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

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

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

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

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

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

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
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();
515
    auto duration_in_ms = std::chrono::duration_cast<std::chrono::nanoseconds>(time_now.time_since_epoch());
516 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
    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 ||
553 554 555 556 557 558 559 560
        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";
561 562 563 564 565
    } 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) {
566
            std::transform(s.begin(), s.end(), s.begin(), ::tolower);
567 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
            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 已提交
662
////////////////////////////////////////////////////////////////////////////////
663 664
Status
Config::CheckConfigVersion(const std::string& value) {
665 666 667 668 669 670 671
    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 已提交
672
            return Status(SERVER_INVALID_ARGUMENT, msg);
673
        }
674 675 676 677
    }
    return Status::OK();
}

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

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

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

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

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

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

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

B
BossZou 已提交
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
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 已提交
762
/* DB config */
Y
yudong.cai 已提交
763
Status
S
starlord 已提交
764
Config::CheckDBConfigBackendUrl(const std::string& value) {
S
shengjh 已提交
765 766 767 768
    auto exist_error = !ValidationUtil::ValidateDbURI(value).ok();
    fiu_do_on("check_config_backend_url_fail", exist_error = true);

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

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

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

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

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

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

    if (table_set.size() != tables.size()) {
        std::string msg =
            "Invalid preload tables. "
805
            "Possible reason: db_config.preload_collection contains duplicate collection.";
806
        return Status(SERVER_INVALID_ARGUMENT, msg);
807 808 809 810 811
    }

    return Status::OK();
}

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

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

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

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

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

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

    return Status::OK();
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

C
Cai Yudong 已提交
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
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 已提交
1137
#ifdef MILVUS_GPU_VERSION
B
BossZou 已提交
1138

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

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

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

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

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

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

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

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

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

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

Z
Zhiru Zhu 已提交
1226 1227 1228
    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 已提交
1229 1230
            std::string msg = "Invalid gpu resource: " + value +
                              ". Possible reason: gpu_resource_config does not match with the hardware.";
Z
Zhiru Zhu 已提交
1231 1232
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }
1233
    }
Z
Zhiru Zhu 已提交
1234

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

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

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

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

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

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

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

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

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

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

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

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

    if (exist_error) {
C
Cai Yudong 已提交
1308 1309 1310 1311 1312 1313 1314 1315
        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 已提交
1316 1317 1318 1319
    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 已提交
1320 1321 1322 1323 1324 1325 1326 1327 1328
        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 已提交
1329 1330 1331 1332
    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 已提交
1333 1334 1335 1336 1337 1338 1339
        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 已提交
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
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 已提交
1350
////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
1351
ConfigNode&
1352
Config::GetConfigRoot() {
1353
    ConfigMgr* mgr = YamlConfigMgr::GetInstance();
1354 1355 1356 1357 1358 1359
    return mgr->GetRootNode();
}

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

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

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

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

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

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

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

1421 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
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 已提交
1447
/* server config */
1448
Status
S
starlord 已提交
1449
Config::GetServerConfigAddress(std::string& value) {
S
starlord 已提交
1450
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, CONFIG_SERVER_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
1451
    return CheckServerConfigAddress(value);
1452 1453 1454
}

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

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

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

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

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

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

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

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

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

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

C
Cai Yudong 已提交
1530
Status
1531 1532 1533
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 已提交
1534
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
C
Cai Yudong 已提交
1535 1536 1537 1538
    return Status::OK();
}

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

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

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

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

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

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

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

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

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

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

1608 1609 1610 1611 1612 1613 1614 1615 1616
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();
}

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

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

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

C
Cai Yudong 已提交
1645 1646 1647 1648 1649 1650 1651 1652 1653
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 已提交
1654
#ifdef MILVUS_GPU_VERSION
B
BossZou 已提交
1655

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1854
Status
1855 1856
Config::SetDBConfigPreloadCollection(const std::string& value) {
    CONFIG_CHECK(CheckDBConfigPreloadCollection(value));
1857
    std::string cor_value = value == "*" ? "\'*\'" : value;
G
groot 已提交
1858
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRELOAD_COLLECTION, cor_value);
1859 1860
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1995 1996 1997 1998 1999 2000 2001
/* 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 已提交
2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
/* 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));
2012
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_RECOVERY_ERROR_IGNORE, value);
J
Jin Hai 已提交
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
}

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 已提交
2027
#ifdef MILVUS_GPU_VERSION
W
wxyu 已提交
2028
Status
2029
Config::SetEngineConfigGpuSearchThreshold(const std::string& value) {
C
Cai Yudong 已提交
2030
    CONFIG_CHECK(CheckEngineConfigGpuSearchThreshold(value));
C
Cai Yudong 已提交
2031
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value));
2032
    return ExecCallBacks(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value);
W
wxyu 已提交
2033
}
C
Cai Yudong 已提交
2034
#endif
W
wxyu 已提交
2035

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

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

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

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

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

Y
yudong.cai 已提交
2068 2069 2070 2071
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 已提交
2072
    CONFIG_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec));
C
Cai Yudong 已提交
2073
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value));
2074
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value);
C
Cai Yudong 已提交
2075
}
S
shengjh 已提交
2076

G
groot 已提交
2077
#endif
2078

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