This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 8de3279f42ca37f5392361d7e6d7fa3913cfb583 Author: bobhan1 <[email protected]> AuthorDate: Wed Aug 30 08:50:07 2023 +0800 [improve](Status) Add new status code`KEY_NOT_FOUND` and `KEY_ALREADY_EXISTS` for merge on write (#23619) --- be/src/common/status.h | 6 ++++- be/src/olap/rowset/segment_v2/segment.cpp | 9 ++++--- be/src/olap/rowset/segment_v2/segment_writer.cpp | 6 ++--- be/src/olap/tablet.cpp | 34 +++++------------------- be/src/olap/tablet.h | 4 --- be/src/service/point_query_executor.cpp | 2 +- 6 files changed, 21 insertions(+), 40 deletions(-) diff --git a/be/src/common/status.h b/be/src/common/status.h index 5950bc1663..a860236f2e 100644 --- a/be/src/common/status.h +++ b/be/src/common/status.h @@ -271,6 +271,8 @@ E(INVERTED_INDEX_NO_TERMS, -6005); E(INVERTED_INDEX_RENAME_FILE_FAILED, -6006); E(INVERTED_INDEX_EVALUATE_SKIPPED, -6007); E(INVERTED_INDEX_BUILD_WAITTING, -6008); +E(KEY_NOT_FOUND, -6009); +E(KEY_ALREADY_EXISTS, -6010); #undef E } // namespace ErrorCode @@ -308,7 +310,9 @@ constexpr bool capture_stacktrace(int code) { && code != ErrorCode::TRANSACTION_NOT_EXIST && code != ErrorCode::TRANSACTION_ALREADY_VISIBLE && code != ErrorCode::TOO_MANY_TRANSACTIONS - && code != ErrorCode::TRANSACTION_ALREADY_COMMITTED; + && code != ErrorCode::TRANSACTION_ALREADY_COMMITTED + && code != ErrorCode::KEY_NOT_FOUND + && code != ErrorCode::KEY_ALREADY_EXISTS; } // clang-format on diff --git a/be/src/olap/rowset/segment_v2/segment.cpp b/be/src/olap/rowset/segment_v2/segment.cpp index f70d1bd1d5..a04c74ce1a 100644 --- a/be/src/olap/rowset/segment_v2/segment.cpp +++ b/be/src/olap/rowset/segment_v2/segment.cpp @@ -368,14 +368,14 @@ Status Segment::lookup_row_key(const Slice& key, bool with_seq_col, RowLocation* DCHECK(_pk_index_reader != nullptr); if (!_pk_index_reader->check_present(key_without_seq)) { - return Status::NotFound("Can't find key in the segment"); + return Status::Error<ErrorCode::KEY_NOT_FOUND>("Can't find key in the segment"); } bool exact_match = false; std::unique_ptr<segment_v2::IndexedColumnIterator> index_iterator; RETURN_IF_ERROR(_pk_index_reader->new_iterator(&index_iterator)); RETURN_IF_ERROR(index_iterator->seek_at_or_after(&key_without_seq, &exact_match)); if (!has_seq_col && !exact_match) { - return Status::NotFound("Can't find key in the segment"); + return Status::Error<ErrorCode::KEY_NOT_FOUND>("Can't find key in the segment"); } row_location->row_id = index_iterator->get_current_ordinal(); row_location->segment_id = _segment_id; @@ -397,7 +397,7 @@ Status Segment::lookup_row_key(const Slice& key, bool with_seq_col, RowLocation* // compare key if (key_without_seq.compare(sought_key_without_seq) != 0) { - return Status::NotFound("Can't find key in the segment"); + return Status::Error<ErrorCode::KEY_NOT_FOUND>("Can't find key in the segment"); } if (!with_seq_col) { @@ -410,7 +410,8 @@ Status Segment::lookup_row_key(const Slice& key, bool with_seq_col, RowLocation* Slice previous_sequence_id = Slice( sought_key.get_data() + sought_key_without_seq.get_size() + 1, seq_col_length - 1); if (sequence_id.compare(previous_sequence_id) < 0) { - return Status::AlreadyExist("key with higher sequence id exists"); + return Status::Error<ErrorCode::KEY_ALREADY_EXISTS>( + "key with higher sequence id exists"); } } diff --git a/be/src/olap/rowset/segment_v2/segment_writer.cpp b/be/src/olap/rowset/segment_v2/segment_writer.cpp index 681934b8ad..dae5c77f34 100644 --- a/be/src/olap/rowset/segment_v2/segment_writer.cpp +++ b/be/src/olap/rowset/segment_v2/segment_writer.cpp @@ -420,7 +420,7 @@ Status SegmentWriter::append_block_with_partial_content(const vectorized::Block* RowsetSharedPtr rowset; auto st = _tablet->lookup_row_key(key, have_input_seq_column, specified_rowsets, &loc, _mow_context->max_version, segment_caches, &rowset); - if (st.is<NOT_FOUND>()) { + if (st.is<KEY_NOT_FOUND>()) { if (_tablet_schema->is_strict_mode()) { ++num_rows_filtered; // delete the invalid newly inserted row @@ -437,7 +437,7 @@ Status SegmentWriter::append_block_with_partial_content(const vectorized::Block* use_default_or_null_flag.emplace_back(true); continue; } - if (!st.ok() && !st.is<ALREADY_EXIST>()) { + if (!st.ok() && !st.is<KEY_ALREADY_EXISTS>()) { LOG(WARNING) << "failed to lookup row key, error: " << st; return st; } @@ -455,7 +455,7 @@ Status SegmentWriter::append_block_with_partial_content(const vectorized::Block* _tablet->prepare_to_read(loc, pos, &_rssid_to_rid); } - if (st.is<ALREADY_EXIST>()) { + if (st.is<KEY_ALREADY_EXISTS>()) { // although we need to mark delete current row, we still need to read missing columns // for this row, we need to ensure that each column is aligned _mow_context->delete_bitmap->add({_opts.rowset_ctx->rowset_id, _segment_id, 0}, pos); diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp index d4bc57ab27..292567fded 100644 --- a/be/src/olap/tablet.cpp +++ b/be/src/olap/tablet.cpp @@ -2830,10 +2830,10 @@ Status Tablet::lookup_row_key(const Slice& encoded_key, bool with_seq_col, for (auto id : picked_segments) { Status s = segments[id]->lookup_row_key(encoded_key, with_seq_col, &loc); - if (s.is<NOT_FOUND>()) { + if (s.is<KEY_NOT_FOUND>()) { continue; } - if (!s.ok() && !s.is<ALREADY_EXIST>()) { + if (!s.ok() && !s.is<KEY_ALREADY_EXISTS>()) { return s; } if (s.ok() && _tablet_meta->delete_bitmap().contains_agg_without_cache( @@ -2846,7 +2846,7 @@ Status Tablet::lookup_row_key(const Slice& encoded_key, bool with_seq_col, // The key is deleted, we don't need to search for it any more. break; } - // `st` is either OK or ALREADY_EXIST now. + // `st` is either OK or KEY_ALREADY_EXISTS now. // for partial update, even if the key is already exists, we still need to // read it's original values to keep all columns align. *row_location = loc; @@ -2859,7 +2859,7 @@ Status Tablet::lookup_row_key(const Slice& encoded_key, bool with_seq_col, } } g_tablet_pk_not_found << 1; - return Status::NotFound("can't find key in all rowsets"); + return Status::Error<ErrorCode::KEY_NOT_FOUND>("can't find key in all rowsets"); } // load segment may do io so it should out lock @@ -2974,17 +2974,17 @@ Status Tablet::calc_segment_delete_bitmap(RowsetSharedPtr rowset, RowsetSharedPtr rowset_find; auto st = lookup_row_key(key, true, specified_rowsets, &loc, dummy_version.first - 1, segment_caches, &rowset_find); - bool expected_st = st.ok() || st.is<NOT_FOUND>() || st.is<ALREADY_EXIST>(); + bool expected_st = st.ok() || st.is<KEY_NOT_FOUND>() || st.is<KEY_ALREADY_EXISTS>(); DCHECK(expected_st) << "unexpected error status while lookup_row_key:" << st; if (!expected_st) { return st; } - if (st.is<NOT_FOUND>()) { + if (st.is<KEY_NOT_FOUND>()) { continue; } // sequence id smaller than the previous one, so delete current row - if (st.is<ALREADY_EXIST>()) { + if (st.is<KEY_ALREADY_EXISTS>()) { delete_bitmap->add({rowset_id, seg->id(), 0}, row_id); continue; } else if (is_partial_update && rowset_writer != nullptr) { @@ -3215,26 +3215,6 @@ void Tablet::prepare_to_read(const RowLocation& row_location, size_t pos, seg_it->second.emplace_back(RidAndPos {row_location.row_id, pos}); } -Status Tablet::_check_pk_in_pre_segments( - RowsetId rowset_id, const std::vector<segment_v2::SegmentSharedPtr>& pre_segments, - const Slice& key, DeleteBitmapPtr delete_bitmap, RowLocation* loc) { - for (auto it = pre_segments.rbegin(); it != pre_segments.rend(); ++it) { - auto st = (*it)->lookup_row_key(key, true, loc); - DCHECK(st.ok() || st.is<NOT_FOUND>() || st.is<ALREADY_EXIST>()) - << "unexpected error status while lookup_row_key:" << st; - if (st.is<NOT_FOUND>()) { - continue; - } else if (st.ok() && _schema->has_sequence_col() && - delete_bitmap->contains({rowset_id, loc->segment_id, 0}, loc->row_id)) { - // if has sequence col, we continue to compare the sequence_id of - // all segments, util we find an existing key. - continue; - } - return st; - } - return Status::NotFound("Can't find key in the segment"); -} - void Tablet::_rowset_ids_difference(const RowsetIdUnorderedSet& cur, const RowsetIdUnorderedSet& pre, RowsetIdUnorderedSet* to_add, RowsetIdUnorderedSet* to_del) { diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h index 8ba3f60c3d..5ea64cce78 100644 --- a/be/src/olap/tablet.h +++ b/be/src/olap/tablet.h @@ -580,10 +580,6 @@ private: bool _reconstruct_version_tracker_if_necessary(); void _init_context_common_fields(RowsetWriterContext& context); - Status _check_pk_in_pre_segments(RowsetId rowset_id, - const std::vector<segment_v2::SegmentSharedPtr>& pre_segments, - const Slice& key, 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, diff --git a/be/src/service/point_query_executor.cpp b/be/src/service/point_query_executor.cpp index 856c65cbdf..c7d1b52362 100644 --- a/be/src/service/point_query_executor.cpp +++ b/be/src/service/point_query_executor.cpp @@ -287,7 +287,7 @@ Status PointQueryExecutor::_lookup_row_key() { st = (_tablet->lookup_row_key(_row_read_ctxs[i]._primary_key, true, specified_rowsets, &location, INT32_MAX /*rethink?*/, segment_caches, rowset_ptr.get())); - if (st.is_not_found()) { + if (st.is<ErrorCode::KEY_NOT_FOUND>()) { continue; } RETURN_IF_ERROR(st); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
