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

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


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new a4baa4aa2a8 branch-4.1: [fix](be) Protect tablet writer map lookup in 
load channel #64604 (#64752)
a4baa4aa2a8 is described below

commit a4baa4aa2a82155c90348b9920b2675a19056950
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jun 24 10:37:41 2026 +0800

    branch-4.1: [fix](be) Protect tablet writer map lookup in load channel 
#64604 (#64752)
    
    Cherry-picked from #64604
    
    Co-authored-by: Refrain <[email protected]>
---
 be/src/load/channel/tablets_channel.cpp | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/be/src/load/channel/tablets_channel.cpp 
b/be/src/load/channel/tablets_channel.cpp
index 2e8dc7e2984..bc1cdf01351 100644
--- a/be/src/load/channel/tablets_channel.cpp
+++ b/be/src/load/channel/tablets_channel.cpp
@@ -587,16 +587,17 @@ Status BaseTabletsChannel::_write_block_data(
 
         // add_batch may concurrency with inc_open but not under _lock.
         // so need to protect it with _tablet_writers_lock.
-        decltype(_tablet_writers.find(tablet_id)) tablet_writer_it;
+        BaseDeltaWriter* tablet_writer = nullptr;
         {
             std::lock_guard<std::mutex> l(_tablet_writers_lock);
-            tablet_writer_it = _tablet_writers.find(tablet_id);
+            auto tablet_writer_it = _tablet_writers.find(tablet_id);
             if (tablet_writer_it == _tablet_writers.end()) {
                 return Status::InternalError("unknown tablet to append data, 
tablet={}", tablet_id);
             }
+            tablet_writer = tablet_writer_it->second.get();
         }
 
-        Status st = write_func(tablet_writer_it->second.get());
+        Status st = write_func(tablet_writer);
         if (!st.ok()) {
             auto err_msg =
                     fmt::format("tablet writer write failed, tablet_id={}, 
txn_id={}, err={}",
@@ -605,7 +606,7 @@ Status BaseTabletsChannel::_write_block_data(
             PTabletError* error = tablet_errors->Add();
             error->set_tablet_id(tablet_id);
             error->set_msg(err_msg);
-            
static_cast<void>(tablet_writer_it->second->cancel_with_status(st));
+            static_cast<void>(tablet_writer->cancel_with_status(st));
             _add_broken_tablet(tablet_id);
             // continue write to other tablet.
             // the error will return back to sender.
@@ -620,9 +621,16 @@ Status BaseTabletsChannel::_write_block_data(
             return writer->write(&send_data, tablet_to_rowidxs_it.second);
         }));
 
-        auto tablet_writer_it = 
_tablet_writers.find(tablet_to_rowidxs_it.first);
-        if (tablet_writer_it != _tablet_writers.end()) {
-            
tablet_writer_it->second->set_tablet_load_rowset_num_info(tablet_load_infos);
+        BaseDeltaWriter* tablet_writer = nullptr;
+        {
+            std::lock_guard<std::mutex> l(_tablet_writers_lock);
+            auto tablet_writer_it = 
_tablet_writers.find(tablet_to_rowidxs_it.first);
+            if (tablet_writer_it != _tablet_writers.end()) {
+                tablet_writer = tablet_writer_it->second.get();
+            }
+        }
+        if (tablet_writer != nullptr) {
+            tablet_writer->set_tablet_load_rowset_num_info(tablet_load_infos);
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to