Optimize config cpu_cache_capacity / gpu_cache_capacity setter (#1572) (#1629)

* add gpu cache config handler

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* remove cpu/gpu cache mgr from Config class by using cache config handler (fix #1572)

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* remove 0.8.0 from config version map

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* clean config header reference

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* fix bug in web readme

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* reduce gpu config handler to gpu resources handler

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* add engine config

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* modify handler hook(fix #1572)

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* update changlog

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* initalize value in handler by config default

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* code style format

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* fix compile error in release mode

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* resolve faiss blas threshold init in DBWrapper

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* modify cache header

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* remove comments

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* order headers

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* convert gpu res config to lower case

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* CI retry

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* adjust header order in cpu cache mar file

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* improve config test case

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* code format

Signed-off-by: Yhz <yinghao.zou@zilliz.com>
pull/1696/head
BossZou 2020-03-19 10:17:53 +08:00 committed by GitHub
parent 616fd13612
commit 504a9e30ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 557 additions and 532 deletions

View File

@ -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

View File

@ -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 ()

View File

@ -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 <utility>
#include <fiu-local.h>
#include <utility>
#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

View File

@ -11,16 +11,17 @@
#pragma once
#include "CacheMgr.h"
#include "DataObj.h"
#include <memory>
#include <string>
#include "cache/CacheMgr.h"
#include "cache/DataObj.h"
#include "config/handler/CacheConfigHandler.h"
namespace milvus {
namespace cache {
class CpuCacheMgr : public CacheMgr<DataObjPtr> {
class CpuCacheMgr : public CacheMgr<DataObjPtr>, public server::CacheConfigHandler {
private:
CpuCacheMgr();
@ -31,6 +32,10 @@ class CpuCacheMgr : public CacheMgr<DataObjPtr> {
DataObjPtr
GetIndex(const std::string& key);
protected:
void
OnCpuCacheCapacityChanged(int64_t value) override;
};
} // namespace cache

View File

@ -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

View File

@ -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 <memory>
#include <string>
#include <unordered_map>
#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<GpuCacheMgr>;
class GpuCacheMgr : public CacheMgr<DataObjPtr> {
class GpuCacheMgr : public CacheMgr<DataObjPtr>, public server::GpuResourceConfigHandler {
public:
GpuCacheMgr();
@ -38,6 +39,10 @@ class GpuCacheMgr : public CacheMgr<DataObjPtr> {
void
InsertItem(const std::string& key, const DataObjPtr& data);
protected:
void
OnGpuCacheCapacityChanged(int64_t capacity) override;
private:
bool gpu_enable_ = true;
std::string identity_;

View File

@ -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 <cache/CpuCacheMgr.h>
#include <cache/GpuCacheMgr.h>
#include <fiu-local.h>
#include <sys/stat.h>
#include <unistd.h>
#include <algorithm>
#include <chrono>
#include <fstream>
#include <iostream>
#include <regex>
#include <string>
@ -25,11 +23,14 @@
#include <unordered_set>
#include <vector>
#include <fiu-local.h>
#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<std::string> 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<int64_t> 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

View File

@ -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

View File

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

View File

@ -20,6 +20,10 @@ namespace milvus {
namespace server {
class ConfigHandler {
public:
ConfigHandler() = default;
virtual ~ConfigHandler() = default;
protected:
void
SetIdentity(const std::string& identity) {

View File

@ -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 <string>
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

View File

@ -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 <exception>
#include <limits>
#include <string>
#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

View File

@ -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 <string>
#include <vector>
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<int64_t>& 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<int64_t> 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

View File

@ -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 <vector>
#include "config/handler/GpuConfigHandler.h"
namespace milvus {
namespace server {
class GpuBuildConfigHandler : virtual public GpuConfigHandler {
public:
GpuBuildConfigHandler();
~GpuBuildConfigHandler();
public:
virtual void
OnGpuBuildResChanged(const std::vector<int64_t>& gpus);
protected:
void
AddGpuBuildResListener();
void
RemoveGpuBuildResListener();
protected:
std::vector<int64_t> build_gpus_;
};
} // namespace server
} // namespace milvus
#endif

View File

@ -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

View File

@ -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

View File

@ -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 <exception>
#include <limits>
#include <string>
#include <vector>
#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<int64_t>& gpus) {
}
virtual void
OnGpuSearchThresholdChanged(int64_t threshold) {
}
virtual void
OnGpuSearchResChanged(const std::vector<int64_t>& 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<int64_t> build_gpus_;
std::vector<int64_t> search_gpus_;
};
} // namespace server
} // namespace milvus
#endif

View File

@ -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 <string>
#include <vector>
#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<int32_t>::max();
}
config.GetGpuResourceConfigSearchResources(search_gpus_);
}
GpuSearchConfigHandler::~GpuSearchConfigHandler() {
RemoveGpuSearchThresholdListener();
RemoveGpuSearchResListener();
}
////////////////////////////////////////////////////////////////////////
void
GpuSearchConfigHandler::OnGpuSearchThresholdChanged(int64_t threshold) {
threshold_ = threshold;
}
void
GpuSearchConfigHandler::OnGpuSearchResChanged(const std::vector<int64_t>& 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<int64_t> 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

View File

@ -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 <limits>
#include <vector>
#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<int64_t>& gpus);
protected:
void
AddGpuSearchThresholdListener();
void
AddGpuSearchResListener();
void
RemoveGpuSearchThresholdListener();
void
RemoveGpuSearchResListener();
protected:
int64_t threshold_ = std::numeric_limits<int64_t>::max();
std::vector<int64_t> search_gpus_;
};
} // namespace server
} // namespace milvus
#endif

View File

@ -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

View File

@ -23,6 +23,7 @@
#include <vector>
#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<server::Context>& context, const std::string& table_id,

View File

@ -11,19 +11,18 @@
#include "db/insert/MemTable.h"
#include <cache/CpuCacheMgr.h>
#include <segment/SegmentReader.h>
#include <wrapper/VecIndex.h>
#include <algorithm>
#include <chrono>
#include <memory>
#include <string>
#include <unordered_map>
#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 {

View File

@ -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;

View File

@ -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

View File

@ -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<std::mutex> lock(mutex_);

View File

@ -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

View File

@ -29,7 +29,7 @@ BuildIndexPass::Init() {
SetIdentity("BuildIndexPass");
AddGpuEnableListener();
AddGpuBuildResListener();
AddGpuBuildResourcesListener();
}
bool

View File

@ -22,13 +22,13 @@
#include <unordered_map>
#include <vector>
#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;

View File

@ -37,7 +37,7 @@ FaissFlatPass::Init() {
SetIdentity("FaissFlatPass");
AddGpuEnableListener();
AddGpuSearchThresholdListener();
AddGpuSearchResListener();
AddGpuSearchResourcesListener();
}
bool

View File

@ -23,13 +23,13 @@
#include <unordered_map>
#include <vector>
#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;

View File

@ -37,7 +37,7 @@ FaissIVFFlatPass::Init() {
SetIdentity("FaissIVFFlatPass");
AddGpuEnableListener();
AddGpuSearchThresholdListener();
AddGpuSearchResListener();
AddGpuSearchResourcesListener();
#endif
}

View File

@ -23,13 +23,13 @@
#include <unordered_map>
#include <vector>
#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;

View File

@ -39,7 +39,7 @@ FaissIVFPQPass::Init() {
SetIdentity("FaissIVFPQPass");
AddGpuEnableListener();
AddGpuSearchThresholdListener();
AddGpuSearchResListener();
AddGpuSearchResourcesListener();
#endif
}

View File

@ -23,13 +23,13 @@
#include <unordered_map>
#include <vector>
#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;

View File

@ -37,7 +37,7 @@ FaissIVFSQ8HPass::Init() {
SetIdentity("FaissIVFSQ8HPass");
AddGpuEnableListener();
AddGpuSearchThresholdListener();
AddGpuSearchResListener();
AddGpuSearchResourcesListener();
#endif
}

View File

@ -23,13 +23,13 @@
#include <unordered_map>
#include <vector>
#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;

View File

@ -37,7 +37,7 @@ FaissIVFSQ8Pass::Init() {
SetIdentity("FaissIVFSQ8Pass");
AddGpuEnableListener();
AddGpuSearchThresholdListener();
AddGpuSearchResListener();
AddGpuSearchResourcesListener();
#endif
}

View File

@ -23,13 +23,13 @@
#include <unordered_map>
#include <vector>
#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;

View File

@ -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 <faiss/utils/distances.h>
#include "server/DBWrapper.h"
#include <omp.h>
#include <cmath>
#include <string>
#include <vector>
#include <faiss/utils/distances.h>
#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;

View File

@ -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

View File

@ -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()) {

View File

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

View File

@ -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 <cmath>
#include <limits>
#include <fiu-control.h>
#include <fiu-local.h>
#include <gtest/gtest-death-test.h>
#include <gtest/gtest.h>
#include <cmath>
#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<int64_t> 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
}

View File

@ -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