Config.h 12.4 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

G
groot 已提交
18 19
#pragma once

Y
yudong.cai 已提交
20
#include <mutex>
S
starlord 已提交
21
#include <string>
Y
yudong.cai 已提交
22
#include <unordered_map>
S
starlord 已提交
23
#include <vector>
S
starlord 已提交
24

G
groot 已提交
25
#include "config/ConfigNode.h"
S
starlord 已提交
26
#include "utils/Status.h"
G
groot 已提交
27

J
jinhai 已提交
28
namespace milvus {
G
groot 已提交
29 30
namespace server {

C
Cai Yudong 已提交
31
static const char* CONFIG_NODE_DELIMITER = ".";
32 33
static const char* CONFIG_VERSION = "version";

34
/* server config */
S
starlord 已提交
35 36 37 38 39 40 41 42 43
static const char* CONFIG_SERVER = "server_config";
static const char* CONFIG_SERVER_ADDRESS = "address";
static const char* CONFIG_SERVER_ADDRESS_DEFAULT = "127.0.0.1";
static const char* CONFIG_SERVER_PORT = "port";
static const char* CONFIG_SERVER_PORT_DEFAULT = "19530";
static const char* CONFIG_SERVER_DEPLOY_MODE = "deploy_mode";
static const char* CONFIG_SERVER_DEPLOY_MODE_DEFAULT = "single";
static const char* CONFIG_SERVER_TIME_ZONE = "time_zone";
static const char* CONFIG_SERVER_TIME_ZONE_DEFAULT = "UTC+8";
G
groot 已提交
44

45
/* db config */
S
starlord 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58
static const char* CONFIG_DB = "db_config";
static const char* CONFIG_DB_PRIMARY_PATH = "primary_path";
static const char* CONFIG_DB_PRIMARY_PATH_DEFAULT = "/tmp/milvus";
static const char* CONFIG_DB_SECONDARY_PATH = "secondary_path";
static const char* CONFIG_DB_SECONDARY_PATH_DEFAULT = "";
static const char* CONFIG_DB_BACKEND_URL = "backend_url";
static const char* CONFIG_DB_BACKEND_URL_DEFAULT = "sqlite://:@:/";
static const char* CONFIG_DB_ARCHIVE_DISK_THRESHOLD = "archive_disk_threshold";
static const char* CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT = "0";
static const char* CONFIG_DB_ARCHIVE_DAYS_THRESHOLD = "archive_days_threshold";
static const char* CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT = "0";
static const char* CONFIG_DB_INSERT_BUFFER_SIZE = "insert_buffer_size";
static const char* CONFIG_DB_INSERT_BUFFER_SIZE_DEFAULT = "4";
S
starlord 已提交
59
static const char* CONFIG_DB_PRELOAD_TABLE = "preload_table";
C
Cai Yudong 已提交
60
static const char* CONFIG_DB_PRELOAD_TABLE_DEFAULT = "";
G
groot 已提交
61

62
/* cache config */
S
starlord 已提交
63 64 65
static const char* CONFIG_CACHE = "cache_config";
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY = "cpu_cache_capacity";
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT = "16";
Y
yudong.cai 已提交
66
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD = "cpu_cache_threshold";
S
starlord 已提交
67 68 69
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT = "0.85";
static const char* CONFIG_CACHE_CACHE_INSERT_DATA = "cache_insert_data";
static const char* CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT = "false";
70 71

/* metric config */
S
starlord 已提交
72 73 74 75 76 77 78 79
static const char* CONFIG_METRIC = "metric_config";
static const char* CONFIG_METRIC_ENABLE_MONITOR = "enable_monitor";
static const char* CONFIG_METRIC_ENABLE_MONITOR_DEFAULT = "false";
static const char* CONFIG_METRIC_COLLECTOR = "collector";
static const char* CONFIG_METRIC_COLLECTOR_DEFAULT = "prometheus";
static const char* CONFIG_METRIC_PROMETHEUS = "prometheus_config";
static const char* CONFIG_METRIC_PROMETHEUS_PORT = "port";
static const char* CONFIG_METRIC_PROMETHEUS_PORT_DEFAULT = "8080";
Y
yu yunfeng 已提交
80

81
/* engine config */
S
starlord 已提交
82 83 84 85 86
static const char* CONFIG_ENGINE = "engine_config";
static const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD = "use_blas_threshold";
static const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT = "20";
static const char* CONFIG_ENGINE_OMP_THREAD_NUM = "omp_thread_num";
static const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT = "0";
87 88
static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD = "gpu_search_threshold";
static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT = "1000";
Y
yu yunfeng 已提交
89

Y
yudong.cai 已提交
90 91
/* gpu resource config */
static const char* CONFIG_GPU_RESOURCE = "gpu_resource_config";
92
static const char* CONFIG_GPU_RESOURCE_ENABLE = "enable";
Y
yudong.cai 已提交
93
#ifdef MILVUS_GPU_VERSION
94
static const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "true";
Y
youny626 已提交
95
#else
Y
yudong.cai 已提交
96
static const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "false";
Y
youny626 已提交
97
#endif
Y
yudong.cai 已提交
98 99 100 101 102 103 104 105 106
static const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY = "cache_capacity";
static const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT = "4";
static const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD = "cache_threshold";
static const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT = "0.85";
static const char* CONFIG_GPU_RESOURCE_DELIMITER = ",";
static const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES = "search_resources";
static const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT = "gpu0";
static const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES = "build_index_resources";
static const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT = "gpu0";
107

Z
Zhiru Zhu 已提交
108 109 110 111 112
// TODO:
/* tracing config */
static const char* CONFIG_TRACING = "tracing_config";
static const char* CONFIG_TRACING_JSON_CONFIG_PATH = "json_config_path";

113
class Config {
G
groot 已提交
114
 public:
S
starlord 已提交
115 116 117 118 119 120 121 122 123 124
    static Config&
    GetInstance();
    Status
    LoadConfigFile(const std::string& filename);
    Status
    ValidateConfig();
    Status
    ResetDefaultConfig();
    void
    PrintAll();
C
Cai Yudong 已提交
125 126
    Status
    HandleConfigCli(std::string& result, const std::string& cmd);
G
groot 已提交
127

Y
yudong.cai 已提交
128
 private:
129 130
    ConfigNode&
    GetConfigRoot();
S
starlord 已提交
131 132
    ConfigNode&
    GetConfigNode(const std::string& name);
C
Cai Yudong 已提交
133 134
    bool
    ConfigNodeValid(const std::string& parent_key, const std::string& child_key);
S
starlord 已提交
135 136
    Status
    GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value);
C
Cai Yudong 已提交
137
    Status
S
starlord 已提交
138 139 140
    SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value);
    void
    PrintConfigSection(const std::string& config_node_name);
C
Cai Yudong 已提交
141 142 143 144
    Status
    GetConfigCli(const std::string& parent_key, const std::string& child_key, std::string& value);
    Status
    SetConfigCli(const std::string& parent_key, const std::string& child_key, const std::string& value);
Y
yudong.cai 已提交
145 146

