rocksdb/util
Peter Dillinger 86a1e3e0e7 Derive cache keys from SST unique IDs (#10394)
Summary:
... so that cache keys can be derived from DB manifest data
before reading the file from storage--so that every part of the file
can potentially go in a persistent cache.

See updated comments in cache_key.cc for technical details. Importantly,
the new cache key encoding uses some fancy but efficient math to pack
data into the cache key without depending on the sizes of the various
pieces. This simplifies some existing code creating cache keys, like
cache warming before the file size is known.

This should provide us an essentially permanent mapping between SST
unique IDs and base cache keys, with the ability to "upgrade" SST
unique IDs (and thus cache keys) with new SST format_versions.

These cache keys are of similar, perhaps indistinguishable quality to
the previous generation. Before this change (see "corrected" days
between collision):

```
./cache_bench -stress_cache_key -sck_keep_bits=43
18 collisions after 2 x 90 days, est 10 days between (1.15292e+19 corrected)
```

After this change (keep 43 bits, up through 50, to validate "trajectory"
is ok on "corrected" days between collision):
```
19 collisions after 3 x 90 days, est 14.2105 days between (1.63836e+19 corrected)
16 collisions after 5 x 90 days, est 28.125 days between (1.6213e+19 corrected)
15 collisions after 7 x 90 days, est 42 days between (1.21057e+19 corrected)
15 collisions after 17 x 90 days, est 102 days between (1.46997e+19 corrected)
15 collisions after 49 x 90 days, est 294 days between (2.11849e+19 corrected)
15 collisions after 62 x 90 days, est 372 days between (1.34027e+19 corrected)
15 collisions after 53 x 90 days, est 318 days between (5.72858e+18 corrected)
15 collisions after 309 x 90 days, est 1854 days between (1.66994e+19 corrected)
```

However, the change does modify (probably weaken) the "guaranteed unique" promise from this

> SST files generated in a single process are guaranteed to have unique cache keys, unless/until number session ids * max file number = 2**86

to this (see https://github.com/facebook/rocksdb/issues/10388)

> With the DB id limitation, we only have nice guaranteed unique cache keys for files generated in a single process until biggest session_id_counter and offset_in_file reach combined 64 bits

I don't think this is a practical concern, though.

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

Test Plan: unit tests updated, see simulation results above

Reviewed By: jay-zhuang

Differential Revision: D38667529

Pulled By: pdillinger

fbshipit-source-id: 49af3fe7f47e5b61162809a78b76c769fd519fba
2022-08-12 13:49:49 -07:00
..
aligned_buffer.h Remove code that only compiles for Visual Studio versions older than 2015 (#10065) 2022-05-26 16:55:08 -07:00
async_file_reader.cc Add some missing headers (#10519) 2022-08-11 12:45:50 -07:00
async_file_reader.h Add some missing headers (#10519) 2022-08-11 12:45:50 -07:00
autovector.h Add wide column serialization primitives (#9915) 2022-06-03 20:54:48 -07:00
autovector_test.cc Remove own ToString() (#9955) 2022-05-06 13:03:58 -07:00
bloom_impl.h FilterPolicy API changes for 7.0 (#9501) 2022-02-08 13:56:46 -08:00
bloom_test.cc Remove deprecated block-based filter (#10184) 2022-06-16 15:51:33 -07:00
build_version.cc.in Remove own ToString() (#9955) 2022-05-06 13:03:58 -07:00
cast_util.h More refactoring ahead of footer & meta changes (#9240) 2021-12-10 08:13:26 -08:00
channel.h
cleanable.cc Fix compile error in Clang 13 (#10033) 2022-05-28 00:15:28 -07:00
coding.cc
coding.h More refactoring ahead of footer & meta changes (#9240) 2021-12-10 08:13:26 -08:00
coding_lean.h New stable, fixed-length cache keys (#9126) 2021-12-16 17:15:13 -08:00
coding_test.cc
compaction_job_stats_impl.cc
comparator.cc Document design/specification bugs with auto_prefix_mode (#10144) 2022-06-13 11:08:50 -07:00
compression.cc Integrate WAL compression into log reader/writer. (#9642) 2022-03-09 15:49:53 -08:00
compression.h Added WAL compression checksum (#10319) 2022-07-13 15:29:20 -07:00
compression_context_cache.cc Remove using namespace (#9369) 2022-01-12 09:31:12 -08:00
compression_context_cache.h
concurrent_task_limiter_impl.cc
concurrent_task_limiter_impl.h
core_local.h
coro_utils.h Add some missing headers (#10519) 2022-08-11 12:45:50 -07:00
crc32c.cc
crc32c.h
crc32c_arm64.cc
crc32c_arm64.h
crc32c_ppc.c
crc32c_ppc.h
crc32c_ppc_asm.S
crc32c_ppc_constants.h
crc32c_test.cc
defer.h
defer_test.cc
distributed_mutex.h Use optimized folly DistributedMutex in LRUCache when available (#10179) 2022-06-17 13:08:45 -07:00
duplicate_detector.h
dynamic_bloom.cc
dynamic_bloom.h Fix major bug with MultiGet, DeleteRange, and memtable Bloom (#9453) 2022-01-27 14:55:04 -08:00
dynamic_bloom_test.cc
fastrange.h
file_checksum_helper.cc Restore Regex support for ObjectLibrary::Register, rename new APIs to allow old one to be deprecated in the future (#9362) 2022-01-11 06:33:48 -08:00
file_checksum_helper.h New stable, fixed-length cache keys (#9126) 2021-12-16 17:15:13 -08:00
file_reader_writer_test.cc WritableFileWriter tries to skip operations after failure (#10489) 2022-08-10 10:19:20 -07:00
filelock_test.cc Remove own ToString() (#9955) 2022-05-06 13:03:58 -07:00
filter_bench.cc Pass rate_limiter_priority through filter block reader functions to FS (#10251) 2022-06-24 16:13:44 -07:00
gflags_compat.h Require C++17 (#9481) 2022-02-04 17:13:10 -08:00
hash.cc Experimental support for SST unique IDs (#8990) 2021-10-18 23:32:01 -07:00
hash.h Experimental support for SST unique IDs (#8990) 2021-10-18 23:32:01 -07:00
hash128.h
hash_containers.h Meta-internal folly integration with F14FastMap (#9546) 2022-04-13 07:34:01 -07:00
hash_map.h
hash_test.cc Derive cache keys from SST unique IDs (#10394) 2022-08-12 13:49:49 -07:00
heap.h Use std::numeric_limits<> (#9954) 2022-05-05 13:08:21 -07:00
heap_test.cc
kv_map.h
log_write_bench.cc
math.h Derive cache keys from SST unique IDs (#10394) 2022-08-12 13:49:49 -07:00
math128.h Derive cache keys from SST unique IDs (#10394) 2022-08-12 13:49:49 -07:00
murmurhash.cc
murmurhash.h
mutexlock.h Fix typo in comments and code (#10233) 2022-06-22 15:45:21 -07:00
ppc-opcode.h
random.cc Remove ROCKSDB_SUPPORT_THREAD_LOCAL define because it's a part of C++11 (#10015) 2022-05-18 15:25:19 -07:00
random.h Experimental support for SST unique IDs (#8990) 2021-10-18 23:32:01 -07:00
random_test.cc
rate_limiter.cc Fix race conditions in GenericRateLimiter (#10374) 2022-07-19 09:31:14 -07:00
rate_limiter.h Fix race conditions in GenericRateLimiter (#10374) 2022-07-19 09:31:14 -07:00
rate_limiter_test.cc Remove Travis CI (#10407) 2022-07-22 20:16:45 -07:00
repeatable_thread.h
repeatable_thread_test.cc
ribbon_alg.h Use only ASCII in source files (#10164) 2022-06-15 14:44:43 -07:00
ribbon_config.cc
ribbon_config.h
ribbon_impl.h Account Bloom/Ribbon filter construction memory in global memory limit (#9073) 2021-11-18 09:42:20 -08:00
ribbon_test.cc Remove own ToString() (#9955) 2022-05-06 13:03:58 -07:00
set_comparator.h
single_thread_executor.h Add some missing headers (#10519) 2022-08-11 12:45:50 -07:00
slice.cc Remove own ToString() (#9955) 2022-05-06 13:03:58 -07:00
slice_test.cc Require C++17 (#9481) 2022-02-04 17:13:10 -08:00
slice_transform_test.cc
status.cc Combine data members of IOStatus with Status (#9549) 2022-02-22 11:23:01 -08:00
stderr_logger.h db_bench -use_stderr_info_logger to print timestamp (#10435) 2022-07-29 11:24:52 -07:00
stop_watch.h
string_util.cc Fix potential ambiguities in/around port/sys_time.h (#10045) 2022-05-24 18:20:17 -07:00
string_util.h Remove own ToString() (#9955) 2022-05-06 13:03:58 -07:00
thread_guard.h
thread_list_test.cc Support reservation in thread pool (#10278) 2022-07-08 19:48:09 -07:00
thread_local.cc Remove ROCKSDB_SUPPORT_THREAD_LOCAL define because it's a part of C++11 (#10015) 2022-05-18 15:25:19 -07:00
thread_local.h
thread_local_test.cc
thread_operation.h
threadpool_imp.cc Support reservation in thread pool (#10278) 2022-07-08 19:48:09 -07:00
threadpool_imp.h Support reservation in thread pool (#10278) 2022-07-08 19:48:09 -07:00
timer.h Add seqno to time mapping (#10338) 2022-07-14 21:49:34 -07:00
timer_queue.h
timer_queue_test.cc
timer_test.cc Fix a timer crash caused by invalid memory management (#9656) 2022-03-12 11:45:56 -08:00
user_comparator_wrapper.h
vector_iterator.h Make InternalKeyComparator not configurable (#10342) 2022-07-14 10:09:31 -07:00
work_queue.h
work_queue_test.cc
xxhash.cc
xxhash.h Use only ASCII in source files (#10164) 2022-06-15 14:44:43 -07:00
xxph3.h