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

J
Jin Hai 已提交
42 43 44
constexpr int32_t PORT_NUMBER_MIN = 1024;
constexpr int32_t PORT_NUMBER_MAX = 65535;

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

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

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

    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 已提交
99 100
    }

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

107 108 109
    // store config file path
    config_file_ = filename;

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

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

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

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

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

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

B
BossZou 已提交
131 132 133
    std::string server_web_port;
    CONFIG_CHECK(GetServerConfigWebPort(server_web_port));

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

138 139
    std::string db_preload_collection;
    CONFIG_CHECK(GetDBConfigPreloadCollection(db_preload_collection));
140

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

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

C
Cai Yudong 已提交
147
    int64_t auto_flush_interval;
148 149
    CONFIG_CHECK(GetDBConfigAutoFlushInterval(auto_flush_interval));

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

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

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

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

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

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

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

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

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

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

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

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

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

193 194 195
    int64_t cache_insert_buffer_size;
    CONFIG_CHECK(GetCacheConfigInsertBufferSize(cache_insert_buffer_size));

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

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

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

C
Cai Yudong 已提交
206 207 208
    bool engine_use_avx512;
    CONFIG_CHECK(GetEngineConfigUseAVX512(engine_use_avx512));

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

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

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

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

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

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

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

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

    bool recovery_error_ignore;
    CONFIG_CHECK(GetWalConfigRecoveryErrorIgnore(recovery_error_ignore));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return status;
C
Cai Yudong 已提交
466 467
}

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

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

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

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

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

    if (exist_error) {
S
starlord 已提交
701
        std::string msg = "Invalid server port: " + value + ". Possible reason: server_config.port is not a number.";
702
        return Status(SERVER_INVALID_ARGUMENT, msg);
703
    } else {
J
Jin Hai 已提交
704 705 706 707 708 709 710 711 712
        try {
            int32_t port = std::stoi(value);
            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
                std::string msg = "Invalid server port: " + value +
                                  ". Possible reason: server_config.port is not in range (1024, 65535).";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.port: " + value);
Z
zhiru 已提交
713 714
        }
    }
Y
yudong.cai 已提交
715 716
    return Status::OK();
}
Z
zhiru 已提交
717

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

Y
yudong.cai 已提交
731
Status
S
starlord 已提交
732
Config::CheckServerConfigTimeZone(const std::string& value) {
S
shengjh 已提交
733 734 735
    fiu_return_on("check_config_time_zone_fail",
                  Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value));

Y
yudong.cai 已提交
736
    if (value.length() <= 3) {
S
starlord 已提交
737
        return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
738
    } else {
Y
yudong.cai 已提交
739
        if (value.substr(0, 3) != "UTC") {
S
starlord 已提交
740
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
741
        } else {
J
Jin Hai 已提交
742
            if (!ValidationUtil::IsNumber(value.substr(4))) {
S
starlord 已提交
743
                return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.time_zone: " + value);
744
            }
745 746
        }
    }
Y
yudong.cai 已提交
747
    return Status::OK();
Z
zhiru 已提交
748 749
}

B
BossZou 已提交
750 751 752 753 754 755 756
Status
Config::CheckServerConfigWebPort(const std::string& value) {
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
        std::string msg =
            "Invalid web server port: " + value + ". Possible reason: server_config.web_port is not a number.";
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
J
Jin Hai 已提交
757 758 759 760 761 762 763 764 765
        try {
            int32_t port = std::stoi(value);
            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
                std::string msg = "Invalid web server port: " + value +
                                  ". Possible reason: server_config.web_port is not in range (1024, 65535).";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid server_config.web_port: " + value);
B
BossZou 已提交
766 767 768 769 770
        }
    }
    return Status::OK();
}

C
Cai Yudong 已提交
771
/* DB config */
Y
yudong.cai 已提交
772
Status
S
starlord 已提交
773
Config::CheckDBConfigBackendUrl(const std::string& value) {
S
shengjh 已提交
774 775 776 777
    auto exist_error = !ValidationUtil::ValidateDbURI(value).ok();
    fiu_do_on("check_config_backend_url_fail", exist_error = true);

    if (exist_error) {
778
        std::string msg =
S
starlord 已提交
779
            "Invalid backend url: " + value + ". Possible reason: db_config.db_backend_url is invalid. " +
780
            "The correct format should be like sqlite://:@:/ or mysql://root:123456@127.0.0.1:3306/milvus.";
781
        return Status(SERVER_INVALID_ARGUMENT, "invalid db_backend_url: " + value);
Z
zhiru 已提交
782
    }
Y
yudong.cai 已提交
783 784
    return Status::OK();
}
Z
zhiru 已提交
785

786
Status
787
Config::CheckDBConfigPreloadCollection(const std::string& value) {
788
    fiu_return_on("check_config_preload_collection_fail", Status(SERVER_INVALID_ARGUMENT, ""));
789

790 791 792 793 794 795
    if (value.empty() || value == "*") {
        return Status::OK();
    }

    std::vector<std::string> tables;
    StringHelpFunctions::SplitStringByDelimeter(value, ",", tables);
796 797 798

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

J
Jin Hai 已提交
799 800 801
    for (auto& collection : tables) {
        if (!ValidationUtil::ValidateCollectionName(collection).ok()) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid collection name: " + collection);
802 803
        }
        bool exist = false;
804
        auto status = DBWrapper::DB()->HasNativeCollection(collection, exist);
805
        if (!(status.ok() && exist)) {
G
groot 已提交
806
            return Status(SERVER_COLLECTION_NOT_EXIST, "Collection " + collection + " not exist");
807
        }
J
Jin Hai 已提交
808
        table_set.insert(collection);
809 810 811 812 813
    }

    if (table_set.size() != tables.size()) {
        std::string msg =
            "Invalid preload tables. "
814
            "Possible reason: db_config.preload_collection contains duplicate collection.";
815
        return Status(SERVER_INVALID_ARGUMENT, msg);
816 817 818 819 820
    }

    return Status::OK();
}

Y
yudong.cai 已提交
821
Status
S
starlord 已提交
822
Config::CheckDBConfigArchiveDiskThreshold(const std::string& value) {
S
shengjh 已提交
823 824 825 826
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_archive_disk_threshold_fail", exist_error = true);

    if (exist_error) {
827
        std::string msg = "Invalid archive disk threshold: " + value +
S
starlord 已提交
828
                          ". Possible reason: db_config.archive_disk_threshold is invalid.";
829
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
830
    }
Y
yudong.cai 已提交
831 832
    return Status::OK();
}
Z
zhiru 已提交
833

Y
yudong.cai 已提交
834
Status
S
starlord 已提交
835
Config::CheckDBConfigArchiveDaysThreshold(const std::string& value) {
S
shengjh 已提交
836 837 838 839
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_archive_days_threshold_fail", exist_error = true);

    if (exist_error) {
840
        std::string msg = "Invalid archive days threshold: " + value +
841
                          ". Possible reason: db_config.archive_days_threshold is invalid.";
842
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
843
    }
Y
yudong.cai 已提交
844 845
    return Status::OK();
}
Z
zhiru 已提交
846

