Skip to content

Commit

Permalink
branch-2.1: [Fix](merge-on-write) Fix `MergeIndexDeleteBitmapCalculat…
Browse files Browse the repository at this point in the history
…or::calculate_one()` coredump #44284 (#44330)

Cherry-picked from #44284

Co-authored-by: bobhan1 <[email protected]>
  • Loading branch information
github-actions[bot] and bobhan1 authored Nov 20, 2024
1 parent b63b97a commit fb163b5
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions be/src/olap/delete_bitmap_calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ bool MergeIndexDeleteBitmapCalculatorContext::Comparator::operator()(
// std::proiroty_queue is a max heap, and function should return the result of `lhs < rhs`
// so if the result of the function is true, rhs will be popped before lhs
Slice key1, key2;
RETURN_IF_ERROR(lhs->get_current_key(key1));
RETURN_IF_ERROR(rhs->get_current_key(key2));
// MergeIndexDeleteBitmapCalculatorContext::get_current_key may return non-OK status if encounter
// memory allocation failure, we can only throw exception here to propagate error in this situation
THROW_IF_ERROR(lhs->get_current_key(key1));
THROW_IF_ERROR(rhs->get_current_key(key2));
if (_sequence_length == 0 && _rowid_length == 0) {
auto cmp_result = key1.compare(key2);
// when key1 is the same as key2,
Expand Down Expand Up @@ -135,28 +137,30 @@ Status MergeIndexDeleteBitmapCalculator::init(RowsetId rowset_id,
std::vector<SegmentSharedPtr> const& segments,
size_t seq_col_length, size_t rowdid_length,
size_t max_batch_size) {
_rowset_id = rowset_id;
_seq_col_length = seq_col_length;
_rowid_length = rowdid_length;
_comparator =
MergeIndexDeleteBitmapCalculatorContext::Comparator(seq_col_length, _rowid_length);
_contexts.reserve(segments.size());
_heap = std::make_unique<Heap>(_comparator);
RETURN_IF_CATCH_EXCEPTION({
_rowset_id = rowset_id;
_seq_col_length = seq_col_length;
_rowid_length = rowdid_length;
_comparator =
MergeIndexDeleteBitmapCalculatorContext::Comparator(seq_col_length, _rowid_length);
_contexts.reserve(segments.size());
_heap = std::make_unique<Heap>(_comparator);

for (auto& segment : segments) {
RETURN_IF_ERROR(segment->load_index());
auto pk_idx = segment->get_primary_key_index();
std::unique_ptr<segment_v2::IndexedColumnIterator> index;
RETURN_IF_ERROR(pk_idx->new_iterator(&index));
auto index_type = vectorized::DataTypeFactory::instance().create_data_type(
pk_idx->type_info()->type(), 1, 0);
_contexts.emplace_back(std::move(index), index_type, segment->id(), pk_idx->num_rows());
_heap->push(&_contexts.back());
}
if (_rowid_length > 0) {
_rowid_coder = get_key_coder(
get_scalar_type_info<FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT>()->type());
}
for (auto& segment : segments) {
RETURN_IF_ERROR(segment->load_index());
auto pk_idx = segment->get_primary_key_index();
std::unique_ptr<segment_v2::IndexedColumnIterator> index;
RETURN_IF_ERROR(pk_idx->new_iterator(&index));
auto index_type = vectorized::DataTypeFactory::instance().create_data_type(
pk_idx->type_info()->type(), 1, 0);
_contexts.emplace_back(std::move(index), index_type, segment->id(), pk_idx->num_rows());
_heap->push(&_contexts.back());
}
if (_rowid_length > 0) {
_rowid_coder = get_key_coder(
get_scalar_type_info<FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT>()->type());
}
});
return Status::OK();
}

Expand Down Expand Up @@ -209,16 +213,18 @@ Status MergeIndexDeleteBitmapCalculator::calculate_one(RowLocation& loc) {
}

Status MergeIndexDeleteBitmapCalculator::calculate_all(DeleteBitmapPtr delete_bitmap) {
RowLocation loc;
while (true) {
auto st = calculate_one(loc);
if (st.is<ErrorCode::END_OF_FILE>()) {
break;
RETURN_IF_CATCH_EXCEPTION({
RowLocation loc;
while (true) {
auto st = calculate_one(loc);
if (st.is<ErrorCode::END_OF_FILE>()) {
break;
}
RETURN_IF_ERROR(st);
delete_bitmap->add({_rowset_id, loc.segment_id, DeleteBitmap::TEMP_VERSION_COMMON},
loc.row_id);
}
RETURN_IF_ERROR(st);
delete_bitmap->add({_rowset_id, loc.segment_id, DeleteBitmap::TEMP_VERSION_COMMON},
loc.row_id);
}
});
return Status::OK();
}

Expand Down

0 comments on commit fb163b5

Please sign in to comment.