rocksdb/db/blob
Bo Wang d490bfcdb6 Avoid recompressing cold block in CompressedSecondaryCache (#10527)
Summary:
**Summary:**
When a block is firstly `Lookup` from the secondary cache, we just insert a dummy block in the primary cache (charging the actual size of the block) and don’t erase the block from the secondary cache. A standalone handle is returned from `Lookup`. Only if the block is hit again, we erase it from the secondary cache and add it into the primary cache.

When a block is firstly evicted from the primary cache to the secondary cache, we just insert a dummy block (size 0) in the secondary cache. When the block is evicted again, it is treated as a hot block and is inserted into the secondary cache.

**Implementation Details**
Add a new state of LRUHandle: The handle is never inserted into the LRUCache (both hash table and LRU list) and it doesn't experience the above three states. The entry can be freed when refs becomes 0.  (refs >= 1 && in_cache == false && IS_STANDALONE == true)

The behaviors of  `LRUCacheShard::Lookup()` are updated if the secondary_cache is CompressedSecondaryCache:
1. If a handle is found in primary cache:
  1.1. If the handle's value is not nullptr, it is returned immediately.
  1.2. If the handle's value is nullptr, this means the handle is a dummy one. For a dummy handle, if it was retrieved from secondary cache, it may still exist in secondary cache.
    - 1.2.1. If no valid handle can be `Lookup` from secondary cache, return nullptr.
    - 1.2.2. If the handle from secondary cache is valid, erase it from the secondary cache and add it into the primary cache.
2. If a handle is not found in primary cache:
  2.1. If no valid handle can be `Lookup` from secondary cache, return nullptr.
  2.2.  If the handle from secondary cache is valid, insert a dummy block in the primary cache (charging the actual size of the block)  and return a standalone handle.

The behaviors of `LRUCacheShard::Promote()` are updated as follows:
1. If `e->sec_handle` has value, one of the following steps can happen:
  1.1. Insert a dummy handle and return a standalone handle to caller when `secondary_cache_` is `CompressedSecondaryCache` and e is a standalone handle.
  1.2. Insert the item into the primary cache and return the handle to caller.
  1.3. Exception handling.
3. If `e->sec_handle` has no value, mark the item as not in cache and charge the cache as its only metadata that'll shortly be released.

The behavior of  `CompressedSecondaryCache::Insert()` is updated:
1. If a block is evicted from the primary cache for the first time, a dummy item is inserted.
4. If a dummy item is found for a block, the block is inserted into the secondary cache.

The behavior of  `CompressedSecondaryCache:::Lookup()` is updated:
1. If a handle is not found or it is a dummy item, a nullptr is returned.
2. If `erase_handle` is true, the handle is erased.

The behaviors of  `LRUCacheShard::Release()` are adjusted for the standalone handles.

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

Test Plan:
1. stress tests.
5. unit tests.
6. CPU profiling for db_bench.

Reviewed By: siying

Differential Revision: D38747613

Pulled By: gitbw95

fbshipit-source-id: 74a1eba7e1957c9affb2bd2ae3e0194584fa6eca
2022-09-07 19:00:27 -07:00
..
blob_constants.h
blob_contents.cc Support custom allocators for the blob cache (#10628) 2022-09-06 13:31:48 -07:00
blob_contents.h Support custom allocators for the blob cache (#10628) 2022-09-06 13:31:48 -07:00
blob_counting_iterator.h
blob_counting_iterator_test.cc
blob_fetcher.cc
blob_fetcher.h
blob_file_addition.cc
blob_file_addition.h
blob_file_addition_test.cc
blob_file_builder.cc Support custom allocators for the blob cache (#10628) 2022-09-06 13:31:48 -07:00
blob_file_builder.h
blob_file_builder_test.cc
blob_file_cache.cc
blob_file_cache.h
blob_file_cache_test.cc
blob_file_completion_callback.h
blob_file_garbage.cc
blob_file_garbage.h
blob_file_garbage_test.cc
blob_file_meta.cc
blob_file_meta.h
blob_file_reader.cc
blob_file_reader.h
blob_file_reader_test.cc
blob_garbage_meter.cc
blob_garbage_meter.h
blob_garbage_meter_test.cc
blob_index.h Remove local static string (#8103) 2022-08-05 23:03:51 -07:00
blob_log_format.cc Remove local static string (#8103) 2022-08-05 23:03:51 -07:00
blob_log_format.h
blob_log_sequential_reader.cc
blob_log_sequential_reader.h
blob_log_writer.cc WritableFileWriter tries to skip operations after failure (#10489) 2022-08-10 10:19:20 -07:00
blob_log_writer.h
blob_read_request.h
blob_source.cc Support custom allocators for the blob cache (#10628) 2022-09-06 13:31:48 -07:00
blob_source.h Pin the newly cached blob after insert (#10625) 2022-09-01 16:25:46 -07:00
blob_source_test.cc Avoid recompressing cold block in CompressedSecondaryCache (#10527) 2022-09-07 19:00:27 -07:00
db_blob_basic_test.cc Avoid recompressing cold block in CompressedSecondaryCache (#10527) 2022-09-07 19:00:27 -07:00
db_blob_compaction_test.cc Fix wrong value passed in compaction filter in BlobDB (#10391) 2022-08-11 13:55:28 -07:00
db_blob_corruption_test.cc
db_blob_index_test.cc
prefetch_buffer_collection.cc
prefetch_buffer_collection.h