847 848
Status
Config::CheckDBConfigAutoFlushInterval(const std::string& value) {
849 850 851 852
    auto exist_error = !ValidationUtil::ValidateStringIsNumber(value).ok();
    fiu_do_on("check_config_auto_flush_interval_fail", exist_error = true);

    if (exist_error) {
853
        std::string msg = "Invalid db configuration auto_flush_interval: " + value +
854
                          ". Possible reason: db.auto_flush_interval is not a natural number.";
855 856 857 858 859 860
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }

    return Status::OK();
}

C
Cai Yudong 已提交
861
/* storage config */
862 863
Status
Config::CheckStorageConfigPrimaryPath(const std::string& value) {
S
shengjh 已提交
864
    fiu_return_on("check_config_primary_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
865 866 867
    if (value.empty()) {
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.db_path is empty.");
    }
868 869

    return ValidationUtil::ValidateStoragePath(value);
870 871 872 873
}

Status
Config::CheckStorageConfigSecondaryPath(const std::string& value) {
S
shengjh 已提交
874
    fiu_return_on("check_config_secondary_path_fail", Status(SERVER_INVALID_ARGUMENT, ""));
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898

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

899 900 901
    return Status::OK();
}

C
Cai Yudong 已提交
902
Status
903
Config::CheckStorageConfigS3Enable(const std::string& value) {
C
Cai Yudong 已提交
904 905
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
        std::string msg =
906
            "Invalid storage config: " + value + ". Possible reason: storage_config.s3_enable is not a boolean.";
C
Cai Yudong 已提交
907 908 909 910 911 912
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
913
Config::CheckStorageConfigS3Address(const std::string& value) {
C
Cai Yudong 已提交
914
    if (!ValidationUtil::ValidateIpAddress(value).ok()) {
915
        std::string msg = "Invalid s3 address: " + value + ". Possible reason: storage_config.s3_address is invalid.";
C
Cai Yudong 已提交
916 917 918 919 920 921
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

Status
922
Config::CheckStorageConfigS3Port(const std::string& value) {
C
Cai Yudong 已提交
923
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
924
        std::string msg = "Invalid s3 port: " + value + ". Possible reason: storage_config.s3_port is not a number.";
C
Cai Yudong 已提交
925 926
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
J
Jin Hai 已提交
927 928 929 930 931 932 933 934 935
        try {
            int32_t port = std::stoi(value);
            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
                std::string msg = "Invalid s3 port: " + value +
                                  ". Possible reason: storage_config.s3_port is not in range (1024, 65535).";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid storage_config.s3_port: " + value);
C
Cai Yudong 已提交
936 937 938 939 940 941
        }
    }
    return Status::OK();
}

Status
942
Config::CheckStorageConfigS3AccessKey(const std::string& value) {
C
Cai Yudong 已提交
943
    if (value.empty()) {
944
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_access_key is empty.");
C
Cai Yudong 已提交
945 946 947 948 949
    }
    return Status::OK();
}

Status
950
Config::CheckStorageConfigS3SecretKey(const std::string& value) {
C
Cai Yudong 已提交
951
    if (value.empty()) {
952
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_secret_key is empty.");
C
Cai Yudong 已提交
953 954 955 956 957
    }
    return Status::OK();
}

Status
958
Config::CheckStorageConfigS3Bucket(const std::string& value) {
C
Cai Yudong 已提交
959
    if (value.empty()) {
960
        return Status(SERVER_INVALID_ARGUMENT, "storage_config.s3_bucket is empty.");
C
Cai Yudong 已提交
961 962 963 964 965
    }
    return Status::OK();
}

/* metric config */
S
starlord 已提交
966
Status
S
starlord 已提交
967
Config::CheckMetricConfigEnableMonitor(const std::string& value) {
S
shengjh 已提交
968 969 970 971
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_config_enable_monitor_fail", exist_error = true);

    if (exist_error) {
972
        std::string msg =
S
starlord 已提交
973
            "Invalid metric config: " + value + ". Possible reason: metric_config.enable_monitor is not a boolean.";
974
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
975
    }
Y
yudong.cai 已提交
976 977
    return Status::OK();
}
Z
zhiru 已提交
978

Y
yudong.cai 已提交
979
Status
C
Cai Yudong 已提交
980
Config::CheckMetricConfigAddress(const std::string& value) {
981
    if (!ValidationUtil::ValidateIpAddress(value).ok()) {
C
Cai Yudong 已提交
982 983
        std::string msg = "Invalid metric ip: " + value + ". Possible reason: metric_config.ip is invalid.";
        return Status(SERVER_INVALID_ARGUMENT, "Invalid metric config ip: " + value);
984 985 986 987
    }
    return Status::OK();
}

Y
yudong.cai 已提交
988
Status
C
Cai Yudong 已提交
989
Config::CheckMetricConfigPort(const std::string& value) {
Y
yudong.cai 已提交
990
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
C
Cai Yudong 已提交
991
        std::string msg = "Invalid metric port: " + value + ". Possible reason: metric_config.port is not a number.";
C
Cai Yudong 已提交
992 993
        return Status(SERVER_INVALID_ARGUMENT, msg);
    } else {
J
Jin Hai 已提交
994 995 996 997 998 999 1000 1001 1002
        try {
            int32_t port = std::stoi(value);
            if (!(port > PORT_NUMBER_MIN && port < PORT_NUMBER_MAX)) {
                std::string msg = "Invalid metric port: " + value +
                                  ". Possible reason: metric_config.port is not in range (1024, 65535).";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid metric_config.port: " + value);
C
Cai Yudong 已提交
1003
        }
Z
zhiru 已提交
1004
    }
Y
yudong.cai 已提交
1005
    return Status::OK();
Z
zhiru 已提交
1006 1007
}

C
Cai Yudong 已提交
1008
/* cache config */
S
starlord 已提交
1009
Status
S
starlord 已提交
1010
Config::CheckCacheConfigCpuCacheCapacity(const std::string& value) {
S
shengjh 已提交
1011 1012
    fiu_return_on("check_config_cpu_cache_capacity_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1013
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1014
        std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1015
                          ". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
1016
        return Status(SERVER_INVALID_ARGUMENT, msg);
1017
    } else {
Y
yudong.cai 已提交
1018
        int64_t cpu_cache_capacity = std::stoll(value) * GB;
1019 1020
        if (cpu_cache_capacity <= 0) {
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1021
                              ". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
1022 1023 1024
            return Status(SERVER_INVALID_ARGUMENT, msg);
        }

S
starlord 已提交
1025
        uint64_t total_mem = 0, free_mem = 0;
Z
zhiru 已提交
1026
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
1027 1028
        if (static_cast<uint64_t>(cpu_cache_capacity) >= total_mem) {
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1029
                              ". Possible reason: cache_config.cpu_cache_capacity exceeds system memory.";
1030
            return Status(SERVER_INVALID_ARGUMENT, msg);
1031
        } else if (static_cast<double>(cpu_cache_capacity) > static_cast<double>(total_mem * 0.9)) {
1032
            std::cerr << "WARNING: cpu cache capacity value is too big" << std::endl;
Z
zhiru 已提交
1033
        }
1034

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

Y
yudong.cai 已提交
1038
        int64_t insert_buffer_size = buffer_value * GB;
S
shengjh 已提交
1039
        fiu_do_on("Config.CheckCacheConfigCpuCacheCapacity.large_insert_buffer", insert_buffer_size = total_mem + 1);
Y
yudong.cai 已提交
1040
        if (insert_buffer_size + cpu_cache_capacity >= total_mem) {
1041
            std::string msg = "Invalid cpu cache capacity: " + value +
S
starlord 已提交
1042
                              ". Possible reason: sum of cache_config.cpu_cache_capacity and "
1043
                              "cache_config.insert_buffer_size exceeds system memory.";
1044
            return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1045 1046
        }
    }
Y
yudong.cai 已提交
1047 1048
    return Status::OK();
}
Z
zhiru 已提交
1049

Y
yudong.cai 已提交
1050
Status
S
starlord 已提交
1051
Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) {
S
shengjh 已提交
1052 1053
    fiu_return_on("check_config_cpu_cache_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1054
    if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
1055
        std::string msg = "Invalid cpu cache threshold: " + value +
S
starlord 已提交
1056
                          ". Possible reason: cache_config.cpu_cache_threshold is not in range (0.0, 1.0].";
1057
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1058
    } else {
Y
yudong.cai 已提交
1059 1060
        float cpu_cache_threshold = std::stof(value);
        if (cpu_cache_threshold <= 0.0 || cpu_cache_threshold >= 1.0) {
1061
            std::string msg = "Invalid cpu cache threshold: " + value +
S
starlord 已提交
1062
                              ". Possible reason: cache_config.cpu_cache_threshold is not in range (0.0, 1.0].";
1063
            return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1064
        }
1065
    }
Y
yudong.cai 已提交
1066 1067
    return Status::OK();
}
1068

1069 1070
Status
Config::CheckCacheConfigInsertBufferSize(const std::string& value) {
S
shengjh 已提交
1071
    fiu_return_on("check_config_insert_buffer_size_fail", Status(SERVER_INVALID_ARGUMENT, ""));
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
    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);
        }

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

1087 1088
        uint64_t total_mem = 0, free_mem = 0;
        CommonUtil::GetSystemMemInfo(total_mem, free_mem);
T
Tinkerrr 已提交
1089
        if (buffer_size + cache_size >= total_mem) {
1090 1091 1092 1093 1094 1095 1096 1097
            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 已提交
1098
Status
S
starlord 已提交
1099
Config::CheckCacheConfigCacheInsertData(const std::string& value) {
S
shengjh 已提交
1100 1101
    fiu_return_on("check_config_cache_insert_data_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1102
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
1103
        std::string msg = "Invalid cache insert data option: " + value +
S
starlord 已提交
1104
                          ". Possible reason: cache_config.cache_insert_data is not a boolean.";
1105
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1106 1107
    }
    return Status::OK();
Z
zhiru 已提交
1108 1109
}

C
Cai Yudong 已提交
1110
/* engine config */
S
starlord 已提交
1111
Status
S
starlord 已提交
1112
Config::CheckEngineConfigUseBlasThreshold(const std::string& value) {
S
shengjh 已提交
1113 1114
    fiu_return_on("check_config_use_blas_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1115
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1116
        std::string msg = "Invalid use blas threshold: " + value +
S
starlord 已提交
1117
                          ". Possible reason: engine_config.use_blas_threshold is not a positive integer.";
1118
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1119
    }
Y
yudong.cai 已提交
1120 1121
    return Status::OK();
}
Z
zhiru 已提交
1122

Y
yudong.cai 已提交
1123
Status
S
starlord 已提交
1124
Config::CheckEngineConfigOmpThreadNum(const std::string& value) {
S
shengjh 已提交
1125 1126
    fiu_return_on("check_config_omp_thread_num_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1127
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1128
        std::string msg = "Invalid omp thread num: " + value +
S
starlord 已提交
1129
                          ". Possible reason: engine_config.omp_thread_num is not a positive integer.";
1130
        return Status(SERVER_INVALID_ARGUMENT, msg);
S
starlord 已提交
1131 1132
    }

Y
yudong.cai 已提交
1133 1134
    int64_t omp_thread = std::stoll(value);
    int64_t sys_thread_cnt = 8;
S
starlord 已提交
1135
    CommonUtil::GetSystemAvailableThreads(sys_thread_cnt);
Y
yudong.cai 已提交
1136
    if (omp_thread > sys_thread_cnt) {
1137
        std::string msg = "Invalid omp thread num: " + value +
S
starlord 已提交
1138
                          ". Possible reason: engine_config.omp_thread_num exceeds system cpu cores.";
1139
        return Status(SERVER_INVALID_ARGUMENT, msg);
Z
zhiru 已提交
1140
    }
Y
yudong.cai 已提交
1141
    return Status::OK();
Z
zhiru 已提交
1142 1143
}

C
Cai Yudong 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
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 已提交
1154
#ifdef MILVUS_GPU_VERSION
B
BossZou 已提交
1155

W
wxyu 已提交
1156
Status
1157
Config::CheckEngineConfigGpuSearchThreshold(const std::string& value) {
S
shengjh 已提交
1158 1159
    fiu_return_on("check_config_gpu_search_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

W
wxyu 已提交
1160
    if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
1161 1162
        std::string msg = "Invalid gpu search threshold: " + value +
                          ". Possible reason: engine_config.gpu_search_threshold is not a positive integer.";
W
wxyu 已提交
1163 1164 1165 1166 1167
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }
    return Status::OK();
}

C
Cai Yudong 已提交
1168
/* gpu resource config */
S
starlord 已提交
1169
Status
1170
Config::CheckGpuResourceConfigEnable(const std::string& value) {
S
shengjh 已提交
1171 1172
    fiu_return_on("check_config_gpu_resource_enable_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1173
    if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
1174 1175
        std::string msg =
            "Invalid gpu resource config: " + value + ". Possible reason: gpu_resource_config.enable is not a boolean.";
1176
        return Status(SERVER_INVALID_ARGUMENT, msg);
W
wxyu 已提交
1177
    }
Y
yudong.cai 已提交
1178 1179
    return Status::OK();
}
1180

Y
yudong.cai 已提交
1181
Status
Y
yudong.cai 已提交
1182
Config::CheckGpuResourceConfigCacheCapacity(const std::string& value) {
S
shengjh 已提交
1183 1184
    fiu_return_on("check_gpu_resource_config_cache_capacity_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1185 1186 1187
    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.";
1188
        return Status(SERVER_INVALID_ARGUMENT, msg);
Y
yudong.cai 已提交
1189
    } else {
Y
yudong.cai 已提交
1190 1191
        int64_t gpu_cache_capacity = std::stoll(value) * GB;
        std::vector<int64_t> gpu_ids;
C
Cai Yudong 已提交
1192
        CONFIG_CHECK(GetGpuResourceConfigBuildIndexResources(gpu_ids));
Y
yudong.cai 已提交
1193

Y
yudong.cai 已提交
1194
        for (int64_t gpu_id : gpu_ids) {
Y
yudong.cai 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
            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 已提交
1207
    }
Y
yudong.cai 已提交
1208 1209
    return Status::OK();
}
1210

Y
yudong.cai 已提交
1211
Status
Y
yudong.cai 已提交
1212
Config::CheckGpuResourceConfigCacheThreshold(const std::string& value) {
S
shengjh 已提交
1213 1214
    fiu_return_on("check_config_gpu_resource_cache_threshold_fail", Status(SERVER_INVALID_ARGUMENT, ""));

Y
yudong.cai 已提交
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
    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 已提交
1232 1233
    std::string s = value;
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
Z
Zhiru Zhu 已提交
1234

Y
yudong.cai 已提交
1235
    const std::regex pat("gpu(\\d+)");
Z
Zhiru Zhu 已提交
1236 1237
    std::smatch m;
    if (!std::regex_match(s, m, pat)) {
Y
yudong.cai 已提交
1238 1239
        std::string msg = "Invalid gpu resource: " + value +
                          ". Possible reason: gpu_resource_config is not in the format of cpux or gpux";
1240
        return Status(SERVER_INVALID_ARGUMENT, msg);
1241 1242
    }

Z
Zhiru Zhu 已提交
1243
    if (s.compare(0, 3, "gpu") == 0) {
J
Jin Hai 已提交
1244 1245 1246 1247 1248 1249 1250 1251 1252
        try {
            int32_t gpu_index = std::stoi(s.substr(3));
            if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
                std::string msg = "Invalid gpu resource: " + value +
                                  ". Possible reason: gpu_resource_config does not match with the hardware.";
                return Status(SERVER_INVALID_ARGUMENT, msg);
            }
        } catch (...) {
            return Status(SERVER_INVALID_ARGUMENT, "Invalid gpu_resource_config: " + value);
Z
Zhiru Zhu 已提交
1253
        }
1254
    }
Z
Zhiru Zhu 已提交
1255

1256 1257 1258 1259
    return Status::OK();
}

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

Y
yudong.cai 已提交
1263
    if (value.empty()) {
1264
        std::string msg =
Y
yudong.cai 已提交
1265 1266
            "Invalid gpu search resource. "
            "Possible reason: gpu_resource_config.search_resources is empty.";
1267
        return Status(SERVER_INVALID_ARGUMENT, msg);
1268 1269
    }

B
BossZou 已提交
1270
    std::unordered_set<std::string> value_set;
Z
Zhiru Zhu 已提交
1271
    for (auto& resource : value) {
C
Cai Yudong 已提交
1272
        CONFIG_CHECK(CheckGpuResource(resource));
B
BossZou 已提交
1273
        value_set.insert(resource);
1274
    }
B
BossZou 已提交
1275 1276 1277 1278 1279 1280 1281 1282

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

1283 1284 1285 1286
    return Status::OK();
}

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

1290 1291
    if (value.empty()) {
        std::string msg =
Y
yudong.cai 已提交
1292 1293
            "Invalid gpu build index resource. "
            "Possible reason: gpu_resource_config.build_index_resources is empty.";
1294 1295 1296
        return Status(SERVER_INVALID_ARGUMENT, msg);
    }

B
BossZou 已提交
1297
    std::unordered_set<std::string> value_set;
1298
    for (auto& resource : value) {
C
Cai Yudong 已提交
1299
        CONFIG_CHECK(CheckGpuResource(resource));
B
BossZou 已提交
1300 1301 1302 1303 1304 1305 1306 1307
        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 已提交
1308
    }
1309

Y
yudong.cai 已提交
1310
    return Status::OK();
G
groot 已提交
1311
}
B
BossZou 已提交
1312

