@nxtedition/rocksdb 8.1.4 → 8.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/deps/rocksdb/rocksdb/CMakeLists.txt +21 -0
  2. package/deps/rocksdb/rocksdb/Makefile +15 -3
  3. package/deps/rocksdb/rocksdb/TARGETS +6 -0
  4. package/deps/rocksdb/rocksdb/cache/cache_bench_tool.cc +32 -35
  5. package/deps/rocksdb/rocksdb/cache/cache_entry_roles.cc +0 -30
  6. package/deps/rocksdb/rocksdb/cache/cache_entry_roles.h +0 -83
  7. package/deps/rocksdb/rocksdb/cache/cache_entry_stats.h +13 -14
  8. package/deps/rocksdb/rocksdb/cache/cache_helpers.cc +40 -0
  9. package/deps/rocksdb/rocksdb/cache/cache_helpers.h +14 -20
  10. package/deps/rocksdb/rocksdb/cache/cache_reservation_manager.cc +8 -9
  11. package/deps/rocksdb/rocksdb/cache/cache_reservation_manager.h +5 -4
  12. package/deps/rocksdb/rocksdb/cache/cache_test.cc +124 -156
  13. package/deps/rocksdb/rocksdb/cache/charged_cache.cc +10 -26
  14. package/deps/rocksdb/rocksdb/cache/charged_cache.h +11 -16
  15. package/deps/rocksdb/rocksdb/cache/clock_cache.cc +35 -32
  16. package/deps/rocksdb/rocksdb/cache/clock_cache.h +19 -21
  17. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.cc +42 -30
  18. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.h +9 -8
  19. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache_test.cc +91 -143
  20. package/deps/rocksdb/rocksdb/cache/lru_cache.cc +54 -60
  21. package/deps/rocksdb/rocksdb/cache/lru_cache.h +37 -63
  22. package/deps/rocksdb/rocksdb/cache/lru_cache_test.cc +120 -106
  23. package/deps/rocksdb/rocksdb/cache/secondary_cache.cc +14 -5
  24. package/deps/rocksdb/rocksdb/cache/sharded_cache.h +16 -31
  25. package/deps/rocksdb/rocksdb/cache/typed_cache.h +339 -0
  26. package/deps/rocksdb/rocksdb/db/blob/blob_contents.cc +0 -48
  27. package/deps/rocksdb/rocksdb/db/blob/blob_contents.h +18 -15
  28. package/deps/rocksdb/rocksdb/db/blob/blob_file_builder.cc +5 -26
  29. package/deps/rocksdb/rocksdb/db/blob/blob_file_cache.cc +7 -8
  30. package/deps/rocksdb/rocksdb/db/blob/blob_file_cache.h +6 -3
  31. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader.cc +2 -7
  32. package/deps/rocksdb/rocksdb/db/blob/blob_source.cc +19 -47
  33. package/deps/rocksdb/rocksdb/db/blob/blob_source.h +13 -5
  34. package/deps/rocksdb/rocksdb/db/blob/blob_source_test.cc +15 -22
  35. package/deps/rocksdb/rocksdb/db/builder.cc +24 -10
  36. package/deps/rocksdb/rocksdb/db/builder.h +2 -1
  37. package/deps/rocksdb/rocksdb/db/c.cc +15 -0
  38. package/deps/rocksdb/rocksdb/db/c_test.c +3 -0
  39. package/deps/rocksdb/rocksdb/db/column_family.cc +11 -6
  40. package/deps/rocksdb/rocksdb/db/column_family.h +20 -6
  41. package/deps/rocksdb/rocksdb/db/compaction/compaction.cc +31 -34
  42. package/deps/rocksdb/rocksdb/db/compaction/compaction.h +3 -0
  43. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +21 -3
  44. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +1 -0
  45. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +4 -0
  46. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +4 -2
  47. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +9 -6
  48. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.cc +275 -82
  49. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +7 -0
  50. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.cc +11 -18
  51. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.h +17 -16
  52. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.cc +19 -6
  53. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.h +5 -5
  54. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.cc +22 -22
  55. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.h +5 -5
  56. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +81 -52
  57. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.cc +5 -1
  58. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.h +5 -5
  59. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_job.cc +8 -2
  60. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.h +3 -0
  61. package/deps/rocksdb/rocksdb/db/compaction/tiered_compaction_test.cc +266 -138
  62. package/deps/rocksdb/rocksdb/db/corruption_test.cc +86 -1
  63. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +98 -9
  64. package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +28 -28
  65. package/deps/rocksdb/rocksdb/db/db_bloom_filter_test.cc +2 -3
  66. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +1022 -123
  67. package/deps/rocksdb/rocksdb/db/db_flush_test.cc +65 -4
  68. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +32 -21
  69. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +32 -24
  70. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +199 -77
  71. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_debug.cc +1 -1
  72. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_experimental.cc +3 -2
  73. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +3 -0
  74. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +8 -4
  75. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_write.cc +43 -23
  76. package/deps/rocksdb/rocksdb/db/db_iter.cc +8 -2
  77. package/deps/rocksdb/rocksdb/db/db_merge_operand_test.cc +42 -0
  78. package/deps/rocksdb/rocksdb/db/db_merge_operator_test.cc +155 -0
  79. package/deps/rocksdb/rocksdb/db/db_properties_test.cc +12 -12
  80. package/deps/rocksdb/rocksdb/db/db_range_del_test.cc +230 -2
  81. package/deps/rocksdb/rocksdb/db/db_test.cc +3 -0
  82. package/deps/rocksdb/rocksdb/db/db_test2.cc +233 -8
  83. package/deps/rocksdb/rocksdb/db/db_test_util.cc +11 -10
  84. package/deps/rocksdb/rocksdb/db/db_test_util.h +39 -24
  85. package/deps/rocksdb/rocksdb/db/db_wal_test.cc +129 -0
  86. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +28 -0
  87. package/deps/rocksdb/rocksdb/db/db_with_timestamp_compaction_test.cc +21 -0
  88. package/deps/rocksdb/rocksdb/db/dbformat.cc +25 -0
  89. package/deps/rocksdb/rocksdb/db/dbformat.h +2 -0
  90. package/deps/rocksdb/rocksdb/db/experimental.cc +3 -2
  91. package/deps/rocksdb/rocksdb/db/external_sst_file_basic_test.cc +3 -0
  92. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +92 -13
  93. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.h +38 -1
  94. package/deps/rocksdb/rocksdb/db/external_sst_file_test.cc +14 -110
  95. package/deps/rocksdb/rocksdb/db/flush_job.cc +12 -10
  96. package/deps/rocksdb/rocksdb/db/flush_job.h +3 -2
  97. package/deps/rocksdb/rocksdb/db/flush_job_test.cc +29 -29
  98. package/deps/rocksdb/rocksdb/db/import_column_family_job.cc +56 -53
  99. package/deps/rocksdb/rocksdb/db/import_column_family_test.cc +3 -4
  100. package/deps/rocksdb/rocksdb/db/internal_stats.cc +11 -11
  101. package/deps/rocksdb/rocksdb/db/internal_stats.h +2 -2
  102. package/deps/rocksdb/rocksdb/db/log_reader.cc +8 -6
  103. package/deps/rocksdb/rocksdb/db/log_test.cc +35 -2
  104. package/deps/rocksdb/rocksdb/db/memtable.cc +31 -6
  105. package/deps/rocksdb/rocksdb/db/merge_helper.cc +47 -29
  106. package/deps/rocksdb/rocksdb/db/merge_helper.h +14 -6
  107. package/deps/rocksdb/rocksdb/db/periodic_task_scheduler_test.cc +10 -10
  108. package/deps/rocksdb/rocksdb/db/range_tombstone_fragmenter_test.cc +1 -1
  109. package/deps/rocksdb/rocksdb/db/repair.cc +65 -22
  110. package/deps/rocksdb/rocksdb/db/repair_test.cc +54 -0
  111. package/deps/rocksdb/rocksdb/db/seqno_time_test.cc +26 -26
  112. package/deps/rocksdb/rocksdb/db/table_cache.cc +41 -91
  113. package/deps/rocksdb/rocksdb/db/table_cache.h +17 -19
  114. package/deps/rocksdb/rocksdb/db/table_cache_sync_and_async.h +7 -9
  115. package/deps/rocksdb/rocksdb/db/table_properties_collector.h +3 -1
  116. package/deps/rocksdb/rocksdb/db/version_builder.cc +102 -52
  117. package/deps/rocksdb/rocksdb/db/version_builder.h +20 -0
  118. package/deps/rocksdb/rocksdb/db/version_builder_test.cc +218 -93
  119. package/deps/rocksdb/rocksdb/db/version_edit.cc +27 -1
  120. package/deps/rocksdb/rocksdb/db/version_edit.h +34 -9
  121. package/deps/rocksdb/rocksdb/db/version_edit_handler.cc +13 -6
  122. package/deps/rocksdb/rocksdb/db/version_edit_handler.h +17 -6
  123. package/deps/rocksdb/rocksdb/db/version_edit_test.cc +19 -17
  124. package/deps/rocksdb/rocksdb/db/version_set.cc +160 -28
  125. package/deps/rocksdb/rocksdb/db/version_set.h +34 -4
  126. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +1 -1
  127. package/deps/rocksdb/rocksdb/db/version_set_test.cc +65 -31
  128. package/deps/rocksdb/rocksdb/db/write_batch.cc +4 -1
  129. package/deps/rocksdb/rocksdb/db/write_thread.cc +5 -2
  130. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +1 -0
  131. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_driver.cc +31 -32
  132. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_driver.h +2 -1
  133. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_env_wrapper.h +8 -6
  134. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +4 -0
  135. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +11 -4
  136. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_tool.cc +16 -15
  137. package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +13 -1
  138. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +1 -0
  139. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +286 -217
  140. package/deps/rocksdb/rocksdb/include/rocksdb/c.h +8 -0
  141. package/deps/rocksdb/rocksdb/include/rocksdb/cache.h +137 -135
  142. package/deps/rocksdb/rocksdb/include/rocksdb/db.h +6 -0
  143. package/deps/rocksdb/rocksdb/include/rocksdb/listener.h +7 -1
  144. package/deps/rocksdb/rocksdb/include/rocksdb/merge_operator.h +21 -0
  145. package/deps/rocksdb/rocksdb/include/rocksdb/metadata.h +9 -3
  146. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +2 -1
  147. package/deps/rocksdb/rocksdb/include/rocksdb/secondary_cache.h +8 -6
  148. package/deps/rocksdb/rocksdb/include/rocksdb/status.h +3 -0
  149. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/backup_engine.h +69 -9
  150. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  151. package/deps/rocksdb/rocksdb/memory/arena.cc +23 -87
  152. package/deps/rocksdb/rocksdb/memory/arena.h +25 -31
  153. package/deps/rocksdb/rocksdb/memory/arena_test.cc +90 -0
  154. package/deps/rocksdb/rocksdb/memory/memory_allocator.h +9 -0
  155. package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +26 -26
  156. package/deps/rocksdb/rocksdb/options/customizable_test.cc +4 -3
  157. package/deps/rocksdb/rocksdb/port/mmap.cc +98 -0
  158. package/deps/rocksdb/rocksdb/port/mmap.h +70 -0
  159. package/deps/rocksdb/rocksdb/port/port_posix.h +2 -0
  160. package/{prebuilds → deps/rocksdb/rocksdb/prebuilds}/linux-x64/node.napi.node +0 -0
  161. package/deps/rocksdb/rocksdb/src.mk +3 -0
  162. package/deps/rocksdb/rocksdb/table/adaptive/adaptive_table_factory.cc +3 -2
  163. package/deps/rocksdb/rocksdb/table/block_based/block.h +3 -0
  164. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +25 -67
  165. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.h +3 -3
  166. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.cc +18 -13
  167. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +159 -225
  168. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +31 -50
  169. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_impl.h +52 -20
  170. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +3 -3
  171. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +1 -1
  172. package/deps/rocksdb/rocksdb/table/block_based/block_cache.cc +96 -0
  173. package/deps/rocksdb/rocksdb/table/block_based/block_cache.h +132 -0
  174. package/deps/rocksdb/rocksdb/table/block_based/cachable_entry.h +28 -0
  175. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.cc +6 -5
  176. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.h +1 -4
  177. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.cc +6 -7
  178. package/deps/rocksdb/rocksdb/table/block_based/index_reader_common.cc +3 -1
  179. package/deps/rocksdb/rocksdb/table/block_based/parsed_full_filter_block.h +6 -1
  180. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +19 -18
  181. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.h +9 -5
  182. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block_test.cc +3 -1
  183. package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_reader.cc +2 -1
  184. package/deps/rocksdb/rocksdb/table/block_based/uncompression_dict_reader.cc +2 -2
  185. package/deps/rocksdb/rocksdb/table/block_fetcher_test.cc +3 -3
  186. package/deps/rocksdb/rocksdb/table/format.cc +24 -20
  187. package/deps/rocksdb/rocksdb/table/format.h +6 -3
  188. package/deps/rocksdb/rocksdb/table/get_context.cc +12 -3
  189. package/deps/rocksdb/rocksdb/table/internal_iterator.h +0 -2
  190. package/deps/rocksdb/rocksdb/table/merging_iterator.cc +69 -35
  191. package/deps/rocksdb/rocksdb/table/meta_blocks.cc +2 -2
  192. package/deps/rocksdb/rocksdb/table/sst_file_dumper.cc +1 -1
  193. package/deps/rocksdb/rocksdb/table/table_test.cc +7 -6
  194. package/deps/rocksdb/rocksdb/test_util/testutil.h +10 -0
  195. package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer_test.cc +66 -1
  196. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +9 -2
  197. package/deps/rocksdb/rocksdb/trace_replay/block_cache_tracer.cc +5 -0
  198. package/deps/rocksdb/rocksdb/trace_replay/block_cache_tracer.h +2 -2
  199. package/deps/rocksdb/rocksdb/trace_replay/trace_replay.cc +1 -1
  200. package/deps/rocksdb/rocksdb/util/async_file_reader.cc +20 -12
  201. package/deps/rocksdb/rocksdb/util/bloom_test.cc +1 -1
  202. package/deps/rocksdb/rocksdb/util/compression.cc +2 -2
  203. package/deps/rocksdb/rocksdb/util/compression.h +11 -2
  204. package/deps/rocksdb/rocksdb/util/status.cc +7 -0
  205. package/deps/rocksdb/rocksdb/util/xxhash.h +1901 -887
  206. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine.cc +250 -74
  207. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine_test.cc +199 -4
  208. package/deps/rocksdb/rocksdb/utilities/cache_dump_load_impl.cc +35 -57
  209. package/deps/rocksdb/rocksdb/utilities/cache_dump_load_impl.h +4 -5
  210. package/deps/rocksdb/rocksdb/utilities/checkpoint/checkpoint_impl.cc +1 -0
  211. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.cc +39 -0
  212. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.h +9 -0
  213. package/deps/rocksdb/rocksdb/utilities/fault_injection_secondary_cache.cc +11 -6
  214. package/deps/rocksdb/rocksdb/utilities/fault_injection_secondary_cache.h +6 -5
  215. package/deps/rocksdb/rocksdb/utilities/memory_allocators.h +0 -1
  216. package/deps/rocksdb/rocksdb/utilities/simulator_cache/cache_simulator.cc +10 -11
  217. package/deps/rocksdb/rocksdb/utilities/simulator_cache/sim_cache.cc +31 -31
  218. package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h +4 -0
  219. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.cc +111 -0
  220. package/deps/rocksdb/rocksdb/utilities/ttl/db_ttl_impl.cc +1 -0
  221. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_internal.cc +12 -3
  222. package/package.json +1 -1
  223. package/deps/rocksdb/rocksdb/table/block_based/block_like_traits.h +0 -182
