From 504a9e30abdad3cf85c4a37de81b9ac77fd18b58 Mon Sep 17 00:00:00 2001 From: BossZou <40255591+BossZou@users.noreply.github.com> Date: Thu, 19 Mar 2020 10:17:53 +0800 Subject: [PATCH] Optimize config cpu_cache_capacity / gpu_cache_capacity setter (#1572) (#1629) * add gpu cache config handler Signed-off-by: Yhz * remove cpu/gpu cache mgr from Config class by using cache config handler (fix #1572) Signed-off-by: Yhz * remove 0.8.0 from config version map Signed-off-by: Yhz * clean config header reference Signed-off-by: Yhz * fix bug in web readme Signed-off-by: Yhz * reduce gpu config handler to gpu resources handler Signed-off-by: Yhz * add engine config Signed-off-by: Yhz * modify handler hook(fix #1572) Signed-off-by: Yhz * update changlog Signed-off-by: Yhz * initalize value in handler by config default Signed-off-by: Yhz * code style format Signed-off-by: Yhz * fix compile error in release mode Signed-off-by: Yhz * resolve faiss blas threshold init in DBWrapper Signed-off-by: Yhz * modify cache header Signed-off-by: Yhz * remove comments Signed-off-by: Yhz * order headers Signed-off-by: Yhz * convert gpu res config to lower case Signed-off-by: Yhz * CI retry Signed-off-by: Yhz * adjust header order in cpu cache mar file Signed-off-by: Yhz * improve config test case Signed-off-by: Yhz * code format Signed-off-by: Yhz --- CHANGELOG.md | 1 + core/cmake/ThirdPartyPackages.cmake | 2 +- core/src/cache/CpuCacheMgr.cpp | 16 +- core/src/cache/CpuCacheMgr.h | 13 +- core/src/cache/GpuCacheMgr.cpp | 20 ++- core/src/cache/GpuCacheMgr.h | 13 +- core/src/config/Config.cpp | 20 +-- .../src/config/handler/CacheConfigHandler.cpp | 63 +++---- core/src/config/handler/CacheConfigHandler.h | 15 +- core/src/config/handler/ConfigHandler.h | 4 + .../config/handler/EngineConfigHandler.cpp | 52 ++++++ ...uConfigHandler.h => EngineConfigHandler.h} | 27 ++- .../config/handler/GpuBuildConfigHandler.cpp | 60 ------- .../config/handler/GpuBuildConfigHandler.h | 44 ----- core/src/config/handler/GpuConfigHandler.cpp | 58 ------ .../handler/GpuResourceConfigHandler.cpp | 166 ++++++++++++++++++ .../config/handler/GpuResourceConfigHandler.h | 94 ++++++++++ .../config/handler/GpuSearchConfigHandler.cpp | 99 ----------- .../config/handler/GpuSearchConfigHandler.h | 55 ------ core/src/db/DBImpl.cpp | 8 +- core/src/db/DBImpl.h | 6 +- core/src/db/insert/MemTable.cpp | 7 +- core/src/db/insert/MemTableFile.cpp | 4 - core/src/db/insert/MemTableFile.h | 2 +- core/src/scheduler/job/BuildIndexJob.cpp | 4 - core/src/scheduler/job/BuildIndexJob.h | 2 +- .../scheduler/optimizer/BuildIndexPass.cpp | 2 +- core/src/scheduler/optimizer/BuildIndexPass.h | 4 +- .../src/scheduler/optimizer/FaissFlatPass.cpp | 2 +- core/src/scheduler/optimizer/FaissFlatPass.h | 4 +- .../scheduler/optimizer/FaissIVFFlatPass.cpp | 2 +- .../scheduler/optimizer/FaissIVFFlatPass.h | 4 +- .../scheduler/optimizer/FaissIVFPQPass.cpp | 2 +- core/src/scheduler/optimizer/FaissIVFPQPass.h | 4 +- .../scheduler/optimizer/FaissIVFSQ8HPass.cpp | 2 +- .../scheduler/optimizer/FaissIVFSQ8HPass.h | 4 +- .../scheduler/optimizer/FaissIVFSQ8Pass.cpp | 2 +- .../src/scheduler/optimizer/FaissIVFSQ8Pass.h | 4 +- core/src/server/DBWrapper.cpp | 18 +- core/src/server/web_impl/README.md | 2 +- .../web_impl/handler/WebRequestHandler.cpp | 4 - .../web_impl/handler/WebRequestHandler.h | 12 -- core/unittest/server/test_config.cpp | 120 ++++++++----- core/unittest/server/test_web.cpp | 42 +++-- 44 files changed, 557 insertions(+), 532 deletions(-) create mode 100644 core/src/config/handler/EngineConfigHandler.cpp rename core/src/config/handler/{GpuConfigHandler.h => EngineConfigHandler.h} (70%) delete mode 100644 core/src/config/handler/GpuBuildConfigHandler.cpp delete mode 100644 core/src/config/handler/GpuBuildConfigHandler.h delete mode 100644 core/src/config/handler/GpuConfigHandler.cpp create mode 100644 core/src/config/handler/GpuResourceConfigHandler.cpp create mode 100644 core/src/config/handler/GpuResourceConfigHandler.h delete mode 100644 core/src/config/handler/GpuSearchConfigHandler.cpp delete mode 100644 core/src/config/handler/GpuSearchConfigHandler.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 77cf2b37c6..d54541170a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Please mark all change in change log and use the issue from GitHub - \#1546 Move Config.cpp to config directory - \#1547 Rename storage/file to storage/disk and rename classes - \#1548 Move store/Directory to storage/Operation and add FSHandler +- \#1572 optimize config cpu/gpu cache_capacity setter - \#1619 Improve compact performance - \#1649 Fix Milvus crash on old CPU - \#1653 IndexFlat (SSE) and IndexBinaryFlat performance improvement for small NQ diff --git a/core/cmake/ThirdPartyPackages.cmake b/core/cmake/ThirdPartyPackages.cmake index b005463eca..25d7afa66f 100644 --- a/core/cmake/ThirdPartyPackages.cmake +++ b/core/cmake/ThirdPartyPackages.cmake @@ -331,7 +331,7 @@ endif () if (DEFINED ENV{MILVUS_OATPP_URL}) set(MILVUS_OATPP_URL "$ENV{MILVUS_OATPP_URL}") else () -# set(OATPP_SOURCE_URL "https://github.com/oatpp/oatpp/archive/${OATPP_VERSION}.tar.gz") + # set(OATPP_SOURCE_URL "https://github.com/oatpp/oatpp/archive/${OATPP_VERSION}.tar.gz") set(OATPP_SOURCE_URL "https://github.com/BossZou/oatpp/archive/master.zip") endif () diff --git a/core/src/cache/CpuCacheMgr.cpp b/core/src/cache/CpuCacheMgr.cpp index 0c8b0477b7..7e2233d427 100644 --- a/core/src/cache/CpuCacheMgr.cpp +++ b/core/src/cache/CpuCacheMgr.cpp @@ -10,11 +10,13 @@ // or implied. See the License for the specific language governing permissions and limitations under the License. #include "cache/CpuCacheMgr.h" -#include "config/Config.h" -#include "utils/Log.h" + +#include #include -#include + +#include "config/Config.h" +#include "utils/Log.h" namespace milvus { namespace cache { @@ -35,6 +37,9 @@ CpuCacheMgr::CpuCacheMgr() { float cpu_cache_threshold; config.GetCacheConfigCpuCacheThreshold(cpu_cache_threshold); cache_->set_freemem_percent(cpu_cache_threshold); + + SetIdentity("CpuCacheMgr"); + AddCpuCacheCapacityListener(); } CpuCacheMgr* @@ -49,5 +54,10 @@ CpuCacheMgr::GetIndex(const std::string& key) { return obj; } +void +CpuCacheMgr::OnCpuCacheCapacityChanged(int64_t value) { + SetCapacity(value * unit); +} + } // namespace cache } // namespace milvus diff --git a/core/src/cache/CpuCacheMgr.h b/core/src/cache/CpuCacheMgr.h index 5d9b247817..95bb80ae96 100644 --- a/core/src/cache/CpuCacheMgr.h +++ b/core/src/cache/CpuCacheMgr.h @@ -11,16 +11,17 @@ #pragma once -#include "CacheMgr.h" -#include "DataObj.h" - #include #include +#include "cache/CacheMgr.h" +#include "cache/DataObj.h" +#include "config/handler/CacheConfigHandler.h" + namespace milvus { namespace cache { -class CpuCacheMgr : public CacheMgr { +class CpuCacheMgr : public CacheMgr, public server::CacheConfigHandler { private: CpuCacheMgr(); @@ -31,6 +32,10 @@ class CpuCacheMgr : public CacheMgr { DataObjPtr GetIndex(const std::string& key); + + protected: + void + OnCpuCacheCapacityChanged(int64_t value) override; }; } // namespace cache diff --git a/core/src/cache/GpuCacheMgr.cpp b/core/src/cache/GpuCacheMgr.cpp index fc3e1269ab..c3b3b0b8df 100644 --- a/core/src/cache/GpuCacheMgr.cpp +++ b/core/src/cache/GpuCacheMgr.cpp @@ -32,15 +32,6 @@ GpuCacheMgr::GpuCacheMgr() { // All config values have been checked in Config::ValidateConfig() server::Config& config = server::Config::GetInstance(); - config.GenUniqueIdentityID("GpuCacheMar", identity_); - - config.GetGpuResourceConfigEnable(gpu_enable_); - server::ConfigCallBackF lambda = [this](const std::string& value) -> Status { - auto& config = server::Config::GetInstance(); - return config.GetGpuResourceConfigEnable(this->gpu_enable_); - }; - config.RegisterCallBack(server::CONFIG_GPU_RESOURCE, server::CONFIG_GPU_RESOURCE_ENABLE, identity_, lambda); - int64_t gpu_cache_cap; config.GetGpuResourceConfigCacheCapacity(gpu_cache_cap); int64_t cap = gpu_cache_cap * G_BYTE; @@ -49,6 +40,10 @@ GpuCacheMgr::GpuCacheMgr() { float gpu_mem_threshold; config.GetGpuResourceConfigCacheThreshold(gpu_mem_threshold); cache_->set_freemem_percent(gpu_mem_threshold); + + SetIdentity("GpuCacheMgr"); + AddGpuEnableListener(); + AddGpuCacheCapacityListener(); } GpuCacheMgr::~GpuCacheMgr() { @@ -83,6 +78,13 @@ GpuCacheMgr::InsertItem(const std::string& key, const milvus::cache::DataObjPtr& } } +void +GpuCacheMgr::OnGpuCacheCapacityChanged(int64_t capacity) { + for (auto& iter : instance_) { + iter.second->SetCapacity(capacity * G_BYTE); + } +} + #endif } // namespace cache diff --git a/core/src/cache/GpuCacheMgr.h b/core/src/cache/GpuCacheMgr.h index b2508afd56..6afad88438 100644 --- a/core/src/cache/GpuCacheMgr.h +++ b/core/src/cache/GpuCacheMgr.h @@ -9,13 +9,14 @@ // 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. -#include "CacheMgr.h" -#include "DataObj.h" - #include #include #include +#include "cache/CacheMgr.h" +#include "cache/DataObj.h" +#include "config/handler/GpuResourceConfigHandler.h" + namespace milvus { namespace cache { @@ -23,7 +24,7 @@ namespace cache { class GpuCacheMgr; using GpuCacheMgrPtr = std::shared_ptr; -class GpuCacheMgr : public CacheMgr { +class GpuCacheMgr : public CacheMgr, public server::GpuResourceConfigHandler { public: GpuCacheMgr(); @@ -38,6 +39,10 @@ class GpuCacheMgr : public CacheMgr { void InsertItem(const std::string& key, const DataObjPtr& data); + protected: + void + OnGpuCacheCapacityChanged(int64_t capacity) override; + private: bool gpu_enable_ = true; std::string identity_; diff --git a/core/src/config/Config.cpp b/core/src/config/Config.cpp index dc227d3d71..cddc8a1203 100644 --- a/core/src/config/Config.cpp +++ b/core/src/config/Config.cpp @@ -9,14 +9,12 @@ // 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. -#include -#include -#include #include #include #include #include +#include #include #include #include @@ -25,11 +23,14 @@ #include #include +#include + #include "config/Config.h" #include "config/YamlConfigMgr.h" #include "server/DBWrapper.h" #include "thirdparty/nlohmann/json.hpp" #include "utils/CommonUtil.h" +#include "utils/Log.h" #include "utils/StringHelpFunctions.h" #include "utils/ValidationUtil.h" @@ -562,6 +563,7 @@ Config::UpdateFileConfigFromMem(const std::string& parent_key, const std::string std::vector vec; StringHelpFunctions::SplitStringByDelimeter(value, ",", vec); for (auto& s : vec) { + std::transform(s.begin(), s.end(), s.begin(), ::tolower); value_str += "\n - " + s; } } else { @@ -1947,8 +1949,7 @@ Status Config::SetCacheConfigCpuCacheCapacity(const std::string& value) { CONFIG_CHECK(CheckCacheConfigCpuCacheCapacity(value)); CONFIG_CHECK(SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value)); - cache::CpuCacheMgr::GetInstance()->SetCapacity(std::stol(value) << 30); - return Status::OK(); + return ExecCallBacks(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value); } Status @@ -2046,14 +2047,7 @@ Status Config::SetGpuResourceConfigCacheCapacity(const std::string& value) { CONFIG_CHECK(CheckGpuResourceConfigCacheCapacity(value)); CONFIG_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value)); - - int64_t cap = std::stol(value); - std::vector gpus; - GetGpuResourceConfigSearchResources(gpus); - for (auto& gpu_id : gpus) { - cache::GpuCacheMgr::GetInstance(gpu_id)->SetCapacity(cap << 30); - } - return Status::OK(); + return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value); } Status diff --git a/core/src/config/handler/CacheConfigHandler.cpp b/core/src/config/handler/CacheConfigHandler.cpp index f691110c11..6136017ef1 100644 --- a/core/src/config/handler/CacheConfigHandler.cpp +++ b/core/src/config/handler/CacheConfigHandler.cpp @@ -28,85 +28,68 @@ CacheConfigHandler::~CacheConfigHandler() { RemoveCacheInsertDataListener(); } -void -CacheConfigHandler::OnCpuCacheCapacityChanged(int64_t value) { - cpu_cache_capacity_ = value; -} - -void -CacheConfigHandler::OnInsertBufferSizeChanged(int64_t value) { - insert_buffer_size_ = value; -} - -void -CacheConfigHandler::OnCacheInsertDataChanged(bool value) { - cache_insert_data_ = value; -} - +//////////////////////////// Listener methods ////////////////////////////////// void CacheConfigHandler::AddCpuCacheCapacityListener() { - server::ConfigCallBackF lambda = [this](const std::string& value) -> Status { - server::Config& config = server::Config::GetInstance(); - int64_t capacity; - auto status = config.GetCacheConfigCpuCacheCapacity(capacity); + ConfigCallBackF lambda = [this](const std::string& value) -> Status { + auto& config = Config::GetInstance(); + auto status = config.GetCacheConfigCpuCacheCapacity(cpu_cache_capacity_); if (status.ok()) { - OnCpuCacheCapacityChanged(capacity); + OnCpuCacheCapacityChanged(cpu_cache_capacity_); } return status; }; - auto& config = server::Config::GetInstance(); - config.RegisterCallBack(server::CONFIG_CACHE, server::CONFIG_CACHE_CPU_CACHE_CAPACITY, identity_, lambda); + auto& config = Config::GetInstance(); + config.RegisterCallBack(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, identity_, lambda); } void CacheConfigHandler::AddInsertBufferSizeListener() { - server::ConfigCallBackF lambda = [this](const std::string& value) -> Status { - server::Config& config = server::Config::GetInstance(); - int64_t size; - auto status = config.GetCacheConfigInsertBufferSize(size); + ConfigCallBackF lambda = [this](const std::string& value) -> Status { + auto& config = Config::GetInstance(); + auto status = config.GetCacheConfigInsertBufferSize(insert_buffer_size_); if (status.ok()) { - OnInsertBufferSizeChanged(size); + OnInsertBufferSizeChanged(insert_buffer_size_); } return status; }; - auto& config = server::Config::GetInstance(); - config.RegisterCallBack(server::CONFIG_CACHE, server::CONFIG_CACHE_INSERT_BUFFER_SIZE, identity_, lambda); + auto& config = Config::GetInstance(); + config.RegisterCallBack(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, identity_, lambda); } void CacheConfigHandler::AddCacheInsertDataListener() { server::ConfigCallBackF lambda = [this](const std::string& value) -> Status { - auto& config = server::Config::GetInstance(); - bool ok; - auto status = config.GetCacheConfigCacheInsertData(ok); + auto& config = Config::GetInstance(); + auto status = config.GetCacheConfigCacheInsertData(cache_insert_data_); if (status.ok()) { - OnCacheInsertDataChanged(ok); + OnCacheInsertDataChanged(cache_insert_data_); } return status; }; - auto& config = server::Config::GetInstance(); - config.RegisterCallBack(server::CONFIG_CACHE, server::CONFIG_CACHE_CACHE_INSERT_DATA, identity_, lambda); + auto& config = Config::GetInstance(); + config.RegisterCallBack(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, identity_, lambda); } void CacheConfigHandler::RemoveCpuCacheCapacityListener() { - auto& config = server::Config::GetInstance(); - config.CancelCallBack(server::CONFIG_CACHE, server::CONFIG_CACHE_CPU_CACHE_CAPACITY, identity_); + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, identity_); } void CacheConfigHandler::RemoveInsertBufferSizeListener() { - auto& config = server::Config::GetInstance(); - config.CancelCallBack(server::CONFIG_CACHE, server::CONFIG_CACHE_INSERT_BUFFER_SIZE, identity_); + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_CACHE, CONFIG_CACHE_INSERT_BUFFER_SIZE, identity_); } void CacheConfigHandler::RemoveCacheInsertDataListener() { - auto& config = server::Config::GetInstance(); + auto& config = Config::GetInstance(); config.CancelCallBack(server::CONFIG_CACHE, server::CONFIG_CACHE_CACHE_INSERT_DATA, identity_); } } // namespace server diff --git a/core/src/config/handler/CacheConfigHandler.h b/core/src/config/handler/CacheConfigHandler.h index 187b66d03c..0ddab20f79 100644 --- a/core/src/config/handler/CacheConfigHandler.h +++ b/core/src/config/handler/CacheConfigHandler.h @@ -20,17 +20,20 @@ namespace server { class CacheConfigHandler : virtual public ConfigHandler { public: CacheConfigHandler(); - ~CacheConfigHandler(); + virtual ~CacheConfigHandler(); protected: virtual void - OnCpuCacheCapacityChanged(int64_t value); + OnCpuCacheCapacityChanged(int64_t value) { + } virtual void - OnInsertBufferSizeChanged(int64_t value); + OnInsertBufferSizeChanged(int64_t value) { + } virtual void - OnCacheInsertDataChanged(bool value); + OnCacheInsertDataChanged(bool value) { + } protected: void @@ -52,8 +55,8 @@ class CacheConfigHandler : virtual public ConfigHandler { RemoveCacheInsertDataListener(); private: - int64_t cpu_cache_capacity_ = 4 /*GiB*/; - int64_t insert_buffer_size_ = 1 /*GiB*/; + int64_t cpu_cache_capacity_ = std::stoll(CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT) /*GiB*/; + int64_t insert_buffer_size_ = std::stoll(CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT) /*GiB*/; bool cache_insert_data_ = false; }; diff --git a/core/src/config/handler/ConfigHandler.h b/core/src/config/handler/ConfigHandler.h index 418a57d044..aa7862b9c5 100644 --- a/core/src/config/handler/ConfigHandler.h +++ b/core/src/config/handler/ConfigHandler.h @@ -20,6 +20,10 @@ namespace milvus { namespace server { class ConfigHandler { + public: + ConfigHandler() = default; + virtual ~ConfigHandler() = default; + protected: void SetIdentity(const std::string& identity) { diff --git a/core/src/config/handler/EngineConfigHandler.cpp b/core/src/config/handler/EngineConfigHandler.cpp new file mode 100644 index 0000000000..51b08e17ba --- /dev/null +++ b/core/src/config/handler/EngineConfigHandler.cpp @@ -0,0 +1,52 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// 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 +// +// 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. + +#include "config/handler/EngineConfigHandler.h" + +#include + +namespace milvus { +namespace server { + +EngineConfigHandler::EngineConfigHandler() { + auto& config = Config::GetInstance(); + config.GetEngineConfigUseBlasThreshold(use_blas_threshold_); +} + +EngineConfigHandler::~EngineConfigHandler() { + RemoveUseBlasThresholdListener(); +} + +//////////////////////////// Listener methods ////////////////////////////////// +void +EngineConfigHandler::AddUseBlasThresholdListener() { + ConfigCallBackF lambda = [this](const std::string& value) -> Status { + auto& config = server::Config::GetInstance(); + auto status = config.GetEngineConfigUseBlasThreshold(use_blas_threshold_); + if (status.ok()) { + OnUseBlasThresholdChanged(use_blas_threshold_); + } + + return status; + }; + + auto& config = Config::GetInstance(); + config.RegisterCallBack(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, identity_, lambda); +} + +void +EngineConfigHandler::RemoveUseBlasThresholdListener() { + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, identity_); +} + +} // namespace server +} // namespace milvus diff --git a/core/src/config/handler/GpuConfigHandler.h b/core/src/config/handler/EngineConfigHandler.h similarity index 70% rename from core/src/config/handler/GpuConfigHandler.h rename to core/src/config/handler/EngineConfigHandler.h index 1b93cb28fc..ebc055c7c8 100644 --- a/core/src/config/handler/GpuConfigHandler.h +++ b/core/src/config/handler/EngineConfigHandler.h @@ -8,12 +8,8 @@ // 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. -#ifdef MILVUS_GPU_VERSION -#pragma once -#include -#include -#include +#pragma once #include "config/Config.h" #include "config/handler/ConfigHandler.h" @@ -21,27 +17,28 @@ namespace milvus { namespace server { -class GpuConfigHandler : virtual public ConfigHandler { +class EngineConfigHandler : virtual public ConfigHandler { public: - GpuConfigHandler(); + EngineConfigHandler(); - ~GpuConfigHandler(); + virtual ~EngineConfigHandler(); protected: virtual void - OnGpuEnableChanged(bool enable); + OnUseBlasThresholdChanged(int64_t threshold) { + } protected: void - AddGpuEnableListener(); - - void - RemoveGpuEnableListener(); + AddUseBlasThresholdListener(); protected: - bool gpu_enable_ = true; + void + RemoveUseBlasThresholdListener(); + + protected: + int64_t use_blas_threshold_ = std::stoll(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT); }; } // namespace server } // namespace milvus -#endif diff --git a/core/src/config/handler/GpuBuildConfigHandler.cpp b/core/src/config/handler/GpuBuildConfigHandler.cpp deleted file mode 100644 index a3e27a9694..0000000000 --- a/core/src/config/handler/GpuBuildConfigHandler.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2019-2020 Zilliz. All rights reserved. -// -// 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 -// -// 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. -#ifdef MILVUS_GPU_VERSION -#include "config/handler/GpuBuildConfigHandler.h" - -#include -#include - -namespace milvus { -namespace server { - -GpuBuildConfigHandler::GpuBuildConfigHandler() { - server::Config& config = server::Config::GetInstance(); - config.GetGpuResourceConfigBuildIndexResources(build_gpus_); -} - -GpuBuildConfigHandler::~GpuBuildConfigHandler() { - RemoveGpuBuildResListener(); -} - -//////////////////////////////////////////////////////////////// -void -GpuBuildConfigHandler::OnGpuBuildResChanged(const std::vector& gpus) { - build_gpus_ = gpus; -} - -void -GpuBuildConfigHandler::AddGpuBuildResListener() { - server::Config& config = server::Config::GetInstance(); - server::ConfigCallBackF lambda = [this](const std::string& value) -> Status { - server::Config& config = server::Config::GetInstance(); - std::vector gpu_ids; - auto status = config.GetGpuResourceConfigSearchResources(gpu_ids); - if (status.ok()) { - OnGpuBuildResChanged(gpu_ids); - } - - return status; - }; - config.RegisterCallBack(server::CONFIG_GPU_RESOURCE, server::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, identity_, - lambda); -} - -void -GpuBuildConfigHandler::RemoveGpuBuildResListener() { - auto& config = server::Config::GetInstance(); - config.CancelCallBack(server::CONFIG_GPU_RESOURCE, server::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, identity_); -} - -} // namespace server -} // namespace milvus -#endif diff --git a/core/src/config/handler/GpuBuildConfigHandler.h b/core/src/config/handler/GpuBuildConfigHandler.h deleted file mode 100644 index 00f610f5eb..0000000000 --- a/core/src/config/handler/GpuBuildConfigHandler.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2019-2020 Zilliz. All rights reserved. -// -// 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 -// -// 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. -#ifdef MILVUS_GPU_VERSION -#pragma once - -#include - -#include "config/handler/GpuConfigHandler.h" - -namespace milvus { -namespace server { - -class GpuBuildConfigHandler : virtual public GpuConfigHandler { - public: - GpuBuildConfigHandler(); - - ~GpuBuildConfigHandler(); - - public: - virtual void - OnGpuBuildResChanged(const std::vector& gpus); - - protected: - void - AddGpuBuildResListener(); - - void - RemoveGpuBuildResListener(); - - protected: - std::vector build_gpus_; -}; - -} // namespace server -} // namespace milvus -#endif diff --git a/core/src/config/handler/GpuConfigHandler.cpp b/core/src/config/handler/GpuConfigHandler.cpp deleted file mode 100644 index 46292ff686..0000000000 --- a/core/src/config/handler/GpuConfigHandler.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -// Copyright (C) 2019-2020 Zilliz. All rights reserved. -// -// 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 -// -// 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. -#ifdef MILVUS_GPU_VERSION -#include "config/handler/GpuConfigHandler.h" - -namespace milvus { -namespace server { - -GpuConfigHandler::GpuConfigHandler() { - server::Config& config = server::Config::GetInstance(); - config.GetGpuResourceConfigEnable(gpu_enable_); -} - -GpuConfigHandler::~GpuConfigHandler() { - RemoveGpuEnableListener(); -} - -////////////////////////////////////////////////////////////// -void -GpuConfigHandler::OnGpuEnableChanged(bool enable) { - gpu_enable_ = enable; -} - -void -GpuConfigHandler::AddGpuEnableListener() { - auto& config = server::Config::GetInstance(); - - server::ConfigCallBackF lambda = [this](const std::string& value) -> Status { - auto& config = server::Config::GetInstance(); - bool enable; - auto status = config.GetGpuResourceConfigEnable(enable); - if (status.ok()) { - OnGpuEnableChanged(enable); - } - - return status; - }; - config.RegisterCallBack(server::CONFIG_GPU_RESOURCE, server::CONFIG_GPU_RESOURCE_ENABLE, identity_, lambda); -} - -void -GpuConfigHandler::RemoveGpuEnableListener() { - server::Config& config = server::Config::GetInstance(); - config.CancelCallBack(server::CONFIG_GPU_RESOURCE, server::CONFIG_GPU_RESOURCE_ENABLE, identity_); -} - -} // namespace server -} // namespace milvus -#endif diff --git a/core/src/config/handler/GpuResourceConfigHandler.cpp b/core/src/config/handler/GpuResourceConfigHandler.cpp new file mode 100644 index 0000000000..ae844ab944 --- /dev/null +++ b/core/src/config/handler/GpuResourceConfigHandler.cpp @@ -0,0 +1,166 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// 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 +// +// 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. +#ifdef MILVUS_GPU_VERSION +#include "config/handler/GpuResourceConfigHandler.h" + +namespace milvus { +namespace server { + +GpuResourceConfigHandler::GpuResourceConfigHandler() { + auto& config = Config::GetInstance(); + config.GetGpuResourceConfigEnable(gpu_enable_); +} + +GpuResourceConfigHandler::~GpuResourceConfigHandler() { + RemoveGpuEnableListener(); + RemoveGpuCacheCapacityListener(); + RemoveGpuBuildResourcesListener(); + RemoveGpuSearchThresholdListener(); + RemoveGpuSearchResourcesListener(); +} + +//////////////////////////// Listener methods ////////////////////////////////// +void +GpuResourceConfigHandler::AddGpuEnableListener() { + auto& config = Config::GetInstance(); + + ConfigCallBackF lambda = [this](const std::string& value) -> Status { + auto& config = Config::GetInstance(); + auto status = config.GetGpuResourceConfigEnable(gpu_enable_); + if (status.ok()) { + OnGpuEnableChanged(gpu_enable_); + } + + return status; + }; + config.RegisterCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, identity_, lambda); +} + +void +GpuResourceConfigHandler::AddGpuCacheCapacityListener() { + ConfigCallBackF lambda = [this](const std::string& value) -> Status { + if (!gpu_enable_) { + std::string msg = + std::string("GPU resources is disable. Cannot set config ") + CONFIG_GPU_RESOURCE_CACHE_CAPACITY; + return Status(SERVER_UNEXPECTED_ERROR, msg); + } + + auto& config = Config::GetInstance(); + auto status = config.GetGpuResourceConfigCacheCapacity(gpu_cache_capacity_); + if (status.ok()) { + OnGpuCacheCapacityChanged(gpu_cache_capacity_); + } + + return status; + }; + + auto& config = Config::GetInstance(); + config.RegisterCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, identity_, lambda); +} + +void +GpuResourceConfigHandler::AddGpuBuildResourcesListener() { + auto& config = Config::GetInstance(); + ConfigCallBackF lambda = [this](const std::string& value) -> Status { + if (!gpu_enable_) { + std::string msg = + std::string("GPU resources is disable. Cannot set config ") + CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES; + return Status(SERVER_UNEXPECTED_ERROR, msg); + } + + auto& config = Config::GetInstance(); + auto status = config.GetGpuResourceConfigSearchResources(build_gpus_); + if (status.ok()) { + OnGpuBuildResChanged(build_gpus_); + } + + return status; + }; + config.RegisterCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, identity_, lambda); +} + +void +GpuResourceConfigHandler::AddGpuSearchThresholdListener() { + auto& config = Config::GetInstance(); + + ConfigCallBackF lambda_gpu_threshold = [this](const std::string& value) -> Status { + if (!gpu_enable_) { + std::string msg = + std::string("GPU resources is disable. Cannot set config ") + CONFIG_ENGINE_GPU_SEARCH_THRESHOLD; + return Status(SERVER_UNEXPECTED_ERROR, msg); + } + + auto& config = Config::GetInstance(); + auto status = config.GetEngineConfigGpuSearchThreshold(threshold_); + if (status.ok()) { + OnGpuSearchThresholdChanged(threshold_); + } + + return status; + }; + config.RegisterCallBack(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, identity_, lambda_gpu_threshold); +} + +void +GpuResourceConfigHandler::AddGpuSearchResourcesListener() { + auto& config = Config::GetInstance(); + + ConfigCallBackF lambda = [this](const std::string& value) -> Status { + if (!gpu_enable_) { + std::string msg = + std::string("GPU resources is disable. Cannot set config ") + CONFIG_GPU_RESOURCE_SEARCH_RESOURCES; + return Status(SERVER_UNEXPECTED_ERROR, msg); + } + + auto& config = Config::GetInstance(); + auto status = config.GetGpuResourceConfigSearchResources(search_gpus_); + if (status.ok()) { + OnGpuSearchResChanged(search_gpus_); + } + + return status; + }; + config.RegisterCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, identity_, lambda); +} + +void +GpuResourceConfigHandler::RemoveGpuEnableListener() { + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, identity_); +} + +void +GpuResourceConfigHandler::RemoveGpuCacheCapacityListener() { + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, identity_); +} + +void +GpuResourceConfigHandler::RemoveGpuBuildResourcesListener() { + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, identity_); +} + +void +GpuResourceConfigHandler::RemoveGpuSearchThresholdListener() { + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, identity_); +} + +void +GpuResourceConfigHandler::RemoveGpuSearchResourcesListener() { + auto& config = Config::GetInstance(); + config.CancelCallBack(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, identity_); +} + +} // namespace server +} // namespace milvus +#endif diff --git a/core/src/config/handler/GpuResourceConfigHandler.h b/core/src/config/handler/GpuResourceConfigHandler.h new file mode 100644 index 0000000000..8d282bc46d --- /dev/null +++ b/core/src/config/handler/GpuResourceConfigHandler.h @@ -0,0 +1,94 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// 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 +// +// 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. +#ifdef MILVUS_GPU_VERSION +#pragma once + +#include +#include +#include +#include + +#include "config/Config.h" +#include "config/handler/ConfigHandler.h" + +namespace milvus { +namespace server { + +class GpuResourceConfigHandler : virtual public ConfigHandler { + public: + GpuResourceConfigHandler(); + + virtual ~GpuResourceConfigHandler(); + + protected: + virtual void + OnGpuEnableChanged(bool enable) { + } + + virtual void + OnGpuCacheCapacityChanged(int64_t capacity) { + } + + virtual void + OnGpuBuildResChanged(const std::vector& gpus) { + } + + virtual void + OnGpuSearchThresholdChanged(int64_t threshold) { + } + + virtual void + OnGpuSearchResChanged(const std::vector& gpus) { + } + + protected: + void + AddGpuEnableListener(); + + void + AddGpuCacheCapacityListener(); + + void + AddGpuBuildResourcesListener(); + + void + AddGpuSearchThresholdListener(); + + void + AddGpuSearchResourcesListener(); + + protected: + void + RemoveGpuEnableListener(); + + void + RemoveGpuCacheCapacityListener(); + + void + RemoveGpuBuildResourcesListener(); + + void + RemoveGpuSearchThresholdListener(); + + void + RemoveGpuSearchResourcesListener(); + + protected: + bool gpu_enable_ = true; + int64_t gpu_cache_capacity_ = std::stoll(CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT) /* GiB */; + int64_t threshold_ = std::stoll(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT); + std::vector build_gpus_; + std::vector search_gpus_; +}; + +} // namespace server +} // namespace milvus +#endif diff --git a/core/src/config/handler/GpuSearchConfigHandler.cpp b/core/src/config/handler/GpuSearchConfigHandler.cpp deleted file mode 100644 index a1a18d2bba..0000000000 --- a/core/src/config/handler/GpuSearchConfigHandler.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2019-2020 Zilliz. All rights reserved. -// -// 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 -// -// 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. -#ifdef MILVUS_GPU_VERSION - -#include -#include - -#include "config/Config.h" -#include "config/handler/GpuSearchConfigHandler.h" - -namespace milvus { -namespace server { - -GpuSearchConfigHandler::GpuSearchConfigHandler() { - server::Config& config = server::Config::GetInstance(); - - Status s = config.GetEngineConfigGpuSearchThreshold(threshold_); - if (!s.ok()) { - threshold_ = std::numeric_limits::max(); - } - - config.GetGpuResourceConfigSearchResources(search_gpus_); -} - -GpuSearchConfigHandler::~GpuSearchConfigHandler() { - RemoveGpuSearchThresholdListener(); - RemoveGpuSearchResListener(); -} - -//////////////////////////////////////////////////////////////////////// -void -GpuSearchConfigHandler::OnGpuSearchThresholdChanged(int64_t threshold) { - threshold_ = threshold; -} - -void -GpuSearchConfigHandler::OnGpuSearchResChanged(const std::vector& gpus) { - search_gpus_ = gpus; -} - -void -GpuSearchConfigHandler::AddGpuSearchThresholdListener() { - server::Config& config = server::Config::GetInstance(); - - server::ConfigCallBackF lambda_gpu_threshold = [this](const std::string& value) -> Status { - server::Config& config = server::Config::GetInstance(); - int64_t threshold; - auto status = config.GetEngineConfigGpuSearchThreshold(threshold); - if (status.ok()) { - OnGpuSearchThresholdChanged(threshold); - } - - return status; - }; - config.RegisterCallBack(server::CONFIG_ENGINE, server::CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, identity_, - lambda_gpu_threshold); -} - -void -GpuSearchConfigHandler::AddGpuSearchResListener() { - server::Config& config = server::Config::GetInstance(); - - server::ConfigCallBackF lambda_gpu_search_res = [this](const std::string& value) -> Status { - server::Config& config = server::Config::GetInstance(); - std::vector gpu_ids; - auto status = config.GetGpuResourceConfigSearchResources(gpu_ids); - if (status.ok()) { - OnGpuSearchResChanged(gpu_ids); - } - - return status; - }; - config.RegisterCallBack(server::CONFIG_GPU_RESOURCE, server::CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, identity_, - lambda_gpu_search_res); -} - -void -GpuSearchConfigHandler::RemoveGpuSearchThresholdListener() { - server::Config& config = server::Config::GetInstance(); - config.CancelCallBack(server::CONFIG_ENGINE, server::CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, identity_); -} - -void -GpuSearchConfigHandler::RemoveGpuSearchResListener() { - auto& config = server::Config::GetInstance(); - config.CancelCallBack(server::CONFIG_GPU_RESOURCE, server::CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, identity_); -} - -} // namespace server -} // namespace milvus -#endif diff --git a/core/src/config/handler/GpuSearchConfigHandler.h b/core/src/config/handler/GpuSearchConfigHandler.h deleted file mode 100644 index 8ae0bba9de..0000000000 --- a/core/src/config/handler/GpuSearchConfigHandler.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2019-2020 Zilliz. All rights reserved. -// -// 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 -// -// 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. -#ifdef MILVUS_GPU_VERSION -#pragma once - -#include -#include - -#include "config/handler/GpuConfigHandler.h" - -namespace milvus { -namespace server { - -class GpuSearchConfigHandler : virtual public GpuConfigHandler { - public: - GpuSearchConfigHandler(); - - ~GpuSearchConfigHandler(); - - public: - virtual void - OnGpuSearchThresholdChanged(int64_t threshold); - - virtual void - OnGpuSearchResChanged(const std::vector& gpus); - - protected: - void - AddGpuSearchThresholdListener(); - - void - AddGpuSearchResListener(); - - void - RemoveGpuSearchThresholdListener(); - - void - RemoveGpuSearchResListener(); - - protected: - int64_t threshold_ = std::numeric_limits::max(); - std::vector search_gpus_; -}; - -} // namespace server -} // namespace milvus -#endif diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index a4062720c2..32c6c01f4a 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -30,6 +30,7 @@ #include "cache/GpuCacheMgr.h" #include "db/IDGenerator.h" #include "engine/EngineFactory.h" +#include "index/thirdparty/faiss/utils/distances.h" #include "insert/MemMenagerFactory.h" #include "meta/MetaConsts.h" #include "meta/MetaFactory.h" @@ -77,12 +78,12 @@ DBImpl::DBImpl(const DBOptions& options) SetIdentity("DBImpl"); AddCacheInsertDataListener(); + AddUseBlasThresholdListener(); Start(); } DBImpl::~DBImpl() { - RemoveCacheInsertDataListener(); Stop(); } @@ -2067,5 +2068,10 @@ DBImpl::OnCacheInsertDataChanged(bool value) { options_.insert_cache_immediately_ = value; } +void +DBImpl::OnUseBlasThresholdChanged(int64_t threshold) { + faiss::distance_compute_blas_threshold = threshold; +} + } // namespace engine } // namespace milvus diff --git a/core/src/db/DBImpl.h b/core/src/db/DBImpl.h index bdec4b3491..eec3f5f93d 100644 --- a/core/src/db/DBImpl.h +++ b/core/src/db/DBImpl.h @@ -23,6 +23,7 @@ #include #include "config/handler/CacheConfigHandler.h" +#include "config/handler/EngineConfigHandler.h" #include "db/DB.h" #include "db/IndexFailedChecker.h" #include "db/OngoingFileChecker.h" @@ -38,7 +39,7 @@ namespace meta { class Meta; } -class DBImpl : public DB, public server::CacheConfigHandler { +class DBImpl : public DB, public server::CacheConfigHandler, public server::EngineConfigHandler { public: explicit DBImpl(const DBOptions& options); ~DBImpl(); @@ -151,6 +152,9 @@ class DBImpl : public DB, public server::CacheConfigHandler { void OnCacheInsertDataChanged(bool value) override; + void + OnUseBlasThresholdChanged(int64_t threshold) override; + private: Status QueryAsync(const std::shared_ptr& context, const std::string& table_id, diff --git a/core/src/db/insert/MemTable.cpp b/core/src/db/insert/MemTable.cpp index ad4a613f5d..2ef361d927 100644 --- a/core/src/db/insert/MemTable.cpp +++ b/core/src/db/insert/MemTable.cpp @@ -11,19 +11,18 @@ #include "db/insert/MemTable.h" -#include -#include -#include - #include #include #include #include #include +#include "cache/CpuCacheMgr.h" #include "db/OngoingFileChecker.h" #include "db/Utils.h" +#include "segment/SegmentReader.h" #include "utils/Log.h" +#include "wrapper/VecIndex.h" namespace milvus { namespace engine { diff --git a/core/src/db/insert/MemTableFile.cpp b/core/src/db/insert/MemTableFile.cpp index f4e55ea23d..96a6af9299 100644 --- a/core/src/db/insert/MemTableFile.cpp +++ b/core/src/db/insert/MemTableFile.cpp @@ -45,10 +45,6 @@ MemTableFile::MemTableFile(const std::string& table_id, const meta::MetaPtr& met AddCacheInsertDataListener(); } -MemTableFile::~MemTableFile() { - RemoveCacheInsertDataListener(); -} - Status MemTableFile::CreateTableFile() { meta::TableFileSchema table_file_schema; diff --git a/core/src/db/insert/MemTableFile.h b/core/src/db/insert/MemTableFile.h index 424c8ca2cc..9cc636dc9f 100644 --- a/core/src/db/insert/MemTableFile.h +++ b/core/src/db/insert/MemTableFile.h @@ -30,7 +30,7 @@ class MemTableFile : public server::CacheConfigHandler { public: MemTableFile(const std::string& table_id, const meta::MetaPtr& meta, const DBOptions& options); - ~MemTableFile(); + ~MemTableFile() = default; public: Status diff --git a/core/src/scheduler/job/BuildIndexJob.cpp b/core/src/scheduler/job/BuildIndexJob.cpp index fd84305952..4a49881028 100644 --- a/core/src/scheduler/job/BuildIndexJob.cpp +++ b/core/src/scheduler/job/BuildIndexJob.cpp @@ -24,10 +24,6 @@ BuildIndexJob::BuildIndexJob(engine::meta::MetaPtr meta_ptr, engine::DBOptions o AddCacheInsertDataListener(); } -BuildIndexJob::~BuildIndexJob() { - RemoveCacheInsertDataListener(); -} - bool BuildIndexJob::AddToIndexFiles(const engine::meta::TableFileSchemaPtr& to_index_file) { std::unique_lock lock(mutex_); diff --git a/core/src/scheduler/job/BuildIndexJob.h b/core/src/scheduler/job/BuildIndexJob.h index 09c8330da7..126877a94f 100644 --- a/core/src/scheduler/job/BuildIndexJob.h +++ b/core/src/scheduler/job/BuildIndexJob.h @@ -38,7 +38,7 @@ class BuildIndexJob : public Job, public server::CacheConfigHandler { public: explicit BuildIndexJob(engine::meta::MetaPtr meta_ptr, engine::DBOptions options); - ~BuildIndexJob(); + ~BuildIndexJob() = default; public: bool diff --git a/core/src/scheduler/optimizer/BuildIndexPass.cpp b/core/src/scheduler/optimizer/BuildIndexPass.cpp index 0e612817e1..ec83e107fe 100644 --- a/core/src/scheduler/optimizer/BuildIndexPass.cpp +++ b/core/src/scheduler/optimizer/BuildIndexPass.cpp @@ -29,7 +29,7 @@ BuildIndexPass::Init() { SetIdentity("BuildIndexPass"); AddGpuEnableListener(); - AddGpuBuildResListener(); + AddGpuBuildResourcesListener(); } bool diff --git a/core/src/scheduler/optimizer/BuildIndexPass.h b/core/src/scheduler/optimizer/BuildIndexPass.h index eab632151f..cd6095d38f 100644 --- a/core/src/scheduler/optimizer/BuildIndexPass.h +++ b/core/src/scheduler/optimizer/BuildIndexPass.h @@ -22,13 +22,13 @@ #include #include -#include "config/handler/GpuBuildConfigHandler.h" +#include "config/handler/GpuResourceConfigHandler.h" #include "scheduler/optimizer/Pass.h" namespace milvus { namespace scheduler { -class BuildIndexPass : public Pass, public server::GpuBuildConfigHandler { +class BuildIndexPass : public Pass, public server::GpuResourceConfigHandler { public: BuildIndexPass() = default; diff --git a/core/src/scheduler/optimizer/FaissFlatPass.cpp b/core/src/scheduler/optimizer/FaissFlatPass.cpp index b6e75f7955..d0016727e4 100644 --- a/core/src/scheduler/optimizer/FaissFlatPass.cpp +++ b/core/src/scheduler/optimizer/FaissFlatPass.cpp @@ -37,7 +37,7 @@ FaissFlatPass::Init() { SetIdentity("FaissFlatPass"); AddGpuEnableListener(); AddGpuSearchThresholdListener(); - AddGpuSearchResListener(); + AddGpuSearchResourcesListener(); } bool diff --git a/core/src/scheduler/optimizer/FaissFlatPass.h b/core/src/scheduler/optimizer/FaissFlatPass.h index 870c2964c7..6878f1c4cb 100644 --- a/core/src/scheduler/optimizer/FaissFlatPass.h +++ b/core/src/scheduler/optimizer/FaissFlatPass.h @@ -23,13 +23,13 @@ #include #include -#include "config/handler/GpuSearchConfigHandler.h" +#include "config/handler/GpuResourceConfigHandler.h" #include "scheduler/optimizer/Pass.h" namespace milvus { namespace scheduler { -class FaissFlatPass : public Pass, public server::GpuSearchConfigHandler { +class FaissFlatPass : public Pass, public server::GpuResourceConfigHandler { public: FaissFlatPass() = default; diff --git a/core/src/scheduler/optimizer/FaissIVFFlatPass.cpp b/core/src/scheduler/optimizer/FaissIVFFlatPass.cpp index 8d9f4ec577..42b171e160 100644 --- a/core/src/scheduler/optimizer/FaissIVFFlatPass.cpp +++ b/core/src/scheduler/optimizer/FaissIVFFlatPass.cpp @@ -37,7 +37,7 @@ FaissIVFFlatPass::Init() { SetIdentity("FaissIVFFlatPass"); AddGpuEnableListener(); AddGpuSearchThresholdListener(); - AddGpuSearchResListener(); + AddGpuSearchResourcesListener(); #endif } diff --git a/core/src/scheduler/optimizer/FaissIVFFlatPass.h b/core/src/scheduler/optimizer/FaissIVFFlatPass.h index b5cc814799..fe21996cda 100644 --- a/core/src/scheduler/optimizer/FaissIVFFlatPass.h +++ b/core/src/scheduler/optimizer/FaissIVFFlatPass.h @@ -23,13 +23,13 @@ #include #include -#include "config/handler/GpuSearchConfigHandler.h" +#include "config/handler/GpuResourceConfigHandler.h" #include "scheduler/optimizer/Pass.h" namespace milvus { namespace scheduler { -class FaissIVFFlatPass : public Pass, public server::GpuSearchConfigHandler { +class FaissIVFFlatPass : public Pass, public server::GpuResourceConfigHandler { public: FaissIVFFlatPass() = default; diff --git a/core/src/scheduler/optimizer/FaissIVFPQPass.cpp b/core/src/scheduler/optimizer/FaissIVFPQPass.cpp index 876d4fef32..6ca1971232 100644 --- a/core/src/scheduler/optimizer/FaissIVFPQPass.cpp +++ b/core/src/scheduler/optimizer/FaissIVFPQPass.cpp @@ -39,7 +39,7 @@ FaissIVFPQPass::Init() { SetIdentity("FaissIVFPQPass"); AddGpuEnableListener(); AddGpuSearchThresholdListener(); - AddGpuSearchResListener(); + AddGpuSearchResourcesListener(); #endif } diff --git a/core/src/scheduler/optimizer/FaissIVFPQPass.h b/core/src/scheduler/optimizer/FaissIVFPQPass.h index 946da20912..cb3239197a 100644 --- a/core/src/scheduler/optimizer/FaissIVFPQPass.h +++ b/core/src/scheduler/optimizer/FaissIVFPQPass.h @@ -23,13 +23,13 @@ #include #include -#include "config/handler/GpuSearchConfigHandler.h" +#include "config/handler/GpuResourceConfigHandler.h" #include "scheduler/optimizer/Pass.h" namespace milvus { namespace scheduler { -class FaissIVFPQPass : public Pass, public server::GpuSearchConfigHandler { +class FaissIVFPQPass : public Pass, public server::GpuResourceConfigHandler { public: FaissIVFPQPass() = default; diff --git a/core/src/scheduler/optimizer/FaissIVFSQ8HPass.cpp b/core/src/scheduler/optimizer/FaissIVFSQ8HPass.cpp index ec090efaad..e2626a41b0 100644 --- a/core/src/scheduler/optimizer/FaissIVFSQ8HPass.cpp +++ b/core/src/scheduler/optimizer/FaissIVFSQ8HPass.cpp @@ -37,7 +37,7 @@ FaissIVFSQ8HPass::Init() { SetIdentity("FaissIVFSQ8HPass"); AddGpuEnableListener(); AddGpuSearchThresholdListener(); - AddGpuSearchResListener(); + AddGpuSearchResourcesListener(); #endif } diff --git a/core/src/scheduler/optimizer/FaissIVFSQ8HPass.h b/core/src/scheduler/optimizer/FaissIVFSQ8HPass.h index c5ea2ff1b3..ffff0a899a 100644 --- a/core/src/scheduler/optimizer/FaissIVFSQ8HPass.h +++ b/core/src/scheduler/optimizer/FaissIVFSQ8HPass.h @@ -23,13 +23,13 @@ #include #include -#include "config/handler/GpuSearchConfigHandler.h" +#include "config/handler/GpuResourceConfigHandler.h" #include "scheduler/optimizer/Pass.h" namespace milvus { namespace scheduler { -class FaissIVFSQ8HPass : public Pass, public server::GpuSearchConfigHandler { +class FaissIVFSQ8HPass : public Pass, public server::GpuResourceConfigHandler { public: FaissIVFSQ8HPass() = default; diff --git a/core/src/scheduler/optimizer/FaissIVFSQ8Pass.cpp b/core/src/scheduler/optimizer/FaissIVFSQ8Pass.cpp index 339d21201f..bddee247ad 100644 --- a/core/src/scheduler/optimizer/FaissIVFSQ8Pass.cpp +++ b/core/src/scheduler/optimizer/FaissIVFSQ8Pass.cpp @@ -37,7 +37,7 @@ FaissIVFSQ8Pass::Init() { SetIdentity("FaissIVFSQ8Pass"); AddGpuEnableListener(); AddGpuSearchThresholdListener(); - AddGpuSearchResListener(); + AddGpuSearchResourcesListener(); #endif } diff --git a/core/src/scheduler/optimizer/FaissIVFSQ8Pass.h b/core/src/scheduler/optimizer/FaissIVFSQ8Pass.h index 29ec94efb5..89219beb78 100644 --- a/core/src/scheduler/optimizer/FaissIVFSQ8Pass.h +++ b/core/src/scheduler/optimizer/FaissIVFSQ8Pass.h @@ -23,13 +23,13 @@ #include #include -#include "config/handler/GpuSearchConfigHandler.h" +#include "config/handler/GpuResourceConfigHandler.h" #include "scheduler/optimizer/Pass.h" namespace milvus { namespace scheduler { -class FaissIVFSQ8Pass : public Pass, public server::GpuSearchConfigHandler { +class FaissIVFSQ8Pass : public Pass, public server::GpuResourceConfigHandler { public: FaissIVFSQ8Pass() = default; diff --git a/core/src/server/DBWrapper.cpp b/core/src/server/DBWrapper.cpp index 8ba206172c..2aea0cc529 100644 --- a/core/src/server/DBWrapper.cpp +++ b/core/src/server/DBWrapper.cpp @@ -9,15 +9,17 @@ // 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. -#include +#include "server/DBWrapper.h" + #include #include #include #include +#include + #include "config/Config.h" #include "db/DBFactory.h" -#include "server/DBWrapper.h" #include "utils/CommonUtil.h" #include "utils/Log.h" #include "utils/StringHelpFunctions.h" @@ -145,19 +147,7 @@ DBWrapper::StartService() { std::cerr << s.ToString() << std::endl; return s; } - faiss::distance_compute_blas_threshold = use_blas_threshold; - server::ConfigCallBackF lambda = [](const std::string& value) -> Status { - Config& config = Config::GetInstance(); - int64_t blas_threshold; - auto status = config.GetEngineConfigUseBlasThreshold(blas_threshold); - if (status.ok()) { - faiss::distance_compute_blas_threshold = blas_threshold; - } - - return status; - }; - config.RegisterCallBack(server::CONFIG_ENGINE, server::CONFIG_ENGINE_USE_BLAS_THRESHOLD, "DBWrapper", lambda); // set archive config engine::ArchiveConf::CriteriaT criterial; diff --git a/core/src/server/web_impl/README.md b/core/src/server/web_impl/README.md index 1032a9dd72..675ed3c6df 100644 --- a/core/src/server/web_impl/README.md +++ b/core/src/server/web_impl/README.md @@ -1145,7 +1145,7 @@ $ curl -X GET "http://127.0.0.1:19121/collections/test_collection/segments/15837 ##### Request ```shell -$ curl -X PUT "http://127.0.0.1:19121/collections/test_collection/vectors" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"search\":{\"topk\":2,\"vectors\":[[0.1]], \"params\":{\"nprobe\":16}}}" +$ curl -X PUT "http://127.0.0.1:19121/collections/test_collection/vectors" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"search\":{\"topk\":2,\"vectors\":[[0.1]],\"params\":{\"nprobe\":16}}}" ``` ##### Response diff --git a/core/src/server/web_impl/handler/WebRequestHandler.cpp b/core/src/server/web_impl/handler/WebRequestHandler.cpp index d08bc4d985..cecb193849 100644 --- a/core/src/server/web_impl/handler/WebRequestHandler.cpp +++ b/core/src/server/web_impl/handler/WebRequestHandler.cpp @@ -1077,10 +1077,6 @@ WebRequestHandler::DropIndex(const OString& collection_name) { ASSIGN_RETURN_STATUS_DTO(status) } -/*********** - * - * Partition { - */ StatusDto::ObjectWrapper WebRequestHandler::CreatePartition(const OString& collection_name, const PartitionRequestDto::ObjectWrapper& param) { if (nullptr == param->partition_tag.get()) { diff --git a/core/src/server/web_impl/handler/WebRequestHandler.h b/core/src/server/web_impl/handler/WebRequestHandler.h index d3e47affb9..24490b43af 100644 --- a/core/src/server/web_impl/handler/WebRequestHandler.h +++ b/core/src/server/web_impl/handler/WebRequestHandler.h @@ -172,10 +172,6 @@ class WebRequestHandler { SetGpuConfig(const GPUConfigDto::ObjectWrapper& gpu_config_dto); #endif - /********** - * - * Table - */ StatusDto::ObjectWrapper CreateTable(const TableRequestDto::ObjectWrapper& table_schema); StatusDto::ObjectWrapper @@ -187,10 +183,6 @@ class WebRequestHandler { StatusDto::ObjectWrapper DropTable(const OString& table_name); - /********** - * - * Index - */ StatusDto::ObjectWrapper CreateIndex(const OString& table_name, const OString& body); @@ -200,10 +192,6 @@ class WebRequestHandler { StatusDto::ObjectWrapper DropIndex(const OString& table_name); - /*********** - * - * Partition - */ StatusDto::ObjectWrapper CreatePartition(const OString& table_name, const PartitionRequestDto::ObjectWrapper& param); diff --git a/core/unittest/server/test_config.cpp b/core/unittest/server/test_config.cpp index 9c547b5036..6e358638a6 100644 --- a/core/unittest/server/test_config.cpp +++ b/core/unittest/server/test_config.cpp @@ -9,13 +9,13 @@ // 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. +#include #include #include #include #include #include -#include #include "config/Config.h" #include "config/YamlConfigMgr.h" @@ -24,7 +24,6 @@ #include "utils/StringHelpFunctions.h" #include "utils/ValidationUtil.h" - namespace { static constexpr uint64_t KB = 1024; @@ -200,6 +199,16 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) { ASSERT_TRUE(config.GetStorageConfigSecondaryPath(str_val).ok()); ASSERT_TRUE(str_val == storage_secondary_path); + storage_secondary_path = "/home/zilliz,/tmp/milvus"; + ASSERT_TRUE(config.SetStorageConfigSecondaryPath(storage_secondary_path).ok()); + ASSERT_TRUE(config.GetStorageConfigSecondaryPath(str_val).ok()); + ASSERT_TRUE(str_val == storage_secondary_path); + + storage_secondary_path = ""; + ASSERT_TRUE(config.SetStorageConfigSecondaryPath(storage_secondary_path).ok()); + ASSERT_TRUE(config.GetStorageConfigSecondaryPath(str_val).ok()); + ASSERT_TRUE(str_val == storage_secondary_path); + bool storage_s3_enable = true; ASSERT_TRUE(config.SetStorageConfigS3Enable(std::to_string(storage_s3_enable)).ok()); ASSERT_TRUE(config.GetStorageConfigS3Enable(bool_val).ok()); @@ -582,8 +591,13 @@ TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) { /* storage config */ ASSERT_FALSE(config.SetStorageConfigPrimaryPath("").ok()); + ASSERT_FALSE(config.SetStorageConfigPrimaryPath("./milvus").ok()); + ASSERT_FALSE(config.SetStorageConfigPrimaryPath("../milvus").ok()); + ASSERT_FALSE(config.SetStorageConfigPrimaryPath("/**milvus").ok()); + ASSERT_FALSE(config.SetStorageConfigPrimaryPath("/milvus--/path").ok()); - // ASSERT_FALSE(config.SetStorageConfigSecondaryPath("").ok()); + ASSERT_FALSE(config.SetStorageConfigSecondaryPath("../milvus,./zilliz").ok()); + ASSERT_FALSE(config.SetStorageConfigSecondaryPath("/home/^^__^^,/zilliz").ok()); ASSERT_FALSE(config.SetStorageConfigS3Enable("10").ok()); @@ -1116,58 +1130,84 @@ TEST_F(ConfigTest, SERVER_CONFIG_OTHER_CONFIGS_FAIL_TEST) { TEST_F(ConfigTest, SERVER_CONFIG_UPDATE_TEST) { std::string conf_file = std::string(CONFIG_PATH) + VALID_CONFIG_FILE; + std::string yaml_value; + std::string reply_set, reply_get; + std::string cmd_set, cmd_get; + + auto lambda = [&conf_file](const std::string& key, const std::string& child_key, + const std::string& default_value, std::string& value) { + auto * ymgr = milvus::server::YamlConfigMgr::GetInstance(); + auto status = ymgr->LoadConfigFile(conf_file); + + if (status.ok()) + value = ymgr->GetRootNode().GetChild(key).GetValue(child_key, default_value); + + return status; + }; + milvus::server::Config& config = milvus::server::Config::GetInstance(); auto status = config.LoadConfigFile(conf_file); ASSERT_TRUE(status.ok()) << status.message(); - // validate if setting config store in files - status = config.SetCacheConfigInsertBufferSize("2"); - ASSERT_TRUE(status.ok()) << status.message(); - + /* validate if setting config store in files */ // test numeric config value - status = config.LoadConfigFile(conf_file); - ASSERT_TRUE(status.ok()) << status.message(); - int64_t value; - status = config.GetCacheConfigInsertBufferSize(value); - ASSERT_TRUE(status.ok()) << status.message(); - ASSERT_EQ(value, 2); + cmd_set = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE, "2"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + + ASSERT_TRUE(lambda(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE, + ms::CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT, yaml_value).ok()); + ASSERT_EQ("2", yaml_value); // test boolean config value - status = config.SetMetricConfigEnableMonitor("True"); - ASSERT_TRUE(status.ok()) << status.message(); + cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "True"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, + ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok()); + ASSERT_EQ("true", yaml_value); - status = config.LoadConfigFile(conf_file); - ASSERT_TRUE(status.ok()) << status.message(); - bool enable; - status = config.GetMetricConfigEnableMonitor(enable); - ASSERT_TRUE(status.ok()) << status.message(); - ASSERT_EQ(true, enable); + cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "On"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, + ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok()); + ASSERT_EQ("true", yaml_value); - // invalid path - status = config.SetStorageConfigPrimaryPath("/a--/a"); - ASSERT_FALSE(status.ok()); + cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "False"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, + ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok()); + ASSERT_EQ("false", yaml_value); + + cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "Off"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, + ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok()); + ASSERT_EQ("false", yaml_value); // test path - status = config.SetStorageConfigPrimaryPath("/tmp/milvus_config_unittest"); - ASSERT_TRUE(status.ok()); + cmd_set = gen_set_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_PRIMARY_PATH, "/tmp/milvus_config_unittest"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_PRIMARY_PATH, + ms::CONFIG_STORAGE_PRIMARY_PATH_DEFAULT, yaml_value).ok()); + ASSERT_EQ("/tmp/milvus_config_unittest", yaml_value); - std::string path_value; - status = config.GetStorageConfigPrimaryPath(path_value); - ASSERT_TRUE(status.ok()); - ASSERT_EQ(path_value, "/tmp/milvus_config_unittest"); + cmd_set = gen_set_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_SECONDARY_PATH, "/home/zilliz,/home/milvus"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_SECONDARY_PATH, + ms::CONFIG_STORAGE_SECONDARY_PATH_DEFAULT, yaml_value).ok()); + ASSERT_EQ("/home/zilliz,/home/milvus", yaml_value); #ifdef MILVUS_GPU_VERSION - status = config.SetGpuResourceConfigBuildIndexResources("gpu0"); - ASSERT_TRUE(status.ok()) << status.message(); + cmd_set = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, "gpu0"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, + ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT, yaml_value).ok()); + ASSERT_EQ("gpu0", yaml_value); - status = config.LoadConfigFile(conf_file); - ASSERT_TRUE(status.ok()) << status.message(); - std::vector gpus; - status = config.GetGpuResourceConfigBuildIndexResources(gpus); - ASSERT_TRUE(status.ok()) << status.message(); - ASSERT_EQ(1, gpus.size()); - ASSERT_EQ(0, gpus[0]); - ASSERT_EQ(value, 2); + cmd_set = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, "GPU0"); + ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok()); + ASSERT_TRUE(lambda(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, + ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT, yaml_value).ok()); + ASSERT_EQ("gpu0", yaml_value); #endif } diff --git a/core/unittest/server/test_web.cpp b/core/unittest/server/test_web.cpp index 34becf6348..9aa53d780d 100644 --- a/core/unittest/server/test_web.cpp +++ b/core/unittest/server/test_web.cpp @@ -29,7 +29,6 @@ #include "server/delivery/RequestScheduler.h" #include "server/delivery/request/BaseRequest.h" #include "server/Server.h" -#include "src/version.h" #include "server/web_impl/Types.h" #include "server/web_impl/WebServer.h" #include "server/web_impl/component/AppComponent.hpp" @@ -638,43 +637,53 @@ class TestClient : public oatpp::web::client::ApiClient { API_CALL("GET", "/collections", showTables, QUERY(String, offset), QUERY(String, page_size)) - API_CALL("OPTIONS", "/collections/{collection_name}", optionsTable, PATH(String, collection_name, "collection_name")) + API_CALL("OPTIONS", "/collections/{collection_name}", optionsTable, + PATH(String, collection_name, "collection_name")) - API_CALL("GET", "/collections/{collection_name}", getTable, PATH(String, collection_name, "collection_name"), QUERY(String, info)) + API_CALL("GET", "/collections/{collection_name}", getTable, + PATH(String, collection_name, "collection_name"), QUERY(String, info)) API_CALL("DELETE", "/collections/{collection_name}", dropTable, PATH(String, collection_name, "collection_name")) - API_CALL("OPTIONS", "/collections/{collection_name}/indexes", optionsIndexes, PATH(String, collection_name, "collection_name")) + API_CALL("OPTIONS", "/collections/{collection_name}/indexes", optionsIndexes, + PATH(String, collection_name, "collection_name")) - API_CALL("POST", "/collections/{collection_name}/indexes", createIndex, PATH(String, collection_name, "collection_name"), - BODY_STRING(OString, body)) + API_CALL("POST", "/collections/{collection_name}/indexes", createIndex, + PATH(String, collection_name, "collection_name"), BODY_STRING(OString, body)) - API_CALL("GET", "/collections/{collection_name}/indexes", getIndex, PATH(String, collection_name, "collection_name")) + API_CALL("GET", "/collections/{collection_name}/indexes", getIndex, + PATH(String, collection_name, "collection_name")) - API_CALL("DELETE", "/collections/{collection_name}/indexes", dropIndex, PATH(String, collection_name, "collection_name")) + API_CALL("DELETE", "/collections/{collection_name}/indexes", dropIndex, + PATH(String, collection_name, "collection_name")) - API_CALL("OPTIONS", "/collections/{collection_name}/partitions", optionsPartitions, PATH(String, collection_name, "collection_name")) + API_CALL("OPTIONS", "/collections/{collection_name}/partitions", optionsPartitions, + PATH(String, collection_name, "collection_name")) - API_CALL("POST", "/collections/{collection_name}/partitions", createPartition, PATH(String, collection_name, "collection_name"), + API_CALL("POST", "/collections/{collection_name}/partitions", createPartition, + PATH(String, collection_name, "collection_name"), BODY_DTO(milvus::server::web::PartitionRequestDto::ObjectWrapper, body)) - API_CALL("GET", "/collections/{collection_name}/partitions", showPartitions, PATH(String, collection_name, "collection_name"), + API_CALL("GET", "/collections/{collection_name}/partitions", showPartitions, + PATH(String, collection_name, "collection_name"), QUERY(String, offset), QUERY(String, page_size)) API_CALL("DELETE", "/collections/{collection_name}/partitions", dropPartition, PATH(String, collection_name, "collection_name"), BODY_STRING(String, body)) - API_CALL("GET", "/collections/{collection_name}/segments", showSegments, PATH(String, collection_name, "collection_name"), - QUERY(String, offset), QUERY(String, page_size), QUERY(String, partition_tag)) + API_CALL("GET", "/collections/{collection_name}/segments", showSegments, + PATH(String, collection_name, "collection_name"), + QUERY(String, offset), QUERY(String, page_size), QUERY(String, partition_tag)) API_CALL("GET", "/collections/{collection_name}/segments/{segment_name}/{info}", getSegmentInfo, PATH(String, collection_name, "collection_name"), PATH(String, segment_name, "segment_name"), PATH(String, info, "info"), QUERY(String, offset), QUERY(String, page_size)) - API_CALL("OPTIONS", "/collections/{collection_name}/vectors", optionsVectors, PATH(String, collection_name, "collection_name")) + API_CALL("OPTIONS", "/collections/{collection_name}/vectors", optionsVectors, + PATH(String, collection_name, "collection_name")) API_CALL("GET", "/collections/{collection_name}/vectors", getVectors, - PATH(String, collection_name, "collection_name"), QUERY(String, id)) + PATH(String, collection_name, "collection_name"), QUERY(String, id)) API_CALL("POST", "/collections/{collection_name}/vectors", insert, PATH(String, collection_name, "collection_name"), BODY_STRING(String, body)) @@ -1133,7 +1142,8 @@ TEST_F(WebControllerTest, INDEX) { ASSERT_EQ(OStatus::CODE_204.code, response->getStatusCode()); // create index without existing table - response = client_ptr->createIndex(collection_name + "fgafafafafafUUUUUUa124254", index_json.dump().c_str(), conncetion_ptr); + response = client_ptr->createIndex(collection_name + "fgafafafafafUUUUUUa124254", + index_json.dump().c_str(), conncetion_ptr); ASSERT_EQ(OStatus::CODE_404.code, response->getStatusCode()); // invalid index type