rocksdb/table/block_based
Peter Dillinger 7555243bcf Refactor ShardedCache for more sharing, static polymorphism (#10801)
Summary:
The motivations for this change include
* Free up space in ClockHandle so that we can add data for secondary cache handling while still keeping within single cache line (64 byte) size.
  * This change frees up space by eliminating the need for the `hash` field by making the fixed-size key itself a hash, using a 128-bit bijective (lossless) hash.
* Generally more customizability of ShardedCache (such as hashing) without worrying about virtual call overheads
  * ShardedCache now uses static polymorphism (template) instead of dynamic polymorphism (virtual overrides) for the CacheShard. No obvious performance benefit is seen from the change (as mostly expected; most calls to virtual functions in CacheShard could already be optimized to static calls), but offers more flexibility without incurring the runtime cost of adhering to a common interface (without type parameters or static callbacks).
  * You'll also notice less `reinterpret_cast`ing and other boilerplate in the Cache implementations, as this can go in ShardedCache.

More detail:
* Don't have LRUCacheShard maintain `std::shared_ptr<SecondaryCache>` copies (extra refcount) when LRUCache can be in charge of keeping a `shared_ptr`.
* Renamed `capacity_mutex_` to `config_mutex_` to better represent the scope of what it guards.
* Some preparation for 64-bit hash and indexing in LRUCache, but didn't include the full change because of slight performance regression.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10801

Test Plan:
Unit test updates were non-trivial because of major changes to the ClockCacheShard interface in handling of key vs. hash.

Performance:
Create with `TEST_TMPDIR=/dev/shm ./db_bench -benchmarks=fillrandom -num=30000000 -disable_wal=1 -bloom_bits=16`

Test with
```
TEST_TMPDIR=/dev/shm ./db_bench -benchmarks=readrandom[-X1000] -readonly -num=30000000 -bloom_bits=16 -cache_index_and_filter_blocks=1 -cache_size=610000000 -duration 20 -threads=16
```

Before: `readrandom [AVG 150 runs] : 321147 (± 253) ops/sec`
After: `readrandom [AVG 150 runs] : 321530 (± 326) ops/sec`

So possibly ~0.1% improvement.

And with `-cache_type=hyper_clock_cache`:
Before: `readrandom [AVG 30 runs] : 614126 (± 7978) ops/sec`
After: `readrandom [AVG 30 runs] : 645349 (± 8087) ops/sec`

So roughly 5% improvement!

Reviewed By: anand1976

Differential Revision: D40252236

Pulled By: pdillinger

fbshipit-source-id: ff8fc70ef569585edc95bcbaaa0386f61355ae5b
2022-10-18 22:06:57 -07:00
..
binary_search_index_reader.cc
binary_search_index_reader.h
block.cc Add API for writing wide-column entities (#10242) 2022-06-25 15:30:47 -07:00
block.h Refactor to avoid confusing "raw block" (#10408) 2022-09-22 11:25:32 -07:00
block_based_table_builder.cc Refactor to avoid confusing "raw block" (#10408) 2022-09-22 11:25:32 -07:00
block_based_table_builder.h Refactor to avoid confusing "raw block" (#10408) 2022-09-22 11:25:32 -07:00
block_based_table_factory.cc Refactor ShardedCache for more sharing, static polymorphism (#10801) 2022-10-18 22:06:57 -07:00
block_based_table_factory.h
block_based_table_iterator.cc Provide support for direct_reads with async_io (#10197) 2022-07-06 11:42:59 -07:00
block_based_table_iterator.h
block_based_table_reader.cc Refactor ShardedCache for more sharing, static polymorphism (#10801) 2022-10-18 22:06:57 -07:00
block_based_table_reader.h Refactor to avoid confusing "raw block" (#10408) 2022-09-22 11:25:32 -07:00
block_based_table_reader_impl.h Updated NewDataBlockIterator to not fetch compression dict for non-da… (#10310) 2022-07-06 09:30:25 -07:00
block_based_table_reader_sync_and_async.h Refactor to avoid confusing "raw block" (#10408) 2022-09-22 11:25:32 -07:00
block_based_table_reader_test.cc Add support for wide-column point lookups (#10540) 2022-08-19 11:51:12 -07:00
block_builder.cc
block_builder.h
block_like_traits.h Revert "Avoid dynamic memory allocation on read path (#10453)" (#10541) 2022-08-19 11:02:54 -07:00
block_prefetcher.cc Fix stress test failure for async_io (#10660) 2022-09-12 14:48:06 -07:00
block_prefetcher.h Provide support for direct_reads with async_io (#10197) 2022-07-06 11:42:59 -07:00
block_prefix_index.cc
block_prefix_index.h
block_test.cc Print stack traces on frozen tests in CI (#10828) 2022-10-18 00:35:35 -07:00
block_type.h
cachable_entry.h Refactor to avoid confusing "raw block" (#10408) 2022-09-22 11:25:32 -07:00
data_block_footer.cc
data_block_footer.h
data_block_hash_index.cc
data_block_hash_index.h
data_block_hash_index_test.cc Print stack traces on frozen tests in CI (#10828) 2022-10-18 00:35:35 -07:00
filter_block.h Pass rate_limiter_priority through filter block reader functions to FS (#10251) 2022-06-24 16:13:44 -07:00
filter_block_reader_common.cc Pass rate_limiter_priority through filter block reader functions to FS (#10251) 2022-06-24 16:13:44 -07:00
filter_block_reader_common.h Pass rate_limiter_priority through filter block reader functions to FS (#10251) 2022-06-24 16:13:44 -07:00
filter_policy.cc Have Cache use Status::MemoryLimit (#10262) 2022-07-06 14:41:46 -07:00
filter_policy_internal.h
flush_block_policy.cc
flush_block_policy.h
full_filter_block.cc Pass rate_limiter_priority through filter block reader functions to FS (#10251) 2022-06-24 16:13:44 -07:00
full_filter_block.h Pass rate_limiter_priority through filter block reader functions to FS (#10251) 2022-06-24 16:13:44 -07:00
full_filter_block_test.cc Print stack traces on frozen tests in CI (#10828) 2022-10-18 00:35:35 -07:00
hash_index_reader.cc
hash_index_reader.h
index_builder.cc Make InternalKeyComparator not configurable (#10342) 2022-07-14 10:09:31 -07:00
index_builder.h Make InternalKeyComparator not configurable (#10342) 2022-07-14 10:09:31 -07:00
index_reader_common.cc
index_reader_common.h
mock_block_based_table.h
parsed_full_filter_block.cc
parsed_full_filter_block.h
partitioned_filter_block.cc Add new option num_file_reads_for_auto_readahead in BlockBasedTableOptions (#10556) 2022-09-01 11:56:00 -07:00
partitioned_filter_block.h Update passing rate_limiter_priority for a PartitionedFilterBlockReader function to FS (#10438) 2022-07-29 11:32:54 -07:00
partitioned_filter_block_test.cc Print stack traces on frozen tests in CI (#10828) 2022-10-18 00:35:35 -07:00
partitioned_index_iterator.cc Provide support for direct_reads with async_io (#10197) 2022-07-06 11:42:59 -07:00
partitioned_index_iterator.h
partitioned_index_reader.cc Add new option num_file_reads_for_auto_readahead in BlockBasedTableOptions (#10556) 2022-09-01 11:56:00 -07:00
partitioned_index_reader.h
reader_common.cc
reader_common.h
uncompression_dict_reader.cc
uncompression_dict_reader.h