G
groot 已提交
1313
#endif
1314 1315 1316 1317 1318 1319 1320
/* 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 已提交
1321

C
Cai Yudong 已提交
1322 1323 1324
/* wal config */
Status
Config::CheckWalConfigEnable(const std::string& value) {
J
Jin Hai 已提交
1325 1326 1327 1328
    auto exist_error = !ValidationUtil::ValidateStringIsBool(value).ok();
    fiu_do_on("check_config_wal_enable_fail", exist_error = true);

    if (exist_error) {
C
Cai Yudong 已提交
1329 1330 1331 1332 1333 1334 1335 1336
        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 已提交
1337 1338 1339 1340
    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 已提交
1341 1342 1343 1344 1345 1346 1347 1348 1349
        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 已提交
1350 1351 1352 1353
    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 已提交
1354 1355 1356 1357 1358 1359 1360
        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 已提交
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
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 已提交
1371
////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
1372
ConfigNode&
1373
Config::GetConfigRoot() {
1374
    ConfigMgr* mgr = YamlConfigMgr::GetInstance();
1375 1376 1377 1378 1379 1380
    return mgr->GetRootNode();
}

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

C
Cai Yudong 已提交
1383 1384 1385 1386 1387
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 已提交
1388
    return config_map_[parent_key].count(child_key) != 0;
C
Cai Yudong 已提交
1389 1390
}

Y
yudong.cai 已提交
1391
Status
S
starlord 已提交
1392
Config::GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value) {
Y
yudong.cai 已提交
1393
    std::lock_guard<std::mutex> lock(mutex_);
Y
yudong.cai 已提交
1394 1395 1396 1397 1398
    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 已提交
1399
    return Status(SERVER_UNEXPECTED_ERROR, "key not exist");
Y
yudong.cai 已提交
1400 1401
}

