@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
@@ -10,6 +10,7 @@
10
10
 
11
11
  #include "cache/cache_key.h"
12
12
  #include "cache/clock_cache.h"
13
+ #include "cache_helpers.h"
13
14
  #include "db/db_test_util.h"
14
15
  #include "file/sst_file_manager_impl.h"
15
16
  #include "port/port.h"
@@ -19,6 +20,7 @@
19
20
  #include "rocksdb/sst_file_manager.h"
20
21
  #include "rocksdb/utilities/cache_dump_load.h"
21
22
  #include "test_util/testharness.h"
23
+ #include "typed_cache.h"
22
24
  #include "util/coding.h"
23
25
  #include "util/random.h"
24
26
  #include "utilities/cache_dump_load_impl.h"
@@ -49,14 +51,15 @@ class LRUCacheTest : public testing::Test {
49
51
  high_pri_pool_ratio, low_pri_pool_ratio,
50
52
  use_adaptive_mutex, kDontChargeCacheMetadata,
51
53
  /*max_upper_hash_bits=*/24,
54
+ /*allocator*/ nullptr,
52
55
  /*secondary_cache=*/nullptr);
53
56
  }
54
57
 
55
58
  void Insert(const std::string& key,
56
59
  Cache::Priority priority = Cache::Priority::LOW) {
57
- EXPECT_OK(cache_->Insert(key, 0 /*hash*/, nullptr /*value*/, 1 /*charge*/,
58
- nullptr /*deleter*/, nullptr /*handle*/,
59
- priority));
60
+ EXPECT_OK(cache_->Insert(key, 0 /*hash*/, nullptr /*value*/,
61
+ &kNoopCacheItemHelper, 1 /*charge*/,
62
+ nullptr /*handle*/, priority));
60
63
  }
61
64
 
