@nxtedition/rocksdb 8.1.3 → 8.1.5

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 (146) hide show
  1. package/deps/rocksdb/rocksdb/CMakeLists.txt +13 -1
  2. package/deps/rocksdb/rocksdb/Makefile +2 -2
  3. package/deps/rocksdb/rocksdb/TARGETS +4 -2
  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_counting_iterator.h +0 -11
  29. package/deps/rocksdb/rocksdb/db/blob/blob_file_builder.cc +5 -26
  30. package/deps/rocksdb/rocksdb/db/blob/blob_file_cache.cc +7 -8
  31. package/deps/rocksdb/rocksdb/db/blob/blob_file_cache.h +6 -3
  32. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader.cc +2 -7
  33. package/deps/rocksdb/rocksdb/db/blob/blob_source.cc +19 -47
  34. package/deps/rocksdb/rocksdb/db/blob/blob_source.h +13 -5
  35. package/deps/rocksdb/rocksdb/db/blob/blob_source_test.cc +15 -22
  36. package/deps/rocksdb/rocksdb/db/builder.cc +17 -12
  37. package/deps/rocksdb/rocksdb/db/column_family.cc +0 -1
  38. package/deps/rocksdb/rocksdb/db/column_family.h +0 -6
  39. package/deps/rocksdb/rocksdb/db/compaction/clipping_iterator.h +0 -5
  40. package/deps/rocksdb/rocksdb/db/compaction/compaction.cc +3 -0
  41. package/deps/rocksdb/rocksdb/db/compaction/compaction.h +0 -2
  42. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +28 -27
  43. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +2 -17
  44. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +1 -0
  45. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.cc +254 -139
  46. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +7 -5
  47. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.h +0 -5
  48. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +98 -9
  49. package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +28 -28
  50. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +125 -0
  51. package/deps/rocksdb/rocksdb/db/db_flush_test.cc +65 -4
  52. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +1 -1
  53. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +27 -15
  54. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +78 -49
  55. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_write.cc +34 -24
  56. package/deps/rocksdb/rocksdb/db/db_iter.cc +8 -2
  57. package/deps/rocksdb/rocksdb/db/db_merge_operand_test.cc +42 -0
  58. package/deps/rocksdb/rocksdb/db/db_merge_operator_test.cc +155 -0
  59. package/deps/rocksdb/rocksdb/db/db_properties_test.cc +12 -12
  60. package/deps/rocksdb/rocksdb/db/db_range_del_test.cc +117 -210
  61. package/deps/rocksdb/rocksdb/db/db_test_util.cc +11 -10
  62. package/deps/rocksdb/rocksdb/db/db_test_util.h +36 -24
  63. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +28 -0
  64. package/deps/rocksdb/rocksdb/db/flush_job.cc +6 -6
  65. package/deps/rocksdb/rocksdb/db/flush_job.h +3 -2
  66. package/deps/rocksdb/rocksdb/db/flush_job_test.cc +29 -29
  67. package/deps/rocksdb/rocksdb/db/history_trimming_iterator.h +0 -4
  68. package/deps/rocksdb/rocksdb/db/internal_stats.cc +11 -11
  69. package/deps/rocksdb/rocksdb/db/internal_stats.h +2 -2
  70. package/deps/rocksdb/rocksdb/db/log_reader.cc +8 -6
  71. package/deps/rocksdb/rocksdb/db/log_test.cc +35 -2
  72. package/deps/rocksdb/rocksdb/db/memtable.cc +30 -5
  73. package/deps/rocksdb/rocksdb/db/merge_helper.cc +47 -33
  74. package/deps/rocksdb/rocksdb/db/merge_helper.h +14 -6
  75. package/deps/rocksdb/rocksdb/db/table_cache.cc +41 -91
  76. package/deps/rocksdb/rocksdb/db/table_cache.h +17 -19
  77. package/deps/rocksdb/rocksdb/db/table_cache_sync_and_async.h +7 -9
  78. package/deps/rocksdb/rocksdb/db/version_builder.cc +12 -9
  79. package/deps/rocksdb/rocksdb/db/version_edit.h +1 -0
  80. package/deps/rocksdb/rocksdb/db/version_set.cc +20 -28
  81. package/deps/rocksdb/rocksdb/db/version_set.h +2 -2
  82. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +1 -1
  83. package/deps/rocksdb/rocksdb/db/write_batch.cc +4 -1
  84. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +1 -0
  85. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +358 -214
  86. package/deps/rocksdb/rocksdb/include/rocksdb/cache.h +137 -135
  87. package/deps/rocksdb/rocksdb/include/rocksdb/merge_operator.h +21 -0
  88. package/deps/rocksdb/rocksdb/include/rocksdb/secondary_cache.h +8 -6
  89. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  90. package/deps/rocksdb/rocksdb/memory/memory_allocator.h +9 -0
  91. package/deps/rocksdb/rocksdb/options/customizable_test.cc +4 -3
  92. package/deps/rocksdb/rocksdb/port/port_posix.h +2 -0
  93. package/{prebuilds → deps/rocksdb/rocksdb/prebuilds}/linux-x64/node.napi.node +0 -0
  94. package/deps/rocksdb/rocksdb/src.mk +2 -1
  95. package/deps/rocksdb/rocksdb/table/block_based/block.h +3 -0
  96. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +25 -67
  97. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.h +3 -3
  98. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.cc +18 -13
  99. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +156 -223
  100. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +31 -50
  101. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_impl.h +46 -18
  102. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +3 -3
  103. package/deps/rocksdb/rocksdb/table/block_based/block_cache.cc +96 -0
  104. package/deps/rocksdb/rocksdb/table/block_based/block_cache.h +132 -0
  105. package/deps/rocksdb/rocksdb/table/block_based/cachable_entry.h +28 -0
  106. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.cc +6 -5
  107. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.h +1 -4
  108. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.cc +6 -7
  109. package/deps/rocksdb/rocksdb/table/block_based/index_reader_common.cc +3 -1
  110. package/deps/rocksdb/rocksdb/table/block_based/parsed_full_filter_block.h +6 -1
  111. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +19 -18
  112. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.h +9 -5
  113. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block_test.cc +3 -1
  114. package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_reader.cc +2 -1
  115. package/deps/rocksdb/rocksdb/table/block_based/uncompression_dict_reader.cc +2 -2
  116. package/deps/rocksdb/rocksdb/table/format.h +1 -1
  117. package/deps/rocksdb/rocksdb/table/get_context.cc +12 -3
  118. package/deps/rocksdb/rocksdb/table/internal_iterator.h +0 -2
  119. package/deps/rocksdb/rocksdb/table/merging_iterator.cc +92 -7
  120. package/deps/rocksdb/rocksdb/table/merging_iterator.h +0 -80
  121. package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer_test.cc +66 -1
  122. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +9 -2
  123. package/deps/rocksdb/rocksdb/trace_replay/block_cache_tracer.cc +5 -0
  124. package/deps/rocksdb/rocksdb/trace_replay/trace_replay.cc +1 -1
  125. package/deps/rocksdb/rocksdb/util/async_file_reader.cc +20 -12
  126. package/deps/rocksdb/rocksdb/util/compression.cc +2 -2
  127. package/deps/rocksdb/rocksdb/util/compression.h +11 -2
  128. package/deps/rocksdb/rocksdb/util/xxhash.h +1901 -887
  129. package/deps/rocksdb/rocksdb/utilities/cache_dump_load_impl.cc +35 -57
  130. package/deps/rocksdb/rocksdb/utilities/cache_dump_load_impl.h +4 -5
  131. package/deps/rocksdb/rocksdb/utilities/fault_injection_secondary_cache.cc +11 -6
  132. package/deps/rocksdb/rocksdb/utilities/fault_injection_secondary_cache.h +6 -5
  133. package/deps/rocksdb/rocksdb/utilities/memory_allocators.h +0 -1
  134. package/deps/rocksdb/rocksdb/utilities/simulator_cache/cache_simulator.cc +10 -11
  135. package/deps/rocksdb/rocksdb/utilities/simulator_cache/sim_cache.cc +31 -31
  136. package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h +4 -0
  137. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.cc +52 -0
  138. package/deps/rocksdb/rocksdb/utilities/ttl/db_ttl_impl.cc +1 -0
  139. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_internal.cc +12 -3
  140. package/deps/rocksdb/rocksdb.gyp +0 -3
  141. package/index.js +2 -2
  142. package/package.json +1 -1
  143. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  144. package/deps/rocksdb/rocksdb/table/block_based/block_like_traits.h +0 -182
  145. package/deps/rocksdb/rocksdb/table/compaction_merging_iterator.cc +0 -142
  146. package/deps/rocksdb/rocksdb/table/compaction_merging_iterator.h +0 -241
