From 2186201fe54cec1db910507dec302a4ad0c20dd5 Mon Sep 17 00:00:00 2001 From: zhaochangle Date: Thu, 29 Aug 2024 19:43:17 +0800 Subject: [PATCH] 1 --- be/src/runtime/tablets_channel.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/be/src/runtime/tablets_channel.cpp b/be/src/runtime/tablets_channel.cpp index eac9693d8390da..329366766f86af 100644 --- a/be/src/runtime/tablets_channel.cpp +++ b/be/src/runtime/tablets_channel.cpp @@ -582,12 +582,15 @@ 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. - std::lock_guard l(_tablet_writers_lock); - - 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); + decltype(_tablet_writers.find(tablet_id)) tablet_writer_it; + { + std::lock_guard l(_tablet_writers_lock); + 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); + } } + Status st = write_func(tablet_writer_it->second.get()); if (!st.ok()) { auto err_msg =