    ///////////////////////////////////////////////////////////////////////////
147 148 149
    Status
    CheckConfigVersion(const std::string& value);

Y
yudong.cai 已提交
150
    /* server config */
S
starlord 已提交
151 152 153 154 155 156 157 158
    Status
    CheckServerConfigAddress(const std::string& value);
    Status
    CheckServerConfigPort(const std::string& value);
    Status
    CheckServerConfigDeployMode(const std::string& value);
    Status
    CheckServerConfigTimeZone(const std::string& value);
Y
yudong.cai 已提交
159 160

    /* db config */
S
starlord 已提交
161 162 163 164 165 166 167 168 169 170 171 172
    Status
    CheckDBConfigPrimaryPath(const std::string& value);
    Status
    CheckDBConfigSecondaryPath(const std::string& value);
    Status
    CheckDBConfigBackendUrl(const std::string& value);
    Status
    CheckDBConfigArchiveDiskThreshold(const std::string& value);
    Status
    CheckDBConfigArchiveDaysThreshold(const std::string& value);
    Status
    CheckDBConfigInsertBufferSize(const std::string& value);
Y
yudong.cai 已提交
173 174

    /* metric config */
S
starlord 已提交
175 176 177 178 179 180
    Status
    CheckMetricConfigEnableMonitor(const std::string& value);
    Status
    CheckMetricConfigCollector(const std::string& value);
    Status
    CheckMetricConfigPrometheusPort(const std::string& value);
Y
yudong.cai 已提交
181 182