C
Cai Yudong 已提交
1402
Status
S
starlord 已提交
1403
Config::SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value) {
Y
yudong.cai 已提交
1404 1405
    std::lock_guard<std::mutex> lock(mutex_);
    config_map_[parent_key][child_key] = value;
C
Cai Yudong 已提交
1406
    return Status::OK();
Y
yudong.cai 已提交
1407 1408 1409
}

////////////////////////////////////////////////////////////////////////////////
Y
yudong.cai 已提交
1410
std::string
S
starlord 已提交
1411
Config::GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value) {
Y
yudong.cai 已提交
1412
    std::string value;
S
starlord 已提交
1413 1414 1415
    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 已提交
1416
    }
Y
yudong.cai 已提交
1417
    return value;
Y
yudong.cai 已提交
1418 1419
}

Z
Zhiru Zhu 已提交
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
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;
}

1436 1437 1438 1439 1440 1441
Status
Config::GetConfigVersion(std::string& value) {
    value = GetConfigRoot().GetValue(CONFIG_VERSION);
    return CheckConfigVersion(value);
}

1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
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 已提交
1468
/* server config */
1469
Status
S
starlord 已提交
1470
Config::GetServerConfigAddress(std::string& value) {
S
starlord 已提交
1471
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, CONFIG_SERVER_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
1472
    return CheckServerConfigAddress(value);
1473 1474 1475
}

