| 1317 | } |
| 1318 | |
| 1319 | void PrefetchRange(TableConstructor* c, Options* opt, |
| 1320 | BlockBasedTableOptions* table_options, const char* key_begin, |
| 1321 | const char* key_end, |
| 1322 | const std::vector<std::string>& keys_in_cache, |
| 1323 | const std::vector<std::string>& keys_not_in_cache, |
| 1324 | const Status expected_status = Status::OK()) { |
| 1325 | // reset the cache and reopen the table |
| 1326 | table_options->block_cache = NewLRUCache(16 * 1024 * 1024, 4); |
| 1327 | opt->table_factory.reset(NewBlockBasedTableFactory(*table_options)); |
| 1328 | const ImmutableCFOptions ioptions2(*opt); |
| 1329 | const MutableCFOptions moptions(*opt); |
| 1330 | ASSERT_OK(c->Reopen(ioptions2, moptions)); |
| 1331 | |
| 1332 | // prefetch |
| 1333 | auto* table_reader = dynamic_cast<BlockBasedTable*>(c->GetTableReader()); |
| 1334 | Status s; |
| 1335 | std::unique_ptr<Slice> begin, end; |
| 1336 | std::unique_ptr<InternalKey> i_begin, i_end; |
| 1337 | if (key_begin != nullptr) { |
| 1338 | if (c->ConvertToInternalKey()) { |
| 1339 | i_begin.reset(new InternalKey(key_begin, kMaxSequenceNumber, kTypeValue)); |
| 1340 | begin.reset(new Slice(i_begin->Encode())); |
| 1341 | } else { |
| 1342 | begin.reset(new Slice(key_begin)); |
| 1343 | } |
| 1344 | } |
| 1345 | if (key_end != nullptr) { |
| 1346 | if (c->ConvertToInternalKey()) { |
| 1347 | i_end.reset(new InternalKey(key_end, kMaxSequenceNumber, kTypeValue)); |
| 1348 | end.reset(new Slice(i_end->Encode())); |
| 1349 | } else { |
| 1350 | end.reset(new Slice(key_end)); |
| 1351 | } |
| 1352 | } |
| 1353 | s = table_reader->Prefetch(begin.get(), end.get()); |
| 1354 | |
| 1355 | ASSERT_TRUE(s.code() == expected_status.code()); |
| 1356 | |
| 1357 | // assert our expectation in cache warmup |
| 1358 | AssertKeysInCache(table_reader, keys_in_cache, keys_not_in_cache, |
| 1359 | c->ConvertToInternalKey()); |
| 1360 | c->ResetTableReader(); |
| 1361 | } |
| 1362 | |
| 1363 | TEST_P(BlockBasedTableTest, PrefetchTest) { |
| 1364 | // The purpose of this test is to test the prefetching operation built into |
no test coverage detected