62
65
  void Insert(char key, Cache::Priority priority = Cache::Priority::LOW) {
@@ -64,7 +67,8 @@ class LRUCacheTest : public testing::Test {
64
67
  }
65
68
 
66
69
  bool Lookup(const std::string& key) {
67
- auto handle = cache_->Lookup(key, 0 /*hash*/);
70
+ auto handle = cache_->Lookup(key, 0 /*hash*/, nullptr, nullptr,
71
+ Cache::Priority::LOW, true, nullptr);
68
72
  if (handle) {
69
73
  cache_->Release(handle, true /*useful*/, false /*erase*/);
70
74
  return true;
@@ -389,15 +393,15 @@ class ClockCacheTest : public testing::Test {
389
393
 
390
394
  Table::Opts opts;
391
395
  opts.estimated_value_size = 1;
392
- new (shard_)
393
- Shard(capacity, strict_capacity_limit, kDontChargeCacheMetadata, opts);
396
+ new (shard_) Shard(capacity, strict_capacity_limit,
397
+ kDontChargeCacheMetadata, /*allocator*/ nullptr, opts);
394
398
  }
395
399
 
396
400
  Status Insert(const UniqueId64x2& hashed_key,
397
401
  Cache::Priority priority = Cache::Priority::LOW) {
398
402
  return shard_->Insert(TestKey(hashed_key), hashed_key, nullptr /*value*/,
399
- 1 /*charge*/, nullptr /*deleter*/, nullptr /*handle*/,
400
- priority);
403
+ &kNoopCacheItemHelper, 1 /*charge*/,
404
+ nullptr /*handle*/, priority);
401
405
  }
402
406
 
403
407
  Status Insert(char key, Cache::Priority priority = Cache::Priority::LOW) {
@@ -407,8 +411,8 @@ class ClockCacheTest : public testing::Test {
407
411
  Status InsertWithLen(char key, size_t len) {
408
412
  std::string skey(len, key);
409
413
  return shard_->Insert(skey, TestHashedKey(key), nullptr /*value*/,
410
- 1 /*charge*/, nullptr /*deleter*/, nullptr /*handle*/,
411
- Cache::Priority::LOW);
414
+ &kNoopCacheItemHelper, 1 /*charge*/,
415
+ nullptr /*handle*/, Cache::Priority::LOW);
412
416
  }
413
417
 
414
418
  bool Lookup(const Slice& key, const UniqueId64x2& hashed_key,
@@ -482,7 +486,7 @@ TEST_F(ClockCacheTest, Limits) {
482
486
  // Single entry charge beyond capacity
483
487
  {
484
488
  Status s = shard_->Insert(TestKey(hkey), hkey, nullptr /*value*/,
485
- 5 /*charge*/, nullptr /*deleter*/,
489
+ &kNoopCacheItemHelper, 5 /*charge*/,
486
490
  nullptr /*handle*/, Cache::Priority::LOW);
487
491
  if (strict_capacity_limit) {
488
492
  EXPECT_TRUE(s.IsMemoryLimit());
@@ -495,7 +499,7 @@ TEST_F(ClockCacheTest, Limits) {
495
499
  {
496
500
  HandleImpl* h;
497
501
  ASSERT_OK(shard_->Insert(TestKey(hkey), hkey, nullptr /*value*/,
498
- 3 /*charge*/, nullptr /*deleter*/, &h,
502
+ &kNoopCacheItemHelper, 3 /*charge*/, &h,
499
503
  Cache::Priority::LOW));
500
504
  // Try to insert more
501
505
  Status s = Insert('a');
@@ -519,8 +523,9 @@ TEST_F(ClockCacheTest, Limits) {
519
523
  for (size_t i = 0; i < n && s.ok(); ++i) {
520
524
  hkey[1] = i;
521
525
  s = shard_->Insert(TestKey(hkey), hkey, nullptr /*value*/,
522
- (i + kCapacity < n) ? 0 : 1 /*charge*/,
523
- nullptr /*deleter*/, &ha[i], Cache::Priority::LOW);
526
+ &kNoopCacheItemHelper,
527
+ (i + kCapacity < n) ? 0 : 1 /*charge*/, &ha[i],
528
+ Cache::Priority::LOW);
524
529
  if (i == 0) {
525
530
  EXPECT_OK(s);
526
531
  }
@@ -658,18 +663,25 @@ TEST_F(ClockCacheTest, ClockEvictionTest) {
658
663
  }
659
664
  }
660
665
 
661
- void IncrementIntDeleter(const Slice& /*key*/, void* value) {
662
- *reinterpret_cast<int*>(value) += 1;
663
- }
666
+ namespace {
667
+ struct DeleteCounter {
668
+ int deleted = 0;
669
+ };
670
+ const Cache::CacheItemHelper kDeleteCounterHelper{
671
+ CacheEntryRole::kMisc,
672
+ [](Cache::ObjectPtr value, MemoryAllocator* /*alloc*/) {
673
+ static_cast<DeleteCounter*>(value)->deleted += 1;
674
+ }};
675
+ } // namespace
664
676
 
665
677
  // Testing calls to CorrectNearOverflow in Release
666
678
  TEST_F(ClockCacheTest, ClockCounterOverflowTest) {
667
679
  NewShard(6, /*strict_capacity_limit*/ false);
668
680
  HandleImpl* h;
669
- int deleted = 0;
681
+ DeleteCounter val;
670
682
  UniqueId64x2 hkey = TestHashedKey('x');
671
- ASSERT_OK(shard_->Insert(TestKey(hkey), hkey, &deleted, 1,
672
- IncrementIntDeleter, &h, Cache::Priority::HIGH));
683
+ ASSERT_OK(shard_->Insert(TestKey(hkey), hkey, &val, &kDeleteCounterHelper, 1,
684
+ &h, Cache::Priority::HIGH));
673
685
 
674
686
  // Some large number outstanding
675
687
  shard_->TEST_RefN(h, 123456789);
@@ -689,18 +701,18 @@ TEST_F(ClockCacheTest, ClockCounterOverflowTest) {
689
701
  // Free all but last 1
690
702
  shard_->TEST_ReleaseN(h, 123456789);
691
703
  // Still alive
692
- ASSERT_EQ(deleted, 0);
704
+ ASSERT_EQ(val.deleted, 0);
693
705
  // Free last ref, which will finalize erasure
694
706
  shard_->Release(h);
695
707
  // Deleted
696
- ASSERT_EQ(deleted, 1);
708
+ ASSERT_EQ(val.deleted, 1);
697
709
  }
698
710
 
699
711
  // This test is mostly to exercise some corner case logic, by forcing two
700
712
  // keys to have the same hash, and more
701
713
  TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
702
714
  NewShard(6, /*strict_capacity_limit*/ false);
703
- int deleted = 0;
715
+ DeleteCounter val;
704
716
  UniqueId64x2 hkey1 = TestHashedKey('x');
705
717
  Slice key1 = TestKey(hkey1);
706
718
  UniqueId64x2 hkey2 = TestHashedKey('y');
@@ -708,13 +720,13 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
708
720
  UniqueId64x2 hkey3 = TestHashedKey('z');
709
721
  Slice key3 = TestKey(hkey3);
710
722
  HandleImpl* h1;
711
- ASSERT_OK(shard_->Insert(key1, hkey1, &deleted, 1, IncrementIntDeleter, &h1,
723
+ ASSERT_OK(shard_->Insert(key1, hkey1, &val, &kDeleteCounterHelper, 1, &h1,
712
724
  Cache::Priority::HIGH));
713
725
  HandleImpl* h2;
714
- ASSERT_OK(shard_->Insert(key2, hkey2, &deleted, 1, IncrementIntDeleter, &h2,
726
+ ASSERT_OK(shard_->Insert(key2, hkey2, &val, &kDeleteCounterHelper, 1, &h2,
715
727
  Cache::Priority::HIGH));
716
728
  HandleImpl* h3;
717
- ASSERT_OK(shard_->Insert(key3, hkey3, &deleted, 1, IncrementIntDeleter, &h3,
729
+ ASSERT_OK(shard_->Insert(key3, hkey3, &val, &kDeleteCounterHelper, 1, &h3,
718
730
  Cache::Priority::HIGH));
719
731
 
720
732
  // Can repeatedly lookup+release despite the hash collision
@@ -739,7 +751,7 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
739
751
  shard_->Erase(key1, hkey1);
740
752
 
741
753
  // All still alive
742
- ASSERT_EQ(deleted, 0);
754
+ ASSERT_EQ(val.deleted, 0);
743
755
 
744
756
  // Invisible to Lookup
745
757
  tmp_h = shard_->Lookup(key1, hkey1);
@@ -757,8 +769,8 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
757
769
  }
758
770
 
759
771
  // Also Insert with invisible entry there
760
- ASSERT_OK(shard_->Insert(key1, hkey1, &deleted, 1, IncrementIntDeleter,
761
- nullptr, Cache::Priority::HIGH));
772
+ ASSERT_OK(shard_->Insert(key1, hkey1, &val, &kDeleteCounterHelper, 1, nullptr,
773
+ Cache::Priority::HIGH));
762
774
  tmp_h = shard_->Lookup(key1, hkey1);
763
775
  // Found but distinct handle
764
776
  ASSERT_NE(nullptr, tmp_h);
@@ -766,13 +778,13 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
766
778
  ASSERT_TRUE(shard_->Release(tmp_h, /*erase_if_last_ref*/ true));
767
779
 
768
780
  // tmp_h deleted
769
- ASSERT_EQ(deleted--, 1);
781
+ ASSERT_EQ(val.deleted--, 1);
770
782
 
771
783
  // Release last ref on h1 (already invisible)
772
784
  ASSERT_TRUE(shard_->Release(h1, /*erase_if_last_ref*/ false));
773
785
 
774
786
  // h1 deleted
775
- ASSERT_EQ(deleted--, 1);
787
+ ASSERT_EQ(val.deleted--, 1);
776
788
  h1 = nullptr;
777
789
 
778
790
  // Can still find h2, h3
@@ -790,7 +802,7 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
790
802
  ASSERT_FALSE(shard_->Release(h2, /*erase_if_last_ref*/ false));
791
803
 
792
804
  // h2 still not deleted (unreferenced in cache)
793
- ASSERT_EQ(deleted, 0);
805
+ ASSERT_EQ(val.deleted, 0);
794
806
 
795
807
  // Can still find it
796
808
  tmp_h = shard_->Lookup(key2, hkey2);
@@ -800,7 +812,7 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
800
812
  ASSERT_TRUE(shard_->Release(h2, /*erase_if_last_ref*/ true));
801
813
 
802
814
  // h2 deleted
803
- ASSERT_EQ(deleted--, 1);
815
+ ASSERT_EQ(val.deleted--, 1);
804
816
  tmp_h = shard_->Lookup(key2, hkey2);
805
817
  ASSERT_EQ(nullptr, tmp_h);
806
818
 
@@ -815,13 +827,13 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
815
827
  ASSERT_FALSE(shard_->Release(h3, /*erase_if_last_ref*/ false));
816
828
 
817
829
  // h3 still not deleted (unreferenced in cache)
818
- ASSERT_EQ(deleted, 0);
830
+ ASSERT_EQ(val.deleted, 0);
819
831
 
820
832
  // Explicit erase
821
833
  shard_->Erase(key3, hkey3);
822
834
 
823
835
  // h3 deleted
824
- ASSERT_EQ(deleted--, 1);
836
+ ASSERT_EQ(val.deleted--, 1);
825
837
  tmp_h = shard_->Lookup(key3, hkey3);
826
838
  ASSERT_EQ(nullptr, tmp_h);
827
839
  }
@@ -884,12 +896,12 @@ class TestSecondaryCache : public SecondaryCache {
884
896
  using ResultMap = std::unordered_map<std::string, ResultType>;
885
897
 
886
898
  explicit TestSecondaryCache(size_t capacity)
887
- : num_inserts_(0), num_lookups_(0), inject_failure_(false) {
888
- cache_ =
889
- NewLRUCache(capacity, 0, false, 0.5 /* high_pri_pool_ratio */, nullptr,
890
- kDefaultToAdaptiveMutex, kDontChargeCacheMetadata);
891
- }
892
- ~TestSecondaryCache() override { cache_.reset(); }
899
+ : cache_(NewLRUCache(capacity, 0, false, 0.5 /* high_pri_pool_ratio */,
900
+ nullptr, kDefaultToAdaptiveMutex,
901
+ kDontChargeCacheMetadata)),
902
+ num_inserts_(0),
903
+ num_lookups_(0),
904
+ inject_failure_(false) {}
893
905
 
894
906
  const char* Name() const override { return "TestSecondaryCache"; }
895
907
 
@@ -897,7 +909,7 @@ class TestSecondaryCache : public SecondaryCache {
897
909
 
898
910
  void ResetInjectFailure() { inject_failure_ = false; }
899
911
 
900
- Status Insert(const Slice& key, void* value,
912
+ Status Insert(const Slice& key, Cache::ObjectPtr value,
901
913
  const Cache::CacheItemHelper* helper) override {
902
914
  if (inject_failure_) {
903
915
  return Status::Corruption("Insertion Data Corrupted");
@@ -916,14 +928,12 @@ class TestSecondaryCache : public SecondaryCache {
916
928
  delete[] buf;
917
929
  return s;
918
930
  }
919
- return cache_->Insert(key, buf, size,
920
- [](const Slice& /*key*/, void* val) -> void {
921
- delete[] static_cast<char*>(val);
922
- });
931
+ return cache_.Insert(key, buf, size);
923
932
  }
924
933
 
925
934
  std::unique_ptr<SecondaryCacheResultHandle> Lookup(
926
- const Slice& key, const Cache::CreateCallback& create_cb, bool /*wait*/,
935
+ const Slice& key, const Cache::CacheItemHelper* helper,
936
+ Cache::CreateContext* create_context, bool /*wait*/,
927
937
  bool /*advise_erase*/, bool& is_in_sec_cache) override {
928
938
  std::string key_str = key.ToString();
929
939
  TEST_SYNC_POINT_CALLBACK("TestSecondaryCache::Lookup", &key_str);
@@ -939,24 +949,25 @@ class TestSecondaryCache : public SecondaryCache {
939
949
  return secondary_handle;
940
950
  }
941
951
 
942
- Cache::Handle* handle = cache_->Lookup(key);
952
+ TypedHandle* handle = cache_.Lookup(key);
943
953
  num_lookups_++;
944
954
  if (handle) {
945
- void* value = nullptr;
955
+ Cache::ObjectPtr value = nullptr;
946
956
  size_t charge = 0;
947
957
  Status s;
948
958
  if (type != ResultType::DEFER_AND_FAIL) {
949
- char* ptr = (char*)cache_->Value(handle);
959
+ char* ptr = cache_.Value(handle);
950
960
  size_t size = DecodeFixed64(ptr);
951
961
  ptr += sizeof(uint64_t);
952
- s = create_cb(ptr, size, &value, &charge);
962
+ s = helper->create_cb(Slice(ptr, size), create_context,
963
+ /*alloc*/ nullptr, &value, &charge);
953
964
  }
954
965
  if (s.ok()) {
955
966
  secondary_handle.reset(new TestSecondaryCacheResultHandle(
956
967
  cache_.get(), handle, value, charge, type));
957
968
  is_in_sec_cache = true;
958
969
  } else {
959
- cache_->Release(handle);
970
+ cache_.Release(handle);
960
971
  }
961
972
  }
962
973
  return secondary_handle;
@@ -995,7 +1006,8 @@ class TestSecondaryCache : public SecondaryCache {
995
1006
  class TestSecondaryCacheResultHandle : public SecondaryCacheResultHandle {
996
1007
  public:
997
1008
  TestSecondaryCacheResultHandle(Cache* cache, Cache::Handle* handle,
998
- void* value, size_t size, ResultType type)
1009
+ Cache::ObjectPtr value, size_t size,
1010
+ ResultType type)
999
1011
  : cache_(cache),
1000
1012
  handle_(handle),
1001
1013
  value_(value),
@@ -1012,7 +1024,7 @@ class TestSecondaryCache : public SecondaryCache {
1012
1024
 
1013
1025
  void Wait() override {}
1014
1026
 
1015
- void* Value() override {
1027
+ Cache::ObjectPtr Value() override {
1016
1028
  assert(is_ready_);
1017
1029
  return value_;
1018
1030
  }
@@ -1024,12 +1036,15 @@ class TestSecondaryCache : public SecondaryCache {
1024
1036
  private:
1025
1037
  Cache* cache_;
1026
1038
  Cache::Handle* handle_;
1027
- void* value_;
1039
+ Cache::ObjectPtr value_;
1028
1040
  size_t size_;
1029
1041
  bool is_ready_;
1030
1042
  };
1031
1043
 
1032
- std::shared_ptr<Cache> cache_;
1044
+ using SharedCache =
1045
+ BasicTypedSharedCacheInterface<char[], CacheEntryRole::kMisc>;
1046
+ using TypedHandle = SharedCache::TypedHandle;
1047
+ SharedCache cache_;
1033
1048
  uint32_t num_inserts_;
1034
1049
  uint32_t num_lookups_;
1035
1050
  bool inject_failure_;
@@ -1049,7 +1064,8 @@ class DBSecondaryCacheTest : public DBTestBase {
1049
1064
  std::unique_ptr<Env> fault_env_;
1050
1065
  };
1051
1066
 
1052
- class LRUCacheSecondaryCacheTest : public LRUCacheTest {
1067
+ class LRUCacheSecondaryCacheTest : public LRUCacheTest,
1068
+ public Cache::CreateContext {
1053
1069
  public:
1054
1070
  LRUCacheSecondaryCacheTest() : fail_create_(false) {}
1055
1071
  ~LRUCacheSecondaryCacheTest() {}
@@ -1071,13 +1087,13 @@ class LRUCacheSecondaryCacheTest : public LRUCacheTest {
1071
1087
  size_t size_;
1072
1088
  };
1073
1089
 
1074
- static size_t SizeCallback(void* obj) {
1075
- return reinterpret_cast<TestItem*>(obj)->Size();
1090
+ static size_t SizeCallback(Cache::ObjectPtr obj) {
1091
+ return static_cast<TestItem*>(obj)->Size();
1076
1092
  }
1077
1093
 
1078
- static Status SaveToCallback(void* from_obj, size_t from_offset,
1079
- size_t length, void* out) {
1080
- TestItem* item = reinterpret_cast<TestItem*>(from_obj);
1094
+ static Status SaveToCallback(Cache::ObjectPtr from_obj, size_t from_offset,
1095
+ size_t length, char* out) {
1096
+ TestItem* item = static_cast<TestItem*>(from_obj);
1081
1097
  char* buf = item->Buf();
1082
1098
  EXPECT_EQ(length, item->Size());
1083
1099
  EXPECT_EQ(from_offset, 0);
@@ -1085,27 +1101,30 @@ class LRUCacheSecondaryCacheTest : public LRUCacheTest {
1085
1101
  return Status::OK();
1086
1102
  }
1087
1103
 
1088
- static void DeletionCallback(const Slice& /*key*/, void* obj) {
1089
- delete reinterpret_cast<TestItem*>(obj);
1104
+ static void DeletionCallback(Cache::ObjectPtr obj,
1105
+ MemoryAllocator* /*alloc*/) {
1106
+ delete static_cast<TestItem*>(obj);
1090
1107
  }
1091
1108
 
1092
1109
  static Cache::CacheItemHelper helper_;
1093
1110
 
1094
- static Status SaveToCallbackFail(void* /*obj*/, size_t /*offset*/,
1095
- size_t /*size*/, void* /*out*/) {
1111
+ static Status SaveToCallbackFail(Cache::ObjectPtr /*from_obj*/,
1112
+ size_t /*from_offset*/, size_t /*length*/,
1113
+ char* /*out*/) {
1096
1114
  return Status::NotSupported();
1097
1115
  }
1098
1116
 
1099
1117
  static Cache::CacheItemHelper helper_fail_;
1100
1118
 
1101
- Cache::CreateCallback test_item_creator = [&](const void* buf, size_t size,
1102
- void** out_obj,
1103
- size_t* charge) -> Status {
1104
- if (fail_create_) {
1119
+ static Status CreateCallback(const Slice& data, Cache::CreateContext* context,
1120
+ MemoryAllocator* /*allocator*/,
1121
+ Cache::ObjectPtr* out_obj, size_t* out_charge) {
1122
+ auto t = static_cast<LRUCacheSecondaryCacheTest*>(context);
1123
+ if (t->fail_create_) {
1105
1124
  return Status::NotSupported();
1106
1125
  }
1107
- *out_obj = reinterpret_cast<void*>(new TestItem((char*)buf, size));
1108
- *charge = size;
1126
+ *out_obj = new TestItem(data.data(), data.size());
1127
+ *out_charge = data.size();
1109
1128
  return Status::OK();
1110
1129
  };
1111
1130
 
@@ -1115,15 +1134,17 @@ class LRUCacheSecondaryCacheTest : public LRUCacheTest {
1115
1134
  bool fail_create_;
1116
1135
  };
1117
1136
 
1118
- Cache::CacheItemHelper LRUCacheSecondaryCacheTest::helper_(
1137
+ Cache::CacheItemHelper LRUCacheSecondaryCacheTest::helper_{
1138
+ CacheEntryRole::kMisc, LRUCacheSecondaryCacheTest::DeletionCallback,
1119
1139
  LRUCacheSecondaryCacheTest::SizeCallback,
1120
1140
  LRUCacheSecondaryCacheTest::SaveToCallback,
1121
- LRUCacheSecondaryCacheTest::DeletionCallback);
1141
+ LRUCacheSecondaryCacheTest::CreateCallback};
1122
1142
 
1123
- Cache::CacheItemHelper LRUCacheSecondaryCacheTest::helper_fail_(
1143
+ Cache::CacheItemHelper LRUCacheSecondaryCacheTest::helper_fail_{
1144
+ CacheEntryRole::kMisc, LRUCacheSecondaryCacheTest::DeletionCallback,
1124
1145
  LRUCacheSecondaryCacheTest::SizeCallback,
1125
1146
  LRUCacheSecondaryCacheTest::SaveToCallbackFail,
1126
- LRUCacheSecondaryCacheTest::DeletionCallback);
1147
+ LRUCacheSecondaryCacheTest::CreateCallback};
1127
1148
 
1128
1149
  TEST_F(LRUCacheSecondaryCacheTest, BasicTest) {
1129
1150
  LRUCacheOptions opts(1024 /* capacity */, 0 /* num_shard_bits */,
@@ -1159,7 +1180,7 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicTest) {
1159
1180
  Cache::Handle* handle;
1160
1181
  handle =
1161
1182
  cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1162
- test_item_creator, Cache::Priority::LOW, true, stats.get());
1183
+ /*context*/ this, Cache::Priority::LOW, true, stats.get());
1163
1184
  ASSERT_NE(handle, nullptr);
1164
1185
  ASSERT_EQ(static_cast<TestItem*>(cache->Value(handle))->Size(), str2.size());
1165
1186
  cache->Release(handle);
@@ -1167,7 +1188,7 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicTest) {
1167
1188
  // This lookup should promote k1 and demote k2
1168
1189
  handle =
1169
1190
  cache->Lookup(k1.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1170
- test_item_creator, Cache::Priority::LOW, true, stats.get());
1191
+ /*context*/ this, Cache::Priority::LOW, true, stats.get());
1171
1192
  ASSERT_NE(handle, nullptr);
1172
1193
  ASSERT_EQ(static_cast<TestItem*>(cache->Value(handle))->Size(), str1.size());
1173
1194
  cache->Release(handle);
@@ -1175,7 +1196,7 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicTest) {
1175
1196
  // This lookup should promote k3 and demote k1
1176
1197
  handle =
1177
1198
  cache->Lookup(k3.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1178
- test_item_creator, Cache::Priority::LOW, true, stats.get());
1199
+ /*context*/ this, Cache::Priority::LOW, true, stats.get());
1179
1200
  ASSERT_NE(handle, nullptr);
1180
1201
  ASSERT_EQ(static_cast<TestItem*>(cache->Value(handle))->Size(), str3.size());
1181
1202
  cache->Release(handle);
@@ -1207,18 +1228,19 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicFailTest) {
1207
1228
  Random rnd(301);
1208
1229
  std::string str1 = rnd.RandomString(1020);
1209
1230
  auto item1 = std::make_unique<TestItem>(str1.data(), str1.length());
1210
- ASSERT_TRUE(cache->Insert(k1.AsSlice(), item1.get(), nullptr, str1.length())
1211
- .IsInvalidArgument());
1231
+ // NOTE: changed to assert helper != nullptr for efficiency / code size
1232
+ // ASSERT_TRUE(cache->Insert(k1.AsSlice(), item1.get(), nullptr,
1233
+ // str1.length()).IsInvalidArgument());
1212
1234
  ASSERT_OK(cache->Insert(k1.AsSlice(), item1.get(),
1213
1235
  &LRUCacheSecondaryCacheTest::helper_, str1.length()));
1214
1236
  item1.release(); // Appease clang-analyze "potential memory leak"
1215
1237
 
1216
1238
  Cache::Handle* handle;
1217
- handle = cache->Lookup(k2.AsSlice(), nullptr, test_item_creator,
1239
+ handle = cache->Lookup(k2.AsSlice(), nullptr, /*context*/ this,
1218
1240
  Cache::Priority::LOW, true);
1219
1241
  ASSERT_EQ(handle, nullptr);
1220
1242
  handle = cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1221
- test_item_creator, Cache::Priority::LOW, false);
1243
+ /*context*/ this, Cache::Priority::LOW, false);
1222
1244
  ASSERT_EQ(handle, nullptr);
1223
1245
 
1224
1246
  cache.reset();
@@ -1256,18 +1278,18 @@ TEST_F(LRUCacheSecondaryCacheTest, SaveFailTest) {
1256
1278
  Cache::Handle* handle;
1257
1279
  handle =
1258
1280
  cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_fail_,
1259
- test_item_creator, Cache::Priority::LOW, true);
1281
+ /*context*/ this, Cache::Priority::LOW, true);
1260
1282
  ASSERT_NE(handle, nullptr);
1261
1283
  cache->Release(handle);
1262
1284
  // This lookup should fail, since k1 demotion would have failed
1263
1285
  handle =
1264
1286
  cache->Lookup(k1.AsSlice(), &LRUCacheSecondaryCacheTest::helper_fail_,
1265
- test_item_creator, Cache::Priority::LOW, true);
1287
+ /*context*/ this, Cache::Priority::LOW, true);
1266
1288
  ASSERT_EQ(handle, nullptr);
1267
1289
  // Since k1 didn't get promoted, k2 should still be in cache
1268
1290
  handle =
1269
1291
  cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_fail_,
1270
- test_item_creator, Cache::Priority::LOW, true);
1292
+ /*context*/ this, Cache::Priority::LOW, true);
1271
1293
  ASSERT_NE(handle, nullptr);
1272
1294
  cache->Release(handle);
1273
1295
  ASSERT_EQ(secondary_cache->num_inserts(), 1u);
@@ -1304,16 +1326,16 @@ TEST_F(LRUCacheSecondaryCacheTest, CreateFailTest) {
1304
1326
  Cache::Handle* handle;
1305
1327
  SetFailCreate(true);
1306
1328
  handle = cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1307
- test_item_creator, Cache::Priority::LOW, true);
1329
+ /*context*/ this, Cache::Priority::LOW, true);
1308
1330
  ASSERT_NE(handle, nullptr);
1309
1331
  cache->Release(handle);
1310
1332
  // This lookup should fail, since k1 creation would have failed
1311
1333
  handle = cache->Lookup(k1.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1312
- test_item_creator, Cache::Priority::LOW, true);
1334
+ /*context*/ this, Cache::Priority::LOW, true);
1313
1335
  ASSERT_EQ(handle, nullptr);
1314
1336
  // Since k1 didn't get promoted, k2 should still be in cache
1315
1337
  handle = cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1316
- test_item_creator, Cache::Priority::LOW, true);
1338
+ /*context*/ this, Cache::Priority::LOW, true);
1317
1339
  ASSERT_NE(handle, nullptr);
1318
1340
  cache->Release(handle);
1319
1341
  ASSERT_EQ(secondary_cache->num_inserts(), 1u);
@@ -1349,19 +1371,19 @@ TEST_F(LRUCacheSecondaryCacheTest, FullCapacityTest) {
1349
1371
 
1350
1372
  Cache::Handle* handle;
1351
1373
  handle = cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1352
- test_item_creator, Cache::Priority::LOW, true);
1374
+ /*context*/ this, Cache::Priority::LOW, true);
1353
1375
  ASSERT_NE(handle, nullptr);
1354
1376
  // k1 promotion should fail due to the block cache being at capacity,
1355
1377
  // but the lookup should still succeed
1356
1378
  Cache::Handle* handle2;
1357
1379
  handle2 = cache->Lookup(k1.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1358
- test_item_creator, Cache::Priority::LOW, true);
1380
+ /*context*/ this, Cache::Priority::LOW, true);
1359
1381
  ASSERT_NE(handle2, nullptr);
1360
1382
  // Since k1 didn't get inserted, k2 should still be in cache
1361
1383
  cache->Release(handle);
1362
1384
  cache->Release(handle2);
1363
1385
  handle = cache->Lookup(k2.AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1364
- test_item_creator, Cache::Priority::LOW, true);
1386
+ /*context*/ this, Cache::Priority::LOW, true);
1365
1387
  ASSERT_NE(handle, nullptr);
1366
1388
  cache->Release(handle);
1367
1389
  ASSERT_EQ(secondary_cache->num_inserts(), 1u);
@@ -1838,7 +1860,7 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicWaitAllTest) {
1838
1860
  for (int i = 0; i < 6; ++i) {
1839
1861
  results.emplace_back(cache->Lookup(
1840
1862
  ock.WithOffset(i).AsSlice(), &LRUCacheSecondaryCacheTest::helper_,
1841
- test_item_creator, Cache::Priority::LOW, false));
1863
+ /*context*/ this, Cache::Priority::LOW, false));
1842
1864
  }
1843
1865
  cache->WaitAll(results);
1844
1866
  for (int i = 0; i < 6; ++i) {
@@ -1964,26 +1986,18 @@ class LRUCacheWithStat : public LRUCache {
1964
1986
  }
1965
1987
  ~LRUCacheWithStat() {}
1966
1988
 
1967
- Status Insert(const Slice& key, void* value, size_t charge, DeleterFn deleter,
1968
- Handle** handle, Priority priority) override {
1969
- insert_count_++;
1970
- return LRUCache::Insert(key, value, charge, deleter, handle, priority);
1971
- }
1972
- Status Insert(const Slice& key, void* value, const CacheItemHelper* helper,
1973
- size_t charge, Handle** handle = nullptr,
1989
+ Status Insert(const Slice& key, Cache::ObjectPtr value,
1990
+ const CacheItemHelper* helper, size_t charge,
1991
+ Handle** handle = nullptr,
1974
1992
  Priority priority = Priority::LOW) override {
1975
1993
  insert_count_++;
1976
1994
  return LRUCache::Insert(key, value, helper, charge, handle, priority);
1977
1995
  }
1978
- Handle* Lookup(const Slice& key, Statistics* stats) override {
1979
- lookup_count_++;
1980
- return LRUCache::Lookup(key, stats);
1981
- }
1982
1996
  Handle* Lookup(const Slice& key, const CacheItemHelper* helper,
1983
- const CreateCallback& create_cb, Priority priority, bool wait,
1997
+ CreateContext* create_context, Priority priority, bool wait,
1984
1998
  Statistics* stats = nullptr) override {
1985
1999
  lookup_count_++;
1986
- return LRUCache::Lookup(key, helper, create_cb, priority, wait, stats);
2000
+ return LRUCache::Lookup(key, helper, create_context, priority, wait, stats);
1987
2001
  }
1988
2002
 
1989
2003
  uint32_t GetInsertCount() { return insert_count_; }
@@ -11,20 +11,29 @@ namespace ROCKSDB_NAMESPACE {
11
11
 
12
12
  namespace {
13
13
 
14
- size_t SliceSize(void* obj) { return static_cast<Slice*>(obj)->size(); }
14
+ void NoopDelete(Cache::ObjectPtr, MemoryAllocator*) {}
15
15
 
16
- Status SliceSaveTo(void* from_obj, size_t from_offset, size_t length,
17
- void* out) {
16
+ size_t SliceSize(Cache::ObjectPtr obj) {
17
+ return static_cast<Slice*>(obj)->size();
18
+ }
19
+
20
+ Status SliceSaveTo(Cache::ObjectPtr from_obj, size_t from_offset, size_t length,
21
+ char* out) {
18
22
  const Slice& slice = *static_cast<Slice*>(from_obj);
19
23
  std::memcpy(out, slice.data() + from_offset, length);
20
24
  return Status::OK();
21
25
  }
22
26
 
27
+ Status FailCreate(const Slice&, Cache::CreateContext*, MemoryAllocator*,
28
+ Cache::ObjectPtr*, size_t*) {
29
+ return Status::NotSupported("Only for dumping data into SecondaryCache");
30
+ }
31
+
23
32
  } // namespace
24
33
 
25
34
  Status SecondaryCache::InsertSaved(const Slice& key, const Slice& saved) {
26
- static Cache::CacheItemHelper helper{
27
- &SliceSize, &SliceSaveTo, GetNoopDeleterForRole<CacheEntryRole::kMisc>()};
35
+ static Cache::CacheItemHelper helper{CacheEntryRole::kMisc, &NoopDelete,
36
+ &SliceSize, &SliceSaveTo, &FailCreate};
28
37
  // NOTE: depends on Insert() being synchronous, not keeping pointer `&saved`
29
38
  return Insert(key, const_cast<Slice*>(&saved), &helper);
30
39
  }