Skip to content

Commit

Permalink
[fix](exception) Fix Block noexcept method not throw exception
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyiZzz committed Apr 23, 2024
1 parent 60bae68 commit 9a7c03f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
40 changes: 29 additions & 11 deletions be/src/runtime/thread_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,27 @@
// Usually used to record query more detailed memory, including ExecNode operators.
#define SCOPED_CONSUME_MEM_TRACKER(mem_tracker) \
auto VARNAME_LINENUM(add_mem_consumer) = doris::AddThreadMemTrackerConsumer(mem_tracker)

#define SKIP_MEMORY_CHECK(...) \
do { \
doris::ThreadLocalHandle::create_thread_local_if_not_exits(); \
doris::thread_context()->skip_memory_check++; \
DEFER({ \
doris::thread_context()->skip_memory_check--; \
doris::ThreadLocalHandle::del_thread_local_if_count_is_zero(); \
}); \
__VA_ARGS__; \
} while (0)

#define SCOPED_SKIP_MEMORY_CHECK() \
auto VARNAME_LINENUM(scope_skip_memory_check) = doris::ScopeSkipMemoryCheck()
#else
#define SCOPED_ATTACH_TASK(arg1, ...) (void)0
#define SCOPED_ATTACH_TASK_WITH_ID(arg1, arg2) (void)0
#define SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(arg1) (void)0
#define SCOPED_CONSUME_MEM_TRACKER(mem_tracker) (void)0
#define SKIP_MEMORY_CHECK(...) (void)0
#define SCOPED_SKIP_MEMORY_CHECK() (void)0
#endif

// Used to tracking the memory usage of the specified code segment use by mem hook.
Expand Down Expand Up @@ -94,17 +110,6 @@
#define MEMORY_ORPHAN_CHECK() (void)0
#endif

#define SKIP_MEMORY_CHECK(...) \
do { \
doris::ThreadLocalHandle::create_thread_local_if_not_exits(); \
doris::thread_context()->skip_memory_check++; \
DEFER({ \
doris::thread_context()->skip_memory_check--; \
doris::ThreadLocalHandle::del_thread_local_if_count_is_zero(); \
}); \
__VA_ARGS__; \
} while (0)

#define SKIP_LARGE_MEMORY_CHECK(...) \
do { \
doris::ThreadLocalHandle::create_thread_local_if_not_exits(); \
Expand Down Expand Up @@ -406,6 +411,19 @@ class AddThreadMemTrackerConsumerByHook {
std::shared_ptr<MemTracker> _mem_tracker;
};

class ScopeSkipMemoryCheck {
public:
explicit ScopeSkipMemoryCheck() {
ThreadLocalHandle::create_thread_local_if_not_exits();
doris::thread_context()->skip_memory_check++;
}

~ScopeSkipMemoryCheck() {
doris::thread_context()->skip_memory_check--;
ThreadLocalHandle::del_thread_local_if_count_is_zero();
}
};

// Basic macros for mem tracker, usually do not need to be modified and used.
#if defined(USE_MEM_TRACKER) && !defined(BE_TEST)
// used to fix the tracking accuracy of caches.
Expand Down
1 change: 1 addition & 0 deletions be/src/vec/columns/subcolumn_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class SubcolumnsTree {

SubcolumnsTree() {
SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(ExecEnv::GetInstance()->subcolumns_tree_tracker());
SCOPED_SKIP_MEMORY_CHECK();
strings_pool = std::make_shared<Arena>();
}

Expand Down
7 changes: 7 additions & 0 deletions be/src/vec/core/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ std::string Block::print_use_count() {
}

void Block::clear_column_data(int column_size) noexcept {
SCOPED_SKIP_MEMORY_CHECK();
// data.size() greater than column_size, means here have some
// function exec result in block, need erase it here
if (column_size != -1 and data.size() > column_size) {
Expand All @@ -707,12 +708,14 @@ void Block::clear_column_data(int column_size) noexcept {
}

void Block::swap(Block& other) noexcept {
SCOPED_SKIP_MEMORY_CHECK();
data.swap(other.data);
index_by_name.swap(other.index_by_name);
row_same_bit.swap(other.row_same_bit);
}

void Block::swap(Block&& other) noexcept {
SCOPED_SKIP_MEMORY_CHECK();
clear();
data = std::move(other.data);
index_by_name = std::move(other.index_by_name);
Expand Down Expand Up @@ -944,13 +947,15 @@ size_t MutableBlock::rows() const {
}

void MutableBlock::swap(MutableBlock& another) noexcept {
SCOPED_SKIP_MEMORY_CHECK();
_columns.swap(another._columns);
_data_types.swap(another._data_types);
_names.swap(another._names);
index_by_name.swap(another.index_by_name);
}

void MutableBlock::swap(MutableBlock&& another) noexcept {
SCOPED_SKIP_MEMORY_CHECK();
clear();
_columns = std::move(another._columns);
_data_types = std::move(another._data_types);
Expand Down Expand Up @@ -1134,6 +1139,7 @@ size_t MutableBlock::allocated_bytes() const {
}

void MutableBlock::clear_column_data() noexcept {
SCOPED_SKIP_MEMORY_CHECK();
for (auto& col : _columns) {
if (col) {
col->clear();
Expand All @@ -1142,6 +1148,7 @@ void MutableBlock::clear_column_data() noexcept {
}

void MutableBlock::reset_column_data() noexcept {
SCOPED_SKIP_MEMORY_CHECK();
_columns.clear();
for (int i = 0; i < _names.size(); i++) {
_columns.emplace_back(_data_types[i]->create_column());
Expand Down

0 comments on commit 9a7c03f

Please sign in to comment.