From eea1cad850c2e268b0bfde208a005e44289dea47 Mon Sep 17 00:00:00 2001 From: Zhongyi Xie Date: Tue, 7 May 2019 20:17:48 -0700 Subject: [PATCH] avoid updating index type during iterator creation (#5288) Summary: Right now there is a potential race condition where two threads are created to iterate through the DB (https://gist.github.com/miasantreble/88f5798a397ee7cb8e7baff9db2d9e85). The problem is that in `BlockBasedTable::NewIndexIterator`, if both threads failed to find index_reader from block cache, they will call `CreateIndexReader->UpdateIndexType()` which creates a race to update `index_type` in the shared rep_ object. By checking the code, we realize the index type is always populated by `PrefetchIndexAndFilterBlocks` during the table `Open` call, so there is no need to update index type every time during iterator creation. This PR attempts to fix the race condition by removing the unnecessary call to `UpdateIndexType` Pull Request resolved: https://github.com/facebook/rocksdb/pull/5288 Differential Revision: D15252509 Pulled By: miasantreble fbshipit-source-id: 6e3258652121d5c76d267f7ac457e15c5e84756e --- table/block_based_table_reader.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/table/block_based_table_reader.cc b/table/block_based_table_reader.cc index e39fd2a86..514587d0b 100644 --- a/table/block_based_table_reader.cc +++ b/table/block_based_table_reader.cc @@ -3178,7 +3178,7 @@ BlockBasedTableOptions::IndexType BlockBasedTable::UpdateIndexType() { Status BlockBasedTable::CreateIndexReader( FilePrefetchBuffer* prefetch_buffer, IndexReader** index_reader, InternalIterator* preloaded_meta_index_iter, int level) { - auto index_type_on_file = UpdateIndexType(); + auto index_type_on_file = rep_->index_type; auto file = rep_->file.get(); const InternalKeyComparator* icomparator = &rep_->internal_comparator;