@nxtedition/rocksdb 7.1.4 → 7.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 (151) hide show
  1. package/deps/rocksdb/iostats.patch +19 -0
  2. package/deps/rocksdb/rocksdb/CMakeLists.txt +15 -1
  3. package/deps/rocksdb/rocksdb/cache/cache_test.cc +93 -58
  4. package/deps/rocksdb/rocksdb/cache/clock_cache.cc +88 -40
  5. package/deps/rocksdb/rocksdb/cache/clock_cache.h +57 -32
  6. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.cc +103 -28
  7. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.h +33 -1
  8. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache_test.cc +177 -38
  9. package/deps/rocksdb/rocksdb/cache/fast_lru_cache.cc +3 -1
  10. package/deps/rocksdb/rocksdb/cache/lru_cache.cc +2 -2
  11. package/deps/rocksdb/rocksdb/cache/lru_cache_test.cc +125 -71
  12. package/deps/rocksdb/rocksdb/crash_test.mk +15 -1
  13. package/deps/rocksdb/rocksdb/db/arena_wrapped_db_iter.cc +2 -2
  14. package/deps/rocksdb/rocksdb/db/blob/blob_index.h +1 -1
  15. package/deps/rocksdb/rocksdb/db/blob/blob_log_format.cc +3 -5
  16. package/deps/rocksdb/rocksdb/db/blob/blob_log_writer.cc +25 -19
  17. package/deps/rocksdb/rocksdb/db/blob/db_blob_basic_test.cc +149 -0
  18. package/deps/rocksdb/rocksdb/db/blob/db_blob_compaction_test.cc +36 -0
  19. package/deps/rocksdb/rocksdb/db/column_family.cc +2 -15
  20. package/deps/rocksdb/rocksdb/db/column_family_test.cc +17 -4
  21. package/deps/rocksdb/rocksdb/db/compact_files_test.cc +8 -8
  22. package/deps/rocksdb/rocksdb/db/compaction/compaction.cc +0 -7
  23. package/deps/rocksdb/rocksdb/db/compaction/compaction.h +5 -0
  24. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +50 -52
  25. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +33 -11
  26. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +41 -10
  27. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +1 -2
  28. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +143 -2
  29. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.cc +43 -18
  30. package/deps/rocksdb/rocksdb/db/compaction/tiered_compaction_test.cc +48 -65
  31. package/deps/rocksdb/rocksdb/db/corruption_test.cc +1 -0
  32. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +73 -4
  33. package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +17 -8
  34. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +71 -2
  35. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +144 -33
  36. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +18 -35
  37. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +11 -5
  38. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_experimental.cc +7 -7
  39. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +15 -8
  40. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.cc +2 -1
  41. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +3 -1
  42. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_write.cc +11 -0
  43. package/deps/rocksdb/rocksdb/db/db_iter.cc +69 -11
  44. package/deps/rocksdb/rocksdb/db/db_iter.h +16 -0
  45. package/deps/rocksdb/rocksdb/db/db_memtable_test.cc +2 -1
  46. package/deps/rocksdb/rocksdb/db/db_merge_operand_test.cc +42 -0
  47. package/deps/rocksdb/rocksdb/db/db_test.cc +61 -28
  48. package/deps/rocksdb/rocksdb/db/db_test2.cc +18 -7
  49. package/deps/rocksdb/rocksdb/db/db_wal_test.cc +17 -0
  50. package/deps/rocksdb/rocksdb/db/db_with_timestamp_compaction_test.cc +61 -0
  51. package/deps/rocksdb/rocksdb/db/db_write_test.cc +130 -0
  52. package/deps/rocksdb/rocksdb/db/experimental.cc +7 -8
  53. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +1 -2
  54. package/deps/rocksdb/rocksdb/db/flush_job.cc +11 -7
  55. package/deps/rocksdb/rocksdb/db/flush_job_test.cc +7 -1
  56. package/deps/rocksdb/rocksdb/db/forward_iterator.cc +4 -2
  57. package/deps/rocksdb/rocksdb/db/import_column_family_job.cc +1 -1
  58. package/deps/rocksdb/rocksdb/db/log_reader.cc +48 -11
  59. package/deps/rocksdb/rocksdb/db/log_reader.h +8 -2
  60. package/deps/rocksdb/rocksdb/db/log_test.cc +10 -1
  61. package/deps/rocksdb/rocksdb/db/log_writer.cc +7 -1
  62. package/deps/rocksdb/rocksdb/db/manual_compaction_test.cc +4 -4
  63. package/deps/rocksdb/rocksdb/db/memtable.cc +49 -14
  64. package/deps/rocksdb/rocksdb/db/memtable.h +60 -14
  65. package/deps/rocksdb/rocksdb/db/memtable_list.cc +14 -8
  66. package/deps/rocksdb/rocksdb/db/memtable_list_test.cc +30 -10
  67. package/deps/rocksdb/rocksdb/db/perf_context_test.cc +5 -5
  68. package/deps/rocksdb/rocksdb/db/pinned_iterators_manager.h +5 -0
  69. package/deps/rocksdb/rocksdb/db/repair.cc +2 -3
  70. package/deps/rocksdb/rocksdb/db/seqno_time_test.cc +3 -7
  71. package/deps/rocksdb/rocksdb/db/table_cache.cc +72 -0
  72. package/deps/rocksdb/rocksdb/db/table_cache.h +19 -1
  73. package/deps/rocksdb/rocksdb/db/table_cache_sync_and_async.h +8 -14
  74. package/deps/rocksdb/rocksdb/db/table_properties_collector_test.cc +2 -2
  75. package/deps/rocksdb/rocksdb/db/version_builder_test.cc +35 -64
  76. package/deps/rocksdb/rocksdb/db/version_edit.cc +3 -32
  77. package/deps/rocksdb/rocksdb/db/version_edit.h +2 -12
  78. package/deps/rocksdb/rocksdb/db/version_edit_test.cc +10 -23
  79. package/deps/rocksdb/rocksdb/db/version_set.cc +34 -10
  80. package/deps/rocksdb/rocksdb/db/version_set.h +3 -3
  81. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +5 -6
  82. package/deps/rocksdb/rocksdb/db/version_set_test.cc +17 -15
  83. package/deps/rocksdb/rocksdb/db/wal_manager.cc +0 -4
  84. package/deps/rocksdb/rocksdb/db/wal_manager_test.cc +2 -1
  85. package/deps/rocksdb/rocksdb/db/wide/db_wide_basic_test.cc +137 -42
  86. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.cc +21 -0
  87. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.h +1 -0
  88. package/deps/rocksdb/rocksdb/db/write_batch_test.cc +2 -1
  89. package/deps/rocksdb/rocksdb/db/write_callback_test.cc +4 -4
  90. package/deps/rocksdb/rocksdb/db/write_thread.cc +51 -46
  91. package/deps/rocksdb/rocksdb/db/write_thread.h +0 -4
  92. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +4 -0
  93. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +6 -0
  94. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +6 -0
  95. package/deps/rocksdb/rocksdb/env/env_posix.cc +1 -1
  96. package/deps/rocksdb/rocksdb/env/env_test.cc +38 -8
  97. package/deps/rocksdb/rocksdb/env/file_system.cc +20 -0
  98. package/deps/rocksdb/rocksdb/env/fs_posix.cc +2 -46
  99. package/deps/rocksdb/rocksdb/env/io_posix.cc +1 -0
  100. package/deps/rocksdb/rocksdb/file/writable_file_writer.cc +110 -5
  101. package/deps/rocksdb/rocksdb/file/writable_file_writer.h +7 -0
  102. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +14 -1
  103. package/deps/rocksdb/rocksdb/include/rocksdb/db.h +4 -0
  104. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +1 -1
  105. package/deps/rocksdb/rocksdb/include/rocksdb/iostats_context.h +7 -0
  106. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +10 -3
  107. package/deps/rocksdb/rocksdb/include/rocksdb/slice.h +3 -1
  108. package/deps/rocksdb/rocksdb/include/rocksdb/status.h +1 -1
  109. package/deps/rocksdb/rocksdb/include/rocksdb/wide_columns.h +2 -0
  110. package/deps/rocksdb/rocksdb/logging/auto_roll_logger.cc +12 -0
  111. package/deps/rocksdb/rocksdb/logging/auto_roll_logger_test.cc +9 -13
  112. package/deps/rocksdb/rocksdb/logging/env_logger.h +39 -13
  113. package/deps/rocksdb/rocksdb/memtable/inlineskiplist.h +1 -1
  114. package/deps/rocksdb/rocksdb/memtable/write_buffer_manager_test.cc +1 -1
  115. package/deps/rocksdb/rocksdb/microbench/db_basic_bench.cc +6 -0
  116. package/deps/rocksdb/rocksdb/monitoring/iostats_context_imp.h +4 -1
  117. package/deps/rocksdb/rocksdb/options/cf_options.cc +6 -3
  118. package/deps/rocksdb/rocksdb/options/cf_options.h +6 -5
  119. package/deps/rocksdb/rocksdb/options/options_helper.cc +2 -1
  120. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +1 -0
  121. package/deps/rocksdb/rocksdb/options/options_test.cc +4 -2
  122. package/deps/rocksdb/rocksdb/port/util_logger.h +1 -3
  123. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +50 -8
  124. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +4 -0
  125. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +7 -0
  126. package/deps/rocksdb/rocksdb/table/block_based/block_like_traits.h +28 -10
  127. package/deps/rocksdb/rocksdb/table/block_based/data_block_hash_index_test.cc +1 -1
  128. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +5 -2
  129. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.h +1 -0
  130. package/deps/rocksdb/rocksdb/table/get_context.cc +16 -6
  131. package/deps/rocksdb/rocksdb/table/table_reader.h +9 -0
  132. package/deps/rocksdb/rocksdb/table/table_test.cc +2 -1
  133. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +14 -1
  134. package/deps/rocksdb/rocksdb/tools/db_sanity_test.cc +5 -2
  135. package/deps/rocksdb/rocksdb/tools/ldb_cmd.cc +7 -8
  136. package/deps/rocksdb/rocksdb/tools/ldb_cmd_test.cc +6 -6
  137. package/deps/rocksdb/rocksdb/tools/reduce_levels_test.cc +1 -1
  138. package/deps/rocksdb/rocksdb/util/file_reader_writer_test.cc +2 -0
  139. package/deps/rocksdb/rocksdb/util/stderr_logger.h +13 -0
  140. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine_test.cc +55 -46
  141. package/deps/rocksdb/rocksdb/utilities/cassandra/cassandra_functional_test.cc +2 -1
  142. package/deps/rocksdb/rocksdb/utilities/counted_fs.cc +10 -0
  143. package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_locking_test.cc +2 -2
  144. package/deps/rocksdb/rocksdb/utilities/transactions/optimistic_transaction_test.cc +2 -2
  145. package/deps/rocksdb/rocksdb/utilities/ttl/ttl_test.cc +2 -2
  146. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_test.cc +2 -2
  147. package/index.js +2 -2
  148. package/package.json +1 -1
  149. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  150. package/prebuilds/linux-x64/node.napi.node +0 -0
  151. package/deps/rocksdb/rocksdb/logging/posix_logger.h +0 -179
