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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new f4b98400783 branch-3.0: [Fix](merge-on-write) Add defensive check 
before partial update #44687 (#45082)
f4b98400783 is described below

commit f4b98400783e207ac2e4e25bcb824ddfafb910fb
Author: bobhan1 <bao...@selectdb.com>
AuthorDate: Fri Dec 6 23:15:47 2024 +0800

    branch-3.0: [Fix](merge-on-write) Add defensive check before partial update 
#44687 (#45082)
    
    pick https://github.com/apache/doris/pull/44687
---
 be/src/olap/rowset/segment_v2/segment_writer.cpp   | 39 +++++++++++++++++++---
 be/src/olap/rowset/segment_v2/segment_writer.h     |  1 +
 .../rowset/segment_v2/vertical_segment_writer.cpp  | 37 ++++++++++++++++++--
 .../rowset/segment_v2/vertical_segment_writer.h    |  1 +
 4 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/be/src/olap/rowset/segment_v2/segment_writer.cpp 
b/be/src/olap/rowset/segment_v2/segment_writer.cpp
index 0db06c2de74..2a61eb3f0fe 100644
--- a/be/src/olap/rowset/segment_v2/segment_writer.cpp
+++ b/be/src/olap/rowset/segment_v2/segment_writer.cpp
@@ -519,6 +519,40 @@ Status SegmentWriter::probe_key_for_mow(
     return Status::OK();
 }
 
+Status SegmentWriter::partial_update_preconditions_check(size_t row_pos) {
+    if (!_is_mow()) {
+        auto msg = fmt::format(
+                "Can only do partial update on merge-on-write unique table, 
but found: "
+                "keys_type={}, _opts.enable_unique_key_merge_on_write={}, 
tablet_id={}",
+                _tablet_schema->keys_type(), 
_opts.enable_unique_key_merge_on_write,
+                _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    if (_opts.rowset_ctx->partial_update_info == nullptr) {
+        auto msg =
+                fmt::format("partial_update_info should not be nullptr, please 
check, tablet_id={}",
+                            _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    if (!_opts.rowset_ctx->partial_update_info->is_partial_update) {
+        auto msg = fmt::format(
+                "in fixed partial update code, but is_partial_update=false, 
please check, "
+                "tablet_id={}",
+                _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    if (row_pos != 0) {
+        auto msg = fmt::format("row_pos should be 0, but found {}, 
tablet_id={}", row_pos,
+                               _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    return Status::OK();
+}
+
 // for partial update, we should do following steps to fill content of block:
 // 1. set block data to data convertor, and get all key_column's converted 
slice
 // 2. get pk of input block, and read missing columns
@@ -536,10 +570,7 @@ Status 
SegmentWriter::append_block_with_partial_content(const vectorized::Block*
                             block->columns(), 
_tablet_schema->num_key_columns(),
                             _tablet_schema->num_columns()));
     }
-    DCHECK(_is_mow());
-
-    DCHECK(_opts.rowset_ctx->partial_update_info);
-    DCHECK(row_pos == 0);
+    RETURN_IF_ERROR(partial_update_preconditions_check(row_pos));
 
     // find missing column cids
     const auto& missing_cids = 
_opts.rowset_ctx->partial_update_info->missing_cids;
diff --git a/be/src/olap/rowset/segment_v2/segment_writer.h 
b/be/src/olap/rowset/segment_v2/segment_writer.h
index 4b157092221..02ae962a16a 100644
--- a/be/src/olap/rowset/segment_v2/segment_writer.h
+++ b/be/src/olap/rowset/segment_v2/segment_writer.h
@@ -102,6 +102,7 @@ public:
                              bool& has_default_or_nullable,
                              std::vector<bool>& use_default_or_null_flag,
                              PartialUpdateStats& stats);
+    Status partial_update_preconditions_check(size_t row_pos);
     Status append_block_with_partial_content(const vectorized::Block* block, 
size_t row_pos,
                                              size_t num_rows);
     Status append_block_with_variant_subcolumns(vectorized::Block& data);
diff --git a/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp 
b/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
index 857f6b2f3c7..cdbdcab4791 100644
--- a/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
+++ b/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
@@ -390,6 +390,39 @@ Status VerticalSegmentWriter::_probe_key_for_mow(
     return Status::OK();
 }
 
+Status VerticalSegmentWriter::_partial_update_preconditions_check(size_t 
row_pos) {
+    if (!_is_mow()) {
+        auto msg = fmt::format(
+                "Can only do partial update on merge-on-write unique table, 
but found: "
+                "keys_type={}, _opts.enable_unique_key_merge_on_write={}, 
tablet_id={}",
+                _tablet_schema->keys_type(), 
_opts.enable_unique_key_merge_on_write,
+                _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    if (_opts.rowset_ctx->partial_update_info == nullptr) {
+        auto msg =
+                fmt::format("partial_update_info should not be nullptr, please 
check, tablet_id={}",
+                            _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    if (!_opts.rowset_ctx->partial_update_info->is_partial_update) {
+        auto msg = fmt::format(
+                "in partial update code, but is_partial_update=false, please 
check, tablet_id={}",
+                _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    if (row_pos != 0) {
+        auto msg = fmt::format("row_pos should be 0, but found {}, 
tablet_id={}", row_pos,
+                               _tablet->tablet_id());
+        DCHECK(false) << msg;
+        return Status::InternalError<false>(msg);
+    }
+    return Status::OK();
+}
+
 // for partial update, we should do following steps to fill content of block:
 // 1. set block data to data convertor, and get all key_column's converted 
slice
 // 2. get pk of input block, and read missing columns
@@ -399,9 +432,7 @@ Status VerticalSegmentWriter::_probe_key_for_mow(
 // 3. set columns to data convertor and then write all columns
 Status VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& 
data,
                                                                  
vectorized::Block& full_block) {
-    DCHECK(_is_mow());
-    DCHECK(_opts.rowset_ctx->partial_update_info != nullptr);
-    DCHECK(data.row_pos == 0);
+    RETURN_IF_ERROR(_partial_update_preconditions_check(data.row_pos));
 
     // create full block and fill with input columns
     full_block = _tablet_schema->create_block();
diff --git a/be/src/olap/rowset/segment_v2/vertical_segment_writer.h 
b/be/src/olap/rowset/segment_v2/vertical_segment_writer.h
index 0e04b49b343..a327873bbce 100644
--- a/be/src/olap/rowset/segment_v2/vertical_segment_writer.h
+++ b/be/src/olap/rowset/segment_v2/vertical_segment_writer.h
@@ -173,6 +173,7 @@ private:
                               bool& has_default_or_nullable,
                               std::vector<bool>& use_default_or_null_flag,
                               PartialUpdateStats& stats);
+    Status _partial_update_preconditions_check(size_t row_pos);
     Status _append_block_with_partial_content(RowsInBlock& data, 
vectorized::Block& full_block);
     Status _append_block_with_variant_subcolumns(RowsInBlock& data);
     Status _generate_key_index(


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

Reply via email to