Skip to content

Commit

Permalink
Add code for PanicInfo (#27364)
Browse files Browse the repository at this point in the history
Signed-off-by: Enwei Jiao <[email protected]>
  • Loading branch information
jiaoew1991 authored Sep 27, 2023
1 parent 4071132 commit b80a3e1
Show file tree
Hide file tree
Showing 47 changed files with 680 additions and 426 deletions.
11 changes: 5 additions & 6 deletions internal/core/src/common/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ class Array {
return true;
}
default:
PanicCodeInfo(Unsupported,
"unsupported element type for array");
PanicInfo(Unsupported, "unsupported element type for array");
}
}

Expand Down Expand Up @@ -264,8 +263,8 @@ class Array {
return static_cast<T>(
reinterpret_cast<double*>(data_)[index]);
default:
PanicCodeInfo(Unsupported,
"unsupported element type for array");
PanicInfo(Unsupported,
"unsupported element type for array");
}
}
return reinterpret_cast<T*>(data_)[index];
Expand Down Expand Up @@ -481,8 +480,8 @@ class ArrayView {
return static_cast<T>(
reinterpret_cast<double*>(data_)[index]);
default:
PanicCodeInfo(Unsupported,
"unsupported element type for array");
PanicInfo(Unsupported,
"unsupported element type for array");
}
}
return reinterpret_cast<T*>(data_)[index];
Expand Down
11 changes: 4 additions & 7 deletions internal/core/src/common/EasyAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ enum ErrorCode {
DataFormatBroken = 2024,
JsonKeyInvalid = 2025,
MetricTypeInvalid = 2026,
FieldNotLoaded = 2027,
ExprInvalid = 2028,
UnistdError = 2030,
KnowhereError = 2100,
};
Expand All @@ -71,7 +73,7 @@ class SegcoreError : public std::runtime_error {
public:
static SegcoreError
success() {
return SegcoreError(ErrorCode::Success, "");
return {ErrorCode::Success, ""};
}

SegcoreError(ErrorCode error_code, const std::string& error_msg)
Expand Down Expand Up @@ -125,13 +127,8 @@ FailureCStatus(std::exception* ex) {
} while (0)

#define Assert(expr) AssertInfo((expr), "")
#define PanicInfo(info) \
do { \
milvus::impl::EasyAssertInfo(false, "", __FILE__, __LINE__, (info)); \
__builtin_unreachable(); \
} while (0)

#define PanicCodeInfo(errcode, info) \
#define PanicInfo(errcode, info) \
do { \
milvus::impl::EasyAssertInfo( \
false, "", __FILE__, __LINE__, (info), errcode); \
Expand Down
5 changes: 2 additions & 3 deletions internal/core/src/common/FieldMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ datatype_name(DataType data_type) {
return "vector_float16";
}
default: {
PanicCodeInfo(DataTypeInvalid,
fmt::format("Unsupported DataType({})",
fmt::underlying(data_type)));
PanicInfo(DataTypeInvalid,
fmt::format("Unsupported DataType({})", data_type));
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion internal/core/src/common/SystemProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <string>

#include "Types.h"
#include "common/Types.h"

namespace milvus {

Expand Down Expand Up @@ -63,3 +63,23 @@ class SystemProperty {
};

} // namespace milvus

template <>
struct fmt::formatter<milvus::SystemFieldType> : formatter<string_view> {
auto
format(milvus::SystemFieldType c, format_context& ctx) const {
string_view name = "unknown";
switch (c) {
case milvus::SystemFieldType::Invalid:
name = "Invalid";
break;
case milvus::SystemFieldType::RowId:
name = "RowId";
break;
case milvus::SystemFieldType::Timestamp:
name = "Timestamp";
break;
}
return formatter<string_view>::format(name, ctx);
}
};
57 changes: 57 additions & 0 deletions internal/core/src/common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <variant>
#include <vector>

#include "fmt/core.h"
#include "knowhere/binaryset.h"
#include "knowhere/comp/index_param.h"
#include "knowhere/dataset.h"
Expand Down Expand Up @@ -238,3 +239,59 @@ struct fmt::formatter<milvus::DataType> : formatter<string_view> {
return formatter<string_view>::format(name, ctx);
}
};

template <>
struct fmt::formatter<milvus::OpType> : formatter<string_view> {
auto
format(milvus::OpType c, format_context& ctx) const {
string_view name = "unknown";
switch (c) {
case milvus::OpType::Invalid:
name = "Invalid";
break;
case milvus::OpType::GreaterThan:
name = "GreaterThan";
break;
case milvus::OpType::GreaterEqual:
name = "GreaterEqual";
break;
case milvus::OpType::LessThan:
name = "LessThan";
break;
case milvus::OpType::LessEqual:
name = "LessEqual";
break;
case milvus::OpType::Equal:
name = "Equal";
break;
case milvus::OpType::NotEqual:
name = "NotEqual";
break;
case milvus::OpType::PrefixMatch:
name = "PrefixMatch";
break;
case milvus::OpType::PostfixMatch:
name = "PostfixMatch";
break;
case milvus::OpType::Match:
name = "Match";
break;
case milvus::OpType::Range:
name = "Range";
break;
case milvus::OpType::In:
name = "In";
break;
case milvus::OpType::NotIn:
name = "NotIn";
break;
case milvus::OpType::OpType_INT_MIN_SENTINEL_DO_NOT_USE_:
name = "OpType_INT_MIN_SENTINEL_DO_NOT_USE";
break;
case milvus::OpType::OpType_INT_MAX_SENTINEL_DO_NOT_USE_:
name = "OpType_INT_MAX_SENTINEL_DO_NOT_USE";
break;
}
return formatter<string_view>::format(name, ctx);
}
};
9 changes: 5 additions & 4 deletions internal/core/src/config/ConfigKnowhere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ KnowhereSetSimdType(const char* value) {
} else if (strcmp(value, "avx") == 0 || strcmp(value, "sse4_2") == 0) {
simd_type = knowhere::KnowhereConfig::SimdType::SSE4_2;
} else {
PanicInfo("invalid SIMD type: " + std::string(value));
PanicInfo(ConfigInvalid, "invalid SIMD type: " + std::string(value));
}
try {
return knowhere::KnowhereConfig::SetSimdType(simd_type);
} catch (std::exception& e) {
LOG_SERVER_ERROR_ << e.what();
PanicInfo(e.what());
PanicInfo(ConfigInvalid, e.what());
}
}

Expand All @@ -81,8 +81,9 @@ void
KnowhereInitSearchThreadPool(const uint32_t num_threads) {
knowhere::KnowhereConfig::SetSearchThreadPoolSize(num_threads);
if (!knowhere::KnowhereConfig::SetAioContextPool(num_threads)) {
PanicInfo("Failed to set aio context pool with num_threads " +
std::to_string(num_threads));
PanicInfo(ConfigInvalid,
"Failed to set aio context pool with num_threads " +
std::to_string(num_threads));
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/index/ScalarIndex-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ ScalarIndex<T>::Query(const DatasetPtr& dataset) {
case OpType::PrefixMatch:
case OpType::PostfixMatch:
default:
throw SegcoreError(OpTypeInvalid,
fmt::format("unsupported operator type: {}",
fmt::underlying(op)));
throw SegcoreError(
OpTypeInvalid,
fmt::format("unsupported operator type: {}", op));
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/index/ScalarIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class ScalarIndex : public IndexBase {
void
BuildWithDataset(const DatasetPtr& dataset,
const Config& config = {}) override {
PanicCodeInfo(Unsupported,
"scalar index don't support build index with dataset");
PanicInfo(Unsupported,
"scalar index don't support build index with dataset");
};

public:
Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/index/ScalarIndexSort-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Meta.h"
#include "common/Utils.h"
#include "common/Slice.h"
#include "common/Types.h"
#include "index/Utils.h"

namespace milvus::index {
Expand Down Expand Up @@ -253,9 +254,8 @@ ScalarIndexSort<T>::Range(const T value, const OpType op) {
data_.begin(), data_.end(), IndexStructure<T>(value));
break;
default:
throw SegcoreError(
OpTypeInvalid,
fmt::format("Invalid OperatorType: {}", fmt::underlying(op)));
throw SegcoreError(OpTypeInvalid,
fmt::format("Invalid OperatorType: {}", op));
}
for (; lb < ub; ++lb) {
bitset[lb->idx_] = true;
Expand Down
33 changes: 16 additions & 17 deletions internal/core/src/index/VectorDiskIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ VectorDiskAnnIndex<T>::Load(const Config& config) {

auto stat = index_.Deserialize(knowhere::BinarySet(), load_config);
if (stat != knowhere::Status::success)
PanicCodeInfo(
ErrorCode::UnexpectedError,
"failed to Deserialize index, " + KnowhereStatusString(stat));
PanicInfo(ErrorCode::UnexpectedError,
"failed to Deserialize index, " + KnowhereStatusString(stat));

SetDim(index_.Dim());
}
Expand Down Expand Up @@ -185,8 +184,8 @@ VectorDiskAnnIndex<T>::BuildWithDataset(const DatasetPtr& dataset,
knowhere::DataSet* ds_ptr = nullptr;
auto stat = index_.Build(*ds_ptr, build_config);
if (stat != knowhere::Status::success)
PanicCodeInfo(ErrorCode::IndexBuildError,
"failed to build index, " + KnowhereStatusString(stat));
PanicInfo(ErrorCode::IndexBuildError,
"failed to build index, " + KnowhereStatusString(stat));
local_chunk_manager->RemoveDir(
storage::GetSegmentRawDataPathPrefix(local_chunk_manager, segment_id));

Expand Down Expand Up @@ -243,20 +242,20 @@ VectorDiskAnnIndex<T>::Query(const DatasetPtr dataset,
auto res = index_.RangeSearch(*dataset, search_config, bitset);

if (!res.has_value()) {
PanicCodeInfo(ErrorCode::UnexpectedError,
fmt::format("failed to range search: {}: {}",
KnowhereStatusString(res.error()),
res.what()));
PanicInfo(ErrorCode::UnexpectedError,
fmt::format("failed to range search: {}: {}",
KnowhereStatusString(res.error()),
res.what()));
}
return ReGenRangeSearchResult(
res.value(), topk, num_queries, GetMetricType());
} else {
auto res = index_.Search(*dataset, search_config, bitset);
if (!res.has_value()) {
PanicCodeInfo(ErrorCode::UnexpectedError,
fmt::format("failed to search: {}: {}",
KnowhereStatusString(res.error()),
res.what()));
PanicInfo(ErrorCode::UnexpectedError,
fmt::format("failed to search: {}: {}",
KnowhereStatusString(res.error()),
res.what()));
}
return res.value();
}
Expand Down Expand Up @@ -298,10 +297,10 @@ std::vector<uint8_t>
VectorDiskAnnIndex<T>::GetVector(const DatasetPtr dataset) const {
auto res = index_.GetVectorByIds(*dataset);
if (!res.has_value()) {
PanicCodeInfo(ErrorCode::UnexpectedError,
fmt::format("failed to get vector: {}: {}",
KnowhereStatusString(res.error()),
res.what()));
PanicInfo(ErrorCode::UnexpectedError,
fmt::format("failed to get vector: {}: {}",
KnowhereStatusString(res.error()),
res.what()));
}
auto index_type = GetIndexType();
auto tensor = res.value()->GetTensor();
Expand Down
7 changes: 3 additions & 4 deletions internal/core/src/index/VectorIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ class VectorIndex : public IndexBase {
BuildWithRawData(size_t n,
const void* values,
const Config& config = {}) override {
PanicCodeInfo(Unsupported,
"vector index don't support build index with raw data");
PanicInfo(Unsupported,
"vector index don't support build index with raw data");
};

virtual void
AddWithDataset(const DatasetPtr& dataset, const Config& config) {
PanicCodeInfo(Unsupported,
"vector index don't support add with dataset");
PanicInfo(Unsupported, "vector index don't support add with dataset");
}

virtual std::unique_ptr<SearchResult>
Expand Down
Loading

0 comments on commit b80a3e1

Please sign in to comment.