    /* cache config */
S
starlord 已提交
183 184 185 186 187 188
    Status
    CheckCacheConfigCpuCacheCapacity(const std::string& value);
    Status
    CheckCacheConfigCpuCacheThreshold(const std::string& value);
    Status
    CheckCacheConfigCacheInsertData(const std::string& value);
Y
yudong.cai 已提交
189 190

    /* engine config */
S
starlord 已提交
191 192 193 194
    Status
    CheckEngineConfigUseBlasThreshold(const std::string& value);
    Status
    CheckEngineConfigOmpThreadNum(const std::string& value);
Y
yudong.cai 已提交
195

G
groot 已提交
196
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
197
    Status
G
groot 已提交
198
    CheckEngineConfigGpuSearchThreshold(const std::string& value);
G
groot 已提交
199 200

    /* gpu resource config */
G
groot 已提交
201
    Status
202
    CheckGpuResourceConfigEnable(const std::string& value);
Y
yudong.cai 已提交
203 204
    Status
    CheckGpuResourceConfigCacheCapacity(const std::string& value);
S
starlord 已提交
205
    Status
Y
yudong.cai 已提交
206
    CheckGpuResourceConfigCacheThreshold(const std::string& value);
S
starlord 已提交
207
    Status
Y
yudong.cai 已提交
208
    CheckGpuResourceConfigSearchResources(const std::vector<std::string>& value);
209
    Status
Y
yudong.cai 已提交
210
    CheckGpuResourceConfigBuildIndexResources(const std::vector<std::string>& value);
G
groot 已提交
211
#endif
Y
yudong.cai 已提交
212

S
starlord 已提交
213
    std::string
S
starlord 已提交
214
    GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value = "");
Z
Zhiru Zhu 已提交
215 216 217
    std::string
    GetConfigSequenceStr(const std::string& parent_key, const std::string& child_key, const std::string& delim = ",",
                         const std::string& default_value = "");
218 219
    Status
    GetConfigVersion(std::string& value);
220

Y
yudong.cai 已提交
221
 public:
222
    /* server config */
S
starlord 已提交
223 224 225 226 227 228 229 230
    Status
    GetServerConfigAddress(std::string& value);
    Status
    GetServerConfigPort(std::string& value);
    Status
    GetServerConfigDeployMode(std::string& value);
    Status
    GetServerConfigTimeZone(std::string& value);
231 232

    /* db config */
S
starlord 已提交
233 234 235 236 237 238 239
    Status
    GetDBConfigPrimaryPath(std::string& value);
    Status
    GetDBConfigSecondaryPath(std::string& value);
    Status
    GetDBConfigBackendUrl(std::string& value);
    Status
Y
yudong.cai 已提交
240
    GetDBConfigArchiveDiskThreshold(int64_t& value);
S
starlord 已提交
241
    Status
Y
yudong.cai 已提交
242
    GetDBConfigArchiveDaysThreshold(int64_t& value);
S
starlord 已提交
243
    Status
Y
yudong.cai 已提交
244
    GetDBConfigInsertBufferSize(int64_t& value);
S
starlord 已提交
245
    Status
S
starlord 已提交
246
    GetDBConfigPreloadTable(std::string& value);
247 248

    /* metric config */
S
starlord 已提交
249 250 251 252 253 254
    Status
    GetMetricConfigEnableMonitor(bool& value);
    Status
    GetMetricConfigCollector(std::string& value);
    Status
    GetMetricConfigPrometheusPort(std::string& value);
255 256

    /* cache config */
S
starlord 已提交
257
    Status
W
wxyu 已提交
258
    GetCacheConfigCpuCacheCapacity(int64_t& value);
S
starlord 已提交
259 260 261 262
    Status
    GetCacheConfigCpuCacheThreshold(float& value);
    Status
    GetCacheConfigCacheInsertData(bool& value);
263 264

    /* engine config */
S
starlord 已提交
265
    Status
Y
yudong.cai 已提交
266
    GetEngineConfigUseBlasThreshold(int64_t& value);
S
starlord 已提交
267
    Status
Y
yudong.cai 已提交
268
    GetEngineConfigOmpThreadNum(int64_t& value);
G
groot 已提交
269 270

