From c4cd8e1accfd010bba9a919e234ba04505071cc1 Mon Sep 17 00:00:00 2001 From: sdong Date: Fri, 13 May 2022 13:15:10 -0700 Subject: [PATCH] Fix a bug handling multiget index I/O error. (#9993) Summary: In one path of BlockBasedTable::MultiGet(), Next() is directly called after calling Seek() against the index iterator. This might cause crash if an I/O error happens in Seek(). The bug is discovered in crash test. Pull Request resolved: https://github.com/facebook/rocksdb/pull/9993 Test Plan: See existing CI tests pass. Reviewed By: anand1976 Differential Revision: D36381758 fbshipit-source-id: a11e0aa48dcee168c2554c33b532646ffdb68877 --- HISTORY.md | 1 + table/block_based/block_based_table_reader.cc | 3 +++ 2 files changed, 4 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 47d16dc20..48026af2f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ * Fixed a bug where RocksDB could corrupt DBs with `avoid_flush_during_recovery == true` by removing valid WALs, leading to `Status::Corruption` with message like "SST file is ahead of WALs" when attempting to reopen. * Fixed a bug in async_io path where incorrect length of data is read by FilePrefetchBuffer if data is consumed from two populated buffers and request for more data is sent. * Fixed a CompactionFilter bug. Compaction filter used to use `Delete` to remove keys, even if the keys should be removed with `SingleDelete`. Mixing `Delete` and `SingleDelete` may cause undefined behavior. +* Fixed a bug which might cause process crash when I/O error happens when reading an index block in MultiGet(). ### New Features * DB::GetLiveFilesStorageInfo is ready for production use. diff --git a/table/block_based/block_based_table_reader.cc b/table/block_based/block_based_table_reader.cc index baef3bf89..19f65cffe 100644 --- a/table/block_based/block_based_table_reader.cc +++ b/table/block_based/block_based_table_reader.cc @@ -2928,6 +2928,9 @@ void BlockBasedTable::MultiGet(const ReadOptions& read_options, } if (first_block) { iiter->Seek(key); + if (!iiter->Valid()) { + break; + } } first_block = false; iiter->Next();