@@ -245,6 +245,14 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
245
245
  endif(HAS_S390X_MARCH_NATIVE)
246
246
  endif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
247
247
 
248
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
249
+ CHECK_C_COMPILER_FLAG("-march=loongarch64" HAS_LOONGARCH64)
250
+ if(HAS_LOONGARCH64)
251
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=loongarch64 -mtune=loongarch64")
252
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=loongarch64 -mtune=loongarch64")
253
+ endif(HAS_LOONGARCH64)
254
+ endif(CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
255
+
248
256
  option(PORTABLE "build a portable binary" OFF)
249
257
  option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
250
258
  option(FORCE_AVX "force building with AVX, even when PORTABLE=ON" OFF)
@@ -275,6 +283,9 @@ if(PORTABLE)
275
283
  if(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390x")
276
284
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z196")
277
285
  endif()
286
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^loongarch64")
287
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=loongarch64")
288
+ endif()
278
289
  endif()
279
290
  else()
280
291
  if(MSVC)
@@ -649,6 +660,7 @@ set(SOURCES
649
660
  cache/cache.cc
650
661
  cache/cache_entry_roles.cc
651
662
  cache/cache_key.cc
663
+ cache/cache_helpers.cc
652
664
  cache/cache_reservation_manager.cc
653
665
  cache/charged_cache.cc
654
666
  cache/clock_cache.cc
@@ -806,6 +818,7 @@ set(SOURCES
806
818
  table/block_based/block_based_table_iterator.cc
807
819
  table/block_based/block_based_table_reader.cc
808
820
  table/block_based/block_builder.cc
821
+ table/block_based/block_cache.cc
809
822
  table/block_based/block_prefetcher.cc
810
823
  table/block_based/block_prefix_index.cc
811
824
  table/block_based/data_block_hash_index.cc
@@ -831,7 +844,6 @@ set(SOURCES
831
844
  table/get_context.cc
832
845
  table/iterator.cc
833
846
  table/merging_iterator.cc
834
- table/compaction_merging_iterator.cc
835
847
  table/meta_blocks.cc
836
848
  table/persistent_cache_helper.cc
837
849
  table/plain/plain_table_bloom.cc
@@ -2070,7 +2070,7 @@ JAVA_INCLUDE = -I$(JAVA_HOME)/include/ -I$(JAVA_HOME)/include/linux
2070
2070
  ifeq ($(PLATFORM), OS_SOLARIS)
2071
2071
  ARCH := $(shell isainfo -b)
2072
2072
  else ifeq ($(PLATFORM), OS_OPENBSD)
2073
- ifneq (,$(filter amd64 ppc64 ppc64le s390x arm64 aarch64 sparc64, $(MACHINE)))
2073
+ ifneq (,$(filter amd64 ppc64 ppc64le s390x arm64 aarch64 sparc64 loongarch64, $(MACHINE)))
2074
2074
  ARCH := 64
2075
2075
  else
2076
2076
  ARCH := 32
@@ -2091,7 +2091,7 @@ ifneq ($(origin JNI_LIBC), undefined)
2091
2091
  endif
2092
2092
 
2093
2093
  ifeq (,$(ROCKSDBJNILIB))
2094
- ifneq (,$(filter ppc% s390x arm64 aarch64 sparc64, $(MACHINE)))
2094
+ ifneq (,$(filter ppc% s390x arm64 aarch64 sparc64 loongarch64, $(MACHINE)))
2095
2095
  ROCKSDBJNILIB = librocksdbjni-linux-$(MACHINE)$(JNI_LIBC_POSTFIX).so
2096
2096
  else
2097
2097
  ROCKSDBJNILIB = librocksdbjni-linux$(ARCH)$(JNI_LIBC_POSTFIX).so
@@ -11,6 +11,7 @@ load("//rocks/buckifier:defs.bzl", "cpp_library_wrapper","rocks_cpp_library_wrap
11
11
  cpp_library_wrapper(name="rocksdb_lib", srcs=[
12
12
  "cache/cache.cc",
13
13
  "cache/cache_entry_roles.cc",
14
+ "cache/cache_helpers.cc",
14
15
  "cache/cache_key.cc",
15
16
  "cache/cache_reservation_manager.cc",
16
17
  "cache/charged_cache.cc",
@@ -180,6 +181,7 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
180
181
  "table/block_based/block_based_table_iterator.cc",
181
182
  "table/block_based/block_based_table_reader.cc",
182
183
  "table/block_based/block_builder.cc",
184
+ "table/block_based/block_cache.cc",
183
185
  "table/block_based/block_prefetcher.cc",
184
186
  "table/block_based/block_prefix_index.cc",
185
187
  "table/block_based/data_block_footer.cc",
@@ -198,7 +200,6 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
198
200
  "table/block_based/reader_common.cc",
199
201
  "table/block_based/uncompression_dict_reader.cc",
200
202
  "table/block_fetcher.cc",
201
- "table/compaction_merging_iterator.cc",
202
203
  "table/cuckoo/cuckoo_table_builder.cc",
203
204
  "table/cuckoo/cuckoo_table_factory.cc",
204
205
  "table/cuckoo/cuckoo_table_reader.cc",
@@ -352,6 +353,7 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
352
353
  cpp_library_wrapper(name="rocksdb_whole_archive_lib", srcs=[
353
354
  "cache/cache.cc",
354
355
  "cache/cache_entry_roles.cc",
356
+ "cache/cache_helpers.cc",
355
357
  "cache/cache_key.cc",
356
358
  "cache/cache_reservation_manager.cc",
357
359
  "cache/charged_cache.cc",
@@ -521,6 +523,7 @@ cpp_library_wrapper(name="rocksdb_whole_archive_lib", srcs=[
521
523
  "table/block_based/block_based_table_iterator.cc",
522
524
  "table/block_based/block_based_table_reader.cc",
523
525
  "table/block_based/block_builder.cc",
526
+ "table/block_based/block_cache.cc",
524
527
  "table/block_based/block_prefetcher.cc",
525
528
  "table/block_based/block_prefix_index.cc",
526
529
  "table/block_based/data_block_footer.cc",
@@ -539,7 +542,6 @@ cpp_library_wrapper(name="rocksdb_whole_archive_lib", srcs=[
539
542
  "table/block_based/reader_common.cc",
540
543
  "table/block_based/uncompression_dict_reader.cc",
541
544
  "table/block_fetcher.cc",
542
- "table/compaction_merging_iterator.cc",
543
545
  "table/cuckoo/cuckoo_table_builder.cc",
544
546
  "table/cuckoo/cuckoo_table_factory.cc",
545
547
  "table/cuckoo/cuckoo_table_reader.cc",
@@ -226,7 +226,7 @@ struct KeyGen {
226
226
  }
227
227
  };
228
228
 
229
- char* createValue(Random64& rnd) {
229
+ Cache::ObjectPtr createValue(Random64& rnd) {
230
230
  char* rv = new char[FLAGS_value_bytes];
231
231
  // Fill with some filler data, and take some CPU time
232
232
  for (uint32_t i = 0; i < FLAGS_value_bytes; i += 8) {
@@ -236,28 +236,33 @@ char* createValue(Random64& rnd) {
236
236
  }
237
237
 
238
238
  // Callbacks for secondary cache
239
- size_t SizeFn(void* /*obj*/) { return FLAGS_value_bytes; }
239
+ size_t SizeFn(Cache::ObjectPtr /*obj*/) { return FLAGS_value_bytes; }
240
240
 
241
- Status SaveToFn(void* obj, size_t /*offset*/, size_t size, void* out) {
242
- memcpy(out, obj, size);
241
+ Status SaveToFn(Cache::ObjectPtr from_obj, size_t /*from_offset*/,
242
+ size_t length, char* out) {
243
+ memcpy(out, from_obj, length);
243
244
  return Status::OK();
244
245
  }
245
246
 
246
- // Different deleters to simulate using deleter to gather
247
- // stats on the code origin and kind of cache entries.
248
- void deleter1(const Slice& /*key*/, void* value) {
249
- delete[] static_cast<char*>(value);
250
- }
251
- void deleter2(const Slice& /*key*/, void* value) {
252
- delete[] static_cast<char*>(value);
253
- }
254
- void deleter3(const Slice& /*key*/, void* value) {
247
+ Status CreateFn(const Slice& data, Cache::CreateContext* /*context*/,
248
+ MemoryAllocator* /*allocator*/, Cache::ObjectPtr* out_obj,
249
+ size_t* out_charge) {
250
+ *out_obj = new char[data.size()];
251
+ memcpy(*out_obj, data.data(), data.size());
252
+ *out_charge = data.size();
253
+ return Status::OK();
254
+ };
255
+
256
+ void DeleteFn(Cache::ObjectPtr value, MemoryAllocator* /*alloc*/) {
255
257
  delete[] static_cast<char*>(value);
256
258
  }
257
259
 
258
- Cache::CacheItemHelper helper1(SizeFn, SaveToFn, deleter1);
259
- Cache::CacheItemHelper helper2(SizeFn, SaveToFn, deleter2);
260
- Cache::CacheItemHelper helper3(SizeFn, SaveToFn, deleter3);
260
+ Cache::CacheItemHelper helper1(CacheEntryRole::kDataBlock, DeleteFn, SizeFn,
261
+ SaveToFn, CreateFn);
262
+ Cache::CacheItemHelper helper2(CacheEntryRole::kIndexBlock, DeleteFn, SizeFn,
263
+ SaveToFn, CreateFn);
264
+ Cache::CacheItemHelper helper3(CacheEntryRole::kFilterBlock, DeleteFn, SizeFn,
265
+ SaveToFn, CreateFn);
261
266
  } // namespace
262
267
 
263
268
  class CacheBench {
@@ -436,7 +441,7 @@ class CacheBench {
436
441
  uint64_t total_entry_count = 0;
437
442
  uint64_t table_occupancy = 0;
438
443
  uint64_t table_size = 0;
439
- std::set<Cache::DeleterFn> deleters;
444
+ std::set<const Cache::CacheItemHelper*> helpers;
440
445
  StopWatchNano timer(clock);
441
446
 
442
447
  for (;;) {
@@ -461,7 +466,7 @@ class CacheBench {
461
466
  << BytesToHumanString(static_cast<uint64_t>(
462
467
  1.0 * total_charge / total_entry_count))
463
468
  << "\n"
464
- << "Unique deleters: " << deleters.size() << "\n";
469
+ << "Unique helpers: " << helpers.size() << "\n";
465
470
  *stats_report = ostr.str();
466
471
  return;
467
472
  }
@@ -477,14 +482,14 @@ class CacheBench {
477
482
  total_key_size = 0;
478
483
  total_charge = 0;
479
484
  total_entry_count = 0;
480
- deleters.clear();
481
- auto fn = [&](const Slice& key, void* /*value*/, size_t charge,
482
- Cache::DeleterFn deleter) {
485
+ helpers.clear();
486
+ auto fn = [&](const Slice& key, Cache::ObjectPtr /*value*/, size_t charge,
487
+ const Cache::CacheItemHelper* helper) {
483
488
  total_key_size += key.size();
484
489
  total_charge += charge;
485
490
  ++total_entry_count;
486
- // Something slightly more expensive as in (future) stats by category
487
- deleters.insert(deleter);
491
+ // Something slightly more expensive as in stats by category
492
+ helpers.insert(helper);
488
493
  };
489
494
  timer.Start();
490
495
  Cache::ApplyToAllEntriesOptions opts;
@@ -533,14 +538,6 @@ class CacheBench {
533
538
  for (uint64_t i = 0; i < FLAGS_ops_per_thread; i++) {
534
539
  Slice key = gen.GetRand(thread->rnd, max_key_, max_log_);
535
540
  uint64_t random_op = thread->rnd.Next();
536
- Cache::CreateCallback create_cb = [](const void* buf, size_t size,
537
- void** out_obj,
538
- size_t* charge) -> Status {
539
- *out_obj = reinterpret_cast<void*>(new char[size]);
540
- memcpy(*out_obj, buf, size);
541
- *charge = size;
542
- return Status::OK();
543
- };
544
541
 
545
542
  timer.Start();
546
543
 
@@ -550,8 +547,8 @@ class CacheBench {
550
547
  handle = nullptr;
551
548
  }
552
549
  // do lookup
553
- handle = cache_->Lookup(key, &helper2, create_cb, Cache::Priority::LOW,
554
- true);
550
+ handle = cache_->Lookup(key, &helper2, /*context*/ nullptr,
551
+ Cache::Priority::LOW, true);
555
552
  if (handle) {
556
553
  if (!FLAGS_lean) {
557
554
  // do something with the data
@@ -579,8 +576,8 @@ class CacheBench {
579
576
  handle = nullptr;
580
577
  }
581
578
  // do lookup
582
- handle = cache_->Lookup(key, &helper2, create_cb, Cache::Priority::LOW,
583
- true);
579
+ handle = cache_->Lookup(key, &helper2, /*context*/ nullptr,
580
+ Cache::Priority::LOW, true);
584
581
  if (handle) {
585
582
  if (!FLAGS_lean) {
586
583
  // do something with the data
@@ -101,34 +101,4 @@ std::string BlockCacheEntryStatsMapKeys::UsedPercent(CacheEntryRole role) {
101
101
  return GetPrefixedCacheEntryRoleName(kPrefix, role);
102
102
  }
103
103
 
104
- namespace {
105
-
106
- struct Registry {
107
- std::mutex mutex;
108
- UnorderedMap<Cache::DeleterFn, CacheEntryRole> role_map;
109
- void Register(Cache::DeleterFn fn, CacheEntryRole role) {
110
- std::lock_guard<std::mutex> lock(mutex);
111
- role_map[fn] = role;
112
- }
113
- UnorderedMap<Cache::DeleterFn, CacheEntryRole> Copy() {
114
- std::lock_guard<std::mutex> lock(mutex);
115
- return role_map;
116
- }
117
- };
118
-
119
- Registry& GetRegistry() {
120
- STATIC_AVOID_DESTRUCTION(Registry, registry);
121
- return registry;
122
- }
123
-
124
- } // namespace
125
-
126
- void RegisterCacheDeleterRole(Cache::DeleterFn fn, CacheEntryRole role) {
127
- GetRegistry().Register(fn, role);
128
- }
129
-
130
- UnorderedMap<Cache::DeleterFn, CacheEntryRole> CopyCacheDeleterRoleMap() {
131
- return GetRegistry().Copy();
132
- }
133
-
134
104
  } // namespace ROCKSDB_NAMESPACE
@@ -7,11 +7,8 @@
7
7
 
8
8
  #include <array>
9
9
  #include <cstdint>
10
- #include <memory>
11
- #include <type_traits>
12
10
 
13
11
  #include "rocksdb/cache.h"
14
- #include "util/hash_containers.h"
15
12
 
16
13
  namespace ROCKSDB_NAMESPACE {
17
14
 
@@ -20,84 +17,4 @@ extern std::array<std::string, kNumCacheEntryRoles>
20
17
  extern std::array<std::string, kNumCacheEntryRoles>
21
18
  kCacheEntryRoleToHyphenString;
22
19
 
23
- // To associate cache entries with their role, we use a hack on the
24
- // existing Cache interface. Because the deleter of an entry can authenticate
25
- // the code origin of an entry, we can elaborate the choice of deleter to
26
- // also encode role information, without inferring false role information
27
- // from entries not choosing to encode a role.
28
- //
29
- // The rest of this file is for handling mappings between deleters and
30
- // roles.
31
-
32
- // To infer a role from a deleter, the deleter must be registered. This
33
- // can be done "manually" with this function. This function is thread-safe,
34
- // and the registration mappings go into private but static storage. (Note
35
- // that DeleterFn is a function pointer, not std::function. Registrations
36
- // should not be too many.)
37
- void RegisterCacheDeleterRole(Cache::DeleterFn fn, CacheEntryRole role);
38
-
39
- // Gets a copy of the registered deleter -> role mappings. This is the only
40
- // function for reading the mappings made with RegisterCacheDeleterRole.
41
- // Why only this interface for reading?
42
- // * This function has to be thread safe, which could incur substantial
43
- // overhead. We should not pay this overhead for every deleter look-up.
44
- // * This is suitable for preparing for batch operations, like with
45
- // CacheEntryStatsCollector.
46
- // * The number of mappings should be sufficiently small (dozens).
47
- UnorderedMap<Cache::DeleterFn, CacheEntryRole> CopyCacheDeleterRoleMap();
48
-
49
- // ************************************************************** //
50
- // An automatic registration infrastructure. This enables code
51
- // to simply ask for a deleter associated with a particular type
52
- // and role, and registration is automatic. In a sense, this is
53
- // a small dependency injection infrastructure, because linking
54
- // in new deleter instantiations is essentially sufficient for
55
- // making stats collection (using CopyCacheDeleterRoleMap) aware
56
- // of them.
57
-
58
- namespace cache_entry_roles_detail {
59
-
60
- template <typename T, CacheEntryRole R>
61
- struct RegisteredDeleter {
62
- RegisteredDeleter() { RegisterCacheDeleterRole(Delete, R); }
63
-
64
- // These have global linkage to help ensure compiler optimizations do not
65
- // break uniqueness for each <T,R>
66
- static void Delete(const Slice& /* key */, void* value) {
67
- // Supports T == Something[], unlike delete operator
68
- std::default_delete<T>()(
69
- static_cast<typename std::remove_extent<T>::type*>(value));
70
- }
71
- };
72
-
73
- template <CacheEntryRole R>
74
- struct RegisteredNoopDeleter {
75
- RegisteredNoopDeleter() { RegisterCacheDeleterRole(Delete, R); }
76
-
77
- static void Delete(const Slice& /* key */, void* /* value */) {
78
- // Here was `assert(value == nullptr);` but we can also put pointers
79
- // to static data in Cache, for testing at least.
80
- }
81
- };
82
-
83
- } // namespace cache_entry_roles_detail
84
-
85
- // Get an automatically registered deleter for value type T and role R.
86
- // Based on C++ semantics, registration is invoked exactly once in a
87
- // thread-safe way on first call to this function, for each <T, R>.
88
- template <typename T, CacheEntryRole R>
89
- Cache::DeleterFn GetCacheEntryDeleterForRole() {
90
- static cache_entry_roles_detail::RegisteredDeleter<T, R> reg;
91
- return reg.Delete;
92
- }
93
-
94
- // Get an automatically registered no-op deleter (value should be nullptr)
95
- // and associated with role R. This is used for Cache "reservation" entries
96
- // such as for WriteBufferManager.
97
- template <CacheEntryRole R>
98
- Cache::DeleterFn GetNoopDeleterForRole() {
99
- static cache_entry_roles_detail::RegisteredNoopDeleter<R> reg;
100
- return reg.Delete;
101
- }
102
-
103
20
  } // namespace ROCKSDB_NAMESPACE
@@ -10,8 +10,8 @@
10
10
  #include <memory>
11
11
  #include <mutex>
12
12
 
13
- #include "cache/cache_helpers.h"
14
13
  #include "cache/cache_key.h"
14
+ #include "cache/typed_cache.h"
15
15
  #include "port/lang.h"
16
16
  #include "rocksdb/cache.h"
17
17
  #include "rocksdb/status.h"
@@ -111,11 +111,14 @@ class CacheEntryStatsCollector {
111
111
  // Gets or creates a shared instance of CacheEntryStatsCollector in the
112
112
  // cache itself, and saves into `ptr`. This shared_ptr will hold the
113
113
  // entry in cache until all refs are destroyed.
114
- static Status GetShared(Cache *cache, SystemClock *clock,
114
+ static Status GetShared(Cache *raw_cache, SystemClock *clock,
115
115
  std::shared_ptr<CacheEntryStatsCollector> *ptr) {
116
- const Slice &cache_key = GetCacheKey();
116
+ assert(raw_cache);
117
+ BasicTypedCacheInterface<CacheEntryStatsCollector, CacheEntryRole::kMisc>
118
+ cache{raw_cache};
117
119
 
118
- Cache::Handle *h = cache->Lookup(cache_key);
120
+ const Slice &cache_key = GetCacheKey();
121
+ auto h = cache.Lookup(cache_key);
119
122
  if (h == nullptr) {
120
123
  // Not yet in cache, but Cache doesn't provide a built-in way to
121
124
  // avoid racing insert. So we double-check under a shared mutex,
@@ -123,15 +126,15 @@ class CacheEntryStatsCollector {
123
126
  STATIC_AVOID_DESTRUCTION(std::mutex, static_mutex);
124
127
  std::lock_guard<std::mutex> lock(static_mutex);
125
128
 
126
- h = cache->Lookup(cache_key);
129
+ h = cache.Lookup(cache_key);
127
130
  if (h == nullptr) {
128
- auto new_ptr = new CacheEntryStatsCollector(cache, clock);
131
+ auto new_ptr = new CacheEntryStatsCollector(cache.get(), clock);
129
132
  // TODO: non-zero charge causes some tests that count block cache
130
133
  // usage to go flaky. Fix the problem somehow so we can use an
131
134
  // accurate charge.
132
135
  size_t charge = 0;
133
- Status s = cache->Insert(cache_key, new_ptr, charge, Deleter, &h,
134
- Cache::Priority::HIGH);
136
+ Status s =
137
+ cache.Insert(cache_key, new_ptr, charge, &h, Cache::Priority::HIGH);
135
138
  if (!s.ok()) {
136
139
  assert(h == nullptr);
137
140
  delete new_ptr;
@@ -140,11 +143,11 @@ class CacheEntryStatsCollector {
140
143
  }
141
144
  }
142
145
  // If we reach here, shared entry is in cache with handle `h`.
143
- assert(cache->GetDeleter(h) == Deleter);
146
+ assert(cache.get()->GetCacheItemHelper(h) == &cache.kBasicHelper);
144
147
 
145
148
  // Build an aliasing shared_ptr that keeps `ptr` in cache while there
146
149
  // are references.
147
- *ptr = MakeSharedCacheHandleGuard<CacheEntryStatsCollector>(cache, h);
150
+ *ptr = cache.SharedGuard(h);
148
151
  return Status::OK();
149
152
  }
150
153
 
@@ -157,10 +160,6 @@ class CacheEntryStatsCollector {
157
160
  cache_(cache),
158
161
  clock_(clock) {}
159
162
 
160
- static void Deleter(const Slice &, void *value) {
161
- delete static_cast<CacheEntryStatsCollector *>(value);
162
- }
163
-
164
163
  static const Slice &GetCacheKey() {
165
164
  // For each template instantiation
166
165
  static CacheKey ckey = CacheKey::CreateUniqueForProcessLifetime();
@@ -0,0 +1,40 @@
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 "cache/cache_helpers.h"
7
+
8
+ namespace ROCKSDB_NAMESPACE {
9
+
10
+ void ReleaseCacheHandleCleanup(void* arg1, void* arg2) {
11
+ Cache* const cache = static_cast<Cache*>(arg1);
12
+ assert(cache);
13
+
14
+ Cache::Handle* const cache_handle = static_cast<Cache::Handle*>(arg2);
15
+ assert(cache_handle);
16
+
17
+ cache->Release(cache_handle);
18
+ }
19
+
20
+ Status WarmInCache(Cache* cache, const Slice& key, const Slice& saved,
21
+ Cache::CreateContext* create_context,
22
+ const Cache::CacheItemHelper* helper,
23
+ Cache::Priority priority, size_t* out_charge) {
24
+ assert(helper);
25
+ assert(helper->create_cb);
26
+ Cache::ObjectPtr value;
27
+ size_t charge;
28
+ Status st = helper->create_cb(saved, create_context,
29
+ cache->memory_allocator(), &value, &charge);
30
+ if (st.ok()) {
31
+ st =
32
+ cache->Insert(key, value, helper, charge, /*handle*/ nullptr, priority);
33
+ if (out_charge) {
34
+ *out_charge = charge;
35
+ }
36
+ }
37
+ return st;
38
+ }
39
+
40
+ } // namespace ROCKSDB_NAMESPACE
@@ -17,22 +17,17 @@ template <typename T>
17
17
  T* GetFromCacheHandle(Cache* cache, Cache::Handle* handle) {
18
18
  assert(cache);
19
19
  assert(handle);
20
-
21
20
  return static_cast<T*>(cache->Value(handle));
22
21
  }
23
22
 
24
- // Simple generic deleter for Cache (to be used with Cache::Insert).
25
- template <typename T>
26
- void DeleteCacheEntry(const Slice& /* key */, void* value) {
27
- delete static_cast<T*>(value);
28
- }
29
-
30
23
  // Turns a T* into a Slice so it can be used as a key with Cache.
31
24
  template <typename T>
32
- Slice GetSlice(const T* t) {
25
+ Slice GetSliceForKey(const T* t) {
33
26
  return Slice(reinterpret_cast<const char*>(t), sizeof(T));
34
27
  }
35
28
 
29
+ void ReleaseCacheHandleCleanup(void* arg1, void* arg2);
30
+
36
31
  // Generic resource management object for cache handles that releases the handle
37
32
  // when destroyed. Has unique ownership of the handle, so copying it is not
38
33
  // allowed, while moving it transfers ownership.
@@ -88,7 +83,7 @@ class CacheHandleGuard {
88
83
  if (cleanable) {
89
84
  if (handle_ != nullptr) {
90
85
  assert(cache_);
91
- cleanable->RegisterCleanup(&ReleaseCacheHandle, cache_, handle_);
86
+ cleanable->RegisterCleanup(&ReleaseCacheHandleCleanup, cache_, handle_);
92
87
  }
93
88
  }
94
89
  ResetFields();
@@ -115,16 +110,6 @@ class CacheHandleGuard {
115
110
  value_ = nullptr;
116
111
  }
117
112
 
118
- static void ReleaseCacheHandle(void* arg1, void* arg2) {
119
- Cache* const cache = static_cast<Cache*>(arg1);
120
- assert(cache);
121
-
122
- Cache::Handle* const cache_handle = static_cast<Cache::Handle*>(arg2);
123
- assert(cache_handle);
124
-
125
- cache->Release(cache_handle);
126
- }
127
-
128
113
  private:
129
114
  Cache* cache_ = nullptr;
130
115
  Cache::Handle* handle_ = nullptr;
@@ -139,7 +124,16 @@ template <typename T>
139
124
  std::shared_ptr<T> MakeSharedCacheHandleGuard(Cache* cache,
140
125
  Cache::Handle* handle) {
141
126
  auto wrapper = std::make_shared<CacheHandleGuard<T>>(cache, handle);
142
- return std::shared_ptr<T>(wrapper, static_cast<T*>(cache->Value(handle)));
127
+ return std::shared_ptr<T>(wrapper, GetFromCacheHandle<T>(cache, handle));
143
128
  }
144
129
 
130
+ // Given the persistable data (saved) for a block cache entry, parse that
131
+ // into a cache entry object and insert it into the given cache. The charge
132
+ // of the new entry can be returned to the caller through `out_charge`.
133
+ Status WarmInCache(Cache* cache, const Slice& key, const Slice& saved,
134
+ Cache::CreateContext* create_context,
135
+ const Cache::CacheItemHelper* helper,
136
+ Cache::Priority priority = Cache::Priority::LOW,
137
+ size_t* out_charge = nullptr);
138
+
145
139
  } // namespace ROCKSDB_NAMESPACE
@@ -13,7 +13,6 @@
13
13
  #include <cstring>
14
14
  #include <memory>
15
15
 
16
- #include "cache/cache_entry_roles.h"
17
16
  #include "rocksdb/cache.h"
18
17
  #include "rocksdb/slice.h"
19
18
  #include "rocksdb/status.h"
@@ -41,17 +40,17 @@ CacheReservationManagerImpl<
41
40
  template <CacheEntryRole R>
42
41
  CacheReservationManagerImpl<R>::CacheReservationManagerImpl(
43
42
  std::shared_ptr<Cache> cache, bool delayed_decrease)
44
- : delayed_decrease_(delayed_decrease),
43
+ : cache_(cache),
44
+ delayed_decrease_(delayed_decrease),
45
45
  cache_allocated_size_(0),
46
46
  memory_used_(0) {
47
47
  assert(cache != nullptr);
48
- cache_ = cache;
49
48
  }
50
49
 
51
50
  template <CacheEntryRole R>
52
51
  CacheReservationManagerImpl<R>::~CacheReservationManagerImpl() {
53
52
  for (auto* handle : dummy_handles_) {
54
- cache_->Release(handle, true);
53
+ cache_.ReleaseAndEraseIfLastRef(handle);
55
54
  }
56
55
  }
57
56
 
@@ -115,8 +114,7 @@ Status CacheReservationManagerImpl<R>::IncreaseCacheReservation(
115
114
  Status return_status = Status::OK();
116
115
  while (new_mem_used > cache_allocated_size_.load(std::memory_order_relaxed)) {
117
116
  Cache::Handle* handle = nullptr;
118
- return_status = cache_->Insert(GetNextCacheKey(), nullptr, kSizeDummyEntry,
119
- GetNoopDeleterForRole<R>(), &handle);
117
+ return_status = cache_.Insert(GetNextCacheKey(), kSizeDummyEntry, &handle);
120
118
 
121
119
  if (return_status != Status::OK()) {
122
120
  return return_status;
@@ -141,7 +139,7 @@ Status CacheReservationManagerImpl<R>::DecreaseCacheReservation(
141
139
  cache_allocated_size_.load(std::memory_order_relaxed)) {
142
140
  assert(!dummy_handles_.empty());
143
141
  auto* handle = dummy_handles_.back();
144
- cache_->Release(handle, true);
142
+ cache_.ReleaseAndEraseIfLastRef(handle);
145
143
  dummy_handles_.pop_back();
146
144
  cache_allocated_size_ -= kSizeDummyEntry;
147
145
  }
@@ -169,8 +167,9 @@ Slice CacheReservationManagerImpl<R>::GetNextCacheKey() {
169
167
  }
170
168
 
171
169
  template <CacheEntryRole R>
172
- Cache::DeleterFn CacheReservationManagerImpl<R>::TEST_GetNoopDeleterForRole() {
173
- return GetNoopDeleterForRole<R>();
170
+ const Cache::CacheItemHelper*
171
+ CacheReservationManagerImpl<R>::TEST_GetCacheItemHelperForRole() {
172
+ return &CacheInterface::kHelper;
174
173
  }
175
174
 
176
175
  template class CacheReservationManagerImpl<
@@ -18,7 +18,7 @@
18
18
 
19
19
  #include "cache/cache_entry_roles.h"
20
20
  #include "cache/cache_key.h"
21
- #include "rocksdb/cache.h"
21
+ #include "cache/typed_cache.h"
22
22
  #include "rocksdb/slice.h"
23
23
  #include "rocksdb/status.h"
24
24
  #include "util/coding.h"
@@ -197,10 +197,10 @@ class CacheReservationManagerImpl
197
197
 
198
198
  static constexpr std::size_t GetDummyEntrySize() { return kSizeDummyEntry; }
199
199
 
200
- // For testing only - it is to help ensure the NoopDeleterForRole<R>
200
+ // For testing only - it is to help ensure the CacheItemHelperForRole<R>
201
201
  // accessed from CacheReservationManagerImpl and the one accessed from the
202
202
  // test are from the same translation units
203
- static Cache::DeleterFn TEST_GetNoopDeleterForRole();
203
+ static const Cache::CacheItemHelper *TEST_GetCacheItemHelperForRole();
204
204
 
205
205
  private:
206
206
  static constexpr std::size_t kSizeDummyEntry = 256 * 1024;
@@ -211,7 +211,8 @@ class CacheReservationManagerImpl
211
211
  Status IncreaseCacheReservation(std::size_t new_mem_used);
212
212
  Status DecreaseCacheReservation(std::size_t new_mem_used);
213
213
 
214
- std::shared_ptr<Cache> cache_;
214
+ using CacheInterface = PlaceholderSharedCacheInterface<R>;
215
+ CacheInterface cache_;
215
216
  bool delayed_decrease_;
216
217
  std::atomic<std::size_t> cache_allocated_size_;
217
218
  std::size_t memory_used_;