This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 98a1db53e63 [fix](exception) Fix Block noexcept method not throw 
exception (#34002)
98a1db53e63 is described below

commit 98a1db53e638e1f8ffb700229cf7269442a5dcf2
Author: Xinyi Zou <zouxiny...@gmail.com>
AuthorDate: Tue Apr 23 19:39:54 2024 +0800

    [fix](exception) Fix Block noexcept method not throw exception (#34002)
---
 be/src/olap/memtable_flush_executor.cpp      |  3 +--
 be/src/olap/rowset/beta_rowset_writer.cpp    |  1 +
 be/src/olap/rowset/beta_rowset_writer_v2.cpp |  1 +
 be/src/runtime/exec_env.h                    |  3 ---
 be/src/runtime/exec_env_init.cpp             |  1 -
 be/src/runtime/thread_context.h              | 32 +++++++++++++++-------------
 be/src/vec/columns/subcolumn_tree.h          |  1 +
 be/src/vec/core/block.cpp                    |  7 ++++++
 8 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/be/src/olap/memtable_flush_executor.cpp 
b/be/src/olap/memtable_flush_executor.cpp
index 3317371387c..ece6930362d 100644
--- a/be/src/olap/memtable_flush_executor.cpp
+++ b/be/src/olap/memtable_flush_executor.cpp
@@ -142,8 +142,7 @@ Status FlushToken::_do_flush_memtable(MemTable* memtable, 
int32_t segment_id, in
     {
         SCOPED_CONSUME_MEM_TRACKER(memtable->flush_mem_tracker());
         std::unique_ptr<vectorized::Block> block = memtable->to_block();
-        SKIP_MEMORY_CHECK(RETURN_IF_ERROR(
-                _rowset_writer->flush_memtable(block.get(), segment_id, 
flush_size)));
+        RETURN_IF_ERROR(_rowset_writer->flush_memtable(block.get(), 
segment_id, flush_size));
     }
     _memtable_stat += memtable->stat();
     DorisMetrics::instance()->memtable_flush_total->increment(1);
diff --git a/be/src/olap/rowset/beta_rowset_writer.cpp 
b/be/src/olap/rowset/beta_rowset_writer.cpp
index de051eea45e..930a9460771 100644
--- a/be/src/olap/rowset/beta_rowset_writer.cpp
+++ b/be/src/olap/rowset/beta_rowset_writer.cpp
@@ -502,6 +502,7 @@ Status BaseBetaRowsetWriter::flush() {
 
 Status BaseBetaRowsetWriter::flush_memtable(vectorized::Block* block, int32_t 
segment_id,
                                             int64_t* flush_size) {
+    SCOPED_SKIP_MEMORY_CHECK();
     if (block->rows() == 0) {
         return Status::OK();
     }
diff --git a/be/src/olap/rowset/beta_rowset_writer_v2.cpp 
b/be/src/olap/rowset/beta_rowset_writer_v2.cpp
index 225ba490a35..921d80cfc58 100644
--- a/be/src/olap/rowset/beta_rowset_writer_v2.cpp
+++ b/be/src/olap/rowset/beta_rowset_writer_v2.cpp
@@ -93,6 +93,7 @@ Status BetaRowsetWriterV2::add_segment(uint32_t segment_id, 
const SegmentStatist
 
 Status BetaRowsetWriterV2::flush_memtable(vectorized::Block* block, int32_t 
segment_id,
                                           int64_t* flush_size) {
+    SCOPED_SKIP_MEMORY_CHECK();
     if (block->rows() == 0) {
         return Status::OK();
     }
diff --git a/be/src/runtime/exec_env.h b/be/src/runtime/exec_env.h
index 4e117b20f1c..d825f6c2957 100644
--- a/be/src/runtime/exec_env.h
+++ b/be/src/runtime/exec_env.h
@@ -83,7 +83,6 @@ class RoutineLoadTaskExecutor;
 class SmallFileMgr;
 class BlockSpillManager;
 class BackendServiceClient;
-class ThreadContext;
 class TPaloBrokerServiceClient;
 class PBackendService_Stub;
 class PFunctionService_Stub;
@@ -166,7 +165,6 @@ public:
         return nullptr;
     }
 
-    ThreadContext* env_thread_context() { return _env_thread_context; }
     // Save all MemTrackerLimiters in use.
     // Each group corresponds to several MemTrackerLimiters and has a lock.
     // Multiple groups are used to reduce the impact of locks.
@@ -335,7 +333,6 @@ private:
     ClientCache<FrontendServiceClient>* _frontend_client_cache = nullptr;
     ClientCache<TPaloBrokerServiceClient>* _broker_client_cache = nullptr;
 
-    ThreadContext* _env_thread_context = nullptr;
     // The default tracker consumed by mem hook. If the thread does not attach 
other trackers,
     // by default all consumption will be passed to the process tracker 
through the orphan tracker.
     // In real time, `consumption of all limiter trackers` + `orphan tracker 
consumption` = `process tracker consumption`.
diff --git a/be/src/runtime/exec_env_init.cpp b/be/src/runtime/exec_env_init.cpp
index d8dbde8405b..816206a1e8e 100644
--- a/be/src/runtime/exec_env_init.cpp
+++ b/be/src/runtime/exec_env_init.cpp
@@ -373,7 +373,6 @@ Status ExecEnv::_init_mem_env() {
     // 1. init mem tracker
     init_mem_tracker();
     thread_context()->thread_mem_tracker_mgr->init();
-    _env_thread_context = thread_context();
 #if defined(USE_MEM_TRACKER) && !defined(__SANITIZE_ADDRESS__) && 
!defined(ADDRESS_SANITIZER) && \
         !defined(LEAK_SANITIZER) && !defined(THREAD_SANITIZER) && 
!defined(USE_JEMALLOC)
     init_hook();
diff --git a/be/src/runtime/thread_context.h b/be/src/runtime/thread_context.h
index 6920dfabe60..25a8ee33388 100644
--- a/be/src/runtime/thread_context.h
+++ b/be/src/runtime/thread_context.h
@@ -58,11 +58,15 @@
 // 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 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 SCOPED_SKIP_MEMORY_CHECK() (void)0
 #endif
 
 // Used to tracking the memory usage of the specified code segment use by mem 
hook.
@@ -94,17 +98,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();      \
@@ -279,10 +272,6 @@ static ThreadContext* thread_context() {
         DCHECK(thread_context_ptr != nullptr);
         return thread_context_ptr;
     }
-#if !defined(USE_MEM_TRACKER) || defined(BE_TEST)
-    DCHECK(doris::ExecEnv::ready());
-    return doris::ExecEnv::GetInstance()->env_thread_context();
-#endif
     if (bthread_self() != 0) {
         // in bthread
         // bthread switching pthread may be very frequent, remember not to use 
lock or other time-consuming operations.
@@ -406,6 +395,19 @@ private:
     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.
diff --git a/be/src/vec/columns/subcolumn_tree.h 
b/be/src/vec/columns/subcolumn_tree.h
index 75893f7a9f7..30d6c36ba13 100644
--- a/be/src/vec/columns/subcolumn_tree.h
+++ b/be/src/vec/columns/subcolumn_tree.h
@@ -278,6 +278,7 @@ public:
 
     SubcolumnsTree() {
         
SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(ExecEnv::GetInstance()->subcolumns_tree_tracker());
+        SCOPED_SKIP_MEMORY_CHECK();
         strings_pool = std::make_shared<Arena>();
     }
 
diff --git a/be/src/vec/core/block.cpp b/be/src/vec/core/block.cpp
index 75c7a74db5a..d30eee8fcef 100644
--- a/be/src/vec/core/block.cpp
+++ b/be/src/vec/core/block.cpp
@@ -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) {
@@ -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);
@@ -944,6 +947,7 @@ 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);
@@ -951,6 +955,7 @@ void MutableBlock::swap(MutableBlock& another) noexcept {
 }
 
 void MutableBlock::swap(MutableBlock&& another) noexcept {
+    SCOPED_SKIP_MEMORY_CHECK();
     clear();
     _columns = std::move(another._columns);
     _data_types = std::move(another._data_types);
@@ -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();
@@ -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());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to