Status
S
starlord 已提交
1476
Config::GetServerConfigPort(std::string& value) {
S
starlord 已提交
1477
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_PORT, CONFIG_SERVER_PORT_DEFAULT);
Y
yudong.cai 已提交
1478
    return CheckServerConfigPort(value);
1479 1480 1481
}

Status
S
starlord 已提交
1482
Config::GetServerConfigDeployMode(std::string& value) {
S
starlord 已提交
1483
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, CONFIG_SERVER_DEPLOY_MODE_DEFAULT);
Y
yudong.cai 已提交
1484
    return CheckServerConfigDeployMode(value);
1485 1486 1487
}

Status
S
starlord 已提交
1488
Config::GetServerConfigTimeZone(std::string& value) {
S
starlord 已提交
1489
    value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, CONFIG_SERVER_TIME_ZONE_DEFAULT);
Y
yudong.cai 已提交
1490
    return CheckServerConfigTimeZone(value);
1491 1492
}

B
BossZou 已提交
1493 1494 1495 1496 1497 1498
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 已提交
1499
/* DB config */
1500
Status
S
starlord 已提交
1501
Config::GetDBConfigBackendUrl(std::string& value) {
S
starlord 已提交
1502
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_BACKEND_URL, CONFIG_DB_BACKEND_URL_DEFAULT);
Y
yudong.cai 已提交
1503
    return CheckDBConfigBackendUrl(value);
1504 1505 1506
}

Status
Y
yudong.cai 已提交
1507
Config::GetDBConfigArchiveDiskThreshold(int64_t& value) {
S
starlord 已提交
1508 1509
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1510
    CONFIG_CHECK(CheckDBConfigArchiveDiskThreshold(str));
Y
yudong.cai 已提交
1511
    value = std::stoll(str);
1512 1513 1514 1515
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1516
Config::GetDBConfigArchiveDaysThreshold(int64_t& value) {
S
starlord 已提交
1517 1518
    std::string str =
        GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1519
    CONFIG_CHECK(CheckDBConfigArchiveDaysThreshold(str));
Y
yudong.cai 已提交
1520
    value = std::stoll(str);
1521 1522 1523
    return Status::OK();
}

S
starlord 已提交
1524
Status
1525
Config::GetDBConfigPreloadCollection(std::string& value) {
G
groot 已提交
1526
    value = GetConfigStr(CONFIG_DB, CONFIG_DB_PRELOAD_COLLECTION);
S
starlord 已提交
1527 1528 1529
    return Status::OK();
}

1530
Status
C
Cai Yudong 已提交
1531
Config::GetDBConfigAutoFlushInterval(int64_t& value) {
1532
    std::string str = GetConfigStr(CONFIG_DB, CONFIG_DB_AUTO_FLUSH_INTERVAL, CONFIG_DB_AUTO_FLUSH_INTERVAL_DEFAULT);
C
Cai Yudong 已提交
1533 1534
    CONFIG_CHECK(CheckDBConfigAutoFlushInterval(str));
    value = std::stoll(str);
1535 1536 1537
    return Status::OK();
}

C
Cai Yudong 已提交
1538
/* storage config */
1539 1540
Status
Config::GetStorageConfigPrimaryPath(std::string& value) {
C
Cai Yudong 已提交
1541
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_PRIMARY_PATH, CONFIG_STORAGE_PRIMARY_PATH_DEFAULT);
1542 1543 1544 1545 1546
    return CheckStorageConfigPrimaryPath(value);
}

Status
Config::GetStorageConfigSecondaryPath(std::string& value) {
C
Cai Yudong 已提交
1547
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_SECONDARY_PATH, CONFIG_STORAGE_SECONDARY_PATH_DEFAULT);
1548 1549 1550
    return CheckStorageConfigSecondaryPath(value);
}

C
Cai Yudong 已提交
1551
Status
1552 1553 1554
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 已提交
1555
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
C
Cai Yudong 已提交
1556 1557 1558 1559
    return Status::OK();
}

Status
1560 1561 1562
Config::GetStorageConfigS3Address(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ADDRESS, CONFIG_STORAGE_S3_ADDRESS_DEFAULT);
    return CheckStorageConfigS3Address(value);
C
Cai Yudong 已提交
1563 1564 1565
}

Status
1566 1567 1568
Config::GetStorageConfigS3Port(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_PORT, CONFIG_STORAGE_S3_PORT_DEFAULT);
    return CheckStorageConfigS3Port(value);
C
Cai Yudong 已提交
1569 1570 1571
}

Status
1572 1573
Config::GetStorageConfigS3AccessKey(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_ACCESS_KEY, CONFIG_STORAGE_S3_ACCESS_KEY_DEFAULT);
C
Cai Yudong 已提交
1574 1575 1576 1577
    return Status::OK();
}

Status
1578 1579
Config::GetStorageConfigS3SecretKey(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_SECRET_KEY, CONFIG_STORAGE_S3_SECRET_KEY_DEFAULT);
C
Cai Yudong 已提交
1580 1581 1582 1583
    return Status::OK();
}

Status
1584 1585
Config::GetStorageConfigS3Bucket(std::string& value) {
    value = GetConfigStr(CONFIG_STORAGE, CONFIG_STORAGE_S3_BUCKET, CONFIG_STORAGE_S3_BUCKET_DEFAULT);
C
Cai Yudong 已提交
1586 1587 1588 1589
    return Status::OK();
}

/* metric config */
1590
Status
S
starlord 已提交
1591
Config::GetMetricConfigEnableMonitor(bool& value) {
1592
    std::string str = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, CONFIG_METRIC_ENABLE_MONITOR_DEFAULT);
C
Cai Yudong 已提交
1593
    CONFIG_CHECK(CheckMetricConfigEnableMonitor(str));
Y
Yhz 已提交
1594
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
1595 1596 1597 1598
    return Status::OK();
}

Status
C
Cai Yudong 已提交
1599 1600
Config::GetMetricConfigAddress(std::string& value) {
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_ADDRESS, CONFIG_METRIC_ADDRESS_DEFAULT);
Y
yudong.cai 已提交
1601
    return Status::OK();
