From 6cbb10466368217a91d3f293d62f48a47862f8e5 Mon Sep 17 00:00:00 2001 From: akankshamahajan Date: Fri, 25 Aug 2023 13:50:48 -0700 Subject: [PATCH] Fix seg fault in auto_readahead_size during IOError (#11761) Summary: Fix seg fault in auto_readahead_size ``` db_stress: internal_repo_rocksdb/repo/table/block_based/partitioned_index_iterator.h:70: virtual rocksdb::IndexValue rocksdb::PartitionedIndexIterator::value() const: Assertion `Valid()' failed. ``` During seek, after calculating readahead_size, db_stress can inject IOError resulting in failure to index_iter_->Seek and making index_iter_ invalid. Pull Request resolved: https://github.com/facebook/rocksdb/pull/11761 Test Plan: Reproducible locally and passed with this fix Reviewed By: anand1976 Differential Revision: D48696248 Pulled By: akankshamahajan15 fbshipit-source-id: 2be43bf56ad0fc2f95f9093c19c9a1b15a716091 --- table/block_based/block_based_table_iterator.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/table/block_based/block_based_table_iterator.cc b/table/block_based/block_based_table_iterator.cc index 8c313ed61..ac47043f0 100644 --- a/table/block_based/block_based_table_iterator.cc +++ b/table/block_based/block_based_table_iterator.cc @@ -79,13 +79,20 @@ void BlockBasedTableIterator::SeekImpl(const Slice* target, } } - if (read_options_.auto_readahead_size && read_options_.iterate_upper_bound) { + if (read_options_.auto_readahead_size && read_options_.iterate_upper_bound && + is_first_pass) { FindReadAheadSizeUpperBound(); if (target) { index_iter_->Seek(*target); } else { index_iter_->SeekToFirst(); } + + // Check for IO error. + if (!index_iter_->Valid()) { + ResetDataIter(); + return; + } } IndexValue v = index_iter_->value(); -- GitLab