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

yiguolei 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 a5643822de [feature-wip](unique-key-merge-on-write) fix calculate 
delete bitmap when has sequence column (#12789)
a5643822de is described below

commit a5643822dee06277cdeeab38590d8fbb2df50924
Author: Xin Liao <liaoxin...@126.com>
AuthorDate: Wed Sep 21 09:21:07 2022 +0800

    [feature-wip](unique-key-merge-on-write) fix calculate delete bitmap when 
has sequence column (#12789)
    
    when the rowset has multiple segments with sequence column, we should 
compare sequence id with previous segment.
---
 be/src/olap/tablet.cpp | 41 ++++++++++++++++++++++++++++-------------
 be/src/olap/tablet.h   |  6 +++---
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp
index fd935c0a12..257c7a04dc 100644
--- a/be/src/olap/tablet.cpp
+++ b/be/src/olap/tablet.cpp
@@ -2002,19 +2002,30 @@ Status Tablet::calc_delete_bitmap(RowsetId rowset_id,
             }
             for (size_t i = 0; i < num_read; i++) {
                 const Slice* key = reinterpret_cast<const 
Slice*>(cvb->cell_ptr(i));
+                RowLocation loc;
                 // first check if exist in pre segment
                 if (check_pre_segments) {
-                    bool find = _check_pk_in_pre_segments(pre_segments, *key, 
dummy_version,
-                                                          delete_bitmap);
-                    if (find) {
+                    auto st = _check_pk_in_pre_segments(pre_segments, *key, 
dummy_version,
+                                                        delete_bitmap, &loc);
+                    if (st.ok()) {
+                        delete_bitmap->add({loc.rowset_id, loc.segment_id, 
dummy_version.first},
+                                           loc.row_id);
+                        cnt++;
+                        ++row_id;
+                        continue;
+                    } else if (st.is_already_exist()) {
+                        delete_bitmap->add({rowset_id, seg->id(), 
dummy_version.first}, row_id);
                         cnt++;
+                        ++row_id;
                         continue;
                     }
                 }
-                RowLocation loc;
                 auto st = lookup_row_key(*key, specified_rowset_ids, &loc, 
dummy_version.first - 1);
                 CHECK(st.ok() || st.is_not_found() || st.is_already_exist());
-                if (st.is_not_found()) continue;
+                if (st.is_not_found()) {
+                    ++row_id;
+                    continue;
+                }
 
                 // sequence id smaller than the previous one, so delete 
current row
                 if (st.is_already_exist()) {
@@ -2041,20 +2052,24 @@ Status Tablet::calc_delete_bitmap(RowsetId rowset_id,
     return Status::OK();
 }
 
-bool Tablet::_check_pk_in_pre_segments(
+Status Tablet::_check_pk_in_pre_segments(
         const std::vector<segment_v2::SegmentSharedPtr>& pre_segments, const 
Slice& key,
-        const Version& version, DeleteBitmapPtr delete_bitmap) {
+        const Version& version, DeleteBitmapPtr delete_bitmap, RowLocation* 
loc) {
     for (auto it = pre_segments.rbegin(); it != pre_segments.rend(); ++it) {
-        RowLocation loc;
-        auto st = (*it)->lookup_row_key(key, &loc);
-        CHECK(st.ok() || st.is_not_found());
+        auto st = (*it)->lookup_row_key(key, loc);
+        CHECK(st.ok() || st.is_not_found() || st.is_already_exist());
         if (st.is_not_found()) {
             continue;
+        } else if (st.ok() && _schema->has_sequence_col() &&
+                   delete_bitmap->contains({loc->rowset_id, loc->segment_id, 
version.first},
+                                           loc->row_id)) {
+            // if has sequence col, we continue to compare the sequence_id of
+            // all segments, util we find an existing key.
+            continue;
         }
-        delete_bitmap->add({loc.rowset_id, loc.segment_id, version.first}, 
loc.row_id);
-        return true;
+        return st;
     }
-    return false;
+    return Status::NotFound("Can't find key in the segment");
 }
 
 void Tablet::_rowset_ids_difference(const RowsetIdUnorderedSet& cur,
diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h
index 7020bf0a7f..8152666d80 100644
--- a/be/src/olap/tablet.h
+++ b/be/src/olap/tablet.h
@@ -379,9 +379,9 @@ private:
     bool _reconstruct_version_tracker_if_necessary();
     void _init_context_common_fields(RowsetWriterContext& context);
 
-    bool _check_pk_in_pre_segments(const 
std::vector<segment_v2::SegmentSharedPtr>& pre_segments,
-                                   const Slice& key, const Version& version,
-                                   DeleteBitmapPtr delete_bitmap);
+    Status _check_pk_in_pre_segments(const 
std::vector<segment_v2::SegmentSharedPtr>& pre_segments,
+                                     const Slice& key, const Version& version,
+                                     DeleteBitmapPtr delete_bitmap, 
RowLocation* loc);
     void _rowset_ids_difference(const RowsetIdUnorderedSet& cur, const 
RowsetIdUnorderedSet& pre,
                                 RowsetIdUnorderedSet* to_add, 
RowsetIdUnorderedSet* to_del);
     Status _load_rowset_segments(const RowsetSharedPtr& rowset,


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

Reply via email to