From 8f3fbe9c501bbe57e292bbfc5f241faa9db6f40b Mon Sep 17 00:00:00 2001 From: bobhan1 Date: Wed, 27 Nov 2024 19:47:55 +0800 Subject: [PATCH] update --- .../olap/rowset/segment_v2/segment_writer.cpp | 39 +++++++++++-- .../olap/rowset/segment_v2/segment_writer.h | 1 + .../segment_v2/vertical_segment_writer.cpp | 56 ++++++++++++++++--- .../segment_v2/vertical_segment_writer.h | 1 + 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/be/src/olap/rowset/segment_v2/segment_writer.cpp b/be/src/olap/rowset/segment_v2/segment_writer.cpp index fc22c3570e52a2..b0dc07f1905e02 100644 --- a/be/src/olap/rowset/segment_v2/segment_writer.cpp +++ b/be/src/olap/rowset/segment_v2/segment_writer.cpp @@ -545,6 +545,39 @@ 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(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(msg); + } + if (!_opts.rowset_ctx->partial_update_info->is_fixed_partial_update()) { + auto msg = fmt::format( + "in fixed partial update code, but update_mode={}, please check, tablet_id={}", + _opts.rowset_ctx->partial_update_info->update_mode(), _tablet->tablet_id()); + DCHECK(false) << msg; + return Status::InternalError(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(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 @@ -562,11 +595,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(_opts.rowset_ctx->partial_update_info->is_fixed_partial_update()); - 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 9a8af131087f92..23ee279c7b2bb0 100644 --- a/be/src/olap/rowset/segment_v2/segment_writer.h +++ b/be/src/olap/rowset/segment_v2/segment_writer.h @@ -105,6 +105,7 @@ class SegmentWriter { const std::function& found_cb, const std::function& not_found_cb, 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 ce16e2d502b622..fc15935e262c0e 100644 --- a/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp +++ b/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp @@ -418,6 +418,51 @@ Status VerticalSegmentWriter::_probe_key_for_mow( return Status::OK(); } +Status VerticalSegmentWriter::_partial_update_preconditions_check(size_t row_pos, + bool is_flexible_update) { + 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(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(msg); + } + if (!is_flexible_update) { + if (!_opts.rowset_ctx->partial_update_info->is_fixed_partial_update()) { + auto msg = fmt::format( + "in fixed partial update code, but update_mode={}, please check, tablet_id={}", + _opts.rowset_ctx->partial_update_info->update_mode(), _tablet->tablet_id()); + DCHECK(false) << msg; + return Status::InternalError(msg); + } + } else { + if (!_opts.rowset_ctx->partial_update_info->is_flexible_partial_update()) { + auto msg = fmt::format( + "in flexible partial update code, but update_mode={}, please check, " + "tablet_id={}", + _opts.rowset_ctx->partial_update_info->update_mode(), _tablet->tablet_id()); + DCHECK(false) << msg; + return Status::InternalError(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(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 @@ -427,11 +472,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(_opts.rowset_ctx->partial_update_info->is_fixed_partial_update()); - DCHECK(data.row_pos == 0); - + RETURN_IF_ERROR(_partial_update_preconditions_check(data.row_pos, false)); // create full block and fill with input columns full_block = _tablet_schema->create_block(); const auto& including_cids = _opts.rowset_ctx->partial_update_info->update_cids; @@ -580,10 +621,7 @@ Status VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& da Status VerticalSegmentWriter::_append_block_with_flexible_partial_content( RowsInBlock& data, vectorized::Block& full_block) { - DCHECK(_is_mow()); - DCHECK(_opts.rowset_ctx->partial_update_info != nullptr); - DCHECK(_opts.rowset_ctx->partial_update_info->is_flexible_partial_update()); - DCHECK(data.row_pos == 0); + RETURN_IF_ERROR(_partial_update_preconditions_check(data.row_pos, true)); // data.block has the same schema with full_block DCHECK(data.block->columns() == _tablet_schema->num_columns()); 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 951e9c2e2838c3..8cec6ed4d1abd6 100644 --- a/be/src/olap/rowset/segment_v2/vertical_segment_writer.h +++ b/be/src/olap/rowset/segment_v2/vertical_segment_writer.h @@ -175,6 +175,7 @@ class VerticalSegmentWriter { const std::function& found_cb, const std::function& not_found_cb, PartialUpdateStats& stats); + Status _partial_update_preconditions_check(size_t row_pos, bool is_flexible_update); Status _append_block_with_partial_content(RowsInBlock& data, vectorized::Block& full_block); Status _append_block_with_flexible_partial_content(RowsInBlock& data, vectorized::Block& full_block);