From 137d8876a37f74eb5e2444021530c94a058f9fb5 Mon Sep 17 00:00:00 2001 From: haitaoyang Date: Thu, 6 Jul 2023 06:47:57 +0000 Subject: [PATCH] Fix sample block return no data bug and sanity core --- .../access/ob_block_sample_iterator.cpp | 23 ++++++++++++++----- .../ob_index_block_tree_cursor.cpp | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/storage/access/ob_block_sample_iterator.cpp b/src/storage/access/ob_block_sample_iterator.cpp index b05c3499dc..00d7b8cb3c 100644 --- a/src/storage/access/ob_block_sample_iterator.cpp +++ b/src/storage/access/ob_block_sample_iterator.cpp @@ -100,7 +100,7 @@ int ObBlockSampleSSTableEndkeyIterator::open( if (OB_SUCC(ret)) { is_inited_ = true; } - + STORAGE_LOG(TRACE, "open iter", K(ret), K(macro_count_), K(micro_count_), K(sstable)); } return ret; @@ -372,7 +372,11 @@ int ObBlockSampleRangeIterator::get_next_range(const ObDatumRange *&range) STORAGE_LOG(WARN, "Fail to deep copy to current key", K(ret), KPC(min_iter)); } else if (FALSE_IT(generate_cur_range(curr_key_.key_))) { } else if (OB_FAIL(move_endkey_iter(*min_iter))) { - STORAGE_LOG(WARN, "Fail to move forward endkey iterator", K(ret), K(*min_iter)); + if (OB_ITER_END == ret) { + ret = OB_SUCCESS; + } else { + STORAGE_LOG(WARN, "Fail to move forward endkey iterator", K(ret), K(*min_iter)); + } } if (OB_SUCC(ret)) { range = &curr_range_; @@ -451,18 +455,23 @@ int ObBlockSampleRangeIterator::calculate_level_and_batch_size(const double perc micro_count += endkey_iters_[i]->get_micro_count(); } if (macro_count > macro_threshold) { - // macro level + // switch to macro level, reset previous info + curr_key_.reset(); + endkey_heap_.reset(); batch_size_ = macro_count * percent / 100 / EXPECTED_OPEN_RANGE_NUM; for (int64_t i = 0 ; OB_SUCC(ret) && i < endkey_iters_.count() ; ++i) { - if (OB_FAIL(endkey_iters_[i]->upgrade_to_macro(*sample_range_))) { + ObBlockSampleSSTableEndkeyIterator *iter = endkey_iters_[i]; + if (OB_FAIL(iter->upgrade_to_macro(*sample_range_))) { STORAGE_LOG(WARN, "Fail to upgrade to macro level", K(ret)); + } else if (!iter->is_reach_end() && OB_FAIL(endkey_heap_.push(iter))) { + STORAGE_LOG(WARN, "Fail to push endkey heap", K(ret), K(iter), K(endkey_heap_)); } } } else { // micro level batch_size_ = micro_count * percent / 100 / EXPECTED_OPEN_RANGE_NUM; } - + STORAGE_LOG(TRACE, "calculate", K(ret), K(macro_count), K(micro_count), K(macro_threshold), K(batch_size_)); return ret; } @@ -550,7 +559,9 @@ int ObBlockSampleRangeIterator::move_endkey_iter(ObBlockSampleSSTableEndkeyItera ret = OB_NOT_INIT; STORAGE_LOG(WARN, "ObBlockSampleRangeIterator is not inited", K(ret), KP(allocator_)); } else if (OB_FAIL(iter.move_forward())) { - STORAGE_LOG(WARN, "Fail to move forward endkey iter", K(ret), K(iter)); + if (OB_UNLIKELY(OB_ITER_END != ret)) { + STORAGE_LOG(WARN, "Fail to move forward endkey iter", K(ret), K(iter)); + } } else if (!iter.is_reach_end() && OB_FAIL(endkey_heap_.push(&iter))) { STORAGE_LOG(WARN, "Fail to push endkey heap", K(ret), K(iter), K(endkey_heap_)); } diff --git a/src/storage/blocksstable/ob_index_block_tree_cursor.cpp b/src/storage/blocksstable/ob_index_block_tree_cursor.cpp index 743062da38..04a0643f2f 100755 --- a/src/storage/blocksstable/ob_index_block_tree_cursor.cpp +++ b/src/storage/blocksstable/ob_index_block_tree_cursor.cpp @@ -929,7 +929,7 @@ int ObIndexBlockTreeCursor::estimate_range_macro_count(const ObDatumRange &range if (OB_FAIL(locate_range_in_curr_block(range, begin_idx, end_idx))) { LOG_WARN("Fail to locate range in current block", K(ret), K(range)); } else { - micro_count = end_idx - begin_idx; + micro_count = end_idx - begin_idx + 1; } } else { micro_count = micro_count * curr_path_item_->row_count_;