From a6d8e30c05ac1a2cd4bfa9aa7d95a498b02b354c Mon Sep 17 00:00:00 2001 From: Sagar Vemuri Date: Fri, 3 Nov 2017 14:34:10 -0700 Subject: [PATCH] Remove unnecessary status check in TableCache::NewIterator Summary: While investigating the usage of `new_table_iterator_nanos` perf counter, I saw some code was wrapper around with unnecessary status check ... so removed it. Closes https://github.com/facebook/rocksdb/pull/3120 Differential Revision: D6229181 Pulled By: sagar0 fbshipit-source-id: f8a44fe67f5a05df94553fdb233b21e54e88cc34 --- db/table_cache.cc | 68 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/db/table_cache.cc b/db/table_cache.cc index 25c3befa4..ca9245391 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -180,46 +180,44 @@ InternalIterator* TableCache::NewIterator( bool create_new_table_reader = false; TableReader* table_reader = nullptr; Cache::Handle* handle = nullptr; - if (s.ok()) { - if (table_reader_ptr != nullptr) { - *table_reader_ptr = nullptr; - } - size_t readahead = 0; - if (for_compaction) { + if (table_reader_ptr != nullptr) { + *table_reader_ptr = nullptr; + } + size_t readahead = 0; + if (for_compaction) { #ifndef NDEBUG - bool use_direct_reads_for_compaction = env_options.use_direct_reads; - TEST_SYNC_POINT_CALLBACK("TableCache::NewIterator:for_compaction", - &use_direct_reads_for_compaction); + bool use_direct_reads_for_compaction = env_options.use_direct_reads; + TEST_SYNC_POINT_CALLBACK("TableCache::NewIterator:for_compaction", + &use_direct_reads_for_compaction); #endif // !NDEBUG - if (ioptions_.new_table_reader_for_compaction_inputs) { - readahead = ioptions_.compaction_readahead_size; - create_new_table_reader = true; - } - } else { - readahead = options.readahead_size; - create_new_table_reader = readahead > 0; + if (ioptions_.new_table_reader_for_compaction_inputs) { + readahead = ioptions_.compaction_readahead_size; + create_new_table_reader = true; } + } else { + readahead = options.readahead_size; + create_new_table_reader = readahead > 0; + } - if (create_new_table_reader) { - unique_ptr table_reader_unique_ptr; - s = GetTableReader( - env_options, icomparator, fd, true /* sequential_mode */, readahead, - !for_compaction /* record stats */, nullptr, &table_reader_unique_ptr, - false /* skip_filters */, level, - true /* prefetch_index_and_filter_in_cache */, for_compaction); + if (create_new_table_reader) { + unique_ptr table_reader_unique_ptr; + s = GetTableReader( + env_options, icomparator, fd, true /* sequential_mode */, readahead, + !for_compaction /* record stats */, nullptr, &table_reader_unique_ptr, + false /* skip_filters */, level, + true /* prefetch_index_and_filter_in_cache */, for_compaction); + if (s.ok()) { + table_reader = table_reader_unique_ptr.release(); + } + } else { + table_reader = fd.table_reader; + if (table_reader == nullptr) { + s = FindTable(env_options, icomparator, fd, &handle, + options.read_tier == kBlockCacheTier /* no_io */, + !for_compaction /* record read_stats */, file_read_hist, + skip_filters, level); if (s.ok()) { - table_reader = table_reader_unique_ptr.release(); - } - } else { - table_reader = fd.table_reader; - if (table_reader == nullptr) { - s = FindTable(env_options, icomparator, fd, &handle, - options.read_tier == kBlockCacheTier /* no_io */, - !for_compaction /* record read_stats */, file_read_hist, - skip_filters, level); - if (s.ok()) { - table_reader = GetTableReaderFromHandle(handle); - } + table_reader = GetTableReaderFromHandle(handle); } } }