@@ -21,6 +21,7 @@
21
21
  #include "rocksdb/table_properties.h"
22
22
  #include "table/block_based/block.h"
23
23
  #include "table/block_based/block_based_table_factory.h"
24
+ #include "table/block_based/block_cache.h"
24
25
  #include "table/block_based/block_type.h"
25
26
  #include "table/block_based/cachable_entry.h"
26
27
  #include "table/block_based/filter_block.h"
@@ -315,22 +316,6 @@ class BlockBasedTable : public TableReader {
315
316
  void UpdateCacheMissMetrics(BlockType block_type,
316
317
  GetContext* get_context) const;
317
318
 
318
- Cache::Handle* GetEntryFromCache(const CacheTier& cache_tier,
319
- Cache* block_cache, const Slice& key,
320
- BlockType block_type, const bool wait,
321
- GetContext* get_context,
322
- const Cache::CacheItemHelper* cache_helper,
323
- const Cache::CreateCallback& create_cb,
324
- Cache::Priority priority) const;
325
-
326
- template <typename TBlocklike>
327
- Status InsertEntryToCache(const CacheTier& cache_tier, Cache* block_cache,
328
- const Slice& key,
329
- const Cache::CacheItemHelper* cache_helper,
330
- std::unique_ptr<TBlocklike>&& block_holder,
331
- size_t charge, Cache::Handle** cache_handle,
332
- Cache::Priority priority) const;
333
-
334
319
  // Either Block::NewDataIterator() or Block::NewIndexIterator().
335
320
  template <typename TBlockIter>
336
321
  static TBlockIter* InitBlockIterator(const Rep* rep, Block* block,
@@ -348,26 +333,24 @@ class BlockBasedTable : public TableReader {
348
333
  // in uncompressed block cache, also sets cache_handle to reference that
349
334
  // block.
350
335
  template <typename TBlocklike>
351
- Status MaybeReadBlockAndLoadToCache(
336
+ WithBlocklikeCheck<Status, TBlocklike> MaybeReadBlockAndLoadToCache(
352
337
  FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro,
353
338
  const BlockHandle& handle, const UncompressionDict& uncompression_dict,
354
339
  const bool wait, const bool for_compaction,
355
- CachableEntry<TBlocklike>* block_entry, BlockType block_type,
356
- GetContext* get_context, BlockCacheLookupContext* lookup_context,
357
- BlockContents* contents, bool async_read) const;
340
+ CachableEntry<TBlocklike>* block_entry, GetContext* get_context,
341
+ BlockCacheLookupContext* lookup_context, BlockContents* contents,
342
+ bool async_read) const;
358
343
 
359
344
  // Similar to the above, with one crucial difference: it will retrieve the
360
345
  // block from the file even if there are no caches configured (assuming the
361
346
  // read options allow I/O).
362
347
  template <typename TBlocklike>
363
- Status RetrieveBlock(FilePrefetchBuffer* prefetch_buffer,
364
- const ReadOptions& ro, const BlockHandle& handle,
365
- const UncompressionDict& uncompression_dict,
366
- CachableEntry<TBlocklike>* block_entry,
367
- BlockType block_type, GetContext* get_context,
368
- BlockCacheLookupContext* lookup_context,
369
- bool for_compaction, bool use_cache, bool wait_for_cache,
370
- bool async_read) const;
348
+ WithBlocklikeCheck<Status, TBlocklike> RetrieveBlock(
349
+ FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro,
350
+ const BlockHandle& handle, const UncompressionDict& uncompression_dict,
351
+ CachableEntry<TBlocklike>* block_entry, GetContext* get_context,
352
+ BlockCacheLookupContext* lookup_context, bool for_compaction,
353
+ bool use_cache, bool wait_for_cache, bool async_read) const;
371
354
 
372
355
  DECLARE_SYNC_AND_ASYNC_CONST(
373
356
  void, RetrieveMultipleBlocks, const ReadOptions& options,
@@ -403,13 +386,12 @@ class BlockBasedTable : public TableReader {
403
386
  // @param uncompression_dict Data for presetting the compression library's
404
387
  // dictionary.
405
388
  template <typename TBlocklike>
406
- Status GetDataBlockFromCache(const Slice& cache_key, Cache* block_cache,
407
- Cache* block_cache_compressed,
408
- const ReadOptions& read_options,
409
- CachableEntry<TBlocklike>* block,
410
- const UncompressionDict& uncompression_dict,
411
- BlockType block_type, const bool wait,
412
- GetContext* get_context) const;
389
+ WithBlocklikeCheck<Status, TBlocklike> GetDataBlockFromCache(
390
+ const Slice& cache_key, BlockCacheInterface<TBlocklike> block_cache,
391
+ CompressedBlockCacheInterface block_cache_compressed,
392
+ const ReadOptions& read_options, CachableEntry<TBlocklike>* block,
393
+ const UncompressionDict& uncompression_dict, const bool wait,
394
+ GetContext* get_context) const;
413
395
 
414
396
  // Put a maybe compressed block to the corresponding block caches.
415
397
  // This method will perform decompression against block_contents if needed
@@ -422,15 +404,13 @@ class BlockBasedTable : public TableReader {
422
404
  // @param uncompression_dict Data for presetting the compression library's
423
405
  // dictionary.
424
406
  template <typename TBlocklike>
425
- Status PutDataBlockToCache(const Slice& cache_key, Cache* block_cache,
426
- Cache* block_cache_compressed,
427
- CachableEntry<TBlocklike>* cached_block,
428
- BlockContents&& block_contents,
429
- CompressionType block_comp_type,
430
- const UncompressionDict& uncompression_dict,
431
- MemoryAllocator* memory_allocator,
432
- BlockType block_type,
433
- GetContext* get_context) const;
407
+ WithBlocklikeCheck<Status, TBlocklike> PutDataBlockToCache(
408
+ const Slice& cache_key, BlockCacheInterface<TBlocklike> block_cache,
409
+ CompressedBlockCacheInterface block_cache_compressed,
410
+ CachableEntry<TBlocklike>* cached_block, BlockContents&& block_contents,
411
+ CompressionType block_comp_type,
412
+ const UncompressionDict& uncompression_dict,
413
+ MemoryAllocator* memory_allocator, GetContext* get_context) const;
434
414
 
435
415
  // Calls (*handle_result)(arg, ...) repeatedly, starting with the entry found
436
416
  // after a call to Seek(key), until handle_result returns false.
@@ -599,6 +579,13 @@ struct BlockBasedTable::Rep {
599
579
 
600
580
  std::shared_ptr<FragmentedRangeTombstoneList> fragmented_range_dels;
601
581
 
582
+ // FIXME
583
+ // If true, data blocks in this file are definitely ZSTD compressed. If false
584
+ // they might not be. When false we skip creating a ZSTD digested
585
+ // uncompression dictionary. Even if we get a false negative, things should
586
+ // still work, just not as quickly.
587
+ BlockCreateContext create_context;
588
+
602
589
  // If global_seqno is used, all Keys in this file will have the same
603
590
  // seqno with value `global_seqno`.
604
591
  //
@@ -617,12 +604,6 @@ struct BlockBasedTable::Rep {
617
604
  // before reading individual blocks enables certain optimizations.
618
605
  bool blocks_maybe_compressed = true;
619
606
 
620
- // If true, data blocks in this file are definitely ZSTD compressed. If false
621
- // they might not be. When false we skip creating a ZSTD digested
622
- // uncompression dictionary. Even if we get a false negative, things should
623
- // still work, just not as quickly.
624
- bool blocks_definitely_zstd_compressed = false;
625
-
626
607
  // These describe how index is encoded.
627
608
  bool index_has_first_key = false;
628
609
  bool index_key_includes_seq = true;
@@ -7,6 +7,10 @@
7
7
  // Use of this source code is governed by a BSD-style license that can be
8
8
  // found in the LICENSE file. See the AUTHORS file for names of contributors.
9
9
  #pragma once
10
+ #include <type_traits>
11
+
12
+ #include "block.h"
13
+ #include "block_cache.h"
10
14
  #include "table/block_based/block_based_table_reader.h"
11
15
  #include "table/block_based/reader_common.h"
12
16
 
@@ -16,6 +20,25 @@
16
20
  // are templates.
17
21
 
18
22
  namespace ROCKSDB_NAMESPACE {
23
+ namespace {
24
+ using IterPlaceholderCacheInterface =
25
+ PlaceholderCacheInterface<CacheEntryRole::kMisc>;
26
+
27
+ template <typename TBlockIter>
28
+ struct IterTraits {};
29
+
30
+ template <>
31
+ struct IterTraits<DataBlockIter> {
32
+ using IterBlocklike = Block_kData;
33
+ };
34
+
35
+ template <>
36
+ struct IterTraits<IndexBlockIter> {
37
+ using IterBlocklike = Block_kIndex;
38
+ };
39
+
40
+ } // namespace
41
+
19
42
  // Convert an index iterator value (i.e., an encoded BlockHandle)
20
43
  // into an iterator over the contents of the corresponding block.
21
44
  // If input_iter is null, new a iterator
@@ -27,6 +50,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
27
50
  BlockCacheLookupContext* lookup_context,
28
51
  FilePrefetchBuffer* prefetch_buffer, bool for_compaction, bool async_read,
29
52
  Status& s) const {
53
+ using IterBlocklike = typename IterTraits<TBlockIter>::IterBlocklike;
30
54
  PERF_TIMER_GUARD(new_table_block_iter_nanos);
31
55
 
32
56
  TBlockIter* iter = input_iter != nullptr ? input_iter : new TBlockIter;
@@ -39,9 +63,13 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
39
63
  if (rep_->uncompression_dict_reader && block_type == BlockType::kData) {
40
64
  CachableEntry<UncompressionDict> uncompression_dict;
41
65
  const bool no_io = (ro.read_tier == kBlockCacheTier);
66
+ // For async scans, don't use the prefetch buffer since an async prefetch
67
+ // might already be under way and this would invalidate it. Also, the
68
+ // uncompression dict is typically at the end of the file and would
69
+ // most likely break the sequentiality of the access pattern.
42
70
  s = rep_->uncompression_dict_reader->GetOrReadUncompressionDictionary(
43
- prefetch_buffer, no_io, ro.verify_checksums, get_context,
44
- lookup_context, &uncompression_dict);
71
+ ro.async_io ? nullptr : prefetch_buffer, no_io, ro.verify_checksums,
72
+ get_context, lookup_context, &uncompression_dict);
45
73
  if (!s.ok()) {
46
74
  iter->Invalidate(s);
47
75
  return iter;
@@ -49,14 +77,14 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
49
77
  const UncompressionDict& dict = uncompression_dict.GetValue()
50
78
  ? *uncompression_dict.GetValue()
51
79
  : UncompressionDict::GetEmptyDict();
52
- s = RetrieveBlock(prefetch_buffer, ro, handle, dict, &block, block_type,
53
- get_context, lookup_context, for_compaction,
54
- /* use_cache */ true, /* wait_for_cache */ true,
55
- async_read);
80
+ s = RetrieveBlock(
81
+ prefetch_buffer, ro, handle, dict, &block.As<IterBlocklike>(),
82
+ get_context, lookup_context, for_compaction,
83
+ /* use_cache */ true, /* wait_for_cache */ true, async_read);
56
84
  } else {
57
85
  s = RetrieveBlock(
58
- prefetch_buffer, ro, handle, UncompressionDict::GetEmptyDict(), &block,
59
- block_type, get_context, lookup_context, for_compaction,
86
+ prefetch_buffer, ro, handle, UncompressionDict::GetEmptyDict(),
87
+ &block.As<IterBlocklike>(), get_context, lookup_context, for_compaction,
60
88
  /* use_cache */ true, /* wait_for_cache */ true, async_read);
61
89
  }
62
90
 
@@ -87,18 +115,20 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
87
115
 
88
116
  if (!block.IsCached()) {
89
117
  if (!ro.fill_cache) {
90
- Cache* const block_cache = rep_->table_options.block_cache.get();
118
+ IterPlaceholderCacheInterface block_cache{
119
+ rep_->table_options.block_cache.get()};
91
120
  if (block_cache) {
92
121
  // insert a dummy record to block cache to track the memory usage
93
122
  Cache::Handle* cache_handle = nullptr;
94
- CacheKey key = CacheKey::CreateUniqueForCacheLifetime(block_cache);
95
- s = block_cache->Insert(key.AsSlice(), nullptr,
96
- block.GetValue()->ApproximateMemoryUsage(),
97
- nullptr, &cache_handle);
123
+ CacheKey key =
124
+ CacheKey::CreateUniqueForCacheLifetime(block_cache.get());
125
+ s = block_cache.Insert(key.AsSlice(),
126
+ block.GetValue()->ApproximateMemoryUsage(),
127
+ &cache_handle);
98
128
 
99
129
  if (s.ok()) {
100
130
  assert(cache_handle != nullptr);
101
- iter->RegisterCleanup(&ForceReleaseCachedEntry, block_cache,
131
+ iter->RegisterCleanup(&ForceReleaseCachedEntry, block_cache.get(),
102
132
  cache_handle);
103
133
  }
104
134
  }
@@ -145,18 +175,20 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(const ReadOptions& ro,
145
175
 
146
176
  if (!block.IsCached()) {
147
177
  if (!ro.fill_cache) {
148
- Cache* const block_cache = rep_->table_options.block_cache.get();
178
+ IterPlaceholderCacheInterface block_cache{
179
+ rep_->table_options.block_cache.get()};
149
180
  if (block_cache) {
150
181
  // insert a dummy record to block cache to track the memory usage
151
182
  Cache::Handle* cache_handle = nullptr;
152
- CacheKey key = CacheKey::CreateUniqueForCacheLifetime(block_cache);
153
- s = block_cache->Insert(key.AsSlice(), nullptr,
154
- block.GetValue()->ApproximateMemoryUsage(),
155
- nullptr, &cache_handle);
183
+ CacheKey key =
184
+ CacheKey::CreateUniqueForCacheLifetime(block_cache.get());
185
+ s = block_cache.Insert(key.AsSlice(),
186
+ block.GetValue()->ApproximateMemoryUsage(),
187
+ &cache_handle);
156
188
 
157
189
  if (s.ok()) {
158
190
  assert(cache_handle != nullptr);
159
- iter->RegisterCleanup(&ForceReleaseCachedEntry, block_cache,
191
+ iter->RegisterCleanup(&ForceReleaseCachedEntry, block_cache.get(),
160
192
  cache_handle);
161
193
  }
162
194
  }
@@ -54,7 +54,7 @@ DEFINE_SYNC_AND_ASYNC(void, BlockBasedTable::RetrieveMultipleBlocks)
54
54
 
55
55
  (*statuses)[idx_in_batch] =
56
56
  RetrieveBlock(nullptr, options, handle, uncompression_dict,
57
- &(*results)[idx_in_batch], BlockType::kData,
57
+ &(*results)[idx_in_batch].As<Block_kData>(),
58
58
  mget_iter->get_context, &lookup_data_block_context,
59
59
  /* for_compaction */ false, /* use_cache */ true,
60
60
  /* wait_for_cache */ true, /* async_read */ false);
@@ -269,7 +269,7 @@ DEFINE_SYNC_AND_ASYNC(void, BlockBasedTable::RetrieveMultipleBlocks)
269
269
  // will avoid looking up the block cache
270
270
  s = MaybeReadBlockAndLoadToCache(
271
271
  nullptr, options, handle, uncompression_dict, /*wait=*/true,
272
- /*for_compaction=*/false, block_entry, BlockType::kData,
272
+ /*for_compaction=*/false, &block_entry->As<Block_kData>(),
273
273
  mget_iter->get_context, &lookup_data_block_context,
274
274
  &serialized_block, /*async_read=*/false);
275
275
 
@@ -441,7 +441,7 @@ DEFINE_SYNC_AND_ASYNC(void, BlockBasedTable::MultiGet)
441
441
  ? *uncompression_dict.GetValue()
442
442
  : UncompressionDict::GetEmptyDict();
443
443
  Status s = RetrieveBlock(
444
- nullptr, ro, handle, dict, &(results.back()), BlockType::kData,
444
+ nullptr, ro, handle, dict, &(results.back()).As<Block_kData>(),
445
445
  miter->get_context, &lookup_data_block_context,
446
446
  /* for_compaction */ false, /* use_cache */ true,
447
447
  /* wait_for_cache */ false, /* async_read */ false);
@@ -50,7 +50,7 @@ class BlockBasedTableReaderBaseTest : public testing::Test {
50
50
  // Internal key is constructed directly from this key,
51
51
  // and internal key size is required to be >= 8 bytes,
52
52
  // so use %08u as the format string.
53
- sprintf(k, "%08u", key);
53
+ snprintf(k, sizeof(k), "%08u", key);
54
54
  std::string v;
55
55
  if (mixed_with_human_readable_string_value) {
56
56
  v = (block % 2) ? rnd.HumanReadableString(256)
@@ -0,0 +1,96 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // This source code is licensed under both the GPLv2 (found in the
3
+ // COPYING file in the root directory) and Apache 2.0 License
4
+ // (found in the LICENSE.Apache file in the root directory).
5
+
6
+ #include "table/block_based/block_cache.h"
7
+
8
+ namespace ROCKSDB_NAMESPACE {
9
+
10
+ void BlockCreateContext::Create(std::unique_ptr<Block_kData>* parsed_out,
11
+ BlockContents&& block) {
12
+ parsed_out->reset(new Block_kData(
13
+ std::move(block), table_options->read_amp_bytes_per_bit, statistics));
14
+ }
15
+ void BlockCreateContext::Create(std::unique_ptr<Block_kIndex>* parsed_out,
16
+ BlockContents&& block) {
17
+ parsed_out->reset(new Block_kIndex(std::move(block),
18
+ /*read_amp_bytes_per_bit*/ 0, statistics));
19
+ }
20
+ void BlockCreateContext::Create(
21
+ std::unique_ptr<Block_kFilterPartitionIndex>* parsed_out,
22
+ BlockContents&& block) {
23
+ parsed_out->reset(new Block_kFilterPartitionIndex(
24
+ std::move(block), /*read_amp_bytes_per_bit*/ 0, statistics));
25
+ }
26
+ void BlockCreateContext::Create(
27
+ std::unique_ptr<Block_kRangeDeletion>* parsed_out, BlockContents&& block) {
28
+ parsed_out->reset(new Block_kRangeDeletion(
29
+ std::move(block), /*read_amp_bytes_per_bit*/ 0, statistics));
30
+ }
31
+ void BlockCreateContext::Create(std::unique_ptr<Block_kMetaIndex>* parsed_out,
32
+ BlockContents&& block) {
33
+ parsed_out->reset(new Block_kMetaIndex(
34
+ std::move(block), /*read_amp_bytes_per_bit*/ 0, statistics));
35
+ }
36
+
37
+ void BlockCreateContext::Create(
38
+ std::unique_ptr<ParsedFullFilterBlock>* parsed_out, BlockContents&& block) {
39
+ parsed_out->reset(new ParsedFullFilterBlock(
40
+ table_options->filter_policy.get(), std::move(block)));
41
+ }
42
+
43
+ void BlockCreateContext::Create(std::unique_ptr<UncompressionDict>* parsed_out,
44
+ BlockContents&& block) {
45
+ parsed_out->reset(new UncompressionDict(
46
+ block.data, std::move(block.allocation), using_zstd));
47
+ }
48
+
49
+ namespace {
50
+ // For getting SecondaryCache-compatible helpers from a BlockType. This is
51
+ // useful for accessing block cache in untyped contexts, such as for generic
52
+ // cache warming in table builder.
53
+ constexpr std::array<const Cache::CacheItemHelper*,
54
+ static_cast<unsigned>(BlockType::kInvalid) + 1>
55
+ kCacheItemFullHelperForBlockType{{
56
+ &BlockCacheInterface<Block_kData>::kFullHelper,
57
+ &BlockCacheInterface<ParsedFullFilterBlock>::kFullHelper,
58
+ &BlockCacheInterface<Block_kFilterPartitionIndex>::kFullHelper,
59
+ nullptr, // kProperties
60
+ &BlockCacheInterface<UncompressionDict>::kFullHelper,
61
+ &BlockCacheInterface<Block_kRangeDeletion>::kFullHelper,
62
+ nullptr, // kHashIndexPrefixes
63
+ nullptr, // kHashIndexMetadata
64
+ nullptr, // kMetaIndex (not yet stored in block cache)
65
+ &BlockCacheInterface<Block_kIndex>::kFullHelper,
66
+ nullptr, // kInvalid
67
+ }};
68
+
69
+ // For getting basic helpers from a BlockType (no SecondaryCache support)
70
+ constexpr std::array<const Cache::CacheItemHelper*,
71
+ static_cast<unsigned>(BlockType::kInvalid) + 1>
72
+ kCacheItemBasicHelperForBlockType{{
73
+ &BlockCacheInterface<Block_kData>::kBasicHelper,
74
+ &BlockCacheInterface<ParsedFullFilterBlock>::kBasicHelper,
75
+ &BlockCacheInterface<Block_kFilterPartitionIndex>::kBasicHelper,
76
+ nullptr, // kProperties
77
+ &BlockCacheInterface<UncompressionDict>::kBasicHelper,
78
+ &BlockCacheInterface<Block_kRangeDeletion>::kBasicHelper,
79
+ nullptr, // kHashIndexPrefixes
80
+ nullptr, // kHashIndexMetadata
81
+ nullptr, // kMetaIndex (not yet stored in block cache)
82
+ &BlockCacheInterface<Block_kIndex>::kBasicHelper,
83
+ nullptr, // kInvalid
84
+ }};
85
+ } // namespace
86
+
87
+ const Cache::CacheItemHelper* GetCacheItemHelper(
88
+ BlockType block_type, CacheTier lowest_used_cache_tier) {
89
+ if (lowest_used_cache_tier == CacheTier::kNonVolatileBlockTier) {
90
+ return kCacheItemFullHelperForBlockType[static_cast<unsigned>(block_type)];
91
+ } else {
92
+ return kCacheItemBasicHelperForBlockType[static_cast<unsigned>(block_type)];
93
+ }
94
+ }
95
+
96
+ } // namespace ROCKSDB_NAMESPACE
@@ -0,0 +1,132 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // This source code is licensed under both the GPLv2 (found in the
3
+ // COPYING file in the root directory) and Apache 2.0 License
4
+ // (found in the LICENSE.Apache file in the root directory).
5
+
6
+ // Code supporting block cache (Cache) access for block-based table, based on
7
+ // the convenient APIs in typed_cache.h
8
+
9
+ #pragma once
10
+
11
+ #include <type_traits>
12
+
13
+ #include "cache/typed_cache.h"
14
+ #include "port/lang.h"
15
+ #include "table/block_based/block.h"
16
+ #include "table/block_based/block_type.h"
17
+ #include "table/block_based/parsed_full_filter_block.h"
18
+ #include "table/format.h"
19
+
20
+ namespace ROCKSDB_NAMESPACE {
21
+
22
+ // Metaprogramming wrappers for Block, to give each type a single role when
23
+ // used with FullTypedCacheInterface.
24
+ // (NOTE: previous attempts to create actual derived classes of Block with
25
+ // virtual calls resulted in performance regression)
26
+
27
+ class Block_kData : public Block {
28
+ public:
29
+ using Block::Block;
30
+
31
+ static constexpr CacheEntryRole kCacheEntryRole = CacheEntryRole::kDataBlock;
32
+ static constexpr BlockType kBlockType = BlockType::kData;
33
+ };
34
+
35
+ class Block_kIndex : public Block {
36
+ public:
37
+ using Block::Block;
38
+
39
+ static constexpr CacheEntryRole kCacheEntryRole = CacheEntryRole::kIndexBlock;
40
+ static constexpr BlockType kBlockType = BlockType::kIndex;
41
+ };
42
+
43
+ class Block_kFilterPartitionIndex : public Block {
44
+ public:
45
+ using Block::Block;
46
+
47
+ static constexpr CacheEntryRole kCacheEntryRole =
48
+ CacheEntryRole::kFilterMetaBlock;
49
+ static constexpr BlockType kBlockType = BlockType::kFilterPartitionIndex;
50
+ };
51
+
52
+ class Block_kRangeDeletion : public Block {
53
+ public:
54
+ using Block::Block;
55
+
56
+ static constexpr CacheEntryRole kCacheEntryRole = CacheEntryRole::kOtherBlock;
57
+ static constexpr BlockType kBlockType = BlockType::kRangeDeletion;
58
+ };
59
+
60
+ // Useful for creating the Block even though meta index blocks are not
61
+ // yet stored in block cache
62
+ class Block_kMetaIndex : public Block {
63
+ public:
64
+ using Block::Block;
65
+
66
+ static constexpr CacheEntryRole kCacheEntryRole = CacheEntryRole::kOtherBlock;
67
+ static constexpr BlockType kBlockType = BlockType::kMetaIndex;
68
+ };
69
+
70
+ struct BlockCreateContext : public Cache::CreateContext {
71
+ BlockCreateContext() {}
72
+ BlockCreateContext(const BlockBasedTableOptions* _table_options,
73
+ Statistics* _statistics, bool _using_zstd)
74
+ : table_options(_table_options),
75
+ statistics(_statistics),
76
+ using_zstd(_using_zstd) {}
77
+
78
+ const BlockBasedTableOptions* table_options = nullptr;
79
+ Statistics* statistics = nullptr;
80
+ bool using_zstd = false;
81
+
82
+ // For TypedCacheInterface
83
+ template <typename TBlocklike>
84
+ inline void Create(std::unique_ptr<TBlocklike>* parsed_out,
85
+ size_t* charge_out, const Slice& data,
86
+ MemoryAllocator* alloc) {
87
+ Create(parsed_out,
88
+ BlockContents(AllocateAndCopyBlock(data, alloc), data.size()));
89
+ *charge_out = parsed_out->get()->ApproximateMemoryUsage();
90
+ }
91
+
92
+ void Create(std::unique_ptr<Block_kData>* parsed_out, BlockContents&& block);
93
+ void Create(std::unique_ptr<Block_kIndex>* parsed_out, BlockContents&& block);
94
+ void Create(std::unique_ptr<Block_kFilterPartitionIndex>* parsed_out,
95
+ BlockContents&& block);
96
+ void Create(std::unique_ptr<Block_kRangeDeletion>* parsed_out,
97
+ BlockContents&& block);
98
+ void Create(std::unique_ptr<Block_kMetaIndex>* parsed_out,
99
+ BlockContents&& block);
100
+ void Create(std::unique_ptr<ParsedFullFilterBlock>* parsed_out,
101
+ BlockContents&& block);
102
+ void Create(std::unique_ptr<UncompressionDict>* parsed_out,
103
+ BlockContents&& block);
104
+ };
105
+
106
+ // Convenient cache interface to use with block_cache_compressed
107
+ using CompressedBlockCacheInterface =
108
+ BasicTypedCacheInterface<BlockContents, CacheEntryRole::kOtherBlock>;
109
+
110
+ // Convenient cache interface to use for block_cache, with support for
111
+ // SecondaryCache.
112
+ template <typename TBlocklike>
113
+ using BlockCacheInterface =
114
+ FullTypedCacheInterface<TBlocklike, BlockCreateContext>;
115
+
116
+ // Shortcut name for cache handles under BlockCacheInterface
117
+ template <typename TBlocklike>
118
+ using BlockCacheTypedHandle =
119
+ typename BlockCacheInterface<TBlocklike>::TypedHandle;
120
+
121
+ // Selects the right helper based on BlockType and CacheTier
122
+ const Cache::CacheItemHelper* GetCacheItemHelper(
123
+ BlockType block_type,
124
+ CacheTier lowest_used_cache_tier = CacheTier::kNonVolatileBlockTier);
125
+
126
+ // For SFINAE check that a type is "blocklike" with a kCacheEntryRole member.
127
+ // Can get difficult compiler/linker errors without a good check like this.
128
+ template <typename TUse, typename TBlocklike>
129
+ using WithBlocklikeCheck = std::enable_if_t<
130
+ TBlocklike::kCacheEntryRole == CacheEntryRole::kMisc || true, TUse>;
131
+
132
+ } // namespace ROCKSDB_NAMESPACE
@@ -10,6 +10,7 @@
10
10
  #pragma once
11
11
 
12
12
  #include <cassert>
13
+ #include <type_traits>
13
14
 
14
15
  #include "port/likely.h"
15
16
  #include "rocksdb/cache.h"
@@ -191,6 +192,29 @@ class CachableEntry {
191
192
  return true;
192
193
  }
193
194
 
195
+ // Since this class is essentially an elaborate pointer, it's sometimes
196
+ // useful to be able to upcast or downcast the base type of the pointer,
197
+ // especially when interacting with typed_cache.h.
198
+ template <class TWrapper>
199
+ std::enable_if_t<sizeof(TWrapper) == sizeof(T) &&
200
+ (std::is_base_of_v<TWrapper, T> ||
201
+ std::is_base_of_v<T, TWrapper>),
202
+ /* Actual return type */
203
+ CachableEntry<TWrapper>&>
204
+ As() {
205
+ CachableEntry<TWrapper>* result_ptr =
206
+ reinterpret_cast<CachableEntry<TWrapper>*>(this);
207
+ // Ensure no weirdness in template instantiations
208
+ assert(static_cast<void*>(&this->value_) ==
209
+ static_cast<void*>(&result_ptr->value_));
210
+ assert(&this->cache_handle_ == &result_ptr->cache_handle_);
211
+ // This function depends on no arithmetic involved in the pointer
212
+ // conversion, which is not statically checkable.
213
+ assert(static_cast<void*>(this->value_) ==
214
+ static_cast<void*>(result_ptr->value_));
215
+ return *result_ptr;
216
+ }
217
+
194
218
  private:
195
219
  void ReleaseResource() noexcept {
196
220
  if (LIKELY(cache_handle_ != nullptr)) {
@@ -223,6 +247,10 @@ class CachableEntry {
223
247
  }
224
248
 
225
249
  private:
250
+ // Have to be your own best friend
251
+ template <class TT>
252
+ friend class CachableEntry;
253
+
226
254
  T* value_ = nullptr;
227
255
  Cache* cache_ = nullptr;
228
256
  Cache::Handle* cache_handle_ = nullptr;
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include "table/block_based/filter_block_reader_common.h"
8
8
 
9
+ #include "block_cache.h"
9
10
  #include "monitoring/perf_context_imp.h"
10
11
  #include "table/block_based/block_based_table_reader.h"
11
12
  #include "table/block_based/parsed_full_filter_block.h"
@@ -17,7 +18,7 @@ Status FilterBlockReaderCommon<TBlocklike>::ReadFilterBlock(
17
18
  const BlockBasedTable* table, FilePrefetchBuffer* prefetch_buffer,
18
19
  const ReadOptions& read_options, bool use_cache, GetContext* get_context,
19
20
  BlockCacheLookupContext* lookup_context,
20
- CachableEntry<TBlocklike>* filter_block, BlockType block_type) {
21
+ CachableEntry<TBlocklike>* filter_block) {
21
22
  PERF_TIMER_GUARD(read_filter_block_nanos);
22
23
 
23
24
  assert(table);
@@ -30,7 +31,7 @@ Status FilterBlockReaderCommon<TBlocklike>::ReadFilterBlock(
30
31
  const Status s =
31
32
  table->RetrieveBlock(prefetch_buffer, read_options, rep->filter_handle,
32
33
  UncompressionDict::GetEmptyDict(), filter_block,
33
- block_type, get_context, lookup_context,
34
+ get_context, lookup_context,
34
35
  /* for_compaction */ false, use_cache,
35
36
  /* wait_for_cache */ true, /* async_read */ false);
36
37
 
@@ -68,7 +69,7 @@ template <typename TBlocklike>
68
69
  Status FilterBlockReaderCommon<TBlocklike>::GetOrReadFilterBlock(
69
70
  bool no_io, GetContext* get_context,
70
71
  BlockCacheLookupContext* lookup_context,
71
- CachableEntry<TBlocklike>* filter_block, BlockType block_type,
72
+ CachableEntry<TBlocklike>* filter_block,
72
73
  Env::IOPriority rate_limiter_priority) const {
73
74
  assert(filter_block);
74
75
 
@@ -85,7 +86,7 @@ Status FilterBlockReaderCommon<TBlocklike>::GetOrReadFilterBlock(
85
86
 
86
87
  return ReadFilterBlock(table_, nullptr /* prefetch_buffer */, read_options,
87
88
  cache_filter_blocks(), get_context, lookup_context,
88
- filter_block, block_type);
89
+ filter_block);
89
90
  }
90
91
 
91
92
  template <typename TBlocklike>
@@ -158,7 +159,7 @@ bool FilterBlockReaderCommon<TBlocklike>::IsFilterCompatible(
158
159
 
159
160
  // Explicitly instantiate templates for both "blocklike" types we use.
160
161
  // This makes it possible to keep the template definitions in the .cc file.
161
- template class FilterBlockReaderCommon<Block>;
162
+ template class FilterBlockReaderCommon<Block_kFilterPartitionIndex>;
162
163
  template class FilterBlockReaderCommon<ParsedFullFilterBlock>;
163
164
 
164
165
  } // namespace ROCKSDB_NAMESPACE
@@ -8,7 +8,6 @@
8
8
 
9
9
  #include <cassert>
10
10
 
11
- #include "block_type.h"
12
11
  #include "table/block_based/cachable_entry.h"
13
12
  #include "table/block_based/filter_block.h"
14
13
 
@@ -49,8 +48,7 @@ class FilterBlockReaderCommon : public FilterBlockReader {
49
48
  const ReadOptions& read_options, bool use_cache,
50
49
  GetContext* get_context,
51
50
  BlockCacheLookupContext* lookup_context,
52
- CachableEntry<TBlocklike>* filter_block,
53
- BlockType block_type);
51
+ CachableEntry<TBlocklike>* filter_block);
54
52
 
55
53
  const BlockBasedTable* table() const { return table_; }
56
54
  const SliceTransform* table_prefix_extractor() const;
@@ -60,7 +58,6 @@ class FilterBlockReaderCommon : public FilterBlockReader {
60
58
  Status GetOrReadFilterBlock(bool no_io, GetContext* get_context,
61
59
  BlockCacheLookupContext* lookup_context,
62
60
  CachableEntry<TBlocklike>* filter_block,
63
- BlockType block_type,
64
61
  Env::IOPriority rate_limiter_priority) const;
65
62
 
66
63
  size_t ApproximateFilterBlockMemoryUsage() const;