1602 1603
}

1604
Status
C
Cai Yudong 已提交
1605 1606 1607
Config::GetMetricConfigPort(std::string& value) {
    value = GetConfigStr(CONFIG_METRIC, CONFIG_METRIC_PORT, CONFIG_METRIC_PORT_DEFAULT);
    return CheckMetricConfigPort(value);
1608 1609
}

C
Cai Yudong 已提交
1610
/* cache config */
1611
Status
W
wxyu 已提交
1612
Config::GetCacheConfigCpuCacheCapacity(int64_t& value) {
S
starlord 已提交
1613 1614
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT);
C
Cai Yudong 已提交
1615
    CONFIG_CHECK(CheckCacheConfigCpuCacheCapacity(str));
Y
yudong.cai 已提交
1616
    value = std::stoll(str);
1617 1618 1619 1620
    return Status::OK();
}

Status
S
starlord 已提交
1621
Config::GetCacheConfigCpuCacheThreshold(float& value) {
S
starlord 已提交
1622 1623
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1624
    CONFIG_CHECK(CheckCacheConfigCpuCacheThreshold(str));
1625 1626 1627 1628
    value = std::stof(str);
    return Status::OK();
}

1629 1630 1631 1632 1633 1634 1635 1636 1637
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();
}

1638
Status
S
starlord 已提交
1639
Config::GetCacheConfigCacheInsertData(bool& value) {
S
starlord 已提交
1640 1641
    std::string str =
        GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
C
Cai Yudong 已提交
1642
    CONFIG_CHECK(CheckCacheConfigCacheInsertData(str));
1643 1644 1645 1646 1647
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    value = (str == "true" || str == "on" || str == "yes" || str == "1");
    return Status::OK();
}

C
Cai Yudong 已提交
1648
/* engine config */
1649
Status
Y
yudong.cai 已提交
1650
Config::GetEngineConfigUseBlasThreshold(int64_t& value) {
S
starlord 已提交
1651 1652
    std::string str =
        GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1653
    CONFIG_CHECK(CheckEngineConfigUseBlasThreshold(str));
Y
yudong.cai 已提交
1654
    value = std::stoll(str);
1655 1656 1657 1658
    return Status::OK();
}

Status
Y
yudong.cai 已提交
1659
Config::GetEngineConfigOmpThreadNum(int64_t& value) {
1660
    std::string str = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
C
Cai Yudong 已提交
1661
    CONFIG_CHECK(CheckEngineConfigOmpThreadNum(str));
Y
yudong.cai 已提交
1662
    value = std::stoll(str);
1663 1664 1665
    return Status::OK();
}

C
Cai Yudong 已提交
1666 1667 1668 1669 1670 1671 1672 1673 1674
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 已提交
1675
#ifdef MILVUS_GPU_VERSION
B
BossZou 已提交
1676

W
wxyu 已提交
1677
Status
Y
yudong.cai 已提交
1678
Config::GetEngineConfigGpuSearchThreshold(int64_t& value) {
W
wxyu 已提交
1679
    std::string str =
1680
        GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT);
C
Cai Yudong 已提交
1681
    CONFIG_CHECK(CheckEngineConfigGpuSearchThreshold(str));
Y
yudong.cai 已提交
1682
    value = std::stoll(str);
W
wxyu 已提交
1683 1684
    return Status::OK();
}
S
shengjh 已提交
1685

C
Cai Yudong 已提交
1686
#endif
W
wxyu 已提交
1687

C
Cai Yudong 已提交
1688 1689
/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
S
shengjh 已提交
1690

1691
Status
1692 1693
Config::GetGpuResourceConfigEnable(bool& value) {
    std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, CONFIG_GPU_RESOURCE_ENABLE_DEFAULT);
C
Cai Yudong 已提交
1694
    CONFIG_CHECK(CheckGpuResourceConfigEnable(str));
Y
Yhz 已提交
1695
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
Y
yudong.cai 已提交
1696
    return Status::OK();
1697 1698 1699
}

Status
Y
yudong.cai 已提交
1700
Config::GetGpuResourceConfigCacheCapacity(int64_t& value) {
1701
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
1702
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
1703
    fiu_do_on("Config.GetGpuResourceConfigCacheCapacity.diable_gpu_resource", gpu_resource_enable = false);
1704 1705
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
1706 1707 1708 1709
        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 已提交
1710
    CONFIG_CHECK(CheckGpuResourceConfigCacheCapacity(str));
Y
yudong.cai 已提交
1711
    value = std::stoll(str);
W
wxyu 已提交
1712 1713 1714
    return Status::OK();
}

1715
Status
Y
yudong.cai 已提交
1716
Config::GetGpuResourceConfigCacheThreshold(float& value) {
1717
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
1718
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
1719
    fiu_do_on("Config.GetGpuResourceConfigCacheThreshold.diable_gpu_resource", gpu_resource_enable = false);
1720 1721
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
1722 1723 1724 1725
        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 已提交
1726
    CONFIG_CHECK(CheckGpuResourceConfigCacheThreshold(str));
Y
yudong.cai 已提交
1727 1728
    value = std::stof(str);
    return Status::OK();
1729 1730 1731
}

Status
Y
yudong.cai 已提交
1732
Config::GetGpuResourceConfigSearchResources(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_search_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 1740 1741 1742 1743
        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 已提交
1744
    CONFIG_CHECK(CheckGpuResourceConfigSearchResources(res_vec));
1745
    value.clear();
Y
yudong.cai 已提交
1746
    for (std::string& res : res_vec) {
Y
yudong.cai 已提交
1747
        value.push_back(std::stoll(res.substr(3)));
Y
yudong.cai 已提交
1748 1749
    }
    return Status::OK();
1750 1751 1752
}

Status
Y
yudong.cai 已提交
1753
Config::GetGpuResourceConfigBuildIndexResources(std::vector<int64_t>& value) {
1754
    bool gpu_resource_enable = false;
C
Cai Yudong 已提交
1755
    CONFIG_CHECK(GetGpuResourceConfigEnable(gpu_resource_enable));
S
shengjh 已提交
1756
    fiu_do_on("get_gpu_config_build_index_resources.disable_gpu_resource_fail", gpu_resource_enable = false);
1757 1758
    if (!gpu_resource_enable) {
        std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
Y
yudong.cai 已提交
1759 1760
        return Status(SERVER_UNSUPPORTED_ERROR, msg);
    }
1761
    std::string str =
Y
yudong.cai 已提交
1762 1763 1764 1765
        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 已提交
1766
    CONFIG_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec));
1767
    value.clear();
Y
yudong.cai 已提交
1768
    for (std::string& res : res_vec) {
Y
yudong.cai 已提交
1769
        value.push_back(std::stoll(res.substr(3)));
Y
yudong.cai 已提交
1770
    }
1771
    return Status::OK();
