Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions be/src/common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ E(EVAL_CONJUNCTS_ERROR, -120);
E(COPY_FILE_ERROR, -121);
E(FILE_ALREADY_EXIST, -122);
E(BAD_CAST, -123);
E(ARITHMETIC_OVERFLOW_ERRROR, -124);
E(CALL_SEQUENCE_ERROR, -202);
E(BUFFER_OVERFLOW, -204);
E(CONFIG_ERROR, -205);
Expand Down
8 changes: 4 additions & 4 deletions be/src/olap/rowset/beta_rowset_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ BetaRowsetWriter::BetaRowsetWriter()
_num_rows_filtered(0),
_segcompaction_worker(this),
_is_doing_segcompaction(false) {
_segcompaction_status.store(OK);
_segcompaction_status.store(ErrorCode::OK);
}

BetaRowsetWriter::~BetaRowsetWriter() {
Expand Down Expand Up @@ -341,7 +341,7 @@ Status BetaRowsetWriter::_segcompaction_if_necessary() {
!_check_and_set_is_doing_segcompaction()) {
return status;
}
if (_segcompaction_status.load() != OK) {
if (_segcompaction_status.load() != ErrorCode::OK) {
status = Status::Error<SEGCOMPACTION_FAILED>(
"BetaRowsetWriter::_segcompaction_if_necessary meet invalid state");
} else if ((_num_segment - _segcompacted_point) >= config::segcompaction_batch_size) {
Expand Down Expand Up @@ -370,7 +370,7 @@ Status BetaRowsetWriter::_segcompaction_rename_last_segments() {
if (!config::enable_segcompaction) {
return Status::OK();
}
if (_segcompaction_status.load() != OK) {
if (_segcompaction_status.load() != ErrorCode::OK) {
return Status::Error<SEGCOMPACTION_FAILED>(
"BetaRowsetWriter::_segcompaction_rename_last_segments meet invalid state");
}
Expand Down Expand Up @@ -497,7 +497,7 @@ Status BetaRowsetWriter::wait_flying_segcompaction() {
if (elapsed >= MICROS_PER_SEC) {
LOG(INFO) << "wait flying segcompaction finish time:" << elapsed << "us";
}
if (_segcompaction_status.load() != OK) {
if (_segcompaction_status.load() != ErrorCode::OK) {
return Status::Error<SEGCOMPACTION_FAILED>("BetaRowsetWriter meet invalid state.");
}
return Status::OK();
Expand Down
24 changes: 24 additions & 0 deletions be/src/vec/common/arithmetic_overflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#pragma once

#include "vec/core/wide_integer.h"
namespace common {
template <typename T>
inline bool add_overflow(T x, T y, T& res) {
Expand Down Expand Up @@ -50,6 +51,13 @@ inline bool add_overflow(__int128 x, __int128 y, __int128& res) {
return (y > 0 && x > max_int128 - y) || (y < 0 && x < min_int128 - y);
}

template <>
inline bool add_overflow(wide::Int256 x, wide::Int256 y, wide::Int256& res) {
static constexpr wide::Int256 min_int256 = std::numeric_limits<wide::Int256>::min();
static constexpr wide::Int256 max_int256 = std::numeric_limits<wide::Int256>::max();
res = x + y;
return (y > 0 && x > max_int256 - y) || (y < 0 && x < min_int256 - y);
}
template <typename T>
inline bool sub_overflow(T x, T y, T& res) {
return __builtin_sub_overflow(x, y, &res);
Expand Down Expand Up @@ -79,6 +87,14 @@ inline bool sub_overflow(__int128 x, __int128 y, __int128& res) {
return (y < 0 && x > max_int128 + y) || (y > 0 && x < min_int128 + y);
}

template <>
inline bool sub_overflow(wide::Int256 x, wide::Int256 y, wide::Int256& res) {
static constexpr wide::Int256 min_int256 = std::numeric_limits<wide::Int256>::min();
static constexpr wide::Int256 max_int256 = std::numeric_limits<wide::Int256>::max();
res = x - y;
return (y < 0 && x > max_int256 + y) || (y > 0 && x < min_int256 + y);
}

template <typename T>
inline bool mul_overflow(T x, T y, T& res) {
return __builtin_mul_overflow(x, y, &res);
Expand Down Expand Up @@ -109,4 +125,12 @@ inline bool mul_overflow(__int128 x, __int128 y, __int128& res) {
unsigned __int128 b = (y > 0) ? y : -y;
return (a * b) / b != a;
}
template <>
inline bool mul_overflow(wide::Int256 x, wide::Int256 y, wide::Int256& res) {
res = static_cast<wide::UInt256>(x) * static_cast<wide::UInt256>(y);
if (!x || !y) return false;
wide::UInt256 a = (x > 0) ? x : -x;
wide::UInt256 b = (y > 0) ? y : -y;
return (a * b) / b != a;
}
} // namespace common
86 changes: 86 additions & 0 deletions be/src/vec/common/int_exp.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,90 @@ constexpr inline __int128 exp10_i128(int x) {
return values[x];
}

constexpr inline int max_i32(int digit_count) {
if (digit_count < 0) {
return 0;
}
if (digit_count > 9) {
return std::numeric_limits<int>::max();
}
constexpr int values[] = {0, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999};
return values[digit_count];
}

constexpr inline int64_t max_i64(int digit_count) {
if (digit_count < 0) {
return 0;
}
if (digit_count > 18) {
return std::numeric_limits<int64_t>::max();
}

constexpr int64_t values[] = {1LL,
9LL,
99LL,
999LL,
9999LL,
99999LL,
999999LL,
9999999LL,
99999999LL,
999999999LL,
9999999999LL,
99999999999LL,
999999999999LL,
9999999999999LL,
99999999999999LL,
999999999999999LL,
9999999999999999LL,
99999999999999999LL,
999999999999999999LL};
return values[digit_count];
}

constexpr inline __int128 max_i128(int digit_count) {
DCHECK(digit_count > 0);
constexpr __int128 values[] = {
static_cast<__int128>(0LL),
static_cast<__int128>(9LL),
static_cast<__int128>(99LL),
static_cast<__int128>(999LL),
static_cast<__int128>(9999LL),
static_cast<__int128>(99999LL),
static_cast<__int128>(999999LL),
static_cast<__int128>(9999999LL),
static_cast<__int128>(99999999LL),
static_cast<__int128>(999999999LL),
static_cast<__int128>(9999999999LL),
static_cast<__int128>(99999999999LL),
static_cast<__int128>(999999999999LL),
static_cast<__int128>(9999999999999LL),
static_cast<__int128>(99999999999999LL),
static_cast<__int128>(999999999999999LL),
static_cast<__int128>(9999999999999999LL),
static_cast<__int128>(99999999999999999LL),
static_cast<__int128>(999999999999999999LL),
static_cast<__int128>(1000000000000000000LL) * 10LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100LL - 1,
static_cast<__int128>(1000000000000000000LL) * 1000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 10000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 1000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 10000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 1000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 10000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 1000000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 10000000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 1000000000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 10000000000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 10LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 100LL - 1,
static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 1000LL - 1};
return values[digit_count];
}

} // namespace common
Loading