diff --git a/.clang-tidy b/.clang-tidy index 2f4e5696cd7b5b740bfe94e4303ea58c1401e53e..88e28ad1f4f23eb29dc25ddb2a79c05b72328166 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -16,7 +16,11 @@ # under the License. # The checks defined here will be run and will display by default as warnings. -Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,google-*,modernize-*,-modernize-use-trailing-return-type' +Checks: > + -*, clang-diagnostic-*, -clang-diagnostic-error, + clang-analyzer-*, -clang-analyzer-alpha*, + google-*, -google-runtime-references, -google-readability-todo, + modernize-*, -modernize-pass-by-value # produce HeaderFilterRegex from core/build-support/lint_exclusions.txt with: # echo -n '^?!('; sed -e 's/*/\.*/g' core/build-support/lint_exclusions.txt | tr '\n' '|'; echo ')$' diff --git a/core/src/config/ConfigMgr.cpp b/core/src/config/ConfigMgr.cpp index a135f1a9e7180b2c2d6986b560259d35e576e536..9966e5ee14c4341160c21f0d2a23de72d113ea37 100644 --- a/core/src/config/ConfigMgr.cpp +++ b/core/src/config/ConfigMgr.cpp @@ -255,8 +255,9 @@ ConfigMgr::Attach(const std::string& name, ConfigObserver* observer) { void ConfigMgr::Detach(const std::string& name, ConfigObserver* observer) { std::lock_guard lock(observer_mutex_); - if (observers_.find(name) == observers_.end()) + if (observers_.find(name) == observers_.end()) { return; + } auto& ob_list = observers_[name]; ob_list.remove(observer); } @@ -264,8 +265,9 @@ ConfigMgr::Detach(const std::string& name, ConfigObserver* observer) { void ConfigMgr::Notify(const std::string& name) { std::lock_guard lock(observer_mutex_); - if (observers_.find(name) == observers_.end()) + if (observers_.find(name) == observers_.end()) { return; + } auto& ob_list = observers_[name]; for (auto& ob : ob_list) { ob->ConfigUpdate(name); diff --git a/core/src/config/ConfigType.cpp b/core/src/config/ConfigType.cpp index 2db20175ba6b78bc205361be601886bfd09960c4..20681844150c6a020a7a4d20b8f6d03aaf698bab 100644 --- a/core/src/config/ConfigType.cpp +++ b/core/src/config/ConfigType.cpp @@ -54,13 +54,14 @@ boundary_check(T val, T lower_bound, T upper_bound) { bool parse_bool(const std::string& str, std::string& err) { - if (!strcasecmp(str.c_str(), "true")) + if (!strcasecmp(str.c_str(), "true")) { return true; - else if (!strcasecmp(str.c_str(), "false")) + } else if (!strcasecmp(str.c_str(), "false")) { return false; - else + } else { err = "The specified value must be true or false"; - return false; + return false; + } } std::string @@ -80,16 +81,20 @@ parse_bytes(const std::string& str, std::string& err) { } std::string s = str; - if (is_number(s)) + if (is_number(s)) { return std::stoll(s); - if (s.length() == 0) + } + if (s.length() == 0) { return 0; + } auto last_two = s.substr(s.length() - 2, 2); auto last_one = s.substr(s.length() - 1); - if (is_alpha(last_two) && is_alpha(last_one)) - if (last_one == "b" or last_one == "B") + if (is_alpha(last_two) && is_alpha(last_one)) { + if (last_one == "b" or last_one == "B") { s = s.substr(0, s.length() - 1); + } + } auto& units = BYTE_UNITS; auto suffix = str_tolower(s.substr(s.length() - 1)); @@ -171,11 +176,13 @@ BoolConfig::Set(const std::string& val, bool update) { std::string err; bool value = parse_bool(val, err); - if (not err.empty()) + if (not err.empty()) { return ConfigStatus(SetReturn::INVALID, err); + } - if (is_valid_fn_ && not is_valid_fn_(value, err)) + if (is_valid_fn_ && not is_valid_fn_(value, err)) { return ConfigStatus(SetReturn::INVALID, err); + } bool prev = *config_; *config_ = value; @@ -227,8 +234,9 @@ StringConfig::Set(const std::string& val, bool update) { } std::string err; - if (is_valid_fn_ && not is_valid_fn_(val, err)) + if (is_valid_fn_ && not is_valid_fn_(val, err)) { return ConfigStatus(SetReturn::INVALID, err); + } std::string prev = *config_; *config_ = val; @@ -369,8 +377,9 @@ IntegerConfig::Set(const std::string& val, bool update) { } std::string err; - if (is_valid_fn_ && not is_valid_fn_(value, err)) + if (is_valid_fn_ && not is_valid_fn_(value, err)) { return ConfigStatus(SetReturn::INVALID, err); + } int64_t prev = *config_; *config_ = value; @@ -432,8 +441,9 @@ FloatingConfig::Set(const std::string& val, bool update) { } std::string err; - if (is_valid_fn_ && not is_valid_fn_(value, err)) + if (is_valid_fn_ && not is_valid_fn_(value, err)) { return ConfigStatus(SetReturn::INVALID, err); + } double prev = *config_; *config_ = value; diff --git a/core/src/index/knowhere/knowhere/common/Exception.cpp b/core/src/index/knowhere/knowhere/common/Exception.cpp index e267e48d23a1b7398365fa58a20a51e18442a9e8..7c379ab79069ee353af8772cb9a4e6d767e2e48c 100644 --- a/core/src/index/knowhere/knowhere/common/Exception.cpp +++ b/core/src/index/knowhere/knowhere/common/Exception.cpp @@ -10,6 +10,7 @@ // or implied. See the License for the specific language governing permissions and limitations under the License #include +#include #include "Log.h" #include "knowhere/common/Exception.h" @@ -17,15 +18,10 @@ namespace milvus { namespace knowhere { -KnowhereException::KnowhereException(const std::string& msg) : msg(msg) { +KnowhereException::KnowhereException(std::string msg) : msg_(std::move(msg)) { } KnowhereException::KnowhereException(const std::string& m, const char* funcName, const char* file, int line) { -#ifdef DEBUG - int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", funcName, file, line, m.c_str()); - msg.resize(size + 1); - snprintf(&msg[0], msg.size(), "Error in %s at %s:%d: %s", funcName, file, line, m.c_str()); -#else std::string filename; try { size_t pos; @@ -37,14 +33,13 @@ KnowhereException::KnowhereException(const std::string& m, const char* funcName, } int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str()); - msg.resize(size + 1); - snprintf(&msg[0], msg.size(), "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str()); -#endif + msg_.resize(size + 1); + snprintf(&msg_[0], msg_.size(), "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str()); } const char* KnowhereException::what() const noexcept { - return msg.c_str(); + return msg_.c_str(); } } // namespace knowhere diff --git a/core/src/index/knowhere/knowhere/common/Exception.h b/core/src/index/knowhere/knowhere/common/Exception.h index 76a08d1a903a678cb18ab2a1b2d9ec208978561a..709c3f6ec74ea599cdbadc7d3ca2393c48497218 100644 --- a/core/src/index/knowhere/knowhere/common/Exception.h +++ b/core/src/index/knowhere/knowhere/common/Exception.h @@ -19,14 +19,14 @@ namespace knowhere { class KnowhereException : public std::exception { public: - explicit KnowhereException(const std::string& msg); + explicit KnowhereException(std::string msg); KnowhereException(const std::string& msg, const char* funName, const char* file, int line); const char* what() const noexcept override; - std::string msg; + std::string msg_; }; #define KNOHWERE_ERROR_MSG(MSG) printf("%s", KnowhereException(MSG, __PRETTY_FUNCTION__, __FILE__, __LINE__).what()) diff --git a/core/src/index/knowhere/knowhere/common/Timer.cpp b/core/src/index/knowhere/knowhere/common/Timer.cpp index ac4c4607adf32db8076b666c5b2b11ad77ac0534..433653761a10b872508555d665c6c78e360cfd67 100644 --- a/core/src/index/knowhere/knowhere/common/Timer.cpp +++ b/core/src/index/knowhere/knowhere/common/Timer.cpp @@ -9,7 +9,8 @@ // 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 // TODO(linxj): using Log instead +#include +#include #include "knowhere/common/Log.h" #include "knowhere/common/Timer.h" @@ -17,13 +18,10 @@ namespace milvus { namespace knowhere { -TimeRecorder::TimeRecorder(const std::string& header, int64_t log_level) : header_(header), log_level_(log_level) { +TimeRecorder::TimeRecorder(std::string hdr, int64_t log_level) : header_(std::move(hdr)), log_level_(log_level) { start_ = last_ = stdclock::now(); } -TimeRecorder::~TimeRecorder() { -} - std::string TimeRecorder::GetTimeSpanStr(double span) { std::string str_sec = std::to_string(span * 0.000001) + ((span > 1000000) ? " seconds" : " second"); @@ -35,8 +33,9 @@ TimeRecorder::GetTimeSpanStr(double span) { void TimeRecorder::PrintTimeRecord(const std::string& msg, double span) { std::string str_log; - if (!header_.empty()) + if (!header_.empty()) { str_log += header_ + ": "; + } str_log += msg; str_log += " ("; str_log += TimeRecorder::GetTimeSpanStr(span); @@ -51,14 +50,17 @@ TimeRecorder::PrintTimeRecord(const std::string& msg, double span) { LOG_KNOWHERE_DEBUG_ << str_log; break; } - // case 2: { - // LOG_KNOWHERE_TRACE_ << str_log; - // break; - // } - // case 3: { - // LOG_KNOWHERE_WARNING_ << str_log; - // break; - // } + // case 2: { + // LOG_KNOWHERE_TRACE_ << str_log; + // break; + // } + // case 3: { + // LOG_KNOWHERE_WARNING_ << str_log; + // break; + // } + default: + LOG_KNOWHERE_DEBUG_ << str_log; + break; } } diff --git a/core/src/index/knowhere/knowhere/common/Timer.h b/core/src/index/knowhere/knowhere/common/Timer.h index 1e98c4ae99a2d26cf502001abc87ff469976388a..79a038535a2785e786332d6caad2941df6d9e259 100644 --- a/core/src/index/knowhere/knowhere/common/Timer.h +++ b/core/src/index/knowhere/knowhere/common/Timer.h @@ -21,9 +21,9 @@ class TimeRecorder { using stdclock = std::chrono::high_resolution_clock; public: - explicit TimeRecorder(const std::string& header, int64_t log_level = 0); - - ~TimeRecorder(); // trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5 + // trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5 + explicit TimeRecorder(std::string hdr, int64_t log_level = 0); + virtual ~TimeRecorder() = default; double RecordSection(const std::string& msg); diff --git a/core/src/metrics/SystemInfo.cpp b/core/src/metrics/SystemInfo.cpp index 9ca70c64f924ee08977eb94a831318ec898dd306..22bfdf963f179178e1856de9d1ee498c5bccaaf1 100644 --- a/core/src/metrics/SystemInfo.cpp +++ b/core/src/metrics/SystemInfo.cpp @@ -157,7 +157,7 @@ SystemInfo::MemoryPercent() { Init(); } - double mem_used = static_cast(GetProcessUsedMemory() * 100); + auto mem_used = static_cast(GetProcessUsedMemory() * 100); return mem_used / static_cast(total_ram_); } @@ -184,7 +184,7 @@ SystemInfo::getTotalCpuTime(std::vector& work_time_array) { try { FILE* file = fopen("/proc/stat", "r"); fiu_do_on("SystemInfo.getTotalCpuTime.open_proc", file = NULL); - if (file == NULL) { + if (file == nullptr) { LOG_SERVER_ERROR_ << "Failed to read /proc/stat"; return total_time_array; } @@ -196,7 +196,7 @@ SystemInfo::getTotalCpuTime(std::vector& work_time_array) { char buffer[1024]; char* ret = fgets(buffer, sizeof(buffer) - 1, file); fiu_do_on("SystemInfo.getTotalCpuTime.read_proc", ret = NULL); - if (ret == NULL) { + if (ret == nullptr) { LOG_SERVER_ERROR_ << "Could not read stat file"; fclose(file); return total_time_array; @@ -248,8 +248,9 @@ std::vector SystemInfo::GPUMemoryTotal() { // get GPU usage percent fiu_do_on("SystemInfo.GPUMemoryTotal.mock", initialized_ = false); - if (!initialized_) + if (!initialized_) { Init(); + } std::vector result; #ifdef MILVUS_GPU_VERSION @@ -268,8 +269,9 @@ SystemInfo::GPUMemoryTotal() { std::vector SystemInfo::GPUTemperature() { fiu_do_on("SystemInfo.GPUTemperature.mock", initialized_ = false); - if (!initialized_) + if (!initialized_) { Init(); + } std::vector result; #ifdef MILVUS_GPU_VERSION @@ -297,8 +299,8 @@ SystemInfo::CPUTemperature() { return result; } - struct dirent* ptr = NULL; - while ((ptr = readdir(dir)) != NULL) { + struct dirent* ptr = nullptr; + while ((ptr = readdir(dir)) != nullptr) { std::string filename(path); filename.append(ptr->d_name); @@ -335,8 +337,9 @@ std::vector SystemInfo::GPUMemoryUsed() { // get GPU memory used fiu_do_on("SystemInfo.GPUMemoryUsed.mock", initialized_ = false); - if (!initialized_) + if (!initialized_) { Init(); + } std::vector result; diff --git a/core/src/server/context/Context.cpp b/core/src/server/context/Context.cpp index d5f17cd3c022cf4c29fd6e361608793a75a27cbd..a0b2d98291a875451ed6fe39449cfedb7534dd19 100644 --- a/core/src/server/context/Context.cpp +++ b/core/src/server/context/Context.cpp @@ -9,21 +9,23 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express // or implied. See the License for the specific language governing permissions and limitations under the License. +#include + #include "server/context/Context.h" namespace milvus { namespace server { -Context::Context(const std::string& req_id) : req_id_(req_id) { +Context::Context(std::string req_id) : req_id_(std::move(req_id)) { } -const std::shared_ptr& +const tracing::TraceContextPtr& Context::GetTraceContext() const { return trace_context_; } void -Context::SetTraceContext(const std::shared_ptr& trace_context) { +Context::SetTraceContext(const tracing::TraceContextPtr& trace_context) { trace_context_ = trace_context; } std::shared_ptr diff --git a/core/src/server/context/Context.h b/core/src/server/context/Context.h index 5f89cf36e005c25d116ee3a401996f4647082291..5e88eda4e074a22ef41655ddc7030c492227100a 100644 --- a/core/src/server/context/Context.h +++ b/core/src/server/context/Context.h @@ -26,7 +26,7 @@ namespace server { class Context { public: - explicit Context(const std::string& request_id); + explicit Context(std::string request_id); inline std::string ReqID() const { @@ -40,9 +40,9 @@ class Context { Follower(const std::string& operation_name) const; void - SetTraceContext(const std::shared_ptr& trace_context); + SetTraceContext(const tracing::TraceContextPtr& trace_context); - const std::shared_ptr& + const tracing::TraceContextPtr& GetTraceContext() const; void @@ -60,7 +60,7 @@ class Context { private: std::string req_id_; ReqType req_type_; - std::shared_ptr trace_context_; + tracing::TraceContextPtr trace_context_; ConnectionContextPtr context_; }; diff --git a/core/src/server/delivery/ReqQueue.cpp b/core/src/server/delivery/ReqQueue.cpp index 6c7cd1e15b2c73b6e91c33180824ac3a6940fd0e..76f33a39c590360006ad32d3c382cd3641430943 100644 --- a/core/src/server/delivery/ReqQueue.cpp +++ b/core/src/server/delivery/ReqQueue.cpp @@ -48,12 +48,6 @@ ScheduleReq(const BaseReqPtr& req, std::queue& queue) { } // namespace //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -ReqQueue::ReqQueue() { -} - -ReqQueue::~ReqQueue() { -} - BaseReqPtr ReqQueue::TakeReq() { return Take(); diff --git a/core/src/server/delivery/ReqQueue.h b/core/src/server/delivery/ReqQueue.h index 2c0cbcc4961b31c277eab71d6ab3069fa56c4c4e..af84b1c8a0e2393199f375a4e4d8e70663f383b9 100644 --- a/core/src/server/delivery/ReqQueue.h +++ b/core/src/server/delivery/ReqQueue.h @@ -28,8 +28,8 @@ using BlockingReqQueue = BlockingQueue; class ReqQueue : public BlockingReqQueue { public: - ReqQueue(); - virtual ~ReqQueue(); + ReqQueue() = default; + virtual ~ReqQueue() = default; BaseReqPtr TakeReq(); diff --git a/core/src/server/delivery/request/Types.cpp b/core/src/server/delivery/request/Types.cpp index b9fbc6105dcbc116ed864f1fc51419edbd70fe8e..2f903f9202fd4c95f21e41eac0b290885ee7d2ed 100644 --- a/core/src/server/delivery/request/Types.cpp +++ b/core/src/server/delivery/request/Types.cpp @@ -63,7 +63,7 @@ GetReqGroup(ReqType type) { auto iter = s_map_type_group.find(type); if (iter == s_map_type_group.end()) { - LOG_SERVER_ERROR_ << "Unsupported request type: " << (int32_t)type; + LOG_SERVER_ERROR_ << "Unsupported request type: " << static_cast(type); throw Exception(SERVER_NOT_IMPLEMENT, "request group undefined"); } return iter->second; diff --git a/core/src/server/grpc_impl/GrpcRequestHandler.cpp b/core/src/server/grpc_impl/GrpcRequestHandler.cpp index a2ad97bcf79591abeb4da89e2f7067f92f5340bb..409cd6d55a612ce303d436d1c3bb757b3db4c078 100644 --- a/core/src/server/grpc_impl/GrpcRequestHandler.cpp +++ b/core/src/server/grpc_impl/GrpcRequestHandler.cpp @@ -726,7 +726,7 @@ GrpcRequestHandler::CreateCollection(::grpc::ServerContext* context, const ::mil const auto& field = request->fields(i); FieldSchema field_schema; - field_schema.field_type_ = (engine::DataType)field.type(); + field_schema.field_type_ = static_cast(field.type()); // Currently only one extra_param if (field.extra_params_size() != 0) { @@ -1127,7 +1127,7 @@ GrpcRequestHandler::Cmd(::grpc::ServerContext* context, const ::milvus::grpc::Co auto request_str = RequestMap(iter.second->GetReqType()) + "-" + iter.second->ReqID(); requests.emplace_back(request_str); } - nlohmann::json reply_json; + milvus::json reply_json; reply_json["requests"] = requests; reply = reply_json.dump(); response->set_string_reply(reply); @@ -1438,8 +1438,7 @@ GrpcRequestHandler::SearchPB(::grpc::ServerContext* context, const ::milvus::grp #if 0 Status -ParseTermQuery(const nlohmann::json& term_json, - std::unordered_map field_type, +ParseTermQuery(const milvus::json& term_json, std::unordered_map field_type, query::TermQueryPtr& term_query) { std::string field_name = term_json["field"].get(); auto term_value_json = term_json["values"]; @@ -1506,7 +1505,7 @@ ParseTermQuery(const nlohmann::json& term_json, } Status -ParseRangeQuery(const nlohmann::json& range_json, query::RangeQueryPtr& range_query) { +ParseRangeQuery(const milvus::json& range_json, query::RangeQueryPtr& range_query) { std::string field_name = range_json["field"]; range_query->field_name = field_name; @@ -1552,36 +1551,35 @@ ParseRangeQuery(const nlohmann::json& range_json, query::RangeQueryPtr& range_qu #endif Status -GrpcRequestHandler::ProcessLeafQueryJson(const nlohmann::json& json, query::BooleanQueryPtr& query, +GrpcRequestHandler::ProcessLeafQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& query, std::string& field_name) { - auto status = Status::OK(); - if (json.contains("term")) { + if (query_json.contains("term")) { auto leaf_query = std::make_shared(); auto term_query = std::make_shared(); - nlohmann::json json_obj = json["term"]; + milvus::json json_obj = query_json["term"]; JSON_NULL_CHECK(json_obj); JSON_OBJECT_CHECK(json_obj); term_query->json_obj = json_obj; - nlohmann::json::iterator json_it = json_obj.begin(); + milvus::json::iterator json_it = json_obj.begin(); field_name = json_it.key(); leaf_query->term_query = term_query; query->AddLeafQuery(leaf_query); - } else if (json.contains("range")) { + } else if (query_json.contains("range")) { auto leaf_query = std::make_shared(); auto range_query = std::make_shared(); - nlohmann::json json_obj = json["range"]; + milvus::json json_obj = query_json["range"]; JSON_NULL_CHECK(json_obj); JSON_OBJECT_CHECK(json_obj); range_query->json_obj = json_obj; - nlohmann::json::iterator json_it = json_obj.begin(); + milvus::json::iterator json_it = json_obj.begin(); field_name = json_it.key(); leaf_query->range_query = range_query; query->AddLeafQuery(leaf_query); - } else if (json.contains("vector")) { + } else if (query_json.contains("vector")) { auto leaf_query = std::make_shared(); - auto vector_json = json["vector"]; + auto vector_json = query_json["vector"]; JSON_NULL_CHECK(vector_json); leaf_query->vector_placeholder = vector_json.get(); @@ -1589,13 +1587,12 @@ GrpcRequestHandler::ProcessLeafQueryJson(const nlohmann::json& json, query::Bool } else { return Status{SERVER_INVALID_ARGUMENT, "Leaf query get wrong key"}; } - return status; + return Status::OK(); } Status -GrpcRequestHandler::ProcessBooleanQueryJson(const nlohmann::json& query_json, query::BooleanQueryPtr& boolean_query, +GrpcRequestHandler::ProcessBooleanQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& boolean_query, query::QueryPtr& query_ptr) { - auto status = Status::OK(); if (query_json.empty()) { return Status{SERVER_INVALID_ARGUMENT, "BoolQuery is null"}; } @@ -1669,7 +1666,7 @@ GrpcRequestHandler::ProcessBooleanQueryJson(const nlohmann::json& query_json, qu } } - return status; + return Status::OK(); } Status @@ -1677,29 +1674,25 @@ GrpcRequestHandler::DeserializeJsonToBoolQuery( const google::protobuf::RepeatedPtrField<::milvus::grpc::VectorParam>& vector_params, const std::string& dsl_string, query::BooleanQueryPtr& boolean_query, query::QueryPtr& query_ptr) { try { - nlohmann::json dsl_json = json::parse(dsl_string); + milvus::json dsl_json = json::parse(dsl_string); if (dsl_json.empty()) { return Status{SERVER_INVALID_ARGUMENT, "Query dsl is null"}; } - auto status = Status::OK(); for (const auto& vector_param : vector_params) { const std::string& vector_string = vector_param.json(); - nlohmann::json vector_json = json::parse(vector_string); - json::iterator it = vector_json.begin(); + milvus::json vector_json = json::parse(vector_string); + milvus::json::iterator it = vector_json.begin(); std::string placeholder = it.key(); auto vector_query = std::make_shared(); - json::iterator vector_param_it = it.value().begin(); + milvus::json::iterator vector_param_it = it.value().begin(); if (vector_param_it != it.value().end()) { const std::string& field_name = vector_param_it.key(); vector_query->field_name = field_name; - nlohmann::json param_json = vector_param_it.value(); + milvus::json param_json = vector_param_it.value(); int64_t topk = param_json["topk"]; - status = server::ValidateSearchTopk(topk); - if (!status.ok()) { - return status; - } + STATUS_CHECK(server::ValidateSearchTopk(topk)); vector_query->topk = topk; if (param_json.contains("metric_type")) { std::string metric_type = param_json["metric_type"]; @@ -1723,12 +1716,9 @@ GrpcRequestHandler::DeserializeJsonToBoolQuery( if (dsl_json.contains("bool")) { auto boolean_query_json = dsl_json["bool"]; JSON_NULL_CHECK(boolean_query_json); - status = ProcessBooleanQueryJson(boolean_query_json, boolean_query, query_ptr); - if (!status.ok()) { - return status; - } + STATUS_CHECK(ProcessBooleanQueryJson(boolean_query_json, boolean_query, query_ptr)); } - return status; + return Status::OK(); } catch (std::exception& e) { return Status{SERVER_INVALID_DSL_PARAMETER, e.what()}; } diff --git a/core/src/server/grpc_impl/GrpcRequestHandler.h b/core/src/server/grpc_impl/GrpcRequestHandler.h index f021cd50c2ad147667ec329b98d99ebf0f1ed484..ccdc8d4671186c7c37b3a2233f735f1b436c3907 100644 --- a/core/src/server/grpc_impl/GrpcRequestHandler.h +++ b/core/src/server/grpc_impl/GrpcRequestHandler.h @@ -324,11 +324,11 @@ class GrpcRequestHandler final : public ::milvus::grpc::MilvusService::Service, query::QueryPtr& query_ptr); Status - ProcessBooleanQueryJson(const nlohmann::json& query_json, query::BooleanQueryPtr& boolean_query, + ProcessBooleanQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& boolean_query, query::QueryPtr& query_ptr); Status - ProcessLeafQueryJson(const nlohmann::json& json, query::BooleanQueryPtr& query, std::string& field_name); + ProcessLeafQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& query, std::string& field_name); private: ReqHandler req_handler_; diff --git a/core/src/server/init/InstanceLockCheck.cpp b/core/src/server/init/InstanceLockCheck.cpp index 6cda2f116ad8514aae397855218f6d333dd0c3ff..9d8fb8515d1036018f983f2a9996b868ce9bc19b 100644 --- a/core/src/server/init/InstanceLockCheck.cpp +++ b/core/src/server/init/InstanceLockCheck.cpp @@ -11,10 +11,9 @@ #include "server/init/InstanceLockCheck.h" -#include #include -#include #include +#include #include diff --git a/core/src/storage/ExtraFileInfo.cpp b/core/src/storage/ExtraFileInfo.cpp index 7abe6ef997613f69b3034d8be346c381718f0aa0..fef6bd20efbb639e0e557c2df0f3104b86ba4647 100644 --- a/core/src/storage/ExtraFileInfo.cpp +++ b/core/src/storage/ExtraFileInfo.cpp @@ -43,7 +43,7 @@ WriteMagic(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path) { LOG_ENGINE_ERROR_ << err_msg; throw Exception(SERVER_WRITE_ERROR, err_msg); } - fs_ptr->writer_ptr_->Write((void*)MAGIC, MAGIC_SIZE); + fs_ptr->writer_ptr_->Write((void*)(MAGIC), MAGIC_SIZE); fs_ptr->writer_ptr_->Close(); } @@ -136,7 +136,7 @@ CheckSum(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path) { fs_ptr->reader_ptr_->Close(); - auto sum = (uint8_t)atoi(record); + auto sum = static_cast(atoi(record)); return sum == result; } diff --git a/core/src/tracing/TraceContext.h b/core/src/tracing/TraceContext.h index 84de27fc9c52b68673bf5192d72983a03540ffcd..e215cce19a074941f231f663c314a8750d31c535 100644 --- a/core/src/tracing/TraceContext.h +++ b/core/src/tracing/TraceContext.h @@ -37,5 +37,7 @@ class TraceContext { std::unique_ptr span_; }; +using TraceContextPtr = std::shared_ptr; + } // namespace tracing } // namespace milvus diff --git a/core/src/utils/ConfigUtils.cpp b/core/src/utils/ConfigUtils.cpp index 4cf49a9a1104c26de9757c28f94e232b30e9167a..f4d810252bd56c48c634f9725df8424bfa4bc346 100644 --- a/core/src/utils/ConfigUtils.cpp +++ b/core/src/utils/ConfigUtils.cpp @@ -66,16 +66,20 @@ int64_t parse_bytes(const std::string& str, std::string& err) { try { std::string s = str; - if (is_number(s)) + if (is_number(s)) { return std::stoll(s); - if (s.length() == 0) + } + if (s.length() == 0) { return 0; + } auto last_two = s.substr(s.length() - 2, 2); auto last_one = s.substr(s.length() - 1); - if (is_alpha(last_two) && is_alpha(last_one)) - if (last_one == "b" or last_one == "B") + if (is_alpha(last_two) && is_alpha(last_one)) { + if (last_one == "b" or last_one == "B") { s = s.substr(0, s.length() - 1); + } + } auto& units = BYTE_UNITS; auto suffix = str_tolower(s.substr(s.length() - 1)); diff --git a/core/src/utils/Exception.h b/core/src/utils/Exception.h index abf1d1d01e3a780c9d6efa4d700d593808fafaec..454fcb508f478df60a5c426add887cdcf0ef9082 100644 --- a/core/src/utils/Exception.h +++ b/core/src/utils/Exception.h @@ -15,6 +15,7 @@ #include #include +#include namespace milvus { @@ -24,7 +25,7 @@ namespace milvus { class Exception : public std::exception { public: - Exception(ErrorCode code, const std::string& message) : code_(code), message_(message) { + Exception(ErrorCode code, std::string msg) : code_(code), message_(std::move(msg)) { } ErrorCode diff --git a/core/src/utils/Status.cpp b/core/src/utils/Status.cpp index a4f987bdf2035f43f6d075b414e1ccff341576cf..75293c181de310d9cb1d6630b2a81c328e4a6603 100644 --- a/core/src/utils/Status.cpp +++ b/core/src/utils/Status.cpp @@ -21,7 +21,7 @@ Status::Status(StatusCode code, const std::string& msg) { // 4 bytes store code // 4 bytes store message length // the left bytes store message string - const uint32_t length = (uint32_t)msg.size(); + auto length = static_cast(msg.size()); auto result = new char[length + sizeof(length) + CODE_WIDTH]; std::memcpy(result, &code, CODE_WIDTH); std::memcpy(result + CODE_WIDTH, &length, sizeof(length)); diff --git a/core/src/utils/TimeRecorder.cpp b/core/src/utils/TimeRecorder.cpp index cb8b674753cdd852b94cdea28771893d12fc77e3..d26f83425194b30c5758fe8d0e5b37569e55dc71 100644 --- a/core/src/utils/TimeRecorder.cpp +++ b/core/src/utils/TimeRecorder.cpp @@ -9,17 +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 "utils/TimeRecorder.h" +#include + #include "utils/Log.h" +#include "utils/TimeRecorder.h" namespace milvus { -TimeRecorder::TimeRecorder(const std::string& header, int64_t log_level) : header_(header), log_level_(log_level) { +TimeRecorder::TimeRecorder(std::string hdr, int64_t log_level) : header_(std::move(hdr)), log_level_(log_level) { start_ = last_ = stdclock::now(); } -TimeRecorder::~TimeRecorder() = default; - std::string TimeRecorder::GetTimeSpanStr(double span) { std::string str_sec = std::to_string(span * 0.000001) + ((span > 1000000) ? " seconds" : " second"); @@ -89,7 +89,7 @@ TimeRecorder::ElapseFromBegin(const std::string& msg) { return span; } -TimeRecorderAuto::TimeRecorderAuto(const std::string& header, int64_t log_level) : TimeRecorder(header, log_level) { +TimeRecorderAuto::TimeRecorderAuto(std::string hdr, int64_t log_level) : TimeRecorder(hdr, log_level) { } TimeRecorderAuto::~TimeRecorderAuto() { diff --git a/core/src/utils/TimeRecorder.h b/core/src/utils/TimeRecorder.h index 5103513cfa981859ac7aaf870dd2beafe5ada674..ffab6c5b88da2cb233ee41349ea041e1d1cffd59 100644 --- a/core/src/utils/TimeRecorder.h +++ b/core/src/utils/TimeRecorder.h @@ -32,9 +32,9 @@ class TimeRecorder { using stdclock = std::chrono::high_resolution_clock; public: - explicit TimeRecorder(const std::string& header, int64_t log_level = 1); - - virtual ~TimeRecorder(); // trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5 + // trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5 + explicit TimeRecorder(std::string hdr, int64_t log_level = 1); + virtual ~TimeRecorder() = default; double RecordSection(const std::string& msg); @@ -58,8 +58,7 @@ class TimeRecorder { class TimeRecorderAuto : public TimeRecorder { public: - explicit TimeRecorderAuto(const std::string& header, int64_t log_level = 1); - + explicit TimeRecorderAuto(std::string hdr, int64_t log_level = 1); ~TimeRecorderAuto() override; };