From 024e3540683df9e318b72e7ff3e4c70ad739636a Mon Sep 17 00:00:00 2001 From: bobhan1 Date: Tue, 29 Aug 2023 16:34:31 +0800 Subject: [PATCH 1/2] tmp --- be/src/common/status.h | 6 +++++- be/src/olap/rowset/segment_v2/segment.cpp | 9 +++++---- .../olap/rowset/segment_v2/segment_writer.cpp | 6 +++--- be/src/olap/tablet.cpp | 20 +++++++++---------- be/src/service/point_query_executor.cpp | 2 +- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/be/src/common/status.h b/be/src/common/status.h index f949b6bbce54b7..deaa56e91d221b 100644 --- a/be/src/common/status.h +++ b/be/src/common/status.h @@ -268,6 +268,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 @@ -305,7 +307,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 c6d472d0358bae..8a11cd004973e0 100644 --- a/be/src/olap/rowset/segment_v2/segment.cpp +++ b/be/src/olap/rowset/segment_v2/segment.cpp @@ -367,14 +367,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("Can't find key in the segment"); } bool exact_match = false; std::unique_ptr 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("Can't find key in the segment"); } row_location->row_id = index_iterator->get_current_ordinal(); row_location->segment_id = _segment_id; @@ -396,7 +396,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("Can't find key in the segment"); } if (!with_seq_col) { @@ -409,7 +409,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( + "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 bd3e31596a6b1c..639e2ec08110e4 100644 --- a/be/src/olap/rowset/segment_v2/segment_writer.cpp +++ b/be/src/olap/rowset/segment_v2/segment_writer.cpp @@ -419,7 +419,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()) { + if (st.is()) { if (_tablet_schema->is_strict_mode()) { ++num_rows_filtered; // delete the invalid newly inserted row @@ -436,7 +436,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()) { + if (!st.ok() && !st.is()) { LOG(WARNING) << "failed to lookup row key, error: " << st; return st; } @@ -454,7 +454,7 @@ Status SegmentWriter::append_block_with_partial_content(const vectorized::Block* _tablet->prepare_to_read(loc, segment_pos, &_rssid_to_rid); } - if (st.is()) { + if (st.is()) { // 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}, diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp index 774cec7bdb1d52..3baa7f98d6deb1 100644 --- a/be/src/olap/tablet.cpp +++ b/be/src/olap/tablet.cpp @@ -2829,10 +2829,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()) { + if (s.is()) { continue; } - if (!s.ok() && !s.is()) { + if (!s.ok() && !s.is()) { return s; } if (s.ok() && _tablet_meta->delete_bitmap().contains_agg_without_cache( @@ -2845,7 +2845,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; @@ -2858,7 +2858,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("can't find key in all rowsets"); } // load segment may do io so it should out lock @@ -2972,17 +2972,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() || st.is(); + bool expected_st = st.ok() || st.is() || st.is(); DCHECK(expected_st) << "unexpected error status while lookup_row_key:" << st; if (!expected_st) { return st; } - if (st.is()) { + if (st.is()) { continue; } // sequence id smaller than the previous one, so delete current row - if (st.is()) { + if (st.is()) { delete_bitmap->add({rowset_id, seg->id(), 0}, row_id); continue; } else if (is_partial_update && rowset_writer != nullptr) { @@ -3217,9 +3217,9 @@ Status Tablet::_check_pk_in_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() || st.is()) + DCHECK(st.ok() || st.is() || st.is()) << "unexpected error status while lookup_row_key:" << st; - if (st.is()) { + if (st.is()) { continue; } else if (st.ok() && _schema->has_sequence_col() && delete_bitmap->contains({rowset_id, loc->segment_id, 0}, loc->row_id)) { @@ -3229,7 +3229,7 @@ Status Tablet::_check_pk_in_pre_segments( } return st; } - return Status::NotFound("Can't find key in the segment"); + return Status::Error("Can't find key in the segment"); } void Tablet::_rowset_ids_difference(const RowsetIdUnorderedSet& cur, diff --git a/be/src/service/point_query_executor.cpp b/be/src/service/point_query_executor.cpp index 4463c0d01ab4c7..c7d1b523621f29 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()) { + if (st.is()) { continue; } RETURN_IF_ERROR(st); From 3f762446d3e4f6259e53b6d779e49a77019fdf9d Mon Sep 17 00:00:00 2001 From: bobhan1 Date: Tue, 29 Aug 2023 18:26:24 +0800 Subject: [PATCH 2/2] remove unused code --- be/src/olap/tablet.cpp | 20 -------------------- be/src/olap/tablet.h | 4 ---- 2 files changed, 24 deletions(-) diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp index 3baa7f98d6deb1..b928ea1b8f925e 100644 --- a/be/src/olap/tablet.cpp +++ b/be/src/olap/tablet.cpp @@ -3212,26 +3212,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& 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() || st.is()) - << "unexpected error status while lookup_row_key:" << st; - if (st.is()) { - 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::Error("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 8ba3f60c3d7ba7..5ea64cce78ea3e 100644 --- a/be/src/olap/tablet.h +++ b/be/src/olap/tablet.h @@ -580,10 +580,6 @@ class Tablet : public BaseTablet { 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& 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,