2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-10-16 21:59:46 +00:00
|
|
|
//
|
2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2013-10-05 05:32:05 +00:00
|
|
|
#pragma once
|
2014-03-01 02:19:07 +00:00
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
#include <stdint.h>
|
2014-03-01 02:19:07 +00:00
|
|
|
#include <memory>
|
2017-03-22 16:11:23 +00:00
|
|
|
#include <set>
|
RocksDB 2.8 to be able to read files generated by 2.6
Summary:
From 2.6 to 2.7, property block name is renamed from rocksdb.stats to rocksdb.properties. Older properties were not able to be loaded. In 2.8, we seem to have added some logic that uses property block without checking null pointers, which create segment faults.
In this patch, we fix it by:
(1) try rocksdb.stats if rocksdb.properties is not found
(2) add some null checking before consuming rep->table_properties
Test Plan: make sure a file generated in 2.7 couldn't be opened now can be opened.
Reviewers: haobo, igor, yhchiang
Reviewed By: igor
CC: ljin, xjin, dhruba, kailiu, leveldb
Differential Revision: https://reviews.facebook.net/D17961
2014-04-17 02:30:33 +00:00
|
|
|
#include <string>
|
2016-08-01 21:50:19 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-03-01 02:19:07 +00:00
|
|
|
|
Cache fragmented range tombstones in BlockBasedTableReader (#4493)
Summary:
This allows tombstone fragmenting to only be performed when the table is opened, and cached for subsequent accesses.
On the same DB used in #4449, running `readrandom` results in the following:
```
readrandom : 0.983 micros/op 1017076 ops/sec; 78.3 MB/s (63103 of 100000 found)
```
Now that Get performance in the presence of range tombstones is reasonable, I also compared the performance between a DB with range tombstones, "expanded" range tombstones (several point tombstones that cover the same keys the equivalent range tombstone would cover, a common workaround for DeleteRange), and no range tombstones. The created DBs had 5 million keys each, and DeleteRange was called at regular intervals (depending on the total number of range tombstones being written) after 4.5 million Puts. The table below summarizes the results of a `readwhilewriting` benchmark (in order to provide somewhat more realistic results):
```
Tombstones? | avg micros/op | stddev micros/op | avg ops/s | stddev ops/s
----------------- | ------------- | ---------------- | ------------ | ------------
None | 0.6186 | 0.04637 | 1,625,252.90 | 124,679.41
500 Expanded | 0.6019 | 0.03628 | 1,666,670.40 | 101,142.65
500 Unexpanded | 0.6435 | 0.03994 | 1,559,979.40 | 104,090.52
1k Expanded | 0.6034 | 0.04349 | 1,665,128.10 | 125,144.57
1k Unexpanded | 0.6261 | 0.03093 | 1,600,457.50 | 79,024.94
5k Expanded | 0.6163 | 0.05926 | 1,636,668.80 | 154,888.85
5k Unexpanded | 0.6402 | 0.04002 | 1,567,804.70 | 100,965.55
10k Expanded | 0.6036 | 0.05105 | 1,667,237.70 | 142,830.36
10k Unexpanded | 0.6128 | 0.02598 | 1,634,633.40 | 72,161.82
25k Expanded | 0.6198 | 0.04542 | 1,620,980.50 | 116,662.93
25k Unexpanded | 0.5478 | 0.0362 | 1,833,059.10 | 121,233.81
50k Expanded | 0.5104 | 0.04347 | 1,973,107.90 | 184,073.49
50k Unexpanded | 0.4528 | 0.03387 | 2,219,034.50 | 170,984.32
```
After a large enough quantity of range tombstones are written, range tombstone Gets can become faster than reading from an equivalent DB with several point tombstones.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4493
Differential Revision: D10842844
Pulled By: abhimadan
fbshipit-source-id: a7d44534f8120e6aabb65779d26c6b9df954c509
2018-10-26 02:25:00 +00:00
|
|
|
#include "db/range_tombstone_fragmenter.h"
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "options/cf_options.h"
|
2014-09-04 23:18:36 +00:00
|
|
|
#include "rocksdb/options.h"
|
2015-12-16 02:20:10 +00:00
|
|
|
#include "rocksdb/persistent_cache.h"
|
2013-11-13 06:46:51 +00:00
|
|
|
#include "rocksdb/statistics.h"
|
2014-03-01 02:19:07 +00:00
|
|
|
#include "rocksdb/status.h"
|
|
|
|
#include "rocksdb/table.h"
|
2018-02-13 00:57:56 +00:00
|
|
|
#include "table/block.h"
|
2018-07-20 21:31:27 +00:00
|
|
|
#include "table/block_based_table_factory.h"
|
2017-03-04 02:09:43 +00:00
|
|
|
#include "table/filter_block.h"
|
|
|
|
#include "table/format.h"
|
Introduce a new MultiGet batching implementation (#5011)
Summary:
This PR introduces a new MultiGet() API, with the underlying implementation grouping keys based on SST file and batching lookups in a file. The reason for the new API is twofold - the definition allows callers to allocate storage for status and values on stack instead of std::vector, as well as return values as PinnableSlices in order to avoid copying, and it keeps the original MultiGet() implementation intact while we experiment with batching.
Batching is useful when there is some spatial locality to the keys being queries, as well as larger batch sizes. The main benefits are due to -
1. Fewer function calls, especially to BlockBasedTableReader::MultiGet() and FullFilterBlockReader::KeysMayMatch()
2. Bloom filter cachelines can be prefetched, hiding the cache miss latency
The next step is to optimize the binary searches in the level_storage_info, index blocks and data blocks, since we could reduce the number of key comparisons if the keys are relatively close to each other. The batching optimizations also need to be extended to other formats, such as PlainTable and filter formats. This also needs to be added to db_stress.
Benchmark results from db_bench for various batch size/locality of reference combinations are given below. Locality was simulated by offsetting the keys in a batch by a stride length. Each SST file is about 8.6MB uncompressed and key/value size is 16/100 uncompressed. To focus on the cpu benefit of batching, the runs were single threaded and bound to the same cpu to eliminate interference from other system events. The results show a 10-25% improvement in micros/op from smaller to larger batch sizes (4 - 32).
Batch Sizes
1 | 2 | 4 | 8 | 16 | 32
Random pattern (Stride length 0)
4.158 | 4.109 | 4.026 | 4.05 | 4.1 | 4.074 - Get
4.438 | 4.302 | 4.165 | 4.122 | 4.096 | 4.075 - MultiGet (no batching)
4.461 | 4.256 | 4.277 | 4.11 | 4.182 | 4.14 - MultiGet (w/ batching)
Good locality (Stride length 16)
4.048 | 3.659 | 3.248 | 2.99 | 2.84 | 2.753
4.429 | 3.728 | 3.406 | 3.053 | 2.911 | 2.781
4.452 | 3.45 | 2.833 | 2.451 | 2.233 | 2.135
Good locality (Stride length 256)
4.066 | 3.786 | 3.581 | 3.447 | 3.415 | 3.232
4.406 | 4.005 | 3.644 | 3.49 | 3.381 | 3.268
4.393 | 3.649 | 3.186 | 2.882 | 2.676 | 2.62
Medium locality (Stride length 4096)
4.012 | 3.922 | 3.768 | 3.61 | 3.582 | 3.555
4.364 | 4.057 | 3.791 | 3.65 | 3.57 | 3.465
4.479 | 3.758 | 3.316 | 3.077 | 2.959 | 2.891
dbbench command used (on a DB with 4 levels, 12 million keys)-
TEST_TMPDIR=/dev/shm numactl -C 10 ./db_bench.tmp -use_existing_db=true -benchmarks="readseq,multireadrandom" -write_buffer_size=4194304 -target_file_size_base=4194304 -max_bytes_for_level_base=16777216 -num=12000000 -reads=12000000 -duration=90 -threads=1 -compression_type=none -cache_size=4194304000 -batch_size=32 -disable_auto_compactions=true -bloom_bits=10 -cache_index_and_filter_blocks=true -pin_l0_filter_and_index_blocks_in_cache=true -multiread_batched=true -multiread_stride=4
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5011
Differential Revision: D14348703
Pulled By: anand1976
fbshipit-source-id: 774406dab3776d979c809522a67bedac6c17f84b
2019-04-11 21:24:09 +00:00
|
|
|
#include "table/get_context.h"
|
|
|
|
#include "table/multiget_context.h"
|
2017-03-04 02:09:43 +00:00
|
|
|
#include "table/persistent_cache_helper.h"
|
2014-11-13 19:39:30 +00:00
|
|
|
#include "table/table_properties_internal.h"
|
2015-12-16 02:20:10 +00:00
|
|
|
#include "table/table_reader.h"
|
2017-02-07 00:29:29 +00:00
|
|
|
#include "table/two_level_iterator.h"
|
2013-09-02 06:23:40 +00:00
|
|
|
#include "util/coding.h"
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
#include "util/file_reader_writer.h"
|
2019-03-27 17:24:16 +00:00
|
|
|
#include "util/user_comparator_wrapper.h"
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
class BlockHandle;
|
2014-03-01 02:19:07 +00:00
|
|
|
class Cache;
|
|
|
|
class FilterBlockReader;
|
2014-09-08 17:37:05 +00:00
|
|
|
class BlockBasedFilterBlockReader;
|
|
|
|
class FullFilterBlockReader;
|
2012-04-17 15:36:46 +00:00
|
|
|
class Footer;
|
2014-03-01 02:19:07 +00:00
|
|
|
class InternalKeyComparator;
|
|
|
|
class Iterator;
|
2011-03-18 22:37:00 +00:00
|
|
|
class RandomAccessFile;
|
2012-04-17 15:36:46 +00:00
|
|
|
class TableCache;
|
2013-10-30 17:52:33 +00:00
|
|
|
class TableReader;
|
2014-03-01 02:19:07 +00:00
|
|
|
class WritableFile;
|
2014-01-24 18:57:15 +00:00
|
|
|
struct BlockBasedTableOptions;
|
2014-03-01 02:19:07 +00:00
|
|
|
struct EnvOptions;
|
|
|
|
struct ReadOptions;
|
2014-09-29 18:09:09 +00:00
|
|
|
class GetContext;
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2016-08-01 21:50:19 +00:00
|
|
|
typedef std::vector<std::pair<std::string, std::string>> KVPairBlock;
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
// A Table is a sorted map from strings to strings. Tables are
|
2011-05-21 02:17:43 +00:00
|
|
|
// immutable and persistent. A Table may be safely accessed from
|
|
|
|
// multiple threads without external synchronization.
|
2013-10-30 17:52:33 +00:00
|
|
|
class BlockBasedTable : public TableReader {
|
2011-03-18 22:37:00 +00:00
|
|
|
public:
|
2013-10-10 18:43:24 +00:00
|
|
|
static const std::string kFilterBlockPrefix;
|
2014-09-08 17:37:05 +00:00
|
|
|
static const std::string kFullFilterBlockPrefix;
|
2017-03-07 21:48:02 +00:00
|
|
|
static const std::string kPartitionedFilterBlockPrefix;
|
2015-12-16 02:20:10 +00:00
|
|
|
// The longest prefix of the cache key used to identify blocks.
|
|
|
|
// For Posix files the unique ID is three varints.
|
|
|
|
static const size_t kMaxCacheKeyPrefixSize = kMaxVarint64Length * 3 + 1;
|
2013-10-10 18:43:24 +00:00
|
|
|
|
2011-03-28 20:43:44 +00:00
|
|
|
// Attempt to open the table that is stored in bytes [0..file_size)
|
|
|
|
// of "file", and read the metadata entries necessary to allow
|
|
|
|
// retrieving data from the table.
|
2011-03-18 22:37:00 +00:00
|
|
|
//
|
2013-10-30 17:52:33 +00:00
|
|
|
// If successful, returns ok and sets "*table_reader" to the newly opened
|
|
|
|
// table. The client should delete "*table_reader" when no longer needed.
|
|
|
|
// If there was an error while initializing the table, sets "*table_reader"
|
|
|
|
// to nullptr and returns a non-ok status.
|
2011-03-18 22:37:00 +00:00
|
|
|
//
|
Skip bottom-level filter block caching when hit-optimized
Summary:
When Get() or NewIterator() trigger file loads, skip caching the filter block if
(1) optimize_filters_for_hits is set and (2) the file is on the bottommost
level. Also skip checking filters under the same conditions, which means that
for a preloaded file or a file that was trivially-moved to the bottom level, its
filter block will eventually expire from the cache.
- added parameters/instance variables in various places in order to propagate the config ("skip_filters") from version_set to block_based_table_reader
- in BlockBasedTable::Rep, this optimization prevents filter from being loaded when the file is opened simply by setting filter_policy = nullptr
- in BlockBasedTable::Get/BlockBasedTable::NewIterator, this optimization prevents filter from being used (even if it was loaded already) by setting filter = nullptr
Test Plan:
updated unit test:
$ ./db_test --gtest_filter=DBTest.OptimizeFiltersForHits
will also run 'make check'
Reviewers: sdong, igor, paultuckfield, anthony, rven, kradhakrishnan, IslamAbdelRahman, yhchiang
Reviewed By: yhchiang
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D51633
2015-12-23 18:15:07 +00:00
|
|
|
// @param file must remain live while this Table is in use.
|
2016-07-20 18:23:31 +00:00
|
|
|
// @param prefetch_index_and_filter_in_cache can be used to disable
|
|
|
|
// prefetching of
|
|
|
|
// index and filter blocks into block cache at startup
|
Skip bottom-level filter block caching when hit-optimized
Summary:
When Get() or NewIterator() trigger file loads, skip caching the filter block if
(1) optimize_filters_for_hits is set and (2) the file is on the bottommost
level. Also skip checking filters under the same conditions, which means that
for a preloaded file or a file that was trivially-moved to the bottom level, its
filter block will eventually expire from the cache.
- added parameters/instance variables in various places in order to propagate the config ("skip_filters") from version_set to block_based_table_reader
- in BlockBasedTable::Rep, this optimization prevents filter from being loaded when the file is opened simply by setting filter_policy = nullptr
- in BlockBasedTable::Get/BlockBasedTable::NewIterator, this optimization prevents filter from being used (even if it was loaded already) by setting filter = nullptr
Test Plan:
updated unit test:
$ ./db_test --gtest_filter=DBTest.OptimizeFiltersForHits
will also run 'make check'
Reviewers: sdong, igor, paultuckfield, anthony, rven, kradhakrishnan, IslamAbdelRahman, yhchiang
Reviewed By: yhchiang
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D51633
2015-12-23 18:15:07 +00:00
|
|
|
// @param skip_filters Disables loading/accessing the filter block. Overrides
|
2016-07-20 18:23:31 +00:00
|
|
|
// prefetch_index_and_filter_in_cache, so filter will be skipped if both
|
|
|
|
// are set.
|
2014-09-04 23:18:36 +00:00
|
|
|
static Status Open(const ImmutableCFOptions& ioptions,
|
|
|
|
const EnvOptions& env_options,
|
2014-01-24 18:57:15 +00:00
|
|
|
const BlockBasedTableOptions& table_options,
|
2014-01-27 21:53:22 +00:00
|
|
|
const InternalKeyComparator& internal_key_comparator,
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<RandomAccessFileReader>&& file,
|
|
|
|
uint64_t file_size,
|
|
|
|
std::unique_ptr<TableReader>* table_reader,
|
2018-05-21 21:33:55 +00:00
|
|
|
const SliceTransform* prefix_extractor = nullptr,
|
2016-07-20 18:23:31 +00:00
|
|
|
bool prefetch_index_and_filter_in_cache = true,
|
2018-06-28 00:09:29 +00:00
|
|
|
bool skip_filters = false, int level = -1,
|
2018-07-20 21:31:27 +00:00
|
|
|
const bool immortal_table = false,
|
2018-07-27 23:00:26 +00:00
|
|
|
const SequenceNumber largest_seqno = 0,
|
2018-07-20 21:31:27 +00:00
|
|
|
TailPrefetchStats* tail_prefetch_stats = nullptr);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2018-05-21 21:33:55 +00:00
|
|
|
bool PrefixMayMatch(const Slice& internal_key,
|
2018-06-26 22:56:26 +00:00
|
|
|
const ReadOptions& read_options,
|
|
|
|
const SliceTransform* options_prefix_extractor,
|
|
|
|
const bool need_upper_bound_check);
|
2013-08-13 21:04:56 +00:00
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
// Returns a new iterator over the table contents.
|
|
|
|
// The result of NewIterator() is initially invalid (caller must
|
|
|
|
// call one of the Seek methods on the iterator before using it).
|
Skip bottom-level filter block caching when hit-optimized
Summary:
When Get() or NewIterator() trigger file loads, skip caching the filter block if
(1) optimize_filters_for_hits is set and (2) the file is on the bottommost
level. Also skip checking filters under the same conditions, which means that
for a preloaded file or a file that was trivially-moved to the bottom level, its
filter block will eventually expire from the cache.
- added parameters/instance variables in various places in order to propagate the config ("skip_filters") from version_set to block_based_table_reader
- in BlockBasedTable::Rep, this optimization prevents filter from being loaded when the file is opened simply by setting filter_policy = nullptr
- in BlockBasedTable::Get/BlockBasedTable::NewIterator, this optimization prevents filter from being used (even if it was loaded already) by setting filter = nullptr
Test Plan:
updated unit test:
$ ./db_test --gtest_filter=DBTest.OptimizeFiltersForHits
will also run 'make check'
Reviewers: sdong, igor, paultuckfield, anthony, rven, kradhakrishnan, IslamAbdelRahman, yhchiang
Reviewed By: yhchiang
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D51633
2015-12-23 18:15:07 +00:00
|
|
|
// @param skip_filters Disables loading/accessing the filter block
|
2018-05-21 21:33:55 +00:00
|
|
|
InternalIterator* NewIterator(const ReadOptions&,
|
|
|
|
const SliceTransform* prefix_extractor,
|
|
|
|
Arena* arena = nullptr,
|
2018-06-25 20:07:38 +00:00
|
|
|
bool skip_filters = false,
|
|
|
|
bool for_compaction = false) override;
|
2013-10-29 00:54:09 +00:00
|
|
|
|
2018-11-28 23:26:56 +00:00
|
|
|
FragmentedRangeTombstoneIterator* NewRangeTombstoneIterator(
|
2016-08-19 22:10:31 +00:00
|
|
|
const ReadOptions& read_options) override;
|
|
|
|
|
Skip bottom-level filter block caching when hit-optimized
Summary:
When Get() or NewIterator() trigger file loads, skip caching the filter block if
(1) optimize_filters_for_hits is set and (2) the file is on the bottommost
level. Also skip checking filters under the same conditions, which means that
for a preloaded file or a file that was trivially-moved to the bottom level, its
filter block will eventually expire from the cache.
- added parameters/instance variables in various places in order to propagate the config ("skip_filters") from version_set to block_based_table_reader
- in BlockBasedTable::Rep, this optimization prevents filter from being loaded when the file is opened simply by setting filter_policy = nullptr
- in BlockBasedTable::Get/BlockBasedTable::NewIterator, this optimization prevents filter from being used (even if it was loaded already) by setting filter = nullptr
Test Plan:
updated unit test:
$ ./db_test --gtest_filter=DBTest.OptimizeFiltersForHits
will also run 'make check'
Reviewers: sdong, igor, paultuckfield, anthony, rven, kradhakrishnan, IslamAbdelRahman, yhchiang
Reviewed By: yhchiang
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D51633
2015-12-23 18:15:07 +00:00
|
|
|
// @param skip_filters Disables loading/accessing the filter block
|
2014-01-28 05:58:46 +00:00
|
|
|
Status Get(const ReadOptions& readOptions, const Slice& key,
|
2018-05-21 21:33:55 +00:00
|
|
|
GetContext* get_context, const SliceTransform* prefix_extractor,
|
|
|
|
bool skip_filters = false) override;
|
2011-03-18 22:37:00 +00:00
|
|
|
|
Introduce a new MultiGet batching implementation (#5011)
Summary:
This PR introduces a new MultiGet() API, with the underlying implementation grouping keys based on SST file and batching lookups in a file. The reason for the new API is twofold - the definition allows callers to allocate storage for status and values on stack instead of std::vector, as well as return values as PinnableSlices in order to avoid copying, and it keeps the original MultiGet() implementation intact while we experiment with batching.
Batching is useful when there is some spatial locality to the keys being queries, as well as larger batch sizes. The main benefits are due to -
1. Fewer function calls, especially to BlockBasedTableReader::MultiGet() and FullFilterBlockReader::KeysMayMatch()
2. Bloom filter cachelines can be prefetched, hiding the cache miss latency
The next step is to optimize the binary searches in the level_storage_info, index blocks and data blocks, since we could reduce the number of key comparisons if the keys are relatively close to each other. The batching optimizations also need to be extended to other formats, such as PlainTable and filter formats. This also needs to be added to db_stress.
Benchmark results from db_bench for various batch size/locality of reference combinations are given below. Locality was simulated by offsetting the keys in a batch by a stride length. Each SST file is about 8.6MB uncompressed and key/value size is 16/100 uncompressed. To focus on the cpu benefit of batching, the runs were single threaded and bound to the same cpu to eliminate interference from other system events. The results show a 10-25% improvement in micros/op from smaller to larger batch sizes (4 - 32).
Batch Sizes
1 | 2 | 4 | 8 | 16 | 32
Random pattern (Stride length 0)
4.158 | 4.109 | 4.026 | 4.05 | 4.1 | 4.074 - Get
4.438 | 4.302 | 4.165 | 4.122 | 4.096 | 4.075 - MultiGet (no batching)
4.461 | 4.256 | 4.277 | 4.11 | 4.182 | 4.14 - MultiGet (w/ batching)
Good locality (Stride length 16)
4.048 | 3.659 | 3.248 | 2.99 | 2.84 | 2.753
4.429 | 3.728 | 3.406 | 3.053 | 2.911 | 2.781
4.452 | 3.45 | 2.833 | 2.451 | 2.233 | 2.135
Good locality (Stride length 256)
4.066 | 3.786 | 3.581 | 3.447 | 3.415 | 3.232
4.406 | 4.005 | 3.644 | 3.49 | 3.381 | 3.268
4.393 | 3.649 | 3.186 | 2.882 | 2.676 | 2.62
Medium locality (Stride length 4096)
4.012 | 3.922 | 3.768 | 3.61 | 3.582 | 3.555
4.364 | 4.057 | 3.791 | 3.65 | 3.57 | 3.465
4.479 | 3.758 | 3.316 | 3.077 | 2.959 | 2.891
dbbench command used (on a DB with 4 levels, 12 million keys)-
TEST_TMPDIR=/dev/shm numactl -C 10 ./db_bench.tmp -use_existing_db=true -benchmarks="readseq,multireadrandom" -write_buffer_size=4194304 -target_file_size_base=4194304 -max_bytes_for_level_base=16777216 -num=12000000 -reads=12000000 -duration=90 -threads=1 -compression_type=none -cache_size=4194304000 -batch_size=32 -disable_auto_compactions=true -bloom_bits=10 -cache_index_and_filter_blocks=true -pin_l0_filter_and_index_blocks_in_cache=true -multiread_batched=true -multiread_stride=4
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5011
Differential Revision: D14348703
Pulled By: anand1976
fbshipit-source-id: 774406dab3776d979c809522a67bedac6c17f84b
2019-04-11 21:24:09 +00:00
|
|
|
void MultiGet(const ReadOptions& readOptions,
|
|
|
|
const MultiGetContext::Range* mget_range,
|
|
|
|
const SliceTransform* prefix_extractor,
|
|
|
|
bool skip_filters = false) override;
|
|
|
|
|
2015-03-03 01:07:03 +00:00
|
|
|
// Pre-fetch the disk blocks that correspond to the key range specified by
|
2016-04-28 09:30:44 +00:00
|
|
|
// (kbegin, kend). The call will return error status in the event of
|
2015-03-03 01:07:03 +00:00
|
|
|
// IO or iteration error.
|
|
|
|
Status Prefetch(const Slice* begin, const Slice* end) override;
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
// Given a key, return an approximate byte offset in the file where
|
|
|
|
// the data for that key begins (or would begin if the key were
|
|
|
|
// present in the file). The returned value is in terms of file
|
|
|
|
// bytes, and so includes effects like compression of the underlying data.
|
|
|
|
// E.g., the approximate offset of the last key in the table will
|
|
|
|
// be close to the file length.
|
2013-10-29 00:54:09 +00:00
|
|
|
uint64_t ApproximateOffsetOf(const Slice& key) override;
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2013-01-31 23:20:24 +00:00
|
|
|
// Returns true if the block for the specified key is in cache.
|
2014-06-20 08:23:02 +00:00
|
|
|
// REQUIRES: key is in this table && block cache enabled
|
2014-01-28 05:58:46 +00:00
|
|
|
bool TEST_KeyInCache(const ReadOptions& options, const Slice& key);
|
2013-01-31 23:20:24 +00:00
|
|
|
|
2013-06-14 00:25:09 +00:00
|
|
|
// Set up the table for Compaction. Might change some parameters with
|
|
|
|
// posix_fadvise
|
2013-10-29 00:54:09 +00:00
|
|
|
void SetupForCompaction() override;
|
|
|
|
|
2014-02-08 03:26:49 +00:00
|
|
|
std::shared_ptr<const TableProperties> GetTableProperties() const override;
|
2013-05-17 22:53:01 +00:00
|
|
|
|
2014-08-05 18:27:34 +00:00
|
|
|
size_t ApproximateMemoryUsage() const override;
|
|
|
|
|
2014-12-23 21:24:07 +00:00
|
|
|
// convert SST file to a human readable form
|
2018-05-21 21:33:55 +00:00
|
|
|
Status DumpTable(WritableFile* out_file,
|
|
|
|
const SliceTransform* prefix_extractor = nullptr) override;
|
2014-12-23 21:24:07 +00:00
|
|
|
|
2017-08-09 22:49:40 +00:00
|
|
|
Status VerifyChecksum() override;
|
|
|
|
|
Adding pin_l0_filter_and_index_blocks_in_cache feature and related fixes.
Summary:
When a block based table file is opened, if prefetch_index_and_filter is true, it will prefetch the index and filter blocks, putting them into the block cache.
What this feature adds: when a L0 block based table file is opened, if pin_l0_filter_and_index_blocks_in_cache is true in the options (and prefetch_index_and_filter is true), then the filter and index blocks aren't released back to the block cache at the end of BlockBasedTableReader::Open(). Instead the table reader takes ownership of them, hence pinning them, ie. the LRU cache will never push them out. Meanwhile in the table reader, further accesses will not hit the block cache, thus avoiding lock contention.
Test Plan:
'export TEST_TMPDIR=/dev/shm/ && DISABLE_JEMALLOC=1 OPT=-g make all valgrind_check -j32' is OK.
I didn't run the Java tests, I don't have Java set up on my devserver.
Reviewers: sdong
Reviewed By: sdong
Subscribers: andrewkr, dhruba
Differential Revision: https://reviews.facebook.net/D56133
2016-04-01 17:42:39 +00:00
|
|
|
void Close() override;
|
|
|
|
|
2013-10-29 00:54:09 +00:00
|
|
|
~BlockBasedTable();
|
2013-10-10 18:43:24 +00:00
|
|
|
|
2014-02-19 23:38:57 +00:00
|
|
|
bool TEST_filter_block_preloaded() const;
|
2014-03-01 02:19:07 +00:00
|
|
|
bool TEST_index_reader_preloaded() const;
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
// IndexReader is the interface that provide the functionality for index
|
|
|
|
// access.
|
|
|
|
class IndexReader {
|
|
|
|
public:
|
2017-05-05 22:01:04 +00:00
|
|
|
explicit IndexReader(const InternalKeyComparator* icomparator,
|
|
|
|
Statistics* stats)
|
|
|
|
: icomparator_(icomparator), statistics_(stats) {}
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
virtual ~IndexReader() {}
|
|
|
|
|
|
|
|
// Create an iterator for index access.
|
|
|
|
// If iter is null then a new object is created on heap and the callee will
|
|
|
|
// have the ownership. If a non-null iter is passed in it will be used, and
|
|
|
|
// the returned value is either the same as iter or a new on-heap object
|
|
|
|
// that
|
|
|
|
// wrapps the passed iter. In the latter case the return value would point
|
|
|
|
// to
|
|
|
|
// a different object then iter and the callee has the ownership of the
|
|
|
|
// returned object.
|
2018-08-09 23:49:45 +00:00
|
|
|
virtual InternalIteratorBase<BlockHandle>* NewIterator(
|
|
|
|
IndexBlockIter* iter = nullptr, bool total_order_seek = true,
|
|
|
|
bool fill_cache = true) = 0;
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
// The size of the index.
|
|
|
|
virtual size_t size() const = 0;
|
|
|
|
// Memory usage of the index block
|
|
|
|
virtual size_t usable_size() const = 0;
|
|
|
|
// return the statistics pointer
|
|
|
|
virtual Statistics* statistics() const { return statistics_; }
|
|
|
|
// Report an approximation of how much memory has been used other than
|
|
|
|
// memory
|
|
|
|
// that was allocated in block cache.
|
|
|
|
virtual size_t ApproximateMemoryUsage() const = 0;
|
|
|
|
|
2017-08-18 17:53:03 +00:00
|
|
|
virtual void CacheDependencies(bool /* unused */) {}
|
|
|
|
|
2017-08-23 14:48:54 +00:00
|
|
|
// Prefetch all the blocks referenced by this index to the buffer
|
|
|
|
void PrefetchBlocks(FilePrefetchBuffer* buf);
|
|
|
|
|
2017-03-04 02:09:43 +00:00
|
|
|
protected:
|
2017-05-05 22:01:04 +00:00
|
|
|
const InternalKeyComparator* icomparator_;
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Statistics* statistics_;
|
|
|
|
};
|
2014-02-19 23:38:57 +00:00
|
|
|
|
2015-12-16 02:20:10 +00:00
|
|
|
static Slice GetCacheKey(const char* cache_key_prefix,
|
|
|
|
size_t cache_key_prefix_size,
|
|
|
|
const BlockHandle& handle, char* cache_key);
|
|
|
|
|
2016-08-01 21:50:19 +00:00
|
|
|
// Retrieve all key value pairs from data blocks in the table.
|
|
|
|
// The key retrieved are internal keys.
|
|
|
|
Status GetKVPairsFromDataBlocks(std::vector<KVPairBlock>* kv_pair_blocks);
|
|
|
|
|
2018-02-13 00:57:56 +00:00
|
|
|
template <class TValue>
|
|
|
|
struct CachableEntry;
|
|
|
|
struct Rep;
|
|
|
|
|
|
|
|
Rep* get_rep() { return rep_; }
|
|
|
|
|
|
|
|
// input_iter: if it is not null, update this one and return it as Iterator
|
2018-07-13 00:19:57 +00:00
|
|
|
template <typename TBlockIter>
|
|
|
|
static TBlockIter* NewDataBlockIterator(
|
Improve direct IO range scan performance with readahead (#3884)
Summary:
This PR extends the improvements in #3282 to also work when using Direct IO.
We see **4.5X performance improvement** in seekrandom benchmark doing long range scans, when using direct reads, on flash.
**Description:**
This change improves the performance of iterators doing long range scans (e.g. big/full index or table scans in MyRocks) by using readahead and prefetching additional data on each disk IO, and storing in a local buffer. This prefetching is automatically enabled on noticing more than 2 IOs for the same table file during iteration. The readahead size starts with 8KB and is exponentially increased on each additional sequential IO, up to a max of 256 KB. This helps in cutting down the number of IOs needed to complete the range scan.
**Implementation Details:**
- Used `FilePrefetchBuffer` as the underlying buffer to store the readahead data. `FilePrefetchBuffer` can now take file_reader, readahead_size and max_readahead_size as input to the constructor, and automatically do readahead.
- `FilePrefetchBuffer::TryReadFromCache` can now call `FilePrefetchBuffer::Prefetch` if readahead is enabled.
- `AlignedBuffer` (which is the underlying store for `FilePrefetchBuffer`) now takes a few additional args in `AlignedBuffer::AllocateNewBuffer` to allow copying data from the old buffer.
- Made sure not to re-read partial chunks of data that were already available in the buffer, from device again.
- Fixed a couple of cases where `AlignedBuffer::cursize_` was not being properly kept up-to-date.
**Constraints:**
- Similar to #3282, this gets currently enabled only when ReadOptions.readahead_size = 0 (which is the default value).
- Since the prefetched data is stored in a temporary buffer allocated on heap, this could increase the memory usage if you have many iterators doing long range scans simultaneously.
- Enabled only for user reads, and disabled for compactions. Compaction reads are controlled by the options `use_direct_io_for_flush_and_compaction` and `compaction_readahead_size`, and the current feature takes precautions not to mess with them.
**Benchmarks:**
I used the same benchmark as used in #3282.
Data fill:
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=fillrandom -num=1000000000 -compression_type="none" -level_compaction_dynamic_level_bytes
```
Do a long range scan: Seekrandom with large number of nexts
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=seekrandom -use_direct_reads -duration=60 -num=1000000000 -use_existing_db -seek_nexts=10000 -statistics -histogram
```
```
Before:
seekrandom : 37939.906 micros/op 26 ops/sec; 29.2 MB/s (1636 of 1999 found)
With this change:
seekrandom : 8527.720 micros/op 117 ops/sec; 129.7 MB/s (6530 of 7999 found)
```
~4.5X perf improvement. Taken on an average of 3 runs.
Closes https://github.com/facebook/rocksdb/pull/3884
Differential Revision: D8082143
Pulled By: sagar0
fbshipit-source-id: 4d7a8561cbac03478663713df4d31ad2620253bb
2018-06-21 18:02:49 +00:00
|
|
|
Rep* rep, const ReadOptions& ro, const Slice& index_value,
|
2018-07-13 00:19:57 +00:00
|
|
|
TBlockIter* input_iter = nullptr, bool is_index = false,
|
2018-08-09 23:49:45 +00:00
|
|
|
bool key_includes_seq = true, bool index_key_is_full = true,
|
|
|
|
GetContext* get_context = nullptr,
|
Improve direct IO range scan performance with readahead (#3884)
Summary:
This PR extends the improvements in #3282 to also work when using Direct IO.
We see **4.5X performance improvement** in seekrandom benchmark doing long range scans, when using direct reads, on flash.
**Description:**
This change improves the performance of iterators doing long range scans (e.g. big/full index or table scans in MyRocks) by using readahead and prefetching additional data on each disk IO, and storing in a local buffer. This prefetching is automatically enabled on noticing more than 2 IOs for the same table file during iteration. The readahead size starts with 8KB and is exponentially increased on each additional sequential IO, up to a max of 256 KB. This helps in cutting down the number of IOs needed to complete the range scan.
**Implementation Details:**
- Used `FilePrefetchBuffer` as the underlying buffer to store the readahead data. `FilePrefetchBuffer` can now take file_reader, readahead_size and max_readahead_size as input to the constructor, and automatically do readahead.
- `FilePrefetchBuffer::TryReadFromCache` can now call `FilePrefetchBuffer::Prefetch` if readahead is enabled.
- `AlignedBuffer` (which is the underlying store for `FilePrefetchBuffer`) now takes a few additional args in `AlignedBuffer::AllocateNewBuffer` to allow copying data from the old buffer.
- Made sure not to re-read partial chunks of data that were already available in the buffer, from device again.
- Fixed a couple of cases where `AlignedBuffer::cursize_` was not being properly kept up-to-date.
**Constraints:**
- Similar to #3282, this gets currently enabled only when ReadOptions.readahead_size = 0 (which is the default value).
- Since the prefetched data is stored in a temporary buffer allocated on heap, this could increase the memory usage if you have many iterators doing long range scans simultaneously.
- Enabled only for user reads, and disabled for compactions. Compaction reads are controlled by the options `use_direct_io_for_flush_and_compaction` and `compaction_readahead_size`, and the current feature takes precautions not to mess with them.
**Benchmarks:**
I used the same benchmark as used in #3282.
Data fill:
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=fillrandom -num=1000000000 -compression_type="none" -level_compaction_dynamic_level_bytes
```
Do a long range scan: Seekrandom with large number of nexts
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=seekrandom -use_direct_reads -duration=60 -num=1000000000 -use_existing_db -seek_nexts=10000 -statistics -histogram
```
```
Before:
seekrandom : 37939.906 micros/op 26 ops/sec; 29.2 MB/s (1636 of 1999 found)
With this change:
seekrandom : 8527.720 micros/op 117 ops/sec; 129.7 MB/s (6530 of 7999 found)
```
~4.5X perf improvement. Taken on an average of 3 runs.
Closes https://github.com/facebook/rocksdb/pull/3884
Differential Revision: D8082143
Pulled By: sagar0
fbshipit-source-id: 4d7a8561cbac03478663713df4d31ad2620253bb
2018-06-21 18:02:49 +00:00
|
|
|
FilePrefetchBuffer* prefetch_buffer = nullptr);
|
2018-07-13 00:19:57 +00:00
|
|
|
template <typename TBlockIter>
|
|
|
|
static TBlockIter* NewDataBlockIterator(
|
Improve direct IO range scan performance with readahead (#3884)
Summary:
This PR extends the improvements in #3282 to also work when using Direct IO.
We see **4.5X performance improvement** in seekrandom benchmark doing long range scans, when using direct reads, on flash.
**Description:**
This change improves the performance of iterators doing long range scans (e.g. big/full index or table scans in MyRocks) by using readahead and prefetching additional data on each disk IO, and storing in a local buffer. This prefetching is automatically enabled on noticing more than 2 IOs for the same table file during iteration. The readahead size starts with 8KB and is exponentially increased on each additional sequential IO, up to a max of 256 KB. This helps in cutting down the number of IOs needed to complete the range scan.
**Implementation Details:**
- Used `FilePrefetchBuffer` as the underlying buffer to store the readahead data. `FilePrefetchBuffer` can now take file_reader, readahead_size and max_readahead_size as input to the constructor, and automatically do readahead.
- `FilePrefetchBuffer::TryReadFromCache` can now call `FilePrefetchBuffer::Prefetch` if readahead is enabled.
- `AlignedBuffer` (which is the underlying store for `FilePrefetchBuffer`) now takes a few additional args in `AlignedBuffer::AllocateNewBuffer` to allow copying data from the old buffer.
- Made sure not to re-read partial chunks of data that were already available in the buffer, from device again.
- Fixed a couple of cases where `AlignedBuffer::cursize_` was not being properly kept up-to-date.
**Constraints:**
- Similar to #3282, this gets currently enabled only when ReadOptions.readahead_size = 0 (which is the default value).
- Since the prefetched data is stored in a temporary buffer allocated on heap, this could increase the memory usage if you have many iterators doing long range scans simultaneously.
- Enabled only for user reads, and disabled for compactions. Compaction reads are controlled by the options `use_direct_io_for_flush_and_compaction` and `compaction_readahead_size`, and the current feature takes precautions not to mess with them.
**Benchmarks:**
I used the same benchmark as used in #3282.
Data fill:
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=fillrandom -num=1000000000 -compression_type="none" -level_compaction_dynamic_level_bytes
```
Do a long range scan: Seekrandom with large number of nexts
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=seekrandom -use_direct_reads -duration=60 -num=1000000000 -use_existing_db -seek_nexts=10000 -statistics -histogram
```
```
Before:
seekrandom : 37939.906 micros/op 26 ops/sec; 29.2 MB/s (1636 of 1999 found)
With this change:
seekrandom : 8527.720 micros/op 117 ops/sec; 129.7 MB/s (6530 of 7999 found)
```
~4.5X perf improvement. Taken on an average of 3 runs.
Closes https://github.com/facebook/rocksdb/pull/3884
Differential Revision: D8082143
Pulled By: sagar0
fbshipit-source-id: 4d7a8561cbac03478663713df4d31ad2620253bb
2018-06-21 18:02:49 +00:00
|
|
|
Rep* rep, const ReadOptions& ro, const BlockHandle& block_hanlde,
|
2018-07-13 00:19:57 +00:00
|
|
|
TBlockIter* input_iter = nullptr, bool is_index = false,
|
2018-08-09 23:49:45 +00:00
|
|
|
bool key_includes_seq = true, bool index_key_is_full = true,
|
|
|
|
GetContext* get_context = nullptr, Status s = Status(),
|
|
|
|
FilePrefetchBuffer* prefetch_buffer = nullptr);
|
2018-02-13 00:57:56 +00:00
|
|
|
|
|
|
|
class PartitionedIndexIteratorState;
|
2017-02-07 00:29:29 +00:00
|
|
|
|
2017-03-22 16:11:23 +00:00
|
|
|
friend class PartitionIndexReader;
|
|
|
|
|
|
|
|
protected:
|
2011-03-18 22:37:00 +00:00
|
|
|
Rep* rep_;
|
2017-05-18 13:28:11 +00:00
|
|
|
explicit BlockBasedTable(Rep* rep) : rep_(rep) {}
|
2017-03-22 16:11:23 +00:00
|
|
|
|
|
|
|
private:
|
2017-08-23 14:48:54 +00:00
|
|
|
friend class MockedBlockBasedTable;
|
2018-01-29 22:34:56 +00:00
|
|
|
static std::atomic<uint64_t> next_cache_key_id_;
|
2018-02-07 23:42:35 +00:00
|
|
|
|
2016-11-05 16:10:51 +00:00
|
|
|
// If block cache enabled (compressed or uncompressed), looks for the block
|
|
|
|
// identified by handle in (1) uncompressed cache, (2) compressed cache, and
|
|
|
|
// then (3) file. If found, inserts into the cache(s) that were searched
|
|
|
|
// unsuccessfully (e.g., if found in file, will add to both uncompressed and
|
|
|
|
// compressed caches if they're enabled).
|
|
|
|
//
|
|
|
|
// @param block_entry value is set to the uncompressed block if found. If
|
|
|
|
// in uncompressed block cache, also sets cache_handle to reference that
|
|
|
|
// block.
|
2018-11-14 01:00:49 +00:00
|
|
|
static Status MaybeReadBlockAndLoadToCache(
|
|
|
|
FilePrefetchBuffer* prefetch_buffer, Rep* rep, const ReadOptions& ro,
|
2019-01-24 02:11:08 +00:00
|
|
|
const BlockHandle& handle, const UncompressionDict& uncompression_dict,
|
2018-11-14 01:00:49 +00:00
|
|
|
CachableEntry<Block>* block_entry, bool is_index = false,
|
|
|
|
GetContext* get_context = nullptr);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2014-03-01 02:19:07 +00:00
|
|
|
// For the following two functions:
|
|
|
|
// if `no_io == true`, we will not try to read filter/index from sst file
|
|
|
|
// were they not present in cache yet.
|
2017-08-23 14:48:54 +00:00
|
|
|
CachableEntry<FilterBlockReader> GetFilter(
|
2018-05-21 21:33:55 +00:00
|
|
|
const SliceTransform* prefix_extractor = nullptr,
|
2017-12-13 05:06:26 +00:00
|
|
|
FilePrefetchBuffer* prefetch_buffer = nullptr, bool no_io = false,
|
|
|
|
GetContext* get_context = nullptr) const;
|
2017-03-22 16:11:23 +00:00
|
|
|
virtual CachableEntry<FilterBlockReader> GetFilter(
|
2017-08-23 14:48:54 +00:00
|
|
|
FilePrefetchBuffer* prefetch_buffer, const BlockHandle& filter_blk_handle,
|
2018-05-21 21:33:55 +00:00
|
|
|
const bool is_a_filter_partition, bool no_io, GetContext* get_context,
|
|
|
|
const SliceTransform* prefix_extractor = nullptr) const;
|
2013-11-13 06:46:51 +00:00
|
|
|
|
2019-01-24 02:11:08 +00:00
|
|
|
static CachableEntry<UncompressionDict> GetUncompressionDict(
|
|
|
|
Rep* rep, FilePrefetchBuffer* prefetch_buffer, bool no_io,
|
|
|
|
GetContext* get_context);
|
|
|
|
|
2014-03-01 02:19:07 +00:00
|
|
|
// Get the iterator from the index reader.
|
2014-07-30 23:34:35 +00:00
|
|
|
// If input_iter is not set, return new Iterator
|
|
|
|
// If input_iter is set, update it and return it as Iterator
|
2013-11-13 06:46:51 +00:00
|
|
|
//
|
2014-03-01 02:19:07 +00:00
|
|
|
// Note: ErrorIterator with Status::Incomplete shall be returned if all the
|
|
|
|
// following conditions are met:
|
|
|
|
// 1. We enabled table_options.cache_index_and_filter_blocks.
|
|
|
|
// 2. index is not present in block cache.
|
|
|
|
// 3. We disallowed any io to be performed, that is, read_options ==
|
|
|
|
// kBlockCacheTier
|
2018-08-09 23:49:45 +00:00
|
|
|
InternalIteratorBase<BlockHandle>* NewIndexIterator(
|
2018-06-26 22:56:26 +00:00
|
|
|
const ReadOptions& read_options, bool need_upper_bound_check = false,
|
2018-07-13 00:19:57 +00:00
|
|
|
IndexBlockIter* input_iter = nullptr,
|
2017-12-13 05:06:26 +00:00
|
|
|
CachableEntry<IndexReader>* index_entry = nullptr,
|
|
|
|
GetContext* get_context = nullptr);
|
2014-03-01 02:19:07 +00:00
|
|
|
|
|
|
|
// Read block cache from block caches (if set): block_cache and
|
|
|
|
// block_cache_compressed.
|
|
|
|
// On success, Status::OK with be returned and @block will be populated with
|
|
|
|
// pointer to the block as well as its block handle.
|
2019-01-24 02:11:08 +00:00
|
|
|
// @param uncompression_dict Data for presetting the compression library's
|
Shared dictionary compression using reference block
Summary:
This adds a new metablock containing a shared dictionary that is used
to compress all data blocks in the SST file. The size of the shared dictionary
is configurable in CompressionOptions and defaults to 0. It's currently only
used for zlib/lz4/lz4hc, but the block will be stored in the SST regardless of
the compression type if the user chooses a nonzero dictionary size.
During compaction, computes the dictionary by randomly sampling the first
output file in each subcompaction. It pre-computes the intervals to sample
by assuming the output file will have the maximum allowable length. In case
the file is smaller, some of the pre-computed sampling intervals can be beyond
end-of-file, in which case we skip over those samples and the dictionary will
be a bit smaller. After the dictionary is generated using the first file in a
subcompaction, it is loaded into the compression library before writing each
block in each subsequent file of that subcompaction.
On the read path, gets the dictionary from the metablock, if it exists. Then,
loads that dictionary into the compression library before reading each block.
Test Plan: new unit test
Reviewers: yhchiang, IslamAbdelRahman, cyan, sdong
Reviewed By: sdong
Subscribers: andrewkr, yoshinorim, kradhakrishnan, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D52287
2016-04-28 00:36:03 +00:00
|
|
|
// dictionary.
|
2014-03-01 02:19:07 +00:00
|
|
|
static Status GetDataBlockFromCache(
|
|
|
|
const Slice& block_cache_key, const Slice& compressed_block_cache_key,
|
2018-11-14 01:00:49 +00:00
|
|
|
Cache* block_cache, Cache* block_cache_compressed, Rep* rep,
|
|
|
|
const ReadOptions& read_options,
|
|
|
|
BlockBasedTable::CachableEntry<Block>* block,
|
2019-01-24 02:11:08 +00:00
|
|
|
const UncompressionDict& uncompression_dict,
|
|
|
|
size_t read_amp_bytes_per_bit, bool is_index = false,
|
|
|
|
GetContext* get_context = nullptr);
|
Shared dictionary compression using reference block
Summary:
This adds a new metablock containing a shared dictionary that is used
to compress all data blocks in the SST file. The size of the shared dictionary
is configurable in CompressionOptions and defaults to 0. It's currently only
used for zlib/lz4/lz4hc, but the block will be stored in the SST regardless of
the compression type if the user chooses a nonzero dictionary size.
During compaction, computes the dictionary by randomly sampling the first
output file in each subcompaction. It pre-computes the intervals to sample
by assuming the output file will have the maximum allowable length. In case
the file is smaller, some of the pre-computed sampling intervals can be beyond
end-of-file, in which case we skip over those samples and the dictionary will
be a bit smaller. After the dictionary is generated using the first file in a
subcompaction, it is loaded into the compression library before writing each
block in each subsequent file of that subcompaction.
On the read path, gets the dictionary from the metablock, if it exists. Then,
loads that dictionary into the compression library before reading each block.
Test Plan: new unit test
Reviewers: yhchiang, IslamAbdelRahman, cyan, sdong
Reviewed By: sdong
Subscribers: andrewkr, yoshinorim, kradhakrishnan, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D52287
2016-04-28 00:36:03 +00:00
|
|
|
|
2014-03-01 02:19:07 +00:00
|
|
|
// Put a raw block (maybe compressed) to the corresponding block caches.
|
|
|
|
// This method will perform decompression against raw_block if needed and then
|
|
|
|
// populate the block caches.
|
|
|
|
// On success, Status::OK will be returned; also @block will be populated with
|
|
|
|
// uncompressed block and its cache handle.
|
2013-11-13 06:46:51 +00:00
|
|
|
//
|
2018-11-14 01:00:49 +00:00
|
|
|
// Allocated memory managed by raw_block_contents will be transferred to
|
|
|
|
// PutDataBlockToCache(). After the call, the object will be invalid.
|
2019-01-24 02:11:08 +00:00
|
|
|
// @param uncompression_dict Data for presetting the compression library's
|
Shared dictionary compression using reference block
Summary:
This adds a new metablock containing a shared dictionary that is used
to compress all data blocks in the SST file. The size of the shared dictionary
is configurable in CompressionOptions and defaults to 0. It's currently only
used for zlib/lz4/lz4hc, but the block will be stored in the SST regardless of
the compression type if the user chooses a nonzero dictionary size.
During compaction, computes the dictionary by randomly sampling the first
output file in each subcompaction. It pre-computes the intervals to sample
by assuming the output file will have the maximum allowable length. In case
the file is smaller, some of the pre-computed sampling intervals can be beyond
end-of-file, in which case we skip over those samples and the dictionary will
be a bit smaller. After the dictionary is generated using the first file in a
subcompaction, it is loaded into the compression library before writing each
block in each subsequent file of that subcompaction.
On the read path, gets the dictionary from the metablock, if it exists. Then,
loads that dictionary into the compression library before reading each block.
Test Plan: new unit test
Reviewers: yhchiang, IslamAbdelRahman, cyan, sdong
Reviewed By: sdong
Subscribers: andrewkr, yoshinorim, kradhakrishnan, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D52287
2016-04-28 00:36:03 +00:00
|
|
|
// dictionary.
|
2014-03-01 02:19:07 +00:00
|
|
|
static Status PutDataBlockToCache(
|
|
|
|
const Slice& block_cache_key, const Slice& compressed_block_cache_key,
|
|
|
|
Cache* block_cache, Cache* block_cache_compressed,
|
2016-08-27 01:55:58 +00:00
|
|
|
const ReadOptions& read_options, const ImmutableCFOptions& ioptions,
|
2018-11-14 01:00:49 +00:00
|
|
|
CachableEntry<Block>* block, BlockContents* raw_block_contents,
|
|
|
|
CompressionType raw_block_comp_type, uint32_t format_version,
|
2019-01-24 02:11:08 +00:00
|
|
|
const UncompressionDict& uncompression_dict, SequenceNumber seq_no,
|
2018-11-29 01:58:08 +00:00
|
|
|
size_t read_amp_bytes_per_bit, MemoryAllocator* memory_allocator,
|
|
|
|
bool is_index = false, Cache::Priority pri = Cache::Priority::LOW,
|
|
|
|
GetContext* get_context = nullptr);
|
2013-11-13 06:46:51 +00:00
|
|
|
|
2013-03-21 22:59:47 +00:00
|
|
|
// Calls (*handle_result)(arg, ...) repeatedly, starting with the entry found
|
|
|
|
// after a call to Seek(key), until handle_result returns false.
|
|
|
|
// May not make such a call if filter policy says that key is not present.
|
2012-04-17 15:36:46 +00:00
|
|
|
friend class TableCache;
|
2013-09-02 06:23:40 +00:00
|
|
|
friend class BlockBasedTableBuilder;
|
2012-04-17 15:36:46 +00:00
|
|
|
|
|
|
|
void ReadMeta(const Footer& footer);
|
2014-05-15 21:09:03 +00:00
|
|
|
|
2018-06-22 22:14:05 +00:00
|
|
|
// Figure the index type, update it in rep_, and also return it.
|
|
|
|
BlockBasedTableOptions::IndexType UpdateIndexType();
|
|
|
|
|
2014-05-15 21:09:03 +00:00
|
|
|
// Create a index reader based on the index type stored in the table.
|
|
|
|
// Optionally, user can pass a preloaded meta_index_iter for the index that
|
|
|
|
// need to access extra meta blocks for index construction. This parameter
|
|
|
|
// helps avoid re-reading meta index block if caller already created one.
|
2015-10-12 22:06:38 +00:00
|
|
|
Status CreateIndexReader(
|
2017-08-11 18:59:13 +00:00
|
|
|
FilePrefetchBuffer* prefetch_buffer, IndexReader** index_reader,
|
2017-03-22 16:11:23 +00:00
|
|
|
InternalIterator* preloaded_meta_index_iter = nullptr,
|
|
|
|
const int level = -1);
|
2012-04-17 15:36:46 +00:00
|
|
|
|
2018-05-21 21:33:55 +00:00
|
|
|
bool FullFilterKeyMayMatch(
|
|
|
|
const ReadOptions& read_options, FilterBlockReader* filter,
|
|
|
|
const Slice& user_key, const bool no_io,
|
|
|
|
const SliceTransform* prefix_extractor = nullptr) const;
|
2015-02-03 01:42:57 +00:00
|
|
|
|
Introduce a new MultiGet batching implementation (#5011)
Summary:
This PR introduces a new MultiGet() API, with the underlying implementation grouping keys based on SST file and batching lookups in a file. The reason for the new API is twofold - the definition allows callers to allocate storage for status and values on stack instead of std::vector, as well as return values as PinnableSlices in order to avoid copying, and it keeps the original MultiGet() implementation intact while we experiment with batching.
Batching is useful when there is some spatial locality to the keys being queries, as well as larger batch sizes. The main benefits are due to -
1. Fewer function calls, especially to BlockBasedTableReader::MultiGet() and FullFilterBlockReader::KeysMayMatch()
2. Bloom filter cachelines can be prefetched, hiding the cache miss latency
The next step is to optimize the binary searches in the level_storage_info, index blocks and data blocks, since we could reduce the number of key comparisons if the keys are relatively close to each other. The batching optimizations also need to be extended to other formats, such as PlainTable and filter formats. This also needs to be added to db_stress.
Benchmark results from db_bench for various batch size/locality of reference combinations are given below. Locality was simulated by offsetting the keys in a batch by a stride length. Each SST file is about 8.6MB uncompressed and key/value size is 16/100 uncompressed. To focus on the cpu benefit of batching, the runs were single threaded and bound to the same cpu to eliminate interference from other system events. The results show a 10-25% improvement in micros/op from smaller to larger batch sizes (4 - 32).
Batch Sizes
1 | 2 | 4 | 8 | 16 | 32
Random pattern (Stride length 0)
4.158 | 4.109 | 4.026 | 4.05 | 4.1 | 4.074 - Get
4.438 | 4.302 | 4.165 | 4.122 | 4.096 | 4.075 - MultiGet (no batching)
4.461 | 4.256 | 4.277 | 4.11 | 4.182 | 4.14 - MultiGet (w/ batching)
Good locality (Stride length 16)
4.048 | 3.659 | 3.248 | 2.99 | 2.84 | 2.753
4.429 | 3.728 | 3.406 | 3.053 | 2.911 | 2.781
4.452 | 3.45 | 2.833 | 2.451 | 2.233 | 2.135
Good locality (Stride length 256)
4.066 | 3.786 | 3.581 | 3.447 | 3.415 | 3.232
4.406 | 4.005 | 3.644 | 3.49 | 3.381 | 3.268
4.393 | 3.649 | 3.186 | 2.882 | 2.676 | 2.62
Medium locality (Stride length 4096)
4.012 | 3.922 | 3.768 | 3.61 | 3.582 | 3.555
4.364 | 4.057 | 3.791 | 3.65 | 3.57 | 3.465
4.479 | 3.758 | 3.316 | 3.077 | 2.959 | 2.891
dbbench command used (on a DB with 4 levels, 12 million keys)-
TEST_TMPDIR=/dev/shm numactl -C 10 ./db_bench.tmp -use_existing_db=true -benchmarks="readseq,multireadrandom" -write_buffer_size=4194304 -target_file_size_base=4194304 -max_bytes_for_level_base=16777216 -num=12000000 -reads=12000000 -duration=90 -threads=1 -compression_type=none -cache_size=4194304000 -batch_size=32 -disable_auto_compactions=true -bloom_bits=10 -cache_index_and_filter_blocks=true -pin_l0_filter_and_index_blocks_in_cache=true -multiread_batched=true -multiread_stride=4
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5011
Differential Revision: D14348703
Pulled By: anand1976
fbshipit-source-id: 774406dab3776d979c809522a67bedac6c17f84b
2019-04-11 21:24:09 +00:00
|
|
|
void FullFilterKeysMayMatch(
|
|
|
|
const ReadOptions& read_options, FilterBlockReader* filter,
|
|
|
|
MultiGetRange* range, const bool no_io,
|
|
|
|
const SliceTransform* prefix_extractor = nullptr) const;
|
|
|
|
|
2018-12-07 21:15:09 +00:00
|
|
|
static Status PrefetchTail(
|
|
|
|
RandomAccessFileReader* file, uint64_t file_size,
|
|
|
|
TailPrefetchStats* tail_prefetch_stats, const bool prefetch_all,
|
|
|
|
const bool preload_all,
|
|
|
|
std::unique_ptr<FilePrefetchBuffer>* prefetch_buffer);
|
2017-08-11 18:59:13 +00:00
|
|
|
static Status ReadMetaBlock(Rep* rep, FilePrefetchBuffer* prefetch_buffer,
|
|
|
|
std::unique_ptr<Block>* meta_block,
|
2015-10-12 22:06:38 +00:00
|
|
|
std::unique_ptr<InternalIterator>* iter);
|
2019-03-26 17:15:43 +00:00
|
|
|
static Status TryReadPropertiesWithGlobalSeqno(
|
|
|
|
Rep* rep, FilePrefetchBuffer* prefetch_buffer, const Slice& handle_value,
|
|
|
|
TableProperties** table_properties);
|
2018-12-07 21:15:09 +00:00
|
|
|
static Status ReadPropertiesBlock(Rep* rep,
|
|
|
|
FilePrefetchBuffer* prefetch_buffer,
|
|
|
|
InternalIterator* meta_iter,
|
|
|
|
const SequenceNumber largest_seqno);
|
|
|
|
static Status ReadRangeDelBlock(
|
|
|
|
Rep* rep, FilePrefetchBuffer* prefetch_buffer,
|
2018-12-21 05:57:18 +00:00
|
|
|
InternalIterator* meta_iter,
|
2018-12-07 21:15:09 +00:00
|
|
|
const InternalKeyComparator& internal_comparator);
|
2019-01-24 02:11:08 +00:00
|
|
|
static Status ReadCompressionDictBlock(
|
|
|
|
Rep* rep, FilePrefetchBuffer* prefetch_buffer,
|
|
|
|
std::unique_ptr<const BlockContents>* compression_dict_block);
|
2018-12-07 21:15:09 +00:00
|
|
|
static Status PrefetchIndexAndFilterBlocks(
|
|
|
|
Rep* rep, FilePrefetchBuffer* prefetch_buffer,
|
|
|
|
InternalIterator* meta_iter, BlockBasedTable* new_table,
|
|
|
|
const SliceTransform* prefix_extractor, bool prefetch_all,
|
|
|
|
const BlockBasedTableOptions& table_options, const int level,
|
|
|
|
const bool prefetch_index_and_filter_in_cache);
|
2013-11-13 06:46:51 +00:00
|
|
|
|
2019-03-26 17:15:43 +00:00
|
|
|
Status VerifyChecksumInMetaBlocks(InternalIteratorBase<Slice>* index_iter);
|
2018-08-09 23:49:45 +00:00
|
|
|
Status VerifyChecksumInBlocks(InternalIteratorBase<BlockHandle>* index_iter);
|
2017-08-09 22:49:40 +00:00
|
|
|
|
2013-11-13 06:46:51 +00:00
|
|
|
// Create the filter from the filter block.
|
2018-06-19 21:06:17 +00:00
|
|
|
virtual FilterBlockReader* ReadFilter(
|
2018-05-21 21:33:55 +00:00
|
|
|
FilePrefetchBuffer* prefetch_buffer, const BlockHandle& filter_handle,
|
|
|
|
const bool is_a_filter_partition,
|
|
|
|
const SliceTransform* prefix_extractor = nullptr) const;
|
2013-11-13 06:46:51 +00:00
|
|
|
|
Index Reader should not be reused after DB restart
Summary:
In block based table reader, wow we put index reader to block cache, which can be retrieved after DB restart. However, index reader may reference internal comparator, which can be destroyed after DB restarts, causing problems.
Fix it by making cache key identical per table reader.
Test Plan: Add a new test which failed with out the commit but now pass.
Reviewers: IslamAbdelRahman
Reviewed By: IslamAbdelRahman
Subscribers: maro, yhchiang, kradhakrishnan, leveldb, andrewkr, dhruba
Differential Revision: https://reviews.facebook.net/D55287
2016-03-10 23:16:11 +00:00
|
|
|
static void SetupCacheKeyPrefix(Rep* rep, uint64_t file_size);
|
2013-01-31 23:20:24 +00:00
|
|
|
|
2013-09-02 06:23:40 +00:00
|
|
|
// Generate a cache key prefix from the file
|
2019-03-27 23:13:08 +00:00
|
|
|
static void GenerateCachePrefix(Cache* cc, RandomAccessFile* file,
|
|
|
|
char* buffer, size_t* size);
|
|
|
|
static void GenerateCachePrefix(Cache* cc, WritableFile* file, char* buffer,
|
|
|
|
size_t* size);
|
2013-09-02 06:23:40 +00:00
|
|
|
|
2014-12-23 21:24:07 +00:00
|
|
|
// Helper functions for DumpTable()
|
|
|
|
Status DumpIndexBlock(WritableFile* out_file);
|
|
|
|
Status DumpDataBlocks(WritableFile* out_file);
|
2016-11-12 17:23:05 +00:00
|
|
|
void DumpKeyValue(const Slice& key, const Slice& value,
|
|
|
|
WritableFile* out_file);
|
2014-12-23 21:24:07 +00:00
|
|
|
|
2013-10-29 00:54:09 +00:00
|
|
|
// No copying allowed
|
2013-10-30 17:52:33 +00:00
|
|
|
explicit BlockBasedTable(const TableReader&) = delete;
|
|
|
|
void operator=(const TableReader&) = delete;
|
2017-03-22 16:11:23 +00:00
|
|
|
|
|
|
|
friend class PartitionedFilterBlockReader;
|
|
|
|
friend class PartitionedFilterBlockTest;
|
2013-10-30 17:52:33 +00:00
|
|
|
};
|
|
|
|
|
2017-02-07 00:29:29 +00:00
|
|
|
// Maitaning state of a two-level iteration on a partitioned index structure
|
2018-02-13 00:57:56 +00:00
|
|
|
class BlockBasedTable::PartitionedIndexIteratorState
|
|
|
|
: public TwoLevelIteratorState {
|
2017-02-07 00:29:29 +00:00
|
|
|
public:
|
2018-02-13 00:57:56 +00:00
|
|
|
PartitionedIndexIteratorState(
|
|
|
|
BlockBasedTable* table,
|
2018-05-26 01:41:31 +00:00
|
|
|
std::unordered_map<uint64_t, CachableEntry<Block>>* block_map,
|
2018-08-09 23:49:45 +00:00
|
|
|
const bool index_key_includes_seq, const bool index_key_is_full);
|
|
|
|
InternalIteratorBase<BlockHandle>* NewSecondaryIterator(
|
|
|
|
const BlockHandle& index_value) override;
|
2017-02-07 00:29:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Don't own table_
|
|
|
|
BlockBasedTable* table_;
|
2017-08-23 14:48:54 +00:00
|
|
|
std::unordered_map<uint64_t, CachableEntry<Block>>* block_map_;
|
2018-05-26 01:41:31 +00:00
|
|
|
bool index_key_includes_seq_;
|
2018-08-09 23:49:45 +00:00
|
|
|
bool index_key_is_full_;
|
2017-02-07 00:29:29 +00:00
|
|
|
};
|
|
|
|
|
2017-03-04 02:09:43 +00:00
|
|
|
// CachableEntry represents the entries that *may* be fetched from block cache.
|
|
|
|
// field `value` is the item we want to get.
|
|
|
|
// field `cache_handle` is the cache handle to the block cache. If the value
|
|
|
|
// was not read from cache, `cache_handle` will be nullptr.
|
|
|
|
template <class TValue>
|
|
|
|
struct BlockBasedTable::CachableEntry {
|
|
|
|
CachableEntry(TValue* _value, Cache::Handle* _cache_handle)
|
|
|
|
: value(_value), cache_handle(_cache_handle) {}
|
|
|
|
CachableEntry() : CachableEntry(nullptr, nullptr) {}
|
2017-05-06 03:10:56 +00:00
|
|
|
void Release(Cache* cache, bool force_erase = false) {
|
2017-03-04 02:09:43 +00:00
|
|
|
if (cache_handle) {
|
2017-05-06 03:10:56 +00:00
|
|
|
cache->Release(cache_handle, force_erase);
|
2017-03-04 02:09:43 +00:00
|
|
|
value = nullptr;
|
|
|
|
cache_handle = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool IsSet() const { return cache_handle != nullptr; }
|
|
|
|
|
|
|
|
TValue* value = nullptr;
|
|
|
|
// if the entry is from the cache, cache_handle will be populated.
|
|
|
|
Cache::Handle* cache_handle = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BlockBasedTable::Rep {
|
|
|
|
Rep(const ImmutableCFOptions& _ioptions, const EnvOptions& _env_options,
|
|
|
|
const BlockBasedTableOptions& _table_opt,
|
2018-06-28 00:09:29 +00:00
|
|
|
const InternalKeyComparator& _internal_comparator, bool skip_filters,
|
2018-10-24 19:10:59 +00:00
|
|
|
int _level, const bool _immortal_table)
|
2017-03-04 02:09:43 +00:00
|
|
|
: ioptions(_ioptions),
|
|
|
|
env_options(_env_options),
|
|
|
|
table_options(_table_opt),
|
|
|
|
filter_policy(skip_filters ? nullptr : _table_opt.filter_policy.get()),
|
|
|
|
internal_comparator(_internal_comparator),
|
|
|
|
filter_type(FilterType::kNoFilter),
|
2017-12-07 19:50:49 +00:00
|
|
|
index_type(BlockBasedTableOptions::IndexType::kBinarySearch),
|
|
|
|
hash_index_allow_collision(false),
|
2017-03-04 02:09:43 +00:00
|
|
|
whole_key_filtering(_table_opt.whole_key_filtering),
|
|
|
|
prefix_filtering(true),
|
2018-06-28 00:09:29 +00:00
|
|
|
global_seqno(kDisableGlobalSequenceNumber),
|
2018-10-24 19:10:59 +00:00
|
|
|
level(_level),
|
2018-06-28 00:09:29 +00:00
|
|
|
immortal_table(_immortal_table) {}
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
const ImmutableCFOptions& ioptions;
|
|
|
|
const EnvOptions& env_options;
|
Fix segfault caused by object premature destruction
Summary:
Please refer to earlier discussion in [issue 3609](https://github.com/facebook/rocksdb/issues/3609).
There was also an alternative fix in [PR 3888](https://github.com/facebook/rocksdb/pull/3888), but the proposed solution requires complex change.
To summarize the cause of the problem. Upon creation of a column family, a `BlockBasedTableFactory` object is `new`ed and encapsulated by a `std::shared_ptr`. Since there is no other `std::shared_ptr` pointing to this `BlockBasedTableFactory`, when the column family is dropped, the `ColumnFamilyData` is `delete`d, causing the destructor of `std::shared_ptr`. Since there is no other `std::shared_ptr`, the underlying memory is also freed.
Later when the db exits, it releases all the table readers, including the table readers that have been operating on the dropped column family. This needs to access the `table_options` owned by `BlockBasedTableFactory` that has already been deleted. Therefore, a segfault is raised.
Previous workaround is to purge all obsolete files upon `ColumnFamilyData` destruction, which leads to a force release of table readers of the dropped column family. However this does not work when the user disables file deletion.
Our solution in this PR is making a copy of `table_options` in `BlockBasedTable::Rep`. This solution increases memory copy and usage, but is much simpler.
Test plan
```
$ make -j16
$ ./column_family_test --gtest_filter=ColumnFamilyTest.CreateDropAndDestroy:ColumnFamilyTest.CreateDropAndDestroyWithoutFileDeletion
```
Expected behavior:
All tests should pass.
Closes https://github.com/facebook/rocksdb/pull/3898
Differential Revision: D8149421
Pulled By: riversand963
fbshipit-source-id: eaecc2e064057ef607fbdd4cc275874f866c3438
2018-05-25 18:45:12 +00:00
|
|
|
const BlockBasedTableOptions table_options;
|
2017-03-04 02:09:43 +00:00
|
|
|
const FilterPolicy* const filter_policy;
|
|
|
|
const InternalKeyComparator& internal_comparator;
|
|
|
|
Status status;
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<RandomAccessFileReader> file;
|
2017-03-04 02:09:43 +00:00
|
|
|
char cache_key_prefix[kMaxCacheKeyPrefixSize];
|
|
|
|
size_t cache_key_prefix_size = 0;
|
|
|
|
char persistent_cache_key_prefix[kMaxCacheKeyPrefixSize];
|
|
|
|
size_t persistent_cache_key_prefix_size = 0;
|
|
|
|
char compressed_cache_key_prefix[kMaxCacheKeyPrefixSize];
|
|
|
|
size_t compressed_cache_key_prefix_size = 0;
|
|
|
|
uint64_t dummy_index_reader_offset =
|
|
|
|
0; // ID that is unique for the block cache.
|
|
|
|
PersistentCacheOptions persistent_cache_options;
|
|
|
|
|
|
|
|
// Footer contains the fixed table information
|
|
|
|
Footer footer;
|
2019-01-24 02:11:08 +00:00
|
|
|
// `index_reader`, `filter`, and `uncompression_dict` will be populated (i.e.,
|
|
|
|
// non-nullptr) and used only when options.block_cache is nullptr or when
|
|
|
|
// `cache_index_and_filter_blocks == false`. Otherwise, we will get the index,
|
|
|
|
// filter, and compression dictionary blocks via the block cache. In that case
|
|
|
|
// `dummy_index_reader_offset`, `filter_handle`, and `compression_dict_handle`
|
|
|
|
// are used to lookup these meta-blocks in block cache.
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<IndexReader> index_reader;
|
|
|
|
std::unique_ptr<FilterBlockReader> filter;
|
2019-01-24 02:11:08 +00:00
|
|
|
std::unique_ptr<UncompressionDict> uncompression_dict;
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
enum class FilterType {
|
|
|
|
kNoFilter,
|
|
|
|
kFullFilter,
|
|
|
|
kBlockFilter,
|
|
|
|
kPartitionedFilter,
|
|
|
|
};
|
|
|
|
FilterType filter_type;
|
|
|
|
BlockHandle filter_handle;
|
2019-01-24 02:11:08 +00:00
|
|
|
BlockHandle compression_dict_handle;
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
std::shared_ptr<const TableProperties> table_properties;
|
|
|
|
BlockBasedTableOptions::IndexType index_type;
|
|
|
|
bool hash_index_allow_collision;
|
|
|
|
bool whole_key_filtering;
|
|
|
|
bool prefix_filtering;
|
|
|
|
// TODO(kailiu) It is very ugly to use internal key in table, since table
|
|
|
|
// module should not be relying on db module. However to make things easier
|
|
|
|
// and compatible with existing code, we introduce a wrapper that allows
|
|
|
|
// block to extract prefix without knowing if a key is internal or not.
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<SliceTransform> internal_prefix_transform;
|
2018-06-26 22:56:26 +00:00
|
|
|
std::shared_ptr<const SliceTransform> table_prefix_extractor;
|
2017-03-04 02:09:43 +00:00
|
|
|
|
2018-06-22 22:14:05 +00:00
|
|
|
// only used in level 0 files when pin_l0_filter_and_index_blocks_in_cache is
|
|
|
|
// true or in all levels when pin_top_level_index_and_filter is set in
|
|
|
|
// combination with partitioned index/filters: then we do use the LRU cache,
|
|
|
|
// but we always keep the filter & index block's handle checked out here (=we
|
|
|
|
// don't call Release()), plus the parsed out objects the LRU cache will never
|
|
|
|
// push flush them out, hence they're pinned
|
2017-03-04 02:09:43 +00:00
|
|
|
CachableEntry<FilterBlockReader> filter_entry;
|
|
|
|
CachableEntry<IndexReader> index_entry;
|
Cache fragmented range tombstones in BlockBasedTableReader (#4493)
Summary:
This allows tombstone fragmenting to only be performed when the table is opened, and cached for subsequent accesses.
On the same DB used in #4449, running `readrandom` results in the following:
```
readrandom : 0.983 micros/op 1017076 ops/sec; 78.3 MB/s (63103 of 100000 found)
```
Now that Get performance in the presence of range tombstones is reasonable, I also compared the performance between a DB with range tombstones, "expanded" range tombstones (several point tombstones that cover the same keys the equivalent range tombstone would cover, a common workaround for DeleteRange), and no range tombstones. The created DBs had 5 million keys each, and DeleteRange was called at regular intervals (depending on the total number of range tombstones being written) after 4.5 million Puts. The table below summarizes the results of a `readwhilewriting` benchmark (in order to provide somewhat more realistic results):
```
Tombstones? | avg micros/op | stddev micros/op | avg ops/s | stddev ops/s
----------------- | ------------- | ---------------- | ------------ | ------------
None | 0.6186 | 0.04637 | 1,625,252.90 | 124,679.41
500 Expanded | 0.6019 | 0.03628 | 1,666,670.40 | 101,142.65
500 Unexpanded | 0.6435 | 0.03994 | 1,559,979.40 | 104,090.52
1k Expanded | 0.6034 | 0.04349 | 1,665,128.10 | 125,144.57
1k Unexpanded | 0.6261 | 0.03093 | 1,600,457.50 | 79,024.94
5k Expanded | 0.6163 | 0.05926 | 1,636,668.80 | 154,888.85
5k Unexpanded | 0.6402 | 0.04002 | 1,567,804.70 | 100,965.55
10k Expanded | 0.6036 | 0.05105 | 1,667,237.70 | 142,830.36
10k Unexpanded | 0.6128 | 0.02598 | 1,634,633.40 | 72,161.82
25k Expanded | 0.6198 | 0.04542 | 1,620,980.50 | 116,662.93
25k Unexpanded | 0.5478 | 0.0362 | 1,833,059.10 | 121,233.81
50k Expanded | 0.5104 | 0.04347 | 1,973,107.90 | 184,073.49
50k Unexpanded | 0.4528 | 0.03387 | 2,219,034.50 | 170,984.32
```
After a large enough quantity of range tombstones are written, range tombstone Gets can become faster than reading from an equivalent DB with several point tombstones.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4493
Differential Revision: D10842844
Pulled By: abhimadan
fbshipit-source-id: a7d44534f8120e6aabb65779d26c6b9df954c509
2018-10-26 02:25:00 +00:00
|
|
|
std::shared_ptr<const FragmentedRangeTombstoneList> fragmented_range_dels;
|
2017-03-04 02:09:43 +00:00
|
|
|
|
|
|
|
// If global_seqno is used, all Keys in this file will have the same
|
|
|
|
// seqno with value `global_seqno`.
|
|
|
|
//
|
|
|
|
// A value of kDisableGlobalSequenceNumber means that this feature is disabled
|
|
|
|
// and every key have it's own seqno.
|
|
|
|
SequenceNumber global_seqno;
|
2018-02-07 23:42:35 +00:00
|
|
|
|
2018-10-24 19:10:59 +00:00
|
|
|
// the level when the table is opened, could potentially change when trivial
|
|
|
|
// move is involved
|
|
|
|
int level;
|
|
|
|
|
2018-02-07 23:42:35 +00:00
|
|
|
// If false, blocks in this file are definitely all uncompressed. Knowing this
|
|
|
|
// before reading individual blocks enables certain optimizations.
|
|
|
|
bool blocks_maybe_compressed = true;
|
|
|
|
|
2019-01-24 02:11:08 +00:00
|
|
|
// If true, data blocks in this file are definitely ZSTD compressed. If false
|
|
|
|
// they might not be. When false we skip creating a ZSTD digested
|
|
|
|
// uncompression dictionary. Even if we get a false negative, things should
|
|
|
|
// still work, just not as quickly.
|
|
|
|
bool blocks_definitely_zstd_compressed = false;
|
|
|
|
|
2017-07-28 03:16:25 +00:00
|
|
|
bool closed = false;
|
2018-06-28 00:09:29 +00:00
|
|
|
const bool immortal_table;
|
2018-11-14 01:00:49 +00:00
|
|
|
|
|
|
|
SequenceNumber get_global_seqno(bool is_index) const {
|
|
|
|
return is_index ? kDisableGlobalSequenceNumber : global_seqno;
|
|
|
|
}
|
2017-03-04 02:09:43 +00:00
|
|
|
};
|
|
|
|
|
2018-08-09 23:49:45 +00:00
|
|
|
template <class TBlockIter, typename TValue = Slice>
|
|
|
|
class BlockBasedTableIterator : public InternalIteratorBase<TValue> {
|
2018-02-13 00:57:56 +00:00
|
|
|
public:
|
|
|
|
BlockBasedTableIterator(BlockBasedTable* table,
|
|
|
|
const ReadOptions& read_options,
|
|
|
|
const InternalKeyComparator& icomp,
|
2018-08-09 23:49:45 +00:00
|
|
|
InternalIteratorBase<BlockHandle>* index_iter,
|
|
|
|
bool check_filter, bool need_upper_bound_check,
|
2018-05-26 01:41:31 +00:00
|
|
|
const SliceTransform* prefix_extractor, bool is_index,
|
2018-06-25 20:07:38 +00:00
|
|
|
bool key_includes_seq = true,
|
2018-08-09 23:49:45 +00:00
|
|
|
bool index_key_is_full = true,
|
2018-06-25 20:07:38 +00:00
|
|
|
bool for_compaction = false)
|
2018-02-13 00:57:56 +00:00
|
|
|
: table_(table),
|
|
|
|
read_options_(read_options),
|
|
|
|
icomp_(icomp),
|
2019-03-27 17:24:16 +00:00
|
|
|
user_comparator_(icomp.user_comparator()),
|
2018-02-13 00:57:56 +00:00
|
|
|
index_iter_(index_iter),
|
|
|
|
pinned_iters_mgr_(nullptr),
|
|
|
|
block_iter_points_to_real_block_(false),
|
2018-05-21 21:33:55 +00:00
|
|
|
check_filter_(check_filter),
|
2018-06-26 22:56:26 +00:00
|
|
|
need_upper_bound_check_(need_upper_bound_check),
|
|
|
|
prefix_extractor_(prefix_extractor),
|
2018-05-26 01:41:31 +00:00
|
|
|
is_index_(is_index),
|
|
|
|
key_includes_seq_(key_includes_seq),
|
2018-08-09 23:49:45 +00:00
|
|
|
index_key_is_full_(index_key_is_full),
|
2018-06-26 22:56:26 +00:00
|
|
|
for_compaction_(for_compaction) {}
|
2018-02-13 00:57:56 +00:00
|
|
|
|
|
|
|
~BlockBasedTableIterator() { delete index_iter_; }
|
|
|
|
|
|
|
|
void Seek(const Slice& target) override;
|
|
|
|
void SeekForPrev(const Slice& target) override;
|
|
|
|
void SeekToFirst() override;
|
|
|
|
void SeekToLast() override;
|
2019-04-18 18:08:33 +00:00
|
|
|
void Next() final override;
|
|
|
|
bool NextAndGetResult(Slice* ret_key) override;
|
2018-02-13 00:57:56 +00:00
|
|
|
void Prev() override;
|
|
|
|
bool Valid() const override {
|
2018-06-19 16:42:40 +00:00
|
|
|
return !is_out_of_bound_ && block_iter_points_to_real_block_ &&
|
2018-07-13 00:19:57 +00:00
|
|
|
block_iter_.Valid();
|
2018-02-13 00:57:56 +00:00
|
|
|
}
|
|
|
|
Slice key() const override {
|
|
|
|
assert(Valid());
|
2018-07-13 00:19:57 +00:00
|
|
|
return block_iter_.key();
|
2018-02-13 00:57:56 +00:00
|
|
|
}
|
2019-04-16 18:32:03 +00:00
|
|
|
Slice user_key() const override {
|
|
|
|
assert(Valid());
|
|
|
|
return block_iter_.user_key();
|
|
|
|
}
|
2018-08-09 23:49:45 +00:00
|
|
|
TValue value() const override {
|
2018-02-13 00:57:56 +00:00
|
|
|
assert(Valid());
|
2018-07-13 00:19:57 +00:00
|
|
|
return block_iter_.value();
|
2018-02-13 00:57:56 +00:00
|
|
|
}
|
|
|
|
Status status() const override {
|
|
|
|
if (!index_iter_->status().ok()) {
|
|
|
|
return index_iter_->status();
|
Change and clarify the relationship between Valid(), status() and Seek*() for all iterators. Also fix some bugs
Summary:
Before this PR, Iterator/InternalIterator may simultaneously have non-ok status() and Valid() = true. That state means that the last operation failed, but the iterator is nevertheless positioned on some unspecified record. Likely intended uses of that are:
* If some sst files are corrupted, a normal iterator can be used to read the data from files that are not corrupted.
* When using read_tier = kBlockCacheTier, read the data that's in block cache, skipping over the data that is not.
However, this behavior wasn't documented well (and until recently the wiki on github had misleading incorrect information). In the code there's a lot of confusion about the relationship between status() and Valid(), and about whether Seek()/SeekToLast()/etc reset the status or not. There were a number of bugs caused by this confusion, both inside rocksdb and in the code that uses rocksdb (including ours).
This PR changes the convention to:
* If status() is not ok, Valid() always returns false.
* Any seek operation resets status. (Before the PR, it depended on iterator type and on particular error.)
This does sacrifice the two use cases listed above, but siying said it's ok.
Overview of the changes:
* A commit that adds missing status checks in MergingIterator. This fixes a bug that actually affects us, and we need it fixed. `DBIteratorTest.NonBlockingIterationBugRepro` explains the scenario.
* Changes to lots of iterator types to make all of them conform to the new convention. Some bug fixes along the way. By far the biggest changes are in DBIter, which is a big messy piece of code; I tried to make it less big and messy but mostly failed.
* A stress-test for DBIter, to gain some confidence that I didn't break it. It does a few million random operations on the iterator, while occasionally modifying the underlying data (like ForwardIterator does) and occasionally returning non-ok status from internal iterator.
To find the iterator types that needed changes I searched for "public .*Iterator" in the code. Here's an overview of all 27 iterator types:
Iterators that didn't need changes:
* status() is always ok(), or Valid() is always false: MemTableIterator, ModelIter, TestIterator, KVIter (2 classes with this name anonymous namespaces), LoggingForwardVectorIterator, VectorIterator, MockTableIterator, EmptyIterator, EmptyInternalIterator.
* Thin wrappers that always pass through Valid() and status(): ArenaWrappedDBIter, TtlIterator, InternalIteratorFromIterator.
Iterators with changes (see inline comments for details):
* DBIter - an overhaul:
- It used to silently skip corrupted keys (`FindParseableKey()`), which seems dangerous. This PR makes it just stop immediately after encountering a corrupted key, just like it would for other kinds of corruption. Let me know if there was actually some deeper meaning in this behavior and I should put it back.
- It had a few code paths silently discarding subiterator's status. The stress test caught a few.
- The backwards iteration code path was expecting the internal iterator's set of keys to be immutable. It's probably always true in practice at the moment, since ForwardIterator doesn't support backwards iteration, but this PR fixes it anyway. See added DBIteratorTest.ReverseToForwardBug for an example.
- Some parts of backwards iteration code path even did things like `assert(iter_->Valid())` after a seek, which is never a safe assumption.
- It used to not reset status on seek for some types of errors.
- Some simplifications and better comments.
- Some things got more complicated from the added error handling. I'm open to ideas for how to make it nicer.
* MergingIterator - check status after every operation on every subiterator, and in some places assert that valid subiterators have ok status.
* ForwardIterator - changed to the new convention, also slightly simplified.
* ForwardLevelIterator - fixed some bugs and simplified.
* LevelIterator - simplified.
* TwoLevelIterator - changed to the new convention. Also fixed a bug that would make SeekForPrev() sometimes silently ignore errors from first_level_iter_.
* BlockBasedTableIterator - minor changes.
* BlockIter - replaced `SetStatus()` with `Invalidate()` to make sure non-ok BlockIter is always invalid.
* PlainTableIterator - some seeks used to not reset status.
* CuckooTableIterator - tiny code cleanup.
* ManagedIterator - fixed some bugs.
* BaseDeltaIterator - changed to the new convention and fixed a bug.
* BlobDBIterator - seeks used to not reset status.
* KeyConvertingIterator - some small change.
Closes https://github.com/facebook/rocksdb/pull/3810
Differential Revision: D7888019
Pulled By: al13n321
fbshipit-source-id: 4aaf6d3421c545d16722a815b2fa2e7912bc851d
2018-05-17 09:44:14 +00:00
|
|
|
} else if (block_iter_points_to_real_block_) {
|
2018-07-13 00:19:57 +00:00
|
|
|
return block_iter_.status();
|
2018-02-13 00:57:56 +00:00
|
|
|
} else {
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 18:32:03 +00:00
|
|
|
// Whether iterator invalidated for being out of bound.
|
2018-02-13 00:57:56 +00:00
|
|
|
bool IsOutOfBound() override { return is_out_of_bound_; }
|
|
|
|
|
|
|
|
void SetPinnedItersMgr(PinnedIteratorsManager* pinned_iters_mgr) override {
|
|
|
|
pinned_iters_mgr_ = pinned_iters_mgr;
|
|
|
|
}
|
|
|
|
bool IsKeyPinned() const override {
|
|
|
|
return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() &&
|
2018-07-13 00:19:57 +00:00
|
|
|
block_iter_points_to_real_block_ && block_iter_.IsKeyPinned();
|
2018-02-13 00:57:56 +00:00
|
|
|
}
|
|
|
|
bool IsValuePinned() const override {
|
2018-03-08 18:09:59 +00:00
|
|
|
// BlockIter::IsValuePinned() is always true. No need to check
|
2018-02-13 00:57:56 +00:00
|
|
|
return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() &&
|
|
|
|
block_iter_points_to_real_block_;
|
|
|
|
}
|
|
|
|
|
2018-06-26 22:56:26 +00:00
|
|
|
bool CheckPrefixMayMatch(const Slice& ikey) {
|
|
|
|
if (check_filter_ &&
|
|
|
|
!table_->PrefixMayMatch(ikey, read_options_, prefix_extractor_,
|
|
|
|
need_upper_bound_check_)) {
|
2018-02-13 00:57:56 +00:00
|
|
|
// TODO remember the iterator is invalidated because of prefix
|
|
|
|
// match. This can avoid the upper level file iterator to falsely
|
|
|
|
// believe the position is the end of the SST file and move to
|
|
|
|
// the first key of the next file.
|
|
|
|
ResetDataIter();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetDataIter() {
|
|
|
|
if (block_iter_points_to_real_block_) {
|
2018-03-08 18:09:59 +00:00
|
|
|
if (pinned_iters_mgr_ != nullptr && pinned_iters_mgr_->PinningEnabled()) {
|
2018-07-13 00:19:57 +00:00
|
|
|
block_iter_.DelegateCleanupsTo(pinned_iters_mgr_);
|
2018-02-13 00:57:56 +00:00
|
|
|
}
|
2018-07-13 00:19:57 +00:00
|
|
|
block_iter_.Invalidate(Status::OK());
|
2018-02-13 00:57:56 +00:00
|
|
|
block_iter_points_to_real_block_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SavePrevIndexValue() {
|
|
|
|
if (block_iter_points_to_real_block_) {
|
|
|
|
// Reseek. If they end up with the same data block, we shouldn't re-fetch
|
|
|
|
// the same data block.
|
2018-08-09 23:49:45 +00:00
|
|
|
prev_index_value_ = index_iter_->value();
|
2018-02-13 00:57:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitDataBlock();
|
2019-04-18 18:08:33 +00:00
|
|
|
inline void FindKeyForward();
|
|
|
|
void FindBlockForward();
|
2018-02-13 00:57:56 +00:00
|
|
|
void FindKeyBackward();
|
2019-04-16 18:32:03 +00:00
|
|
|
void CheckOutOfBound();
|
2018-02-13 00:57:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BlockBasedTable* table_;
|
|
|
|
const ReadOptions read_options_;
|
|
|
|
const InternalKeyComparator& icomp_;
|
2019-03-27 17:24:16 +00:00
|
|
|
UserComparatorWrapper user_comparator_;
|
2018-08-09 23:49:45 +00:00
|
|
|
InternalIteratorBase<BlockHandle>* index_iter_;
|
2018-02-13 00:57:56 +00:00
|
|
|
PinnedIteratorsManager* pinned_iters_mgr_;
|
2018-07-13 00:19:57 +00:00
|
|
|
TBlockIter block_iter_;
|
2018-02-13 00:57:56 +00:00
|
|
|
bool block_iter_points_to_real_block_;
|
|
|
|
bool is_out_of_bound_ = false;
|
|
|
|
bool check_filter_;
|
2018-06-26 22:56:26 +00:00
|
|
|
// TODO(Zhongyi): pick a better name
|
|
|
|
bool need_upper_bound_check_;
|
|
|
|
const SliceTransform* prefix_extractor_;
|
2018-05-26 01:41:31 +00:00
|
|
|
// If the blocks over which we iterate are index blocks
|
|
|
|
bool is_index_;
|
|
|
|
// If the keys in the blocks over which we iterate include 8 byte sequence
|
|
|
|
bool key_includes_seq_;
|
2018-08-09 23:49:45 +00:00
|
|
|
bool index_key_is_full_;
|
2018-06-25 20:07:38 +00:00
|
|
|
// If this iterator is created for compaction
|
|
|
|
bool for_compaction_;
|
2018-08-09 23:49:45 +00:00
|
|
|
BlockHandle prev_index_value_;
|
2018-02-13 00:57:56 +00:00
|
|
|
|
2019-04-27 04:20:25 +00:00
|
|
|
// All the below fields control iterator readahead
|
|
|
|
static const size_t kInitAutoReadaheadSize = 8 * 1024;
|
2018-02-13 00:57:56 +00:00
|
|
|
// Found that 256 KB readahead size provides the best performance, based on
|
2019-04-27 04:20:25 +00:00
|
|
|
// experiments, for auto readahead. Experiment data is in PR #3282.
|
|
|
|
static const size_t kMaxAutoReadaheadSize;
|
|
|
|
static const int kMinNumFileReadsToStartAutoReadahead = 2;
|
|
|
|
size_t readahead_size_ = kInitAutoReadaheadSize;
|
2018-02-13 00:57:56 +00:00
|
|
|
size_t readahead_limit_ = 0;
|
2019-04-27 04:20:25 +00:00
|
|
|
int64_t num_file_reads_ = 0;
|
Improve direct IO range scan performance with readahead (#3884)
Summary:
This PR extends the improvements in #3282 to also work when using Direct IO.
We see **4.5X performance improvement** in seekrandom benchmark doing long range scans, when using direct reads, on flash.
**Description:**
This change improves the performance of iterators doing long range scans (e.g. big/full index or table scans in MyRocks) by using readahead and prefetching additional data on each disk IO, and storing in a local buffer. This prefetching is automatically enabled on noticing more than 2 IOs for the same table file during iteration. The readahead size starts with 8KB and is exponentially increased on each additional sequential IO, up to a max of 256 KB. This helps in cutting down the number of IOs needed to complete the range scan.
**Implementation Details:**
- Used `FilePrefetchBuffer` as the underlying buffer to store the readahead data. `FilePrefetchBuffer` can now take file_reader, readahead_size and max_readahead_size as input to the constructor, and automatically do readahead.
- `FilePrefetchBuffer::TryReadFromCache` can now call `FilePrefetchBuffer::Prefetch` if readahead is enabled.
- `AlignedBuffer` (which is the underlying store for `FilePrefetchBuffer`) now takes a few additional args in `AlignedBuffer::AllocateNewBuffer` to allow copying data from the old buffer.
- Made sure not to re-read partial chunks of data that were already available in the buffer, from device again.
- Fixed a couple of cases where `AlignedBuffer::cursize_` was not being properly kept up-to-date.
**Constraints:**
- Similar to #3282, this gets currently enabled only when ReadOptions.readahead_size = 0 (which is the default value).
- Since the prefetched data is stored in a temporary buffer allocated on heap, this could increase the memory usage if you have many iterators doing long range scans simultaneously.
- Enabled only for user reads, and disabled for compactions. Compaction reads are controlled by the options `use_direct_io_for_flush_and_compaction` and `compaction_readahead_size`, and the current feature takes precautions not to mess with them.
**Benchmarks:**
I used the same benchmark as used in #3282.
Data fill:
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=fillrandom -num=1000000000 -compression_type="none" -level_compaction_dynamic_level_bytes
```
Do a long range scan: Seekrandom with large number of nexts
```
TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=seekrandom -use_direct_reads -duration=60 -num=1000000000 -use_existing_db -seek_nexts=10000 -statistics -histogram
```
```
Before:
seekrandom : 37939.906 micros/op 26 ops/sec; 29.2 MB/s (1636 of 1999 found)
With this change:
seekrandom : 8527.720 micros/op 117 ops/sec; 129.7 MB/s (6530 of 7999 found)
```
~4.5X perf improvement. Taken on an average of 3 runs.
Closes https://github.com/facebook/rocksdb/pull/3884
Differential Revision: D8082143
Pulled By: sagar0
fbshipit-source-id: 4d7a8561cbac03478663713df4d31ad2620253bb
2018-06-21 18:02:49 +00:00
|
|
|
std::unique_ptr<FilePrefetchBuffer> prefetch_buffer_;
|
2018-02-13 00:57:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|