#ifdef MILVUS_GPU_VERSION
W
wxyu 已提交
271
    Status
Y
yudong.cai 已提交
272
    GetEngineConfigGpuSearchThreshold(int64_t& value);
273

Y
yudong.cai 已提交
274 275
    /* gpu resource config */
    Status
276
    GetGpuResourceConfigEnable(bool& value);
Y
yudong.cai 已提交
277 278
    Status
    GetGpuResourceConfigCacheCapacity(int64_t& value);
S
starlord 已提交
279
    Status
Y
yudong.cai 已提交
280
    GetGpuResourceConfigCacheThreshold(float& value);
S
starlord 已提交
281
    Status
Y
yudong.cai 已提交
282
    GetGpuResourceConfigSearchResources(std::vector<int64_t>& value);
283
    Status
Y
yudong.cai 已提交
284
    GetGpuResourceConfigBuildIndexResources(std::vector<int64_t>& value);
G
groot 已提交
285
#endif
Y
yudong.cai 已提交
286

Z
Zhiru Zhu 已提交
287 288 289 290
    /* tracing config */
    Status
    GetTracingConfigJsonConfigPath(std::string& value);

Y
yudong.cai 已提交
291 292
 public:
    /* server config */
S
starlord 已提交
293 294 295 296 297 298 299 300
    Status
    SetServerConfigAddress(const std::string& value);
    Status
    SetServerConfigPort(const std::string& value);
    Status
    SetServerConfigDeployMode(const std::string& value);
    Status
    SetServerConfigTimeZone(const std::string& value);
Y
yudong.cai 已提交
301 302

    /* db config */
S
starlord 已提交
303 304 305 306 307 308 309 310 311 312 313 314
    Status
    SetDBConfigPrimaryPath(const std::string& value);
    Status
    SetDBConfigSecondaryPath(const std::string& value);
    Status
    SetDBConfigBackendUrl(const std::string& value);
    Status
    SetDBConfigArchiveDiskThreshold(const std::string& value);
    Status
    SetDBConfigArchiveDaysThreshold(const std::string& value);
    Status
    SetDBConfigInsertBufferSize(const std::string& value);
Y
yudong.cai 已提交
315 316

    /* metric config */
S
starlord 已提交
317 318 319 320 321 322
    Status
    SetMetricConfigEnableMonitor(const std::string& value);
    Status
    SetMetricConfigCollector(const std::string& value);
    Status
    SetMetricConfigPrometheusPort(const std::string& value);
Y
yudong.cai 已提交
323 324

    /* cache config */
S
starlord 已提交
325 326 327 328 329 330
    Status
    SetCacheConfigCpuCacheCapacity(const std::string& value);
    Status
    SetCacheConfigCpuCacheThreshold(const std::string& value);
    Status
    SetCacheConfigCacheInsertData(const std::string& value);
Y
yudong.cai 已提交
331 332

    /* engine config */
S
starlord 已提交
333 334 335 336
    Status
    SetEngineConfigUseBlasThreshold(const std::string& value);
    Status
    SetEngineConfigOmpThreadNum(const std::string& value);
Y
yudong.cai 已提交
337

G
groot 已提交
338
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
339
    Status
G
groot 已提交
340
    SetEngineConfigGpuSearchThreshold(const std::string& value);
G
groot 已提交
341 342

    /* gpu resource config */
G
groot 已提交
343
    Status
344
    SetGpuResourceConfigEnable(const std::string& value);
Y
yudong.cai 已提交
345 346
    Status
    SetGpuResourceConfigCacheCapacity(const std::string& value);
S
starlord 已提交
347
    Status
Y
yudong.cai 已提交
348
    SetGpuResourceConfigCacheThreshold(const std::string& value);
349
    Status
Y
yudong.cai 已提交
350
    SetGpuResourceConfigSearchResources(const std::string& value);
Z
Zhiru Zhu 已提交
351
    Status
Y
yudong.cai 已提交
352
    SetGpuResourceConfigBuildIndexResources(const std::string& value);
G
groot 已提交
353
#endif
Y
yudong.cai 已提交
354

Y
yudong.cai 已提交
355 356 357
 private:
    std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_;
    std::mutex mutex_;
G
groot 已提交
358 359
};

S
starlord 已提交
360 361
}  // namespace server
}  // namespace milvus