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

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


The following commit(s) were added to refs/heads/master by this push:
     new a17214dce89 [Fix](inverted index) fix race condition for column reader 
load inverted index reader (#34922)
a17214dce89 is described below

commit a17214dce89fcc9104cfe671da348ee596827fe3
Author: airborne12 <airborn...@gmail.com>
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: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to