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

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

commit b76b3e91197ae79a834a936a1b3ab2c2e9937ec4
Author: airborne12 <[email protected]>
AuthorDate: Thu May 16 10:12:02 2024 +0800

    [Fix](inverted index) fix race condition for column reader load inverted 
index reader (#34922)
---
 be/src/olap/rowset/segment_v2/column_reader.cpp | 11 +++++++----
 be/src/olap/rowset/segment_v2/column_reader.h   |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/be/src/olap/rowset/segment_v2/column_reader.cpp 
b/be/src/olap/rowset/segment_v2/column_reader.cpp
index 93437131863..a83788a3261 100644
--- a/be/src/olap/rowset/segment_v2/column_reader.cpp
+++ b/be/src/olap/rowset/segment_v2/column_reader.cpp
@@ -263,9 +263,12 @@ Status ColumnReader::new_inverted_index_iterator(
         std::shared_ptr<InvertedIndexFileReader> index_file_reader, const 
TabletIndex* index_meta,
         const StorageReadOptions& read_options, 
std::unique_ptr<InvertedIndexIterator>* iterator) {
     
RETURN_IF_ERROR(_ensure_inverted_index_loaded(std::move(index_file_reader), 
index_meta));
-    if (_inverted_index) {
-        RETURN_IF_ERROR(_inverted_index->new_iterator(read_options.stats,
-                                                      
read_options.runtime_state, iterator));
+    {
+        std::shared_lock<std::shared_mutex> rlock(_load_index_lock);
+        if (_inverted_index) {
+            RETURN_IF_ERROR(_inverted_index->new_iterator(read_options.stats,
+                                                          
read_options.runtime_state, iterator));
+        }
     }
     return Status::OK();
 }
@@ -537,7 +540,7 @@ Status ColumnReader::_load_bitmap_index(bool 
use_page_cache, bool kept_in_memory
 
 Status ColumnReader::_load_inverted_index_index(
         std::shared_ptr<InvertedIndexFileReader> index_file_reader, const 
TabletIndex* index_meta) {
-    std::lock_guard<std::mutex> wlock(_load_index_lock);
+    std::unique_lock<std::shared_mutex> wlock(_load_index_lock);
 
     if (_inverted_index && index_meta &&
         _inverted_index->get_index_id() == index_meta->index_id()) {
diff --git a/be/src/olap/rowset/segment_v2/column_reader.h 
b/be/src/olap/rowset/segment_v2/column_reader.h
index 480a009d336..0d71c4107e1 100644
--- a/be/src/olap/rowset/segment_v2/column_reader.h
+++ b/be/src/olap/rowset/segment_v2/column_reader.h
@@ -250,7 +250,7 @@ private:
     // meta for various column indexes (null if the index is absent)
     std::unique_ptr<ZoneMapPB> _segment_zone_map;
 
-    mutable std::mutex _load_index_lock;
+    mutable std::shared_mutex _load_index_lock;
     std::unique_ptr<ZoneMapIndexReader> _zone_map_index;
     std::unique_ptr<OrdinalIndexReader> _ordinal_index;
     std::unique_ptr<BitmapIndexReader> _bitmap_index;


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

Reply via email to