@@ -7,9 +7,12 @@
7
7
 
8
8
  #include <algorithm>
9
9
  #include <cstdint>
10
+ #include <iterator>
10
11
 
12
+ #include "cache/lru_cache.h"
11
13
  #include "memory/jemalloc_nodump_allocator.h"
12
14
  #include "memory/memory_allocator.h"
15
+ #include "rocksdb/compression_type.h"
13
16
  #include "rocksdb/convenience.h"
14
17
  #include "rocksdb/secondary_cache.h"
15
18
  #include "test_util/testharness.h"
@@ -136,7 +139,6 @@ class CompressedSecondaryCacheTest : public testing::Test {
136
139
  CompressedSecondaryCacheOptions opts;
137
140
  opts.capacity = 2048;
138
141
  opts.num_shard_bits = 0;
139
- opts.metadata_charge_policy = kDontChargeCacheMetadata;
140
142
 
141
143
  if (sec_cache_is_compressed) {
142
144
  if (!LZ4_Supported()) {
@@ -162,6 +164,8 @@ class CompressedSecondaryCacheTest : public testing::Test {
162
164
  }
163
165
  std::shared_ptr<SecondaryCache> sec_cache =
164
166
  NewCompressedSecondaryCache(opts);
167
+
168
+ BasicTestHelper(sec_cache);
165
169
  }
166
170
 
167
171
  void FailsTest(bool sec_cache_is_compressed) {
@@ -177,7 +181,6 @@ class CompressedSecondaryCacheTest : public testing::Test {
177
181
 
178
182
  secondary_cache_opts.capacity = 1100;
179
183
  secondary_cache_opts.num_shard_bits = 0;
180
- secondary_cache_opts.metadata_charge_policy = kDontChargeCacheMetadata;
181
184
  std::shared_ptr<SecondaryCache> sec_cache =
182
185
  NewCompressedSecondaryCache(secondary_cache_opts);
183
186
 
@@ -235,34 +238,35 @@ class CompressedSecondaryCacheTest : public testing::Test {
235
238
 
236
239
  secondary_cache_opts.capacity = 2300;
237
240
  secondary_cache_opts.num_shard_bits = 0;
238
- secondary_cache_opts.metadata_charge_policy = kDontChargeCacheMetadata;
239
241
  std::shared_ptr<SecondaryCache> secondary_cache =
240
242
  NewCompressedSecondaryCache(secondary_cache_opts);
241
- LRUCacheOptions lru_cache_opts(1024, 0, false, 0.5, nullptr,
242
- kDefaultToAdaptiveMutex,
243
- kDontChargeCacheMetadata);
243
+ LRUCacheOptions lru_cache_opts(1300, 0, /*_strict_capacity_limit=*/false,
244
+ 0.5, nullptr, kDefaultToAdaptiveMutex,
245
+ kDefaultCacheMetadataChargePolicy);
244
246
  lru_cache_opts.secondary_cache = secondary_cache;
245
247
  std::shared_ptr<Cache> cache = NewLRUCache(lru_cache_opts);
246
248
  std::shared_ptr<Statistics> stats = CreateDBStatistics();
247
249
 
248
250
  Random rnd(301);
249
251
 
250
- std::string str1 = rnd.RandomString(1010);
252
+ std::string str1;
253
+ test::CompressibleString(&rnd, 0.5, 1001, &str1);
251
254
  std::string str1_clone{str1};
252
255
  TestItem* item1 = new TestItem(str1.data(), str1.length());
253
256
  ASSERT_OK(cache->Insert("k1", item1, &CompressedSecondaryCacheTest::helper_,
254
257
  str1.length()));
255
258
 
256
- std::string str2 = rnd.RandomString(1020);
259
+ std::string str2;
260
+ test::CompressibleString(&rnd, 0.5, 1012, &str2);
257
261
  TestItem* item2 = new TestItem(str2.data(), str2.length());
258
- // After Insert, lru cache contains k2 and secondary cache contains k1.
262
+ // After Insert, cache contains k2 and secondary cache contains k1.
259
263
  ASSERT_OK(cache->Insert("k2", item2, &CompressedSecondaryCacheTest::helper_,
260
264
  str2.length()));
261
265
 
262
- std::string str3 = rnd.RandomString(1020);
266
+ std::string str3;
267
+ test::CompressibleString(&rnd, 0.5, 1024, &str3);
263
268
  TestItem* item3 = new TestItem(str3.data(), str3.length());
264
- // After Insert, lru cache contains k3 and secondary cache contains k1 and
265
- // k2
269
+ // After Insert, cache contains k3 and secondary cache contains k1 and k2.
266
270
  ASSERT_OK(cache->Insert("k3", item3, &CompressedSecondaryCacheTest::helper_,
267
271
  str3.length()));
268
272
 
@@ -287,7 +291,6 @@ class CompressedSecondaryCacheTest : public testing::Test {
287
291
  handle = cache->Lookup("k1", &CompressedSecondaryCacheTest::helper_,
288
292
  test_item_creator, Cache::Priority::LOW, true,
289
293
  stats.get());
290
-
291
294
  ASSERT_NE(handle, nullptr);
292
295
  TestItem* val1_1 = static_cast<TestItem*>(cache->Value(handle));
293
296
  ASSERT_NE(val1_1, nullptr);
@@ -316,19 +319,20 @@ class CompressedSecondaryCacheTest : public testing::Test {
316
319
  secondary_cache_opts.compression_type = CompressionType::kNoCompression;
317
320
  }
318
321
 
319
- secondary_cache_opts.capacity = 2048;
322
+ secondary_cache_opts.capacity = 2300;
320
323
  secondary_cache_opts.num_shard_bits = 0;
321
- secondary_cache_opts.metadata_charge_policy = kDontChargeCacheMetadata;
322
324
  std::shared_ptr<SecondaryCache> secondary_cache =
323
325
  NewCompressedSecondaryCache(secondary_cache_opts);
324
326
 
325
- LRUCacheOptions opts(1024, 0, false, 0.5, nullptr, kDefaultToAdaptiveMutex,
326
- kDontChargeCacheMetadata);
327
+ LRUCacheOptions opts(1024, 0, /*_strict_capacity_limit=*/false, 0.5,
328
+ nullptr, kDefaultToAdaptiveMutex,
329
+ kDefaultCacheMetadataChargePolicy);
327
330
  opts.secondary_cache = secondary_cache;
328
331
  std::shared_ptr<Cache> cache = NewLRUCache(opts);
329
332
 
330
333
  Random rnd(301);
331
- std::string str1 = rnd.RandomString(1020);
334
+ std::string str1;
335
+ test::CompressibleString(&rnd, 0.5, 1001, &str1);
332
336
  auto item1 =
333
337
  std::unique_ptr<TestItem>(new TestItem(str1.data(), str1.length()));
334
338
  ASSERT_NOK(cache->Insert("k1", item1.get(), nullptr, str1.length()));
@@ -361,25 +365,28 @@ class CompressedSecondaryCacheTest : public testing::Test {
361
365
  secondary_cache_opts.compression_type = CompressionType::kNoCompression;
362
366
  }
363
367
 
364
- secondary_cache_opts.capacity = 2048;
368
+ secondary_cache_opts.capacity = 2300;
365
369
  secondary_cache_opts.num_shard_bits = 0;
366
- secondary_cache_opts.metadata_charge_policy = kDontChargeCacheMetadata;
367
370
 
368
371
  std::shared_ptr<SecondaryCache> secondary_cache =
369
372
  NewCompressedSecondaryCache(secondary_cache_opts);
370
373
 
371
- LRUCacheOptions opts(1024, 0, false, 0.5, nullptr, kDefaultToAdaptiveMutex,
372
- kDontChargeCacheMetadata);
374
+ LRUCacheOptions opts(1200, 0, /*_strict_capacity_limit=*/false, 0.5,
375
+ nullptr, kDefaultToAdaptiveMutex,
376
+ kDefaultCacheMetadataChargePolicy);
373
377
  opts.secondary_cache = secondary_cache;
374
378
  std::shared_ptr<Cache> cache = NewLRUCache(opts);
375
379
 
376
380
  Random rnd(301);
377
- std::string str1 = rnd.RandomString(1020);
381
+ std::string str1;
382
+ test::CompressibleString(&rnd, 0.5, 1001, &str1);
378
383
  TestItem* item1 = new TestItem(str1.data(), str1.length());
379
384
  ASSERT_OK(cache->Insert("k1", item1,
380
385
  &CompressedSecondaryCacheTest::helper_fail_,
381
386
  str1.length()));
382
- std::string str2 = rnd.RandomString(1020);
387
+
388
+ std::string str2;
389
+ test::CompressibleString(&rnd, 0.5, 1002, &str2);
383
390
  TestItem* item2 = new TestItem(str2.data(), str2.length());
384
391
  // k1 should be demoted to the secondary cache.
385
392
  ASSERT_OK(cache->Insert("k2", item2,
@@ -417,25 +424,27 @@ class CompressedSecondaryCacheTest : public testing::Test {
417
424
  secondary_cache_opts.compression_type = CompressionType::kNoCompression;
418
425
  }
419
426
 
420
- secondary_cache_opts.capacity = 2048;
427
+ secondary_cache_opts.capacity = 2300;
421
428
  secondary_cache_opts.num_shard_bits = 0;
422
- secondary_cache_opts.metadata_charge_policy = kDontChargeCacheMetadata;
423
429
 
424
430
  std::shared_ptr<SecondaryCache> secondary_cache =
425
431
  NewCompressedSecondaryCache(secondary_cache_opts);
426
432
 
427
- LRUCacheOptions opts(1024, 0, false, 0.5, nullptr, kDefaultToAdaptiveMutex,
428
- kDontChargeCacheMetadata);
433
+ LRUCacheOptions opts(1200, 0, /*_strict_capacity_limit=*/false, 0.5,
434
+ nullptr, kDefaultToAdaptiveMutex,
435
+ kDefaultCacheMetadataChargePolicy);
429
436
  opts.secondary_cache = secondary_cache;
430
437
  std::shared_ptr<Cache> cache = NewLRUCache(opts);
431
438
 
432
439
  Random rnd(301);
433
- std::string str1 = rnd.RandomString(1020);
440
+ std::string str1;
441
+ test::CompressibleString(&rnd, 0.5, 1001, &str1);
434
442
  TestItem* item1 = new TestItem(str1.data(), str1.length());
435
443
  ASSERT_OK(cache->Insert("k1", item1, &CompressedSecondaryCacheTest::helper_,
436
444
  str1.length()));
437
445
 
438
- std::string str2 = rnd.RandomString(1020);
446
+ std::string str2;
447
+ test::CompressibleString(&rnd, 0.5, 1002, &str2);
439
448
  TestItem* item2 = new TestItem(str2.data(), str2.length());
440
449
  // k1 should be demoted to the secondary cache.
441
450
  ASSERT_OK(cache->Insert("k2", item2, &CompressedSecondaryCacheTest::helper_,
@@ -473,24 +482,28 @@ class CompressedSecondaryCacheTest : public testing::Test {
473
482
  secondary_cache_opts.compression_type = CompressionType::kNoCompression;
474
483
  }
475
484
 
476
- secondary_cache_opts.capacity = 2048;
485
+ secondary_cache_opts.capacity = 2300;
477
486
  secondary_cache_opts.num_shard_bits = 0;
478
- secondary_cache_opts.metadata_charge_policy = kDontChargeCacheMetadata;
479
487
 
480
488
  std::shared_ptr<SecondaryCache> secondary_cache =
481
489
  NewCompressedSecondaryCache(secondary_cache_opts);
482
490
 
483
- LRUCacheOptions opts(1024, 0, /*_strict_capacity_limit=*/true, 0.5, nullptr,
484
- kDefaultToAdaptiveMutex, kDontChargeCacheMetadata);
491
+ LRUCacheOptions opts(1200, 0, /*_strict_capacity_limit=*/true, 0.5, nullptr,
492
+ kDefaultToAdaptiveMutex,
493
+ kDefaultCacheMetadataChargePolicy);
485
494
  opts.secondary_cache = secondary_cache;
486
495
  std::shared_ptr<Cache> cache = NewLRUCache(opts);
487
496
 
488
497
  Random rnd(301);
489
- std::string str1 = rnd.RandomString(1020);
498
+ std::string str1;
499
+ test::CompressibleString(&rnd, 0.5, 1001, &str1);
490
500
  TestItem* item1 = new TestItem(str1.data(), str1.length());
491
501
  ASSERT_OK(cache->Insert("k1", item1, &CompressedSecondaryCacheTest::helper_,
492
502
  str1.length()));
493
- std::string str2 = rnd.RandomString(1020);
503
+
504
+ std::string str2;
505
+ test::CompressibleString(&rnd, 0.5, 1002, &str2);
506
+ std::string str2_clone{str2};
494
507
  TestItem* item2 = new TestItem(str2.data(), str2.length());
495
508
  // k1 should be demoted to the secondary cache.
496
509
  ASSERT_OK(cache->Insert("k2", item2, &CompressedSecondaryCacheTest::helper_,
@@ -501,8 +514,9 @@ class CompressedSecondaryCacheTest : public testing::Test {
501
514
  test_item_creator, Cache::Priority::LOW, true);
502
515
  ASSERT_NE(handle2, nullptr);
503
516
  cache->Release(handle2);
504
- // k1 promotion should fail due to the block cache being at capacity,
505
- // but the lookup should still succeed
517
+
518
+ // k1 promotion should fail because cache is at capacity and
519
+ // strict_capacity_limit is true, but the lookup should still succeed.
506
520
  Cache::Handle* handle1;
507
521
  handle1 = cache->Lookup("k1", &CompressedSecondaryCacheTest::helper_,
508
522
  test_item_creator, Cache::Priority::LOW, true);
@@ -519,6 +533,119 @@ class CompressedSecondaryCacheTest : public testing::Test {
519
533
  secondary_cache.reset();
520
534
  }
521
535
 
536
+ void SplitValueIntoChunksTest() {
537
+ JemallocAllocatorOptions jopts;
538
+ std::shared_ptr<MemoryAllocator> allocator;
539
+ std::string msg;
540
+ if (JemallocNodumpAllocator::IsSupported(&msg)) {
541
+ Status s = NewJemallocNodumpAllocator(jopts, &allocator);
542
+ if (!s.ok()) {
543
+ ROCKSDB_GTEST_BYPASS("JEMALLOC not supported");
544
+ }
545
+ } else {
546
+ ROCKSDB_GTEST_BYPASS("JEMALLOC not supported");
547
+ }
548
+
549
+ using CacheValueChunk = CompressedSecondaryCache::CacheValueChunk;
550
+ std::unique_ptr<CompressedSecondaryCache> sec_cache =
551
+ std::make_unique<CompressedSecondaryCache>(1000, 0, true, 0.5,
552
+ allocator);
553
+ Random rnd(301);
554
+ // 10000 = 8169 + 1769 + 62 , so there should be 3 chunks after split.
555
+ size_t str_size{10000};
556
+ std::string str = rnd.RandomString(static_cast<int>(str_size));
557
+ size_t charge{0};
558
+ CacheValueChunk* chunks_head =
559
+ sec_cache->SplitValueIntoChunks(str, kLZ4Compression, charge);
560
+ ASSERT_EQ(charge, str_size + 3 * (sizeof(CacheValueChunk) - 1));
561
+
562
+ CacheValueChunk* current_chunk = chunks_head;
563
+ ASSERT_EQ(current_chunk->size, 8192 - sizeof(CacheValueChunk) + 1);
564
+ current_chunk = current_chunk->next;
565
+ ASSERT_EQ(current_chunk->size, 1792 - sizeof(CacheValueChunk) + 1);
566
+ current_chunk = current_chunk->next;
567
+ ASSERT_EQ(current_chunk->size, 62);
568
+
569
+ sec_cache->DeletionCallback("dummy", chunks_head);
570
+ }
571
+
572
+ void MergeChunksIntoValueTest() {
573
+ using CacheValueChunk = CompressedSecondaryCache::CacheValueChunk;
574
+ Random rnd(301);
575
+ size_t size1{2048};
576
+ std::string str1 = rnd.RandomString(static_cast<int>(size1));
577
+ CacheValueChunk* current_chunk = reinterpret_cast<CacheValueChunk*>(
578
+ new char[sizeof(CacheValueChunk) - 1 + size1]);
579
+ CacheValueChunk* chunks_head = current_chunk;
580
+ memcpy(current_chunk->data, str1.data(), size1);
581
+ current_chunk->size = size1;
582
+
583
+ size_t size2{256};
584
+ std::string str2 = rnd.RandomString(static_cast<int>(size2));
585
+ current_chunk->next = reinterpret_cast<CacheValueChunk*>(
586
+ new char[sizeof(CacheValueChunk) - 1 + size2]);
587
+ current_chunk = current_chunk->next;
588
+ memcpy(current_chunk->data, str2.data(), size2);
589
+ current_chunk->size = size2;
590
+
591
+ size_t size3{31};
592
+ std::string str3 = rnd.RandomString(static_cast<int>(size3));
593
+ current_chunk->next = reinterpret_cast<CacheValueChunk*>(
594
+ new char[sizeof(CacheValueChunk) - 1 + size3]);
595
+ current_chunk = current_chunk->next;
596
+ memcpy(current_chunk->data, str3.data(), size3);
597
+ current_chunk->size = size3;
598
+ current_chunk->next = nullptr;
599
+
600
+ std::string str = str1 + str2 + str3;
601
+
602
+ std::unique_ptr<CompressedSecondaryCache> sec_cache =
603
+ std::make_unique<CompressedSecondaryCache>(1000, 0, true, 0.5);
604
+ size_t charge{0};
605
+ CacheAllocationPtr value =
606
+ sec_cache->MergeChunksIntoValue(chunks_head, charge);
607
+ ASSERT_EQ(charge, size1 + size2 + size3);
608
+ std::string value_str{value.get(), charge};
609
+ ASSERT_EQ(strcmp(value_str.data(), str.data()), 0);
610
+
611
+ sec_cache->DeletionCallback("dummy", chunks_head);
612
+ }
613
+
614
+ void SplictValueAndMergeChunksTest() {
615
+ JemallocAllocatorOptions jopts;
616
+ std::shared_ptr<MemoryAllocator> allocator;
617
+ std::string msg;
618
+ if (JemallocNodumpAllocator::IsSupported(&msg)) {
619
+ Status s = NewJemallocNodumpAllocator(jopts, &allocator);
620
+ if (!s.ok()) {
621
+ ROCKSDB_GTEST_BYPASS("JEMALLOC not supported");
622
+ }
623
+ } else {
624
+ ROCKSDB_GTEST_BYPASS("JEMALLOC not supported");
625
+ }
626
+
627
+ using CacheValueChunk = CompressedSecondaryCache::CacheValueChunk;
628
+ std::unique_ptr<CompressedSecondaryCache> sec_cache =
629
+ std::make_unique<CompressedSecondaryCache>(1000, 0, true, 0.5,
630
+ allocator);
631
+ Random rnd(301);
632
+ // 10000 = 8169 + 1769 + 62 , so there should be 3 chunks after split.
633
+ size_t str_size{10000};
634
+ std::string str = rnd.RandomString(static_cast<int>(str_size));
635
+ size_t charge{0};
636
+ CacheValueChunk* chunks_head =
637
+ sec_cache->SplitValueIntoChunks(str, kLZ4Compression, charge);
638
+ ASSERT_EQ(charge, str_size + 3 * (sizeof(CacheValueChunk) - 1));
639
+
640
+ CacheAllocationPtr value =
641
+ sec_cache->MergeChunksIntoValue(chunks_head, charge);
642
+ ASSERT_EQ(charge, str_size);
643
+ std::string value_str{value.get(), charge};
644
+ ASSERT_EQ(strcmp(value_str.data(), str.data()), 0);
645
+
646
+ sec_cache->DeletionCallback("dummy", chunks_head);
647
+ }
648
+
522
649
  private:
523
650
  bool fail_create_;
524
651
  };
@@ -639,6 +766,18 @@ TEST_F(CompressedSecondaryCacheTest,
639
766
  IntegrationFullCapacityTest(true);
640
767
  }
641
768
 
769
+ TEST_F(CompressedSecondaryCacheTest, SplitValueIntoChunksTest) {
770
+ SplitValueIntoChunksTest();
771
+ }
772
+
773
+ TEST_F(CompressedSecondaryCacheTest, MergeChunksIntoValueTest) {
774
+ MergeChunksIntoValueTest();
775
+ }
776
+
777
+ TEST_F(CompressedSecondaryCacheTest, SplictValueAndMergeChunksTest) {
778
+ SplictValueAndMergeChunksTest();
779
+ }
780
+
642
781
  } // namespace ROCKSDB_NAMESPACE
643
782
 
644
783
  int main(int argc, char** argv) {
@@ -299,10 +299,12 @@ int LRUCacheShard::CalcHashBits(
299
299
  }
300
300
 
301
301
  void LRUCacheShard::SetCapacity(size_t capacity) {
302
- assert(false); // Not supported. TODO(Guido) Support it?
303
302
  autovector<LRUHandle> last_reference_list;
304
303
  {
305
304
  DMutexLock l(mutex_);
305
+ if (capacity > capacity_) {
306
+ assert(false); // Not supported.
307
+ }
306
308
  capacity_ = capacity;
307
309
  EvictFromLRU(0, &last_reference_list);
308
310
  }
@@ -458,11 +458,12 @@ Cache::Handle* LRUCacheShard::Lookup(
458
458
  memcpy(e->key_data, key.data(), key.size());
459
459
  e->value = nullptr;
460
460
  e->sec_handle = secondary_handle.release();
461
+ e->total_charge = 0;
461
462
  e->Ref();
463
+ e->SetIsInSecondaryCache(is_in_sec_cache);
462
464
 
463
465
  if (wait) {
464
466
  Promote(e);
465
- e->SetIsInSecondaryCache(is_in_sec_cache);
466
467
  if (!e->value) {
467
468
  // The secondary cache returned a handle, but the lookup failed.
468
469
  e->Unref();
@@ -476,7 +477,6 @@ Cache::Handle* LRUCacheShard::Lookup(
476
477
  // If wait is false, we always return a handle and let the caller
477
478
  // release the handle after checking for success or failure.
478
479
  e->SetIncomplete(true);
479
- e->SetIsInSecondaryCache(is_in_sec_cache);
480
480
  // This may be slightly inaccurate, if the lookup eventually fails.
481
481
  // But the probability is very low.
482
482
  PERF_COUNTER_ADD(secondary_cache_hit_count, 1);