Y
yudong.cai 已提交
1772
}
B
BossZou 已提交
1773

G
groot 已提交
1774
#endif
G
groot 已提交
1775

Z
Zhiru Zhu 已提交
1776 1777 1778 1779
/* tracing config */
Status
Config::GetTracingConfigJsonConfigPath(std::string& value) {
    value = GetConfigStr(CONFIG_TRACING, CONFIG_TRACING_JSON_CONFIG_PATH, "");
S
shengjh 已提交
1780
    fiu_do_on("get_config_json_config_path_fail", value = "error_config_json_path");
Z
Zhiru Zhu 已提交
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
    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();
}

1792 1793 1794 1795
/* wal config */
Status
Config::GetWalConfigEnable(bool& wal_enable) {
    std::string str = GetConfigStr(CONFIG_WAL, CONFIG_WAL_ENABLE, CONFIG_WAL_ENABLE_DEFAULT);
C
Cai Yudong 已提交
1796
    CONFIG_CHECK(CheckWalConfigEnable(str));
Y
Yhz 已提交
1797
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, wal_enable));
1798 1799 1800 1801 1802 1803 1804
    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 已提交
1805
    CONFIG_CHECK(CheckWalConfigRecoveryErrorIgnore(str));
Y
Yhz 已提交
1806
    CONFIG_CHECK(StringHelpFunctions::ConvertToBoolean(str, recovery_error_ignore));
1807 1808 1809 1810
    return Status::OK();
}

Status
C
Cai Yudong 已提交
1811
Config::GetWalConfigBufferSize(int64_t& buffer_size) {
1812
    std::string str = GetConfigStr(CONFIG_WAL, CONFIG_WAL_BUFFER_SIZE, CONFIG_WAL_BUFFER_SIZE_DEFAULT);
C
Cai Yudong 已提交
1813 1814
    CONFIG_CHECK(CheckWalConfigBufferSize(str));
    buffer_size = std::stoll(str);
1815 1816 1817 1818 1819
    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;
    }
1820 1821 1822 1823 1824
    return Status::OK();
}

Status
Config::GetWalConfigWalPath(std::string& wal_path) {
C
Cai Yudong 已提交
1825
    wal_path = GetConfigStr(CONFIG_WAL, CONFIG_WAL_WAL_PATH, CONFIG_WAL_WAL_PATH_DEFAULT);
J
Jin Hai 已提交
1826
    CONFIG_CHECK(CheckWalConfigWalPath(wal_path));
1827 1828 1829
    return Status::OK();
}

1830 1831 1832 1833 1834 1835
Status
Config::GetServerRestartRequired(bool& required) {
    required = restart_required_;
    return Status::OK();
}

Y
yudong.cai 已提交
1836 1837 1838
///////////////////////////////////////////////////////////////////////////////
/* server config */
Status
S
starlord 已提交
1839
Config::SetServerConfigAddress(const std::string& value) {
C
Cai Yudong 已提交
1840 1841
    CONFIG_CHECK(CheckServerConfigAddress(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
Y
yudong.cai 已提交
1842 1843 1844
}

Status
S
starlord 已提交
1845
Config::SetServerConfigPort(const std::string& value) {
C
Cai Yudong 已提交
1846 1847
    CONFIG_CHECK(CheckServerConfigPort(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value);
Y
yudong.cai 已提交
1848 1849 1850
}

Status
S
starlord 已提交
1851
Config::SetServerConfigDeployMode(const std::string& value) {
C
Cai Yudong 已提交
1852 1853
    CONFIG_CHECK(CheckServerConfigDeployMode(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, value);
Y
yudong.cai 已提交
1854 1855 1856
}

Status
S
starlord 已提交
1857
Config::SetServerConfigTimeZone(const std::string& value) {
C
Cai Yudong 已提交
1858 1859
    CONFIG_CHECK(CheckServerConfigTimeZone(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
Y
yudong.cai 已提交
1860 1861
}

B
BossZou 已提交
1862 1863 1864 1865 1866 1867
Status
Config::SetServerConfigWebPort(const std::string& value) {
    CONFIG_CHECK(CheckServerConfigWebPort(value));
    return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_WEB_PORT, value);
}

Y
yudong.cai 已提交
1868 1869
/* db config */
Status
S
starlord 已提交
1870
Config::SetDBConfigBackendUrl(const std::string& value) {
C
Cai Yudong 已提交
1871 1872
    CONFIG_CHECK(CheckDBConfigBackendUrl(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value);
Y
yudong.cai 已提交
1873 1874
}

1875
Status
1876 1877
Config::SetDBConfigPreloadCollection(const std::string& value) {
    CONFIG_CHECK(CheckDBConfigPreloadCollection(value));
1878
    std::string cor_value = value == "*" ? "\'*\'" : value;
G
groot 已提交
1879
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRELOAD_COLLECTION, cor_value);
1880 1881
}

Y
yudong.cai 已提交
1882
Status
S
starlord 已提交
1883
Config::SetDBConfigArchiveDiskThreshold(const std::string& value) {
C
Cai Yudong 已提交
1884 1885
    CONFIG_CHECK(CheckDBConfigArchiveDiskThreshold(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value);
Y
yudong.cai 已提交
1886 1887 1888
}

Status
S
starlord 已提交
1889
Config::SetDBConfigArchiveDaysThreshold(const std::string& value) {
C
Cai Yudong 已提交
1890 1891
    CONFIG_CHECK(CheckDBConfigArchiveDaysThreshold(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value);
Y
yudong.cai 已提交
1892 1893
}

1894 1895 1896 1897 1898 1899
Status
Config::SetDBConfigAutoFlushInterval(const std::string& value) {
    CONFIG_CHECK(CheckDBConfigAutoFlushInterval(value));
    return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_AUTO_FLUSH_INTERVAL, value);
}

C
Cai Yudong 已提交
1900
/* storage config */
1901 1902 1903
Status
Config::SetStorageConfigPrimaryPath(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigPrimaryPath(value));
C
Cai Yudong 已提交
1904
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_PRIMARY_PATH, value);
1905 1906 1907 1908 1909
}

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

C
Cai Yudong 已提交
1913
Status
1914 1915 1916
Config::SetStorageConfigS3Enable(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Enable(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ENABLE, value);
C
Cai Yudong 已提交
1917 1918 1919
}

Status
1920 1921 1922
Config::SetStorageConfigS3Address(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Address(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ADDRESS, value);
C
Cai Yudong 已提交
1923 1924 1925
}

Status
1926 1927 1928
Config::SetStorageConfigS3Port(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Port(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_PORT, value);
C
Cai Yudong 已提交
1929 1930 1931
}

Status
1932 1933 1934
Config::SetStorageConfigS3AccessKey(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3AccessKey(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_ACCESS_KEY, value);
C
Cai Yudong 已提交
1935 1936 1937
}

Status
1938 1939 1940
Config::SetStorageConfigS3SecretKey(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3SecretKey(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_SECRET_KEY, value);
C
Cai Yudong 已提交
1941 1942 1943
}

Status
1944 1945 1946
Config::SetStorageConfigS3Bucket(const std::string& value) {
    CONFIG_CHECK(CheckStorageConfigS3Bucket(value));
    return SetConfigValueInMem(CONFIG_STORAGE, CONFIG_STORAGE_S3_BUCKET, value);
Y
yudong.cai 已提交
1947 1948 1949 1950
}

/* metric config */
Status
S
starlord 已提交
1951
Config::SetMetricConfigEnableMonitor(const std::string& value) {
C
Cai Yudong 已提交
1952 1953
    CONFIG_CHECK(CheckMetricConfigEnableMonitor(value));
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, value);
Y
yudong.cai 已提交
1954 1955 1956
}

Status
C
Cai Yudong 已提交
1957 1958 1959
Config::SetMetricConfigAddress(const std::string& value) {
    CONFIG_CHECK(CheckMetricConfigAddress(value));
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ADDRESS, value);
1960 1961
}

Y
yudong.cai 已提交
1962
Status
C
Cai Yudong 已提交
1963 1964 1965
Config::SetMetricConfigPort(const std::string& value) {
    CONFIG_CHECK(CheckMetricConfigPort(value));
    return SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_PORT, value);
Y
yudong.cai 已提交
1966 1967 1968 1969
}

/* cache config */
Status
S
starlord 已提交
1970
Config::SetCacheConfigCpuCacheCapacity(const std::string& value) {
C
Cai Yudong 已提交
1971
    CONFIG_CHECK(CheckCacheConfigCpuCacheCapacity(value));
C
Cai Yudong 已提交
1972
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value));
1973
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value);
Y
yudong.cai 已提交
1974 1975 1976
}

Status
S
starlord 已提交
1977
Config::SetCacheConfigCpuCacheThreshold(const std::string& value) {
C
Cai Yudong 已提交
1978 1979
    CONFIG_CHECK(CheckCacheConfigCpuCacheThreshold(value));
    return SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, value);
Y
yudong.cai 已提交
1980 1981
}

1982 1983 1984
Status
Config::SetCacheConfigInsertBufferSize(const std::string& value) {
    CONFIG_CHECK(CheckCacheConfigInsertBufferSize(value));
C
Cai Yudong 已提交
1985
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, value));
1986
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, value);
1987 1988
}

Y
yudong.cai 已提交
1989
Status
S
starlord 已提交
1990
Config::SetCacheConfigCacheInsertData(const std::string& value) {
C
Cai Yudong 已提交
1991
    CONFIG_CHECK(CheckCacheConfigCacheInsertData(value));
C
Cai Yudong 已提交
1992
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value));
1993
    return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value);
Y
yudong.cai 已提交
1994 1995 1996 1997
}

/* engine config */
Status
S
starlord 已提交
1998
Config::SetEngineConfigUseBlasThreshold(const std::string& value) {
C
Cai Yudong 已提交
1999
    CONFIG_CHECK(CheckEngineConfigUseBlasThreshold(value));
C
Cai Yudong 已提交
2000
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value));
2001
    return ExecCallBacks(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value);
Y
yudong.cai 已提交
2002 2003 2004
}

Status
S
starlord 已提交
2005
Config::SetEngineConfigOmpThreadNum(const std::string& value) {
C
Cai Yudong 已提交
2006 2007
    CONFIG_CHECK(CheckEngineConfigOmpThreadNum(value));
    return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, value);
Y
yudong.cai 已提交
2008 2009
}

C
Cai Yudong 已提交
2010 2011 2012 2013 2014 2015
Status
Config::SetEngineConfigUseAVX512(const std::string& value) {
    CONFIG_CHECK(CheckEngineConfigUseAVX512(value));
    return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_AVX512, value);
}

2016 2017 2018 2019 2020 2021 2022
/* 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 已提交
2023 2024 2025 2026 2027 2028 2029 2030 2031 2032
/* 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));
2033
    return SetConfigValueInMem(CONFIG_WAL, CONFIG_WAL_RECOVERY_ERROR_IGNORE, value);
J
Jin Hai 已提交
2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047
}

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 已提交
2048
#ifdef MILVUS_GPU_VERSION
W
wxyu 已提交
2049
Status
2050
Config::SetEngineConfigGpuSearchThreshold(const std::string& value) {
C
Cai Yudong 已提交
2051
    CONFIG_CHECK(CheckEngineConfigGpuSearchThreshold(value));
C
Cai Yudong 已提交
2052
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value));
2053
    return ExecCallBacks(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value);
W
wxyu 已提交
2054
}
C
Cai Yudong 已提交
2055
#endif
W
wxyu 已提交
2056

C
Cai Yudong 已提交
2057 2058
/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
S
shengjh 已提交
2059

Y
yudong.cai 已提交
2060
Status
2061
Config::SetGpuResourceConfigEnable(const std::string& value) {
C
Cai Yudong 已提交
2062
    CONFIG_CHECK(CheckGpuResourceConfigEnable(value));
C
Cai Yudong 已提交
2063
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value));
2064
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value);
Z
Zhiru Zhu 已提交
2065 2066 2067
}

Status
Y
yudong.cai 已提交
2068
Config::SetGpuResourceConfigCacheCapacity(const std::string& value) {
C
Cai Yudong 已提交
2069
    CONFIG_CHECK(CheckGpuResourceConfigCacheCapacity(value));
C
Cai Yudong 已提交
2070
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value));
2071
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value);
Y
yudong.cai 已提交
2072
}
Z
Zhiru Zhu 已提交
2073

Y
yudong.cai 已提交
2074 2075
Status
Config::SetGpuResourceConfigCacheThreshold(const std::string& value) {
C
Cai Yudong 已提交
2076 2077
    CONFIG_CHECK(CheckGpuResourceConfigCacheThreshold(value));
    return SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD, value);
Y
yudong.cai 已提交
2078 2079
}

2080
Status
Y
yudong.cai 已提交
2081
Config::SetGpuResourceConfigSearchResources(const std::string& value) {
2082
    std::vector<std::string> res_vec;
Y
yudong.cai 已提交
2083
    server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
C
Cai Yudong 已提交
2084
    CONFIG_CHECK(CheckGpuResourceConfigSearchResources(res_vec));
C
Cai Yudong 已提交
2085
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value));
2086
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value);
2087 2088
}

Y
yudong.cai 已提交
2089 2090 2091 2092
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 已提交
2093
    CONFIG_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec));
C
Cai Yudong 已提交
2094
    CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value));
2095
    return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value);
C
Cai Yudong 已提交
2096
}
S
shengjh 已提交
2097

G
groot 已提交
2098
#endif
2099

S
starlord 已提交
2100 2101
}  // namespace server
}  // namespace milvus