@@ -148,26 +148,20 @@ class BinarySearchIndexReader : public IndexReader {
148
148
public:
149
149
// Read index from the file and create an intance for
150
150
// `BinarySearchIndexReader`.
151
- // The return value is a pair, where
152
- // * first element is the status indicating if the operation succeeded.
153
- // * second element is the index reader to be created. On failure, this
154
- // element will be nullptr
155
- static std::pair<Status, IndexReader*> Create (RandomAccessFile* file,
156
- const BlockHandle& index_handle,
157
- Env* env,
158
- const Comparator* comparator) {
151
+ // On success, index_reader will be populated; otherwise it will remain
152
+ // unmodified.
153
+ static Status Create (RandomAccessFile* file, const BlockHandle& index_handle,
154
+ Env* env, const Comparator* comparator,
155
+ IndexReader** index_reader) {
159
156
Block* index_block = nullptr ;
160
- auto s =
161
- ReadBlockFromFile (file, ReadOptions (), index_handle, &index_block, env);
157
+ auto s = ReadBlockFromFile (file, ReadOptions (), index_handle,
158
+ &index_block, env);
162
159
163
- if (!s.ok ()) {
164
- // Logically, index_block shouldn't have been populated if any error
165
- // occurred.
166
- assert (index_block == nullptr );
167
- return {s, nullptr };
160
+ if (s.ok ()) {
161
+ *index_reader = new BinarySearchIndexReader (comparator, index_block);
168
162
}
169
163
170
- return {s, new BinarySearchIndexReader (comparator, index_block)} ;
164
+ return s ;
171
165
}
172
166
173
167
virtual Iterator* NewIterator () override {
@@ -190,12 +184,12 @@ class BinarySearchIndexReader : public IndexReader {
190
184
// key.
191
185
class HashIndexReader : public IndexReader {
192
186
public:
193
- static std::pair< Status, IndexReader*> Create (
194
- RandomAccessFile* file, const BlockHandle& index_handle, Env* env,
195
- const Comparator* comparator, BlockBasedTable* table,
196
- const SliceTransform* prefix_extractor) {
197
- return { Status::NotSupported ( " not implemented yet! " ),
198
- nullptr }; // not finished
187
+ static Status Create (RandomAccessFile* file, const BlockHandle& index_handle,
188
+ Env* env, const Comparator* comparator ,
189
+ BlockBasedTable* table,
190
+ const SliceTransform* prefix_extractor,
191
+ IndexReader** index_reader) {
192
+ return Status::NotSupported ( " not implemented yet! " );
199
193
}
200
194
};
201
195
@@ -367,7 +361,7 @@ Status BlockBasedTable::Open(const Options& options, const EnvOptions& soptions,
367
361
// and with a same life-time as this table object.
368
362
IndexReader* index_reader = nullptr ;
369
363
// TODO: we never really verify check sum for index block
370
- std::tie (s, index_reader) = new_table->CreateIndexReader ();
364
+ s = new_table->CreateIndexReader (&index_reader );
371
365
372
366
if (s.ok ()) {
373
367
rep->index_reader .reset (index_reader);
@@ -779,7 +773,7 @@ Iterator* BlockBasedTable::NewIndexIterator(const ReadOptions& read_options)
779
773
} else {
780
774
// Create index reader and put it in the cache.
781
775
Status s;
782
- std::tie (s, index_reader) = CreateIndexReader ();
776
+ s = CreateIndexReader (&index_reader );
783
777
784
778
if (!s.ok ()) {
785
779
// make sure if something goes wrong, index_reader shall remain intact.
@@ -979,7 +973,7 @@ bool BlockBasedTable::TEST_KeyInCache(const ReadOptions& options,
979
973
// 3. options
980
974
// 4. internal_comparator
981
975
// 5. index_type
982
- std::pair< Status, IndexReader*> BlockBasedTable::CreateIndexReader () const {
976
+ Status BlockBasedTable::CreateIndexReader (IndexReader** index_reader ) const {
983
977
// Some old version of block-based tables don't have index type present in
984
978
// table properties. If that's the case we can safely use the kBinarySearch.
985
979
auto index_type = BlockBasedTableOptions::kBinarySearch ;
@@ -994,15 +988,14 @@ std::pair<Status, IndexReader*> BlockBasedTable::CreateIndexReader() const {
994
988
case BlockBasedTableOptions::kBinarySearch : {
995
989
return BinarySearchIndexReader::Create (
996
990
rep_->file .get (), rep_->index_handle , rep_->options .env ,
997
- &rep_->internal_comparator );
991
+ &rep_->internal_comparator , index_reader );
998
992
}
999
993
default : {
1000
994
std::string error_message =
1001
995
" Unrecognized index type: " + std::to_string (rep_->index_type );
1002
996
// equivalent to assert(false), but more informative.
1003
997
assert (!error_message.c_str ());
1004
- return {Status::InvalidArgument (error_message.c_str ()),
1005
- nullptr }; // cannot reach here
998
+ return Status::InvalidArgument (error_message.c_str ());
1006
999
}
1007
1000
}
1008
1001
}
0 commit comments