From b3e8856a348a2fc87dcaad4b7672da7e59508c41 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Fri, 19 Jun 2020 15:53:36 +0800 Subject: [PATCH] move all APIs in utils into namespace milvus (#2614) * move APIs in util into namespace milvus Signed-off-by: yudong.cai * fix clang-format Signed-off-by: yudong.cai * update changelog Signed-off-by: yudong.cai * combine BlockingQueue.h and src/utils/BlockingQueue.inl Signed-off-by: yudong.cai * retry ci Signed-off-by: yudong.cai --- CHANGELOG.md | 1 + core/src/config/Config.cpp | 16 +-- core/src/db/DBImpl.cpp | 8 +- core/src/db/Utils.cpp | 4 +- core/src/db/engine/ExecutionEngineImpl.cpp | 2 +- core/src/db/meta/MySQLMetaImpl.cpp | 8 +- core/src/db/meta/SqliteMetaImpl.cpp | 6 +- core/src/db/snapshot/OperationExecutor.h | 3 +- core/src/db/wal/WalManager.cpp | 2 +- .../helpers/FaissGpuResourceMgr.h | 2 +- core/src/main.cpp | 14 +-- core/src/scheduler/task/BuildIndexTask.cpp | 2 +- core/src/utils/BlockingQueue.h | 48 +++++++-- core/src/utils/BlockingQueue.inl | 80 -------------- core/src/utils/CommonUtil.cpp | 2 - core/src/utils/CommonUtil.h | 2 - core/src/utils/Error.h | 24 ----- core/src/utils/Json.h | 5 +- core/src/utils/Log.cpp | 1 + core/src/utils/Log.h | 53 --------- core/src/utils/LogUtil.cpp | 28 ++--- core/src/utils/LogUtil.h | 2 - core/src/utils/SignalHandler.cpp | 2 - core/src/utils/SignalHandler.h | 2 - core/src/utils/StringHelpFunctions.cpp | 2 - core/src/utils/StringHelpFunctions.h | 2 - core/src/utils/TimeRecorder.h | 1 + core/unittest/db/test_db.cpp | 6 +- core/unittest/db/test_snapshot.cpp | 4 +- core/unittest/db/test_web.cpp | 2 +- core/unittest/server/test_config.cpp | 4 +- core/unittest/server/test_util.cpp | 101 +++++++++--------- core/unittest/server/utils.cpp | 4 +- core/unittest/storage/utils.cpp | 4 +- 34 files changed, 152 insertions(+), 295 deletions(-) delete mode 100644 core/src/utils/BlockingQueue.inl diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f013507..61a8540c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Please mark all changes in change log and use the issue from GitHub - \#2543 Remove secondary_path related code - \#2544 Optimize unittest build - \#2561 Clean util dependencies with other modules +- \#2612 Move all APIs in utils into namespace milvus ## Task diff --git a/core/src/config/Config.cpp b/core/src/config/Config.cpp index 89c346d3..032a429b 100644 --- a/core/src/config/Config.cpp +++ b/core/src/config/Config.cpp @@ -648,7 +648,7 @@ Status Config::ProcessConfigCli(std::string& result, const std::string& cmd) { std::vector tokens; std::vector nodes; - server::StringHelpFunctions::SplitStringByDelimeter(cmd, " ", tokens); + StringHelpFunctions::SplitStringByDelimeter(cmd, " ", tokens); if (tokens[0] == "get_config") { if (tokens.size() != 2) { return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd); @@ -657,7 +657,7 @@ Config::ProcessConfigCli(std::string& result, const std::string& cmd) { GetConfigJsonStr(result); return Status::OK(); } else { - server::StringHelpFunctions::SplitStringByDelimeter(tokens[1], CONFIG_NODE_DELIMITER, nodes); + StringHelpFunctions::SplitStringByDelimeter(tokens[1], CONFIG_NODE_DELIMITER, nodes); if (nodes.size() < 2) { return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd); } else if (nodes.size() > 2) { @@ -676,7 +676,7 @@ Config::ProcessConfigCli(std::string& result, const std::string& cmd) { if (tokens.size() != 3) { return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd); } - server::StringHelpFunctions::SplitStringByDelimeter(tokens[1], CONFIG_NODE_DELIMITER, nodes); + StringHelpFunctions::SplitStringByDelimeter(tokens[1], CONFIG_NODE_DELIMITER, nodes); if (nodes.size() < 2) { return Status(SERVER_UNEXPECTED_ERROR, "Invalid command: " + cmd); } else if (nodes.size() > 2) { @@ -1694,7 +1694,7 @@ Config::GetConfigSequenceStr(const std::string& parent_key, const std::string& c if (sequence.empty()) { value = default_value; } else { - server::StringHelpFunctions::MergeStringWithDelimeter(sequence, delim, value); + StringHelpFunctions::MergeStringWithDelimeter(sequence, delim, value); } SetConfigValueInMem(parent_key, child_key, value); } @@ -2026,7 +2026,7 @@ Config::GetGpuResourceConfigSearchResources(std::vector& value) { std::string str = GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT); std::vector res_vec; - server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); + StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); STATUS_CHECK(CheckGpuResourceConfigSearchResources(res_vec)); value.clear(); for (std::string& res : res_vec) { @@ -2048,7 +2048,7 @@ Config::GetGpuResourceConfigBuildIndexResources(std::vector& value) { GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT); std::vector res_vec; - server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); + StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); STATUS_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec)); value.clear(); for (std::string& res : res_vec) { @@ -2387,7 +2387,7 @@ Config::SetGpuResourceConfigGpuSearchThreshold(const std::string& value) { Status Config::SetGpuResourceConfigSearchResources(const std::string& value) { std::vector res_vec; - server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); + StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); STATUS_CHECK(CheckGpuResourceConfigSearchResources(res_vec)); STATUS_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value)); return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value); @@ -2396,7 +2396,7 @@ Config::SetGpuResourceConfigSearchResources(const std::string& value) { Status Config::SetGpuResourceConfigBuildIndexResources(const std::string& value) { std::vector res_vec; - server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); + StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec); STATUS_CHECK(CheckGpuResourceConfigBuildIndexResources(res_vec)); STATUS_CHECK(SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value)); return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value); diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index f40a21a8..8df457bc 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -630,7 +630,7 @@ DBImpl::HasPartition(const std::string& collection_id, const std::string& tag, b // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); if (valid_tag == milvus::engine::DEFAULT_PARTITON_TAG) { has_or_not = true; @@ -2808,7 +2808,7 @@ DBImpl::GetPartitionByTag(const std::string& collection_id, const std::string& p // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = partition_tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); if (valid_tag == milvus::engine::DEFAULT_PARTITON_TAG) { partition_name = collection_id; @@ -2834,7 +2834,7 @@ DBImpl::GetPartitionsByTags(const std::string& collection_id, const std::vector< // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); if (valid_tag == milvus::engine::DEFAULT_PARTITON_TAG) { partition_name_array.insert(collection_id); @@ -2842,7 +2842,7 @@ DBImpl::GetPartitionsByTags(const std::string& collection_id, const std::vector< } for (auto& schema : partition_array) { - if (server::StringHelpFunctions::IsRegexMatch(schema.partition_tag_, valid_tag)) { + if (StringHelpFunctions::IsRegexMatch(schema.partition_tag_, valid_tag)) { partition_name_array.insert(schema.collection_id_); } } diff --git a/core/src/db/Utils.cpp b/core/src/db/Utils.cpp index 905b2bbb..6d1061fa 100644 --- a/core/src/db/Utils.cpp +++ b/core/src/db/Utils.cpp @@ -60,7 +60,7 @@ Status CreateCollectionPath(const DBMetaOptions& options, const std::string& collection_id) { std::string db_path = options.path_; std::string table_path = db_path + TABLES_FOLDER + collection_id; - auto status = server::CommonUtil::CreateDirectory(table_path); + auto status = CommonUtil::CreateDirectory(table_path); if (!status.ok()) { LOG_ENGINE_ERROR_ << status.message(); return status; @@ -100,7 +100,7 @@ Status CreateCollectionFilePath(const DBMetaOptions& options, meta::SegmentSchema& table_file) { std::string parent_path = ConstructParentFolder(options.path_, table_file); - auto status = server::CommonUtil::CreateDirectory(parent_path); + auto status = CommonUtil::CreateDirectory(parent_path); fiu_do_on("CreateCollectionFilePath.fail_create", status = Status(DB_INVALID_PATH, "")); if (!status.ok()) { LOG_ENGINE_ERROR_ << status.message(); diff --git a/core/src/db/engine/ExecutionEngineImpl.cpp b/core/src/db/engine/ExecutionEngineImpl.cpp index f98af96c..9df036ae 100644 --- a/core/src/db/engine/ExecutionEngineImpl.cpp +++ b/core/src/db/engine/ExecutionEngineImpl.cpp @@ -371,7 +371,7 @@ ExecutionEngineImpl::Serialize() { // here we reset index size by file size, // since some index type(such as SQ8) data size become smaller after serialized - index_->SetIndexSize(server::CommonUtil::GetFileSize(location_)); + index_->SetIndexSize(CommonUtil::GetFileSize(location_)); LOG_ENGINE_DEBUG_ << "Finish serialize index file: " << location_ << " size: " << index_->Size(); if (index_->Size() == 0) { diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 24a227dd..718ca9e0 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -101,7 +101,7 @@ class MetaField { // only check field type, don't check field width, for example: VARCHAR(255) and VARCHAR(100) is equal std::vector type_split; - milvus::server::StringHelpFunctions::SplitStringByDelimeter(type_, "(", type_split); + milvus::StringHelpFunctions::SplitStringByDelimeter(type_, "(", type_split); if (!type_split.empty()) { type_len_min = type_split[0].length() > type_len_min ? type_len_min : type_split[0].length(); } @@ -1484,7 +1484,7 @@ MySQLMetaImpl::CreatePartition(const std::string& collection_id, const std::stri // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); // not allow duplicated partition std::string exist_partition; @@ -1525,7 +1525,7 @@ MySQLMetaImpl::HasPartition(const std::string& collection_id, const std::string& // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); { mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_); @@ -1624,7 +1624,7 @@ MySQLMetaImpl::GetPartitionName(const std::string& collection_id, const std::str // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); { mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_); diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index c57ae29c..1219ddf9 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -918,7 +918,7 @@ SqliteMetaImpl::CreatePartition(const std::string& collection_id, const std::str // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); // not allow duplicated partition std::string exist_partition; @@ -957,7 +957,7 @@ SqliteMetaImpl::HasPartition(const std::string& collection_id, const std::string // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); auto name = ConnectorPtr->select(columns(&CollectionSchema::collection_id_), where(c(&CollectionSchema::owner_collection_) == collection_id and @@ -1031,7 +1031,7 @@ SqliteMetaImpl::GetPartitionName(const std::string& collection_id, const std::st // trim side-blank of tag, only compare valid characters // for example: " ab cd " is treated as "ab cd" std::string valid_tag = tag; - server::StringHelpFunctions::TrimStringBlank(valid_tag); + StringHelpFunctions::TrimStringBlank(valid_tag); auto name = ConnectorPtr->select(columns(&CollectionSchema::collection_id_), where(c(&CollectionSchema::owner_collection_) == collection_id and diff --git a/core/src/db/snapshot/OperationExecutor.h b/core/src/db/snapshot/OperationExecutor.h index 23744ca4..695f5a96 100644 --- a/core/src/db/snapshot/OperationExecutor.h +++ b/core/src/db/snapshot/OperationExecutor.h @@ -10,6 +10,7 @@ // or implied. See the License for the specific language governing permissions and limitations under the License. #pragma once + #include #include #include @@ -22,7 +23,7 @@ namespace engine { namespace snapshot { using ThreadPtr = std::shared_ptr; -using OperationQueue = server::BlockingQueue; +using OperationQueue = BlockingQueue; using OperationQueuePtr = std::shared_ptr; class OperationExecutor { diff --git a/core/src/db/wal/WalManager.cpp b/core/src/db/wal/WalManager.cpp index 6d32b668..61db243f 100644 --- a/core/src/db/wal/WalManager.cpp +++ b/core/src/db/wal/WalManager.cpp @@ -39,7 +39,7 @@ WalManager::WalManager(const MXLogConfiguration& config) { mxlog_config_.mxlog_path += '/'; } // check path exist - auto status = server::CommonUtil::CreateDirectory(mxlog_config_.mxlog_path); + auto status = CommonUtil::CreateDirectory(mxlog_config_.mxlog_path); if (!status.ok()) { std::string msg = "failed to create wal directory " + mxlog_config_.mxlog_path; LOG_ENGINE_ERROR_ << msg; diff --git a/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissGpuResourceMgr.h b/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissGpuResourceMgr.h index 9b86ac57..48eb11f2 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissGpuResourceMgr.h +++ b/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissGpuResourceMgr.h @@ -39,7 +39,7 @@ using ResWPtr = std::weak_ptr; class FaissGpuResourceMgr { public: friend class ResScope; - using ResBQ = milvus::server::BlockingQueue; + using ResBQ = BlockingQueue; public: struct DeviceParams { diff --git a/core/src/main.cpp b/core/src/main.cpp index 6b0af67c..caab68ab 100644 --- a/core/src/main.cpp +++ b/core/src/main.cpp @@ -117,16 +117,16 @@ main(int argc, char* argv[]) { } /* Handle Signal */ - milvus::server::signal_routine_func = [](int32_t exit_code) { + milvus::signal_routine_func = [](int32_t exit_code) { milvus::server::Server::GetInstance().Stop(); exit(exit_code); }; - signal(SIGHUP, milvus::server::HandleSignal); - signal(SIGINT, milvus::server::HandleSignal); - signal(SIGUSR1, milvus::server::HandleSignal); - signal(SIGSEGV, milvus::server::HandleSignal); - signal(SIGUSR2, milvus::server::HandleSignal); - signal(SIGTERM, milvus::server::HandleSignal); + signal(SIGHUP, milvus::HandleSignal); + signal(SIGINT, milvus::HandleSignal); + signal(SIGUSR1, milvus::HandleSignal); + signal(SIGSEGV, milvus::HandleSignal); + signal(SIGUSR2, milvus::HandleSignal); + signal(SIGTERM, milvus::HandleSignal); server.Init(start_daemonized, pid_filename, config_filename); diff --git a/core/src/scheduler/task/BuildIndexTask.cpp b/core/src/scheduler/task/BuildIndexTask.cpp index 3ccd630c..68cab7c2 100644 --- a/core/src/scheduler/task/BuildIndexTask.cpp +++ b/core/src/scheduler/task/BuildIndexTask.cpp @@ -203,7 +203,7 @@ XBuildIndexTask::Execute() { // step 5: update meta table_file.file_type_ = engine::meta::SegmentSchema::INDEX; - table_file.file_size_ = server::CommonUtil::GetFileSize(table_file.location_); + table_file.file_size_ = CommonUtil::GetFileSize(table_file.location_); table_file.row_count_ = file_->row_count_; // index->Count(); auto origin_file = *file_; diff --git a/core/src/utils/BlockingQueue.h b/core/src/utils/BlockingQueue.h index 0003e594..55919f8a 100644 --- a/core/src/utils/BlockingQueue.h +++ b/core/src/utils/BlockingQueue.h @@ -18,7 +18,6 @@ #include namespace milvus { -namespace server { template class BlockingQueue { @@ -35,25 +34,55 @@ class BlockingQueue { operator=(const BlockingQueue& rhs) = delete; void - Put(const T& task); + Put(const T& task) { + std::unique_lock lock(mtx); + full_.wait(lock, [this] { return (queue_.size() < capacity_); }); + queue_.push(task); + empty_.notify_all(); + } T - Take(); + Take() { + std::unique_lock lock(mtx); + empty_.wait(lock, [this] { return !queue_.empty(); }); + T front(queue_.front()); + queue_.pop(); + full_.notify_all(); + return front; + } T - Front(); + Front() { + std::unique_lock lock(mtx); + empty_.wait(lock, [this] { return !queue_.empty(); }); + T front(queue_.front()); + return front; + } T - Back(); + Back() { + std::unique_lock lock(mtx); + empty_.wait(lock, [this] { return !queue_.empty(); }); + T back(queue_.back()); + return back; + } size_t - Size(); + Size() { + std::lock_guard lock(mtx); + return queue_.size(); + } bool - Empty(); + Empty() { + std::unique_lock lock(mtx); + return queue_.empty(); + } void - SetCapacity(const size_t capacity); + SetCapacity(const size_t capacity) { + capacity_ = (capacity > 0 ? capacity : capacity_); + } protected: mutable std::mutex mtx; @@ -63,7 +92,4 @@ class BlockingQueue { size_t capacity_ = 32; }; -} // namespace server } // namespace milvus - -#include "./BlockingQueue.inl" diff --git a/core/src/utils/BlockingQueue.inl b/core/src/utils/BlockingQueue.inl deleted file mode 100644 index 2cd6979c..00000000 --- a/core/src/utils/BlockingQueue.inl +++ /dev/null @@ -1,80 +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. - -#pragma once - -namespace milvus { -namespace server { - -template -void -BlockingQueue::Put(const T& task) { - std::unique_lock lock(mtx); - full_.wait(lock, [this] { return (queue_.size() < capacity_); }); - - queue_.push(task); - empty_.notify_all(); -} - -template -T -BlockingQueue::Take() { - std::unique_lock lock(mtx); - empty_.wait(lock, [this] { return !queue_.empty(); }); - - T front(queue_.front()); - queue_.pop(); - full_.notify_all(); - return front; -} - -template -size_t -BlockingQueue::Size() { - std::lock_guard lock(mtx); - return queue_.size(); -} - -template -T -BlockingQueue::Front() { - std::unique_lock lock(mtx); - empty_.wait(lock, [this] { return !queue_.empty(); }); - - T front(queue_.front()); - return front; -} - -template -T -BlockingQueue::Back() { - std::unique_lock lock(mtx); - empty_.wait(lock, [this] { return !queue_.empty(); }); - - T back(queue_.back()); - return back; -} - -template -bool -BlockingQueue::Empty() { - std::unique_lock lock(mtx); - return queue_.empty(); -} - -template -void -BlockingQueue::SetCapacity(const size_t capacity) { - capacity_ = (capacity > 0 ? capacity : capacity_); -} - -} // namespace server -} // namespace milvus diff --git a/core/src/utils/CommonUtil.cpp b/core/src/utils/CommonUtil.cpp index e59aa470..1656bdf9 100644 --- a/core/src/utils/CommonUtil.cpp +++ b/core/src/utils/CommonUtil.cpp @@ -23,7 +23,6 @@ #include namespace milvus { -namespace server { namespace fs = boost::filesystem; @@ -204,5 +203,4 @@ CommonUtil::GetCurrentTimeStr() { } #endif -} // namespace server } // namespace milvus diff --git a/core/src/utils/CommonUtil.h b/core/src/utils/CommonUtil.h index 8f057561..1a19294b 100644 --- a/core/src/utils/CommonUtil.h +++ b/core/src/utils/CommonUtil.h @@ -17,7 +17,6 @@ #include namespace milvus { -namespace server { class CommonUtil { public: @@ -52,5 +51,4 @@ class CommonUtil { #endif }; -} // namespace server } // namespace milvus diff --git a/core/src/utils/Error.h b/core/src/utils/Error.h index 054727b7..07d9b96e 100644 --- a/core/src/utils/Error.h +++ b/core/src/utils/Error.h @@ -130,28 +130,4 @@ constexpr ErrorCode SS_CONSTRAINT_CHECK_ERROR = ToSSErrorCode(7); constexpr ErrorCode SS_INVALID_ARGUMENT_ERROR = ToSSErrorCode(8); constexpr ErrorCode SS_OPERATION_PENDING = ToSSErrorCode(9); -namespace server { -class ServerException : public std::exception { - public: - explicit ServerException(ErrorCode error_code, const std::string& message = std::string()) - : error_code_(error_code), message_(message) { - } - - public: - ErrorCode - error_code() const { - return error_code_; - } - - virtual const char* - what() const noexcept { - return message_.c_str(); - } - - private: - ErrorCode error_code_; - std::string message_; -}; -} // namespace server - } // namespace milvus diff --git a/core/src/utils/Json.h b/core/src/utils/Json.h index 90a2a1e6..95a2c70d 100644 --- a/core/src/utils/Json.h +++ b/core/src/utils/Json.h @@ -8,10 +8,13 @@ // 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. + #pragma once #include "nlohmann/json.hpp" namespace milvus { + using json = nlohmann::json; -} + +} // namespace milvus diff --git a/core/src/utils/Log.cpp b/core/src/utils/Log.cpp index 500a997d..c91b08a8 100644 --- a/core/src/utils/Log.cpp +++ b/core/src/utils/Log.cpp @@ -8,6 +8,7 @@ // 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 "utils/Log.h" #include diff --git a/core/src/utils/Log.h b/core/src/utils/Log.h index 68e7d6f7..a1ab5d94 100644 --- a/core/src/utils/Log.h +++ b/core/src/utils/Log.h @@ -122,59 +122,6 @@ namespace milvus { #define LOG_WAL_ERROR_ LOG(ERROR) << WAL_MODULE_FUNCTION #define LOG_WAL_FATAL_ LOG(FATAL) << WAL_MODULE_FUNCTION -/* - * Deprecated - */ - -///////////////////////////////////////////////////////////////////////////////////////////////// -// #define SERVER_DOMAIN_NAME "[SERVER]" - -// #define LOG_SERVER_TRACE_ LOG(TRACE) << SERVER_DOMAIN_NAME -// #define LOG_SERVER_DEBUG_ LOG(DEBUG) << SERVER_DOMAIN_NAME -// #define LOG_SERVER_INFO_ LOG(INFO) << SERVER_DOMAIN_NAME -// #define LOG_SERVER_WARNING_ LOG(WARNING) << SERVER_DOMAIN_NAME -// #define LOG_SERVER_ERROR_ LOG(ERROR) << SERVER_DOMAIN_NAME -// #define LOG_SERVER_FATAL_ LOG(FATAL) << SERVER_DOMAIN_NAME - -///////////////////////////////////////////////////////////////////////////////////////////////// -// #define ENGINE_DOMAIN_NAME "[ENGINE]" - -// #define LOG_ENGINE_TRACE_ LOG(TRACE) << ENGINE_DOMAIN_NAME -// #define LOG_ENGINE_DEBUG_ LOG(DEBUG) << ENGINE_DOMAIN_NAME -// #define LOG_ENGINE_INFO_ LOG(INFO) << ENGINE_DOMAIN_NAME -// #define LOG_ENGINE_WARNING_ LOG(WARNING) << ENGINE_DOMAIN_NAME -// #define LOG_ENGINE_ERROR_ LOG(ERROR) << ENGINE_DOMAIN_NAME -// #define LOG_ENGINE_FATAL_ LOG(FATAL) << ENGINE_DOMAIN_NAME - -///////////////////////////////////////////////////////////////////////////////////////////////// -// #define WRAPPER_DOMAIN_NAME "[WRAPPER]" - -// #define WRAPPER_LOG_TRACE LOG(TRACE) << WRAPPER_DOMAIN_NAME -// #define WRAPPER_LOG_DEBUG LOG(DEBUG) << WRAPPER_DOMAIN_NAME -// #define WRAPPER_LOG_INFO LOG(INFO) << WRAPPER_DOMAIN_NAME -// #define WRAPPER_LOG_WARNING LOG(WARNING) << WRAPPER_DOMAIN_NAME -// #define WRAPPER_LOG_ERROR LOG(ERROR) << WRAPPER_DOMAIN_NAME -// #define WRAPPER_LOG_FATAL LOG(FATAL) << WRAPPER_DOMAIN_NAME - -///////////////////////////////////////////////////////////////////////////////////////////////// -// #define STORAGE_DOMAIN_NAME "[STORAGE]" - -// #define LOG_STORAGE_TRACE_ LOG(TRACE) << STORAGE_DOMAIN_NAME -// #define LOG_STORAGE_DEBUG_ LOG(DEBUG) << STORAGE_DOMAIN_NAME -// #define LOG_STORAGE_INFO_ LOG(INFO) << STORAGE_DOMAIN_NAME -// #define LOG_STORAGE_WARNING_ LOG(WARNING) << STORAGE_DOMAIN_NAME -// #define LOG_STORAGE_ERROR_ LOG(ERROR) << STORAGE_DOMAIN_NAME -// #define LOG_STORAGE_FATAL_ LOG(FATAL) << STORAGE_DOMAIN_NAME - -// #define WAL_DOMAIN_NAME "[WAL]" - -// #define LOG_WAL_TRACE_ LOG(TRACE) << WAL_DOMAIN_NAME -// #define LOG_WAL_DEBUG_ LOG(DEBUG) << WAL_DOMAIN_NAME -// #define LOG_WAL_INFO_ LOG(INFO) << WAL_DOMAIN_NAME -// #define LOG_WAL_WARNING_ LOG(WARNING) << WAL_DOMAIN_NAME -// #define LOG_WAL_ERROR_ LOG(ERROR) << WAL_DOMAIN_NAME -// #define LOG_WAL_FATAL_ LOG(FATAL) << WAL_DOMAIN_NAME - ///////////////////////////////////////////////////////////////////////////////////////////////////// std::string LogOut(const char* pattern, ...); diff --git a/core/src/utils/LogUtil.cpp b/core/src/utils/LogUtil.cpp index 1491c738..3233fe47 100644 --- a/core/src/utils/LogUtil.cpp +++ b/core/src/utils/LogUtil.cpp @@ -23,7 +23,6 @@ #include "utils/Log.h" namespace milvus { -namespace server { namespace { static int global_idx = 0; @@ -191,13 +190,13 @@ InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_ena } fiu_do_on("LogUtil.InitLog.set_max_log_size_small_than_min", - max_log_file_size = CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN - 1); - if (max_log_file_size < CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN || - max_log_file_size > CONFIG_LOGS_MAX_LOG_FILE_SIZE_MAX) { + max_log_file_size = server::CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN - 1); + if (max_log_file_size < server::CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN || + max_log_file_size > server::CONFIG_LOGS_MAX_LOG_FILE_SIZE_MAX) { return Status(SERVER_UNEXPECTED_ERROR, "max_log_file_size must in range[" + - std::to_string(CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN) + ", " + - std::to_string(CONFIG_LOGS_MAX_LOG_FILE_SIZE_MAX) + "], now is " + - std::to_string(max_log_file_size)); + std::to_string(server::CONFIG_LOGS_MAX_LOG_FILE_SIZE_MIN) + ", " + + std::to_string(server::CONFIG_LOGS_MAX_LOG_FILE_SIZE_MAX) + + "], now is " + std::to_string(max_log_file_size)); } defaultConf.setGlobally(el::ConfigurationType::MaxLogFileSize, std::to_string(max_log_file_size)); el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck); @@ -206,12 +205,14 @@ InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_ena // set delete_exceeds = 0 means disable throw away log file even they reach certain limit. if (delete_exceeds != 0) { - fiu_do_on("LogUtil.InitLog.delete_exceeds_small_than_min", delete_exceeds = CONFIG_LOGS_LOG_ROTATE_NUM_MIN - 1); - if (delete_exceeds < CONFIG_LOGS_LOG_ROTATE_NUM_MIN || delete_exceeds > CONFIG_LOGS_LOG_ROTATE_NUM_MAX) { + fiu_do_on("LogUtil.InitLog.delete_exceeds_small_than_min", + delete_exceeds = server::CONFIG_LOGS_LOG_ROTATE_NUM_MIN - 1); + if (delete_exceeds < server::CONFIG_LOGS_LOG_ROTATE_NUM_MIN || + delete_exceeds > server::CONFIG_LOGS_LOG_ROTATE_NUM_MAX) { return Status(SERVER_UNEXPECTED_ERROR, "delete_exceeds must in range[" + - std::to_string(CONFIG_LOGS_LOG_ROTATE_NUM_MIN) + ", " + - std::to_string(CONFIG_LOGS_LOG_ROTATE_NUM_MAX) + "], now is " + - std::to_string(delete_exceeds)); + std::to_string(server::CONFIG_LOGS_LOG_ROTATE_NUM_MIN) + ", " + + std::to_string(server::CONFIG_LOGS_LOG_ROTATE_NUM_MAX) + + "], now is " + std::to_string(delete_exceeds)); } enable_log_delete = true; logs_delete_exceeds = delete_exceeds; @@ -235,7 +236,7 @@ LogConfigInFile(const std::string& path) { void LogConfigInMem() { - auto& config = Config::GetInstance(); + auto& config = server::Config::GetInstance(); std::string config_str; config.GetConfigJsonStr(config_str, 3); LOG_SERVER_INFO_ << "\n\n" @@ -267,5 +268,4 @@ LogCpuInfo() { LOG_SERVER_INFO_ << "\n\n" << std::string(15, '*') << "CPU" << std::string(15, '*') << "\n\n" << sub_str; } -} // namespace server } // namespace milvus diff --git a/core/src/utils/LogUtil.h b/core/src/utils/LogUtil.h index 7c9b2533..687ea461 100644 --- a/core/src/utils/LogUtil.h +++ b/core/src/utils/LogUtil.h @@ -18,7 +18,6 @@ #include namespace milvus { -namespace server { Status InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_enable, bool error_enable, @@ -43,5 +42,4 @@ LogConfigInMem(); void LogCpuInfo(); -} // namespace server } // namespace milvus diff --git a/core/src/utils/SignalHandler.cpp b/core/src/utils/SignalHandler.cpp index a6341057..69ef16fe 100644 --- a/core/src/utils/SignalHandler.cpp +++ b/core/src/utils/SignalHandler.cpp @@ -17,7 +17,6 @@ #include namespace milvus { -namespace server { signal_func_ptr signal_routine_func = nullptr; @@ -59,5 +58,4 @@ PrintStacktrace() { free(stacktrace); } -} // namespace server } // namespace milvus diff --git a/core/src/utils/SignalHandler.h b/core/src/utils/SignalHandler.h index 2e76a70f..5c58886e 100644 --- a/core/src/utils/SignalHandler.h +++ b/core/src/utils/SignalHandler.h @@ -14,7 +14,6 @@ #include namespace milvus { -namespace server { typedef void (*signal_func_ptr)(int32_t); @@ -26,5 +25,4 @@ HandleSignal(int signum); extern void PrintStacktrace(); -} // namespace server } // namespace milvus diff --git a/core/src/utils/StringHelpFunctions.cpp b/core/src/utils/StringHelpFunctions.cpp index d8ec33b2..3f9e111b 100644 --- a/core/src/utils/StringHelpFunctions.cpp +++ b/core/src/utils/StringHelpFunctions.cpp @@ -17,7 +17,6 @@ #include namespace milvus { -namespace server { void StringHelpFunctions::TrimStringBlank(std::string& string) { @@ -161,5 +160,4 @@ StringHelpFunctions::ConvertToBoolean(const std::string& str, bool& value) { return Status::OK(); } -} // namespace server } // namespace milvus diff --git a/core/src/utils/StringHelpFunctions.h b/core/src/utils/StringHelpFunctions.h index 48dd9ceb..2b779084 100644 --- a/core/src/utils/StringHelpFunctions.h +++ b/core/src/utils/StringHelpFunctions.h @@ -17,7 +17,6 @@ #include namespace milvus { -namespace server { class StringHelpFunctions { private: @@ -72,5 +71,4 @@ class StringHelpFunctions { ConvertToBoolean(const std::string& str, bool& value); }; -} // namespace server } // namespace milvus diff --git a/core/src/utils/TimeRecorder.h b/core/src/utils/TimeRecorder.h index ac114149..5103513c 100644 --- a/core/src/utils/TimeRecorder.h +++ b/core/src/utils/TimeRecorder.h @@ -16,6 +16,7 @@ #include "utils/Log.h" namespace milvus { + inline void print_timestamp(const std::string& message) { std::chrono::time_point now = std::chrono::system_clock::now(); diff --git a/core/unittest/db/test_db.cpp b/core/unittest/db/test_db.cpp index f0f7901a..d21374e3 100644 --- a/core/unittest/db/test_db.cpp +++ b/core/unittest/db/test_db.cpp @@ -81,11 +81,11 @@ ConvertTimeRangeToDBDates(const std::string& start_value, const std::string& end time_t tt_start, tt_end; tm tm_start, tm_end; - if (!milvus::server::CommonUtil::TimeStrToTime(start_value, tt_start, tm_start)) { + if (!milvus::CommonUtil::TimeStrToTime(start_value, tt_start, tm_start)) { return; } - if (!milvus::server::CommonUtil::TimeStrToTime(end_value, tt_end, tm_end)) { + if (!milvus::CommonUtil::TimeStrToTime(end_value, tt_end, tm_end)) { return; } @@ -97,7 +97,7 @@ ConvertTimeRangeToDBDates(const std::string& start_value, const std::string& end for (int64_t i = 0; i < days; i++) { time_t tt_day = tt_start + DAY_SECONDS * i; tm tm_day; - milvus::server::CommonUtil::ConvertTime(tt_day, tm_day); + milvus::CommonUtil::ConvertTime(tt_day, tm_day); int64_t date = tm_day.tm_year * 10000 + tm_day.tm_mon * 100 + tm_day.tm_mday; // according to db logic dates.push_back(date); diff --git a/core/unittest/db/test_snapshot.cpp b/core/unittest/db/test_snapshot.cpp index 41eace44..35283439 100644 --- a/core/unittest/db/test_snapshot.cpp +++ b/core/unittest/db/test_snapshot.cpp @@ -60,8 +60,8 @@ using FieldElement = milvus::engine::snapshot::FieldElement; using Snapshots = milvus::engine::snapshot::Snapshots; using ScopedSnapshotT = milvus::engine::snapshot::ScopedSnapshotT; using ReferenceProxy = milvus::engine::snapshot::ReferenceProxy; -using Queue = milvus::server::BlockingQueue; -using TQueue = milvus::server::BlockingQueue>; +using Queue = milvus::BlockingQueue; +using TQueue = milvus::BlockingQueue>; int RandomInt(int start, int end) { std::random_device dev; diff --git a/core/unittest/db/test_web.cpp b/core/unittest/db/test_web.cpp index 8566787c..242d9fa9 100644 --- a/core/unittest/db/test_web.cpp +++ b/core/unittest/db/test_web.cpp @@ -1268,7 +1268,7 @@ TEST_F(WebControllerTest, GET_VECTORS_BY_IDS) { } std::string query_ids; - milvus::server::StringHelpFunctions::MergeStringWithDelimeter(vector_ids, ",", query_ids); + milvus::StringHelpFunctions::MergeStringWithDelimeter(vector_ids, ",", query_ids); auto response = client_ptr->getVectors(collection_name, query_ids.c_str(), conncetion_ptr); ASSERT_EQ(OStatus::CODE_200.code, response->getStatusCode()) << response->readBodyToString()->c_str(); diff --git a/core/unittest/server/test_config.cpp b/core/unittest/server/test_config.cpp index 53482faf..2768c173 100644 --- a/core/unittest/server/test_config.cpp +++ b/core/unittest/server/test_config.cpp @@ -323,7 +323,7 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) { std::vector search_resources = {"gpu0"}; std::vector search_res_vec; std::string search_res_str; - milvus::server::StringHelpFunctions::MergeStringWithDelimeter( + milvus::StringHelpFunctions::MergeStringWithDelimeter( search_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, search_res_str); ASSERT_TRUE(config.SetGpuResourceConfigSearchResources(search_res_str).ok()); ASSERT_TRUE(config.GetGpuResourceConfigSearchResources(search_res_vec).ok()); @@ -334,7 +334,7 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) { std::vector build_index_resources = {"gpu0"}; std::vector build_index_res_vec; std::string build_index_res_str; - milvus::server::StringHelpFunctions::MergeStringWithDelimeter( + milvus::StringHelpFunctions::MergeStringWithDelimeter( build_index_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, build_index_res_str); ASSERT_TRUE(config.SetGpuResourceConfigBuildIndexResources(build_index_res_str).ok()); ASSERT_TRUE(config.GetGpuResourceConfigBuildIndexResources(build_index_res_vec).ok()); diff --git a/core/unittest/server/test_util.cpp b/core/unittest/server/test_util.cpp index 689893c8..eb20f1be 100644 --- a/core/unittest/server/test_util.cpp +++ b/core/unittest/server/test_util.cpp @@ -44,16 +44,11 @@ CopyStatus(milvus::Status& st1, milvus::Status& st2) { TEST(UtilTest, EXCEPTION_TEST) { std::string err_msg = "failed"; - milvus::server::ServerException ex(milvus::SERVER_UNEXPECTED_ERROR, err_msg); - ASSERT_EQ(ex.error_code(), milvus::SERVER_UNEXPECTED_ERROR); + milvus::Exception ex(milvus::SERVER_UNEXPECTED_ERROR, err_msg); + ASSERT_EQ(ex.code(), milvus::SERVER_UNEXPECTED_ERROR); std::string msg = ex.what(); ASSERT_EQ(msg, err_msg); - milvus::Exception ex1(milvus::SERVER_UNEXPECTED_ERROR, err_msg); - ASSERT_EQ(ex1.code(), milvus::SERVER_UNEXPECTED_ERROR); - msg = ex1.what(); - ASSERT_EQ(msg, err_msg); - std::string empty_err_msg; milvus::Exception empty_ex(milvus::SERVER_UNEXPECTED_ERROR, empty_err_msg); ASSERT_EQ(empty_ex.code(), milvus::SERVER_UNEXPECTED_ERROR); @@ -62,8 +57,8 @@ TEST(UtilTest, EXCEPTION_TEST) { } TEST(UtilTest, SIGNAL_TEST) { - milvus::server::HandleSignal(SIGINT); - milvus::server::HandleSignal(SIGABRT); + milvus::HandleSignal(SIGINT); + milvus::HandleSignal(SIGABRT); } TEST(UtilTest, COMMON_TEST) { @@ -86,50 +81,50 @@ TEST(UtilTest, COMMON_TEST) { std::string path1 = "/tmp/milvus_test/"; std::string path2 = path1 + "common_test_12345/"; std::string path3 = path2 + "abcdef"; - milvus::Status status = milvus::server::CommonUtil::CreateDirectory(path3); + milvus::Status status = milvus::CommonUtil::CreateDirectory(path3); ASSERT_TRUE(status.ok()); - status = milvus::server::CommonUtil::CreateDirectory(empty_path); + status = milvus::CommonUtil::CreateDirectory(empty_path); ASSERT_TRUE(status.ok()); // test again - status = milvus::server::CommonUtil::CreateDirectory(path3); + status = milvus::CommonUtil::CreateDirectory(path3); ASSERT_TRUE(status.ok()); - ASSERT_TRUE(milvus::server::CommonUtil::IsDirectoryExist(path3)); + ASSERT_TRUE(milvus::CommonUtil::IsDirectoryExist(path3)); - status = milvus::server::CommonUtil::DeleteDirectory(empty_path); + status = milvus::CommonUtil::DeleteDirectory(empty_path); ASSERT_TRUE(status.ok()); - status = milvus::server::CommonUtil::DeleteDirectory(path1); + status = milvus::CommonUtil::DeleteDirectory(path1); ASSERT_TRUE(status.ok()); // test again - status = milvus::server::CommonUtil::DeleteDirectory(path1); + status = milvus::CommonUtil::DeleteDirectory(path1); ASSERT_TRUE(status.ok()); - ASSERT_FALSE(milvus::server::CommonUtil::IsDirectoryExist(path1)); - ASSERT_FALSE(milvus::server::CommonUtil::IsFileExist(path1)); + ASSERT_FALSE(milvus::CommonUtil::IsDirectoryExist(path1)); + ASSERT_FALSE(milvus::CommonUtil::IsFileExist(path1)); - std::string exe_path = milvus::server::CommonUtil::GetExePath(); + std::string exe_path = milvus::CommonUtil::GetExePath(); ASSERT_FALSE(exe_path.empty()); fiu_enable("CommonUtil.GetExePath.readlink_fail", 1, NULL, 0); - exe_path = milvus::server::CommonUtil::GetExePath(); + exe_path = milvus::CommonUtil::GetExePath(); ASSERT_FALSE(!exe_path.empty()); fiu_disable("CommonUtil.GetExePath.readlink_fail"); fiu_enable("CommonUtil.GetExePath.exe_path_error", 1, NULL, 0); - exe_path = milvus::server::CommonUtil::GetExePath(); + exe_path = milvus::CommonUtil::GetExePath(); ASSERT_FALSE(exe_path.empty()); fiu_disable("CommonUtil.GetExePath.exe_path_error"); fiu_enable("CommonUtil.CreateDirectory.create_parent_fail", 1, NULL, 0); - status = milvus::server::CommonUtil::CreateDirectory(path3); + status = milvus::CommonUtil::CreateDirectory(path3); ASSERT_FALSE(status.ok()); fiu_disable("CommonUtil.CreateDirectory.create_parent_fail"); fiu_enable("CommonUtil.CreateDirectory.create_dir_fail", 1, NULL, 0); - status = milvus::server::CommonUtil::CreateDirectory(path3); + status = milvus::CommonUtil::CreateDirectory(path3); ASSERT_FALSE(status.ok()); fiu_disable("CommonUtil.CreateDirectory.create_dir_fail"); @@ -137,14 +132,14 @@ TEST(UtilTest, COMMON_TEST) { time(&tt); tm time_struct; memset(&time_struct, 0, sizeof(tm)); - milvus::server::CommonUtil::ConvertTime(tt, time_struct); + milvus::CommonUtil::ConvertTime(tt, time_struct); ASSERT_GE(time_struct.tm_year, 0); ASSERT_GE(time_struct.tm_mon, 0); ASSERT_GE(time_struct.tm_mday, 0); - milvus::server::CommonUtil::ConvertTime(time_struct, tt); + milvus::CommonUtil::ConvertTime(time_struct, tt); ASSERT_GT(tt, 0); - bool res = milvus::server::CommonUtil::TimeStrToTime("2019-03-23", tt, time_struct); + bool res = milvus::CommonUtil::TimeStrToTime("2019-03-23", tt, time_struct); ASSERT_EQ(time_struct.tm_year, 119); ASSERT_EQ(time_struct.tm_mon, 2); ASSERT_EQ(time_struct.tm_mday, 23); @@ -154,72 +149,72 @@ TEST(UtilTest, COMMON_TEST) { TEST(UtilTest, STRINGFUNCTIONS_TEST) { std::string str = " test str"; - milvus::server::StringHelpFunctions::TrimStringBlank(str); + milvus::StringHelpFunctions::TrimStringBlank(str); ASSERT_EQ(str, "test str"); str = "\"test str\""; - milvus::server::StringHelpFunctions::TrimStringQuote(str, "\""); + milvus::StringHelpFunctions::TrimStringQuote(str, "\""); ASSERT_EQ(str, "test str"); str = "a,b,c"; std::vector result; - milvus::server::StringHelpFunctions::SplitStringByDelimeter(str, ",", result); + milvus::StringHelpFunctions::SplitStringByDelimeter(str, ",", result); ASSERT_EQ(result.size(), 3UL); std::string merge_str; - milvus::server::StringHelpFunctions::MergeStringWithDelimeter(result, ",", merge_str); + milvus::StringHelpFunctions::MergeStringWithDelimeter(result, ",", merge_str); ASSERT_EQ(merge_str, "a,b,c"); result.clear(); - milvus::server::StringHelpFunctions::MergeStringWithDelimeter(result, ",", merge_str); + milvus::StringHelpFunctions::MergeStringWithDelimeter(result, ",", merge_str); ASSERT_TRUE(merge_str.empty()); - auto status = milvus::server::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); + auto status = milvus::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); ASSERT_TRUE(status.ok()); ASSERT_EQ(result.size(), 3UL); result.clear(); - status = milvus::server::StringHelpFunctions::SplitStringByQuote(str, ",", "", result); + status = milvus::StringHelpFunctions::SplitStringByQuote(str, ",", "", result); ASSERT_TRUE(status.ok()); ASSERT_EQ(result.size(), 3UL); str = "55,\"aa,gg,yy\",b"; result.clear(); - status = milvus::server::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); + status = milvus::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); ASSERT_TRUE(status.ok()); ASSERT_EQ(result.size(), 3UL); fiu_init(0); fiu_enable("StringHelpFunctions.SplitStringByQuote.invalid_index", 1, NULL, 0); result.clear(); - status = milvus::server::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); + status = milvus::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); ASSERT_FALSE(status.ok()); fiu_disable("StringHelpFunctions.SplitStringByQuote.invalid_index"); fiu_enable("StringHelpFunctions.SplitStringByQuote.index_gt_last", 1, NULL, 0); result.clear(); - status = milvus::server::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); + status = milvus::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); ASSERT_TRUE(status.ok()); fiu_disable("StringHelpFunctions.SplitStringByQuote.index_gt_last"); fiu_enable("StringHelpFunctions.SplitStringByQuote.invalid_index2", 1, NULL, 0); result.clear(); - status = milvus::server::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); + status = milvus::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); ASSERT_FALSE(status.ok()); fiu_disable("StringHelpFunctions.SplitStringByQuote.invalid_index2"); fiu_enable("StringHelpFunctions.SplitStringByQuote.last_is_end", 1, NULL, 0); result.clear(); - status = milvus::server::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); + status = milvus::StringHelpFunctions::SplitStringByQuote(str, ",", "\"", result); ASSERT_TRUE(status.ok()); fiu_disable("StringHelpFunctions.SplitStringByQuote.last_is_end2"); - ASSERT_TRUE(milvus::server::StringHelpFunctions::IsRegexMatch("abc", "abc")); - ASSERT_TRUE(milvus::server::StringHelpFunctions::IsRegexMatch("a8c", "a\\d.")); - ASSERT_FALSE(milvus::server::StringHelpFunctions::IsRegexMatch("abc", "a\\dc")); + ASSERT_TRUE(milvus::StringHelpFunctions::IsRegexMatch("abc", "abc")); + ASSERT_TRUE(milvus::StringHelpFunctions::IsRegexMatch("a8c", "a\\d.")); + ASSERT_FALSE(milvus::StringHelpFunctions::IsRegexMatch("abc", "a\\dc")); } TEST(UtilTest, BLOCKINGQUEUE_TEST) { - milvus::server::BlockingQueue bq; + milvus::BlockingQueue bq; static const size_t count = 10; bq.SetCapacity(count); @@ -251,13 +246,13 @@ TEST(UtilTest, LOG_TEST) { fiu_init(0); fiu_enable("LogUtil.InitLog.set_max_log_size_small_than_min", 1, NULL, 0); - auto status = milvus::server::InitLog(true, true, true, true, true, true, + auto status = milvus::InitLog(true, true, true, true, true, true, "/tmp/test_util", 1024 * 1024 * 1024, 10); // 1024 MB ASSERT_FALSE(status.ok()); fiu_disable("LogUtil.InitLog.set_max_log_size_small_than_min"); fiu_enable("LogUtil.InitLog.delete_exceeds_small_than_min", 1, NULL, 0); - status = milvus::server::InitLog(true, true, true, true, true, true, + status = milvus::InitLog(true, true, true, true, true, true, "/tmp/test_util", 1024 * 1024 * 1024, 10); // 1024 MB ASSERT_FALSE(status.ok()); fiu_disable("LogUtil.InitLog.delete_exceeds_small_than_min"); @@ -268,7 +263,7 @@ TEST(UtilTest, LOG_TEST) { fiu_enable("LogUtil.InitLog.trace_enable_to_false", 1, NULL, 0); fiu_enable("LogUtil.InitLog.error_enable_to_false", 1, NULL, 0); fiu_enable("LogUtil.InitLog.fatal_enable_to_false", 1, NULL, 0); - status = milvus::server::InitLog(true, true, true, true, true, true, + status = milvus::InitLog(true, true, true, true, true, true, "/tmp/test_util", 1024 * 1024 * 1024, 10); // 1024 MB ASSERT_TRUE(status.ok()) << status.message(); fiu_disable("LogUtil.InitLog.fatal_enable_to_false"); @@ -278,26 +273,26 @@ TEST(UtilTest, LOG_TEST) { fiu_disable("LogUtil.InitLog.debug_enable_to_false"); fiu_disable("LogUtil.InitLog.info_enable_to_false"); - status = milvus::server::InitLog(true, true, true, true, true, true, + status = milvus::InitLog(true, true, true, true, true, true, "/tmp/test_util", 1024 * 1024 * 1024, 10); // 1024 MB ASSERT_TRUE(status.ok()) << status.message(); EXPECT_FALSE(el::Loggers::hasFlag(el::LoggingFlag::NewLineForContainer)); EXPECT_FALSE(el::Loggers::hasFlag(el::LoggingFlag::LogDetailedCrashReason)); - std::string fname = milvus::server::CommonUtil::GetFileName(LOG_FILE_PATH); + std::string fname = milvus::CommonUtil::GetFileName(LOG_FILE_PATH); ASSERT_EQ(fname, "log_config.conf"); - ASSERT_NO_THROW(milvus::server::LogConfigInMem()); - ASSERT_NO_THROW(milvus::server::LogCpuInfo()); + ASSERT_NO_THROW(milvus::LogConfigInMem()); + ASSERT_NO_THROW(milvus::LogCpuInfo()); // test log config file - ASSERT_ANY_THROW(milvus::server::LogConfigInFile("log_config.conf")); + ASSERT_ANY_THROW(milvus::LogConfigInFile("log_config.conf")); const char * config_str = "server_config:\n address: 0.0.0.0\n port: 19530"; std::fstream fs("/tmp/config.yaml", std::ios_base::out); fs << config_str; fs.close(); - ASSERT_NO_THROW(milvus::server::LogConfigInFile("/tmp/config.yaml")); + ASSERT_NO_THROW(milvus::LogConfigInFile("/tmp/config.yaml")); boost::filesystem::remove("/tmp/config.yaml"); } @@ -826,7 +821,7 @@ TEST(UtilTest, ROLLOUTHANDLER_TEST) { file.open(tmp.c_str()); file << "test" << std::endl; - milvus::server::RolloutHandler(tmp.c_str(), 0, list[i]); + milvus::RolloutHandler(tmp.c_str(), 0, list[i]); tmp.append(".1"); std::ifstream file2; @@ -842,7 +837,7 @@ TEST(UtilTest, ROLLOUTHANDLER_TEST) { std::ofstream file; file.open(tmp.c_str()); file << "test" << std::endl; - milvus::server::RolloutHandler(tmp.c_str(), 0, el::Level::Unknown); + milvus::RolloutHandler(tmp.c_str(), 0, el::Level::Unknown); tmp.append(".1"); std::ifstream file2; file2.open(tmp); diff --git a/core/unittest/server/utils.cpp b/core/unittest/server/utils.cpp index 0c32f733..184466dc 100644 --- a/core/unittest/server/utils.cpp +++ b/core/unittest/server/utils.cpp @@ -92,7 +92,7 @@ WriteToFile(const std::string& file_path, const char* content) { void ConfigTest::SetUp() { std::string config_path(CONFIG_PATH); - milvus::server::CommonUtil::CreateDirectory(config_path); + milvus::CommonUtil::CreateDirectory(config_path); WriteToFile(config_path + VALID_CONFIG_FILE, VALID_CONFIG_STR); WriteToFile(config_path + INVALID_CONFIG_FILE, INVALID_CONFIG_STR); } @@ -100,5 +100,5 @@ ConfigTest::SetUp() { void ConfigTest::TearDown() { std::string config_path(CONFIG_PATH); - milvus::server::CommonUtil::DeleteDirectory(config_path); + milvus::CommonUtil::DeleteDirectory(config_path); } diff --git a/core/unittest/storage/utils.cpp b/core/unittest/storage/utils.cpp index fa1b4e67..ac25b804 100644 --- a/core/unittest/storage/utils.cpp +++ b/core/unittest/storage/utils.cpp @@ -44,7 +44,7 @@ WriteToFile(const std::string& file_path, const char* content) { void StorageTest::SetUp() { std::string config_path(CONFIG_PATH); - milvus::server::CommonUtil::CreateDirectory(config_path); + milvus::CommonUtil::CreateDirectory(config_path); config_path += CONFIG_FILE; WriteToFile(config_path, CONFIG_STR); @@ -55,5 +55,5 @@ StorageTest::SetUp() { void StorageTest::TearDown() { std::string config_path(CONFIG_PATH); - milvus::server::CommonUtil::DeleteDirectory(config_path); + milvus::CommonUtil::DeleteDirectory(config_path); } -- GitLab