@nxtedition/rocksdb 7.1.20 → 7.1.21

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 (262) hide show
  1. package/deps/rocksdb/rocksdb/CMakeLists.txt +13 -6
  2. package/deps/rocksdb/rocksdb/Makefile +1 -1
  3. package/deps/rocksdb/rocksdb/TARGETS +2 -0
  4. package/deps/rocksdb/rocksdb/cache/cache_reservation_manager_test.cc +1 -0
  5. package/deps/rocksdb/rocksdb/cache/cache_test.cc +4 -4
  6. package/deps/rocksdb/rocksdb/cache/clock_cache.cc +139 -161
  7. package/deps/rocksdb/rocksdb/cache/clock_cache.h +92 -82
  8. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.cc +16 -3
  9. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.h +9 -3
  10. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache_test.cc +73 -30
  11. package/deps/rocksdb/rocksdb/cache/fast_lru_cache.cc +25 -67
  12. package/deps/rocksdb/rocksdb/cache/fast_lru_cache.h +41 -40
  13. package/deps/rocksdb/rocksdb/cache/lru_cache.cc +109 -155
  14. package/deps/rocksdb/rocksdb/cache/lru_cache.h +127 -149
  15. package/deps/rocksdb/rocksdb/cache/lru_cache_test.cc +75 -80
  16. package/deps/rocksdb/rocksdb/cache/sharded_cache.cc +22 -172
  17. package/deps/rocksdb/rocksdb/cache/sharded_cache.h +272 -85
  18. package/deps/rocksdb/rocksdb/db/arena_wrapped_db_iter.cc +12 -4
  19. package/deps/rocksdb/rocksdb/db/blob/blob_counting_iterator_test.cc +1 -0
  20. package/deps/rocksdb/rocksdb/db/blob/blob_file_addition_test.cc +1 -0
  21. package/deps/rocksdb/rocksdb/db/blob/blob_file_builder_test.cc +1 -0
  22. package/deps/rocksdb/rocksdb/db/blob/blob_file_cache_test.cc +1 -0
  23. package/deps/rocksdb/rocksdb/db/blob/blob_file_garbage_test.cc +1 -0
  24. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader_test.cc +1 -0
  25. package/deps/rocksdb/rocksdb/db/blob/blob_garbage_meter_test.cc +1 -0
  26. package/deps/rocksdb/rocksdb/db/blob/blob_source_test.cc +13 -4
  27. package/deps/rocksdb/rocksdb/db/builder.cc +1 -1
  28. package/deps/rocksdb/rocksdb/db/column_family.cc +15 -1
  29. package/deps/rocksdb/rocksdb/db/compact_files_test.cc +1 -0
  30. package/deps/rocksdb/rocksdb/db/compaction/clipping_iterator_test.cc +1 -0
  31. package/deps/rocksdb/rocksdb/db/compaction/compaction.cc +25 -7
  32. package/deps/rocksdb/rocksdb/db/compaction/compaction.h +10 -0
  33. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +22 -8
  34. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +14 -5
  35. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator_test.cc +1 -0
  36. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +38 -12
  37. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +9 -6
  38. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +408 -6
  39. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.cc +244 -54
  40. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +27 -6
  41. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.cc +25 -30
  42. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.cc +87 -26
  43. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.cc +23 -4
  44. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +61 -0
  45. package/deps/rocksdb/rocksdb/db/compaction/tiered_compaction_test.cc +294 -21
  46. package/deps/rocksdb/rocksdb/db/comparator_db_test.cc +1 -0
  47. package/deps/rocksdb/rocksdb/db/cuckoo_table_db_test.cc +1 -0
  48. package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +28 -10
  49. package/deps/rocksdb/rocksdb/db/db_bloom_filter_test.cc +4 -4
  50. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +272 -0
  51. package/deps/rocksdb/rocksdb/db/db_flush_test.cc +38 -0
  52. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +69 -25
  53. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -3
  54. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +29 -12
  55. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_debug.cc +0 -12
  56. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +10 -4
  57. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +35 -22
  58. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +5 -1
  59. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_write.cc +40 -5
  60. package/deps/rocksdb/rocksdb/db/db_iter.cc +1 -0
  61. package/deps/rocksdb/rocksdb/db/db_iter_stress_test.cc +1 -0
  62. package/deps/rocksdb/rocksdb/db/db_iter_test.cc +1 -0
  63. package/deps/rocksdb/rocksdb/db/db_iterator_test.cc +22 -0
  64. package/deps/rocksdb/rocksdb/db/db_kv_checksum_test.cc +1 -0
  65. package/deps/rocksdb/rocksdb/db/db_logical_block_size_cache_test.cc +1 -0
  66. package/deps/rocksdb/rocksdb/db/db_range_del_test.cc +72 -5
  67. package/deps/rocksdb/rocksdb/db/db_tailing_iter_test.cc +60 -21
  68. package/deps/rocksdb/rocksdb/db/db_test.cc +170 -1
  69. package/deps/rocksdb/rocksdb/db/db_test2.cc +9 -3
  70. package/deps/rocksdb/rocksdb/db/db_test_util.cc +19 -0
  71. package/deps/rocksdb/rocksdb/db/db_test_util.h +32 -0
  72. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +444 -3
  73. package/deps/rocksdb/rocksdb/db/db_write_test.cc +8 -8
  74. package/deps/rocksdb/rocksdb/db/dbformat.cc +13 -0
  75. package/deps/rocksdb/rocksdb/db/dbformat.h +59 -4
  76. package/deps/rocksdb/rocksdb/db/dbformat_test.cc +1 -0
  77. package/deps/rocksdb/rocksdb/db/experimental.cc +3 -1
  78. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +24 -3
  79. package/deps/rocksdb/rocksdb/db/fault_injection_test.cc +1 -0
  80. package/deps/rocksdb/rocksdb/db/filename_test.cc +1 -0
  81. package/deps/rocksdb/rocksdb/db/flush_job.cc +4 -3
  82. package/deps/rocksdb/rocksdb/db/flush_job_test.cc +1 -0
  83. package/deps/rocksdb/rocksdb/db/forward_iterator.cc +85 -43
  84. package/deps/rocksdb/rocksdb/db/forward_iterator.h +3 -1
  85. package/deps/rocksdb/rocksdb/db/internal_stats.cc +33 -6
  86. package/deps/rocksdb/rocksdb/db/internal_stats.h +6 -0
  87. package/deps/rocksdb/rocksdb/db/listener_test.cc +1 -0
  88. package/deps/rocksdb/rocksdb/db/log_test.cc +1 -0
  89. package/deps/rocksdb/rocksdb/db/log_writer.cc +1 -1
  90. package/deps/rocksdb/rocksdb/db/log_writer.h +1 -1
  91. package/deps/rocksdb/rocksdb/db/manual_compaction_test.cc +1 -0
  92. package/deps/rocksdb/rocksdb/db/memtable.cc +158 -56
  93. package/deps/rocksdb/rocksdb/db/memtable.h +2 -0
  94. package/deps/rocksdb/rocksdb/db/memtable_list_test.cc +1 -0
  95. package/deps/rocksdb/rocksdb/db/merge_helper_test.cc +1 -0
  96. package/deps/rocksdb/rocksdb/db/options_file_test.cc +1 -0
  97. package/deps/rocksdb/rocksdb/db/perf_context_test.cc +1 -0
  98. package/deps/rocksdb/rocksdb/db/periodic_task_scheduler_test.cc +1 -0
  99. package/deps/rocksdb/rocksdb/db/plain_table_db_test.cc +1 -0
  100. package/deps/rocksdb/rocksdb/db/prefix_test.cc +1 -0
  101. package/deps/rocksdb/rocksdb/db/range_del_aggregator.cc +52 -9
  102. package/deps/rocksdb/rocksdb/db/range_del_aggregator.h +31 -2
  103. package/deps/rocksdb/rocksdb/db/range_del_aggregator_test.cc +1 -0
  104. package/deps/rocksdb/rocksdb/db/range_tombstone_fragmenter.cc +81 -42
  105. package/deps/rocksdb/rocksdb/db/range_tombstone_fragmenter.h +78 -12
  106. package/deps/rocksdb/rocksdb/db/range_tombstone_fragmenter_test.cc +1 -0
  107. package/deps/rocksdb/rocksdb/db/repair_test.cc +1 -0
  108. package/deps/rocksdb/rocksdb/db/seqno_time_test.cc +154 -27
  109. package/deps/rocksdb/rocksdb/db/seqno_to_time_mapping.cc +21 -4
  110. package/deps/rocksdb/rocksdb/db/seqno_to_time_mapping.h +4 -1
  111. package/deps/rocksdb/rocksdb/db/table_cache.cc +18 -6
  112. package/deps/rocksdb/rocksdb/db/table_properties_collector_test.cc +1 -0
  113. package/deps/rocksdb/rocksdb/db/version_builder_test.cc +1 -0
  114. package/deps/rocksdb/rocksdb/db/version_edit_test.cc +1 -0
  115. package/deps/rocksdb/rocksdb/db/version_set.cc +15 -7
  116. package/deps/rocksdb/rocksdb/db/version_set.h +2 -1
  117. package/deps/rocksdb/rocksdb/db/version_set_test.cc +1 -0
  118. package/deps/rocksdb/rocksdb/db/version_util.h +3 -1
  119. package/deps/rocksdb/rocksdb/db/wal_manager_test.cc +1 -0
  120. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.cc +28 -9
  121. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.h +21 -0
  122. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization_test.cc +30 -0
  123. package/deps/rocksdb/rocksdb/db/wide/wide_columns.cc +4 -0
  124. package/deps/rocksdb/rocksdb/db/write_batch.cc +30 -7
  125. package/deps/rocksdb/rocksdb/db/write_batch_internal.h +24 -13
  126. package/deps/rocksdb/rocksdb/db/write_batch_test.cc +5 -4
  127. package/deps/rocksdb/rocksdb/db/write_callback_test.cc +1 -0
  128. package/deps/rocksdb/rocksdb/db/write_controller_test.cc +1 -0
  129. package/deps/rocksdb/rocksdb/db_stress_tool/batched_ops_stress.cc +104 -60
  130. package/deps/rocksdb/rocksdb/db_stress_tool/cf_consistency_stress.cc +199 -108
  131. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.cc +39 -0
  132. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +8 -0
  133. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_driver.cc +3 -1
  134. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +19 -0
  135. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_shared_state.h +26 -0
  136. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +247 -118
  137. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.h +24 -4
  138. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_tool.cc +18 -0
  139. package/deps/rocksdb/rocksdb/db_stress_tool/expected_state.cc +129 -1
  140. package/deps/rocksdb/rocksdb/db_stress_tool/multi_ops_txns_stress.cc +22 -0
  141. package/deps/rocksdb/rocksdb/db_stress_tool/multi_ops_txns_stress.h +4 -0
  142. package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +312 -117
  143. package/deps/rocksdb/rocksdb/env/env_basic_test.cc +1 -0
  144. package/deps/rocksdb/rocksdb/env/fs_posix.cc +10 -2
  145. package/deps/rocksdb/rocksdb/env/io_posix_test.cc +1 -0
  146. package/deps/rocksdb/rocksdb/env/mock_env_test.cc +1 -0
  147. package/deps/rocksdb/rocksdb/file/delete_scheduler.cc +5 -1
  148. package/deps/rocksdb/rocksdb/file/delete_scheduler_test.cc +1 -0
  149. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +1 -0
  150. package/deps/rocksdb/rocksdb/file/writable_file_writer.h +1 -1
  151. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +49 -1
  152. package/deps/rocksdb/rocksdb/include/rocksdb/cache.h +44 -18
  153. package/deps/rocksdb/rocksdb/include/rocksdb/db.h +8 -7
  154. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +6 -1
  155. package/deps/rocksdb/rocksdb/include/rocksdb/listener.h +3 -0
  156. package/deps/rocksdb/rocksdb/include/rocksdb/secondary_cache.h +17 -4
  157. package/deps/rocksdb/rocksdb/include/rocksdb/sst_file_reader.h +4 -0
  158. package/deps/rocksdb/rocksdb/include/rocksdb/sst_file_writer.h +7 -0
  159. package/deps/rocksdb/rocksdb/include/rocksdb/universal_compaction.h +1 -1
  160. package/deps/rocksdb/rocksdb/include/rocksdb/wide_columns.h +9 -0
  161. package/deps/rocksdb/rocksdb/include/rocksdb/write_batch.h +3 -6
  162. package/deps/rocksdb/rocksdb/logging/auto_roll_logger_test.cc +1 -0
  163. package/deps/rocksdb/rocksdb/logging/env_logger_test.cc +1 -0
  164. package/deps/rocksdb/rocksdb/logging/event_logger_test.cc +1 -0
  165. package/deps/rocksdb/rocksdb/memory/arena.cc +23 -88
  166. package/deps/rocksdb/rocksdb/memory/arena.h +25 -31
  167. package/deps/rocksdb/rocksdb/memory/arena_test.cc +61 -0
  168. package/deps/rocksdb/rocksdb/memory/memory_allocator_test.cc +1 -0
  169. package/deps/rocksdb/rocksdb/memtable/inlineskiplist_test.cc +1 -0
  170. package/deps/rocksdb/rocksdb/memtable/skiplist_test.cc +1 -0
  171. package/deps/rocksdb/rocksdb/memtable/write_buffer_manager_test.cc +1 -0
  172. package/deps/rocksdb/rocksdb/monitoring/histogram_test.cc +1 -0
  173. package/deps/rocksdb/rocksdb/monitoring/iostats_context_test.cc +1 -0
  174. package/deps/rocksdb/rocksdb/options/cf_options.cc +19 -0
  175. package/deps/rocksdb/rocksdb/options/cf_options.h +8 -0
  176. package/deps/rocksdb/rocksdb/options/configurable_test.cc +1 -0
  177. package/deps/rocksdb/rocksdb/options/options.cc +7 -0
  178. package/deps/rocksdb/rocksdb/options/options_helper.cc +6 -0
  179. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +6 -0
  180. package/deps/rocksdb/rocksdb/options/options_test.cc +63 -40
  181. package/deps/rocksdb/rocksdb/port/mmap.cc +98 -0
  182. package/deps/rocksdb/rocksdb/port/mmap.h +70 -0
  183. package/deps/rocksdb/rocksdb/port/stack_trace.cc +7 -0
  184. package/deps/rocksdb/rocksdb/port/stack_trace.h +4 -1
  185. package/deps/rocksdb/rocksdb/port/win/port_win.h +2 -7
  186. package/deps/rocksdb/rocksdb/src.mk +1 -0
  187. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.cc +7 -7
  188. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +3 -3
  189. package/deps/rocksdb/rocksdb/table/block_based/block_test.cc +1 -0
  190. package/deps/rocksdb/rocksdb/table/block_based/data_block_hash_index_test.cc +1 -0
  191. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block_test.cc +1 -0
  192. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block_test.cc +1 -0
  193. package/deps/rocksdb/rocksdb/table/cuckoo/cuckoo_table_builder_test.cc +1 -0
  194. package/deps/rocksdb/rocksdb/table/cuckoo/cuckoo_table_reader_test.cc +1 -0
  195. package/deps/rocksdb/rocksdb/table/get_context.cc +19 -1
  196. package/deps/rocksdb/rocksdb/table/get_context.h +9 -0
  197. package/deps/rocksdb/rocksdb/table/merger_test.cc +1 -0
  198. package/deps/rocksdb/rocksdb/table/merging_iterator.cc +10 -11
  199. package/deps/rocksdb/rocksdb/table/mock_table.cc +37 -19
  200. package/deps/rocksdb/rocksdb/table/mock_table.h +5 -1
  201. package/deps/rocksdb/rocksdb/table/sst_file_reader.cc +6 -0
  202. package/deps/rocksdb/rocksdb/table/sst_file_reader_test.cc +33 -0
  203. package/deps/rocksdb/rocksdb/table/sst_file_writer.cc +45 -6
  204. package/deps/rocksdb/rocksdb/test_util/testharness.h +2 -0
  205. package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer_test.cc +1 -0
  206. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +5 -0
  207. package/deps/rocksdb/rocksdb/tools/db_bench_tool_test.cc +1 -0
  208. package/deps/rocksdb/rocksdb/tools/io_tracer_parser_test.cc +1 -0
  209. package/deps/rocksdb/rocksdb/tools/ldb_cmd_test.cc +36 -0
  210. package/deps/rocksdb/rocksdb/tools/reduce_levels_test.cc +1 -0
  211. package/deps/rocksdb/rocksdb/tools/trace_analyzer_test.cc +1 -0
  212. package/deps/rocksdb/rocksdb/trace_replay/block_cache_tracer_test.cc +1 -0
  213. package/deps/rocksdb/rocksdb/trace_replay/io_tracer_test.cc +1 -0
  214. package/deps/rocksdb/rocksdb/util/autovector_test.cc +1 -0
  215. package/deps/rocksdb/rocksdb/util/bloom_test.cc +1 -0
  216. package/deps/rocksdb/rocksdb/util/coding_test.cc +1 -0
  217. package/deps/rocksdb/rocksdb/util/crc32c_test.cc +1 -0
  218. package/deps/rocksdb/rocksdb/util/dynamic_bloom_test.cc +1 -0
  219. package/deps/rocksdb/rocksdb/util/file_reader_writer_test.cc +1 -0
  220. package/deps/rocksdb/rocksdb/util/filelock_test.cc +1 -0
  221. package/deps/rocksdb/rocksdb/util/gflags_compat.h +12 -7
  222. package/deps/rocksdb/rocksdb/util/hash_test.cc +1 -0
  223. package/deps/rocksdb/rocksdb/util/heap_test.cc +4 -2
  224. package/deps/rocksdb/rocksdb/util/random_test.cc +1 -0
  225. package/deps/rocksdb/rocksdb/util/rate_limiter_test.cc +1 -0
  226. package/deps/rocksdb/rocksdb/util/repeatable_thread_test.cc +1 -0
  227. package/deps/rocksdb/rocksdb/util/ribbon_test.cc +1 -0
  228. package/deps/rocksdb/rocksdb/util/slice_transform_test.cc +1 -0
  229. package/deps/rocksdb/rocksdb/util/thread_list_test.cc +1 -0
  230. package/deps/rocksdb/rocksdb/util/thread_local_test.cc +1 -0
  231. package/deps/rocksdb/rocksdb/util/timer_test.cc +1 -0
  232. package/deps/rocksdb/rocksdb/util/work_queue_test.cc +4 -0
  233. package/deps/rocksdb/rocksdb/utilities/agg_merge/agg_merge_test.cc +1 -0
  234. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine.cc +13 -0
  235. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine_test.cc +9 -3
  236. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db_test.cc +1 -0
  237. package/deps/rocksdb/rocksdb/utilities/cassandra/cassandra_format_test.cc +1 -0
  238. package/deps/rocksdb/rocksdb/utilities/cassandra/cassandra_functional_test.cc +1 -0
  239. package/deps/rocksdb/rocksdb/utilities/cassandra/cassandra_row_merge_test.cc +1 -0
  240. package/deps/rocksdb/rocksdb/utilities/cassandra/cassandra_serialize_test.cc +1 -0
  241. package/deps/rocksdb/rocksdb/utilities/env_mirror_test.cc +1 -0
  242. package/deps/rocksdb/rocksdb/utilities/env_timed_test.cc +1 -0
  243. package/deps/rocksdb/rocksdb/utilities/fault_injection_secondary_cache.h +8 -0
  244. package/deps/rocksdb/rocksdb/utilities/memory/memory_test.cc +1 -0
  245. package/deps/rocksdb/rocksdb/utilities/object_registry_test.cc +1 -0
  246. package/deps/rocksdb/rocksdb/utilities/options/options_util_test.cc +1 -0
  247. package/deps/rocksdb/rocksdb/utilities/persistent_cache/hash_table_test.cc +1 -0
  248. package/deps/rocksdb/rocksdb/utilities/persistent_cache/persistent_cache_test.cc +1 -0
  249. package/deps/rocksdb/rocksdb/utilities/simulator_cache/cache_simulator_test.cc +1 -0
  250. package/deps/rocksdb/rocksdb/utilities/transactions/optimistic_transaction_test.cc +1 -0
  251. package/deps/rocksdb/rocksdb/utilities/transactions/timestamped_snapshot_test.cc +1 -0
  252. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.cc +1 -0
  253. package/deps/rocksdb/rocksdb/utilities/transactions/write_committed_transaction_ts_test.cc +1 -0
  254. package/deps/rocksdb/rocksdb/utilities/transactions/write_unprepared_transaction_test.cc +1 -0
  255. package/deps/rocksdb/rocksdb/utilities/ttl/ttl_test.cc +1 -0
  256. package/deps/rocksdb/rocksdb/utilities/util_merge_operators_test.cc +1 -0
  257. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index.cc +7 -0
  258. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_test.cc +20 -0
  259. package/index.js +12 -4
  260. package/package.json +1 -1
  261. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  262. package/prebuilds/linux-x64/node.napi.node +0 -0
@@ -303,30 +303,24 @@ constexpr double kLoadFactor = 0.7;
303
303
  // strict upper bound on the load factor.
304
304
  constexpr double kStrictLoadFactor = 0.84;
305
305
 
306
- using CacheKeyBytes = std::array<char, kCacheKeySize>;
307
-
308
306
  struct ClockHandleBasicData {
309
307
  void* value = nullptr;
310
308
  Cache::DeleterFn deleter = nullptr;
311
- CacheKeyBytes key = {};
309
+ // A lossless, reversible hash of the fixed-size (16 byte) cache key. This
310
+ // eliminates the need to store a hash separately.
311
+ UniqueId64x2 hashed_key = kNullUniqueId64x2;
312
312
  size_t total_charge = 0;
313
313
 
314
- Slice KeySlice() const { return Slice(key.data(), kCacheKeySize); }
314
+ // Calls deleter (if non-null) on cache key and value
315
+ void FreeData() const;
315
316
 
316
- void FreeData() const {
317
- if (deleter) {
318
- (*deleter)(KeySlice(), value);
319
- }
320
- }
321
- };
322
-
323
- struct ClockHandleMoreData : public ClockHandleBasicData {
324
- uint32_t hash = 0;
317
+ // Required by concept HandleImpl
318
+ const UniqueId64x2& GetHash() const { return hashed_key; }
325
319
  };
326
320
 
327
321
  // Target size to be exactly a common cache line size (see static_assert in
328
322
  // clock_cache.cc)
329
- struct ALIGN_AS(64U) ClockHandle : public ClockHandleMoreData {
323
+ struct ALIGN_AS(64U) ClockHandle : public ClockHandleBasicData {
330
324
  // Constants for handling the atomic `meta` word, which tracks most of the
331
325
  // state of the handle. The meta word looks like this:
332
326
  // low bits high bits
@@ -391,31 +385,31 @@ class ClockHandleTable {
391
385
  explicit ClockHandleTable(int hash_bits, bool initial_charge_metadata);
392
386
  ~ClockHandleTable();
393
387
 
394
- Status Insert(const ClockHandleMoreData& proto, ClockHandle** handle,
388
+ Status Insert(const ClockHandleBasicData& proto, ClockHandle** handle,
395
389
  Cache::Priority priority, size_t capacity,
396
390
  bool strict_capacity_limit);
397
391
 
398
- ClockHandle* Lookup(const CacheKeyBytes& key, uint32_t hash);
392
+ ClockHandle* Lookup(const UniqueId64x2& hashed_key);
399
393
 
400
394
  bool Release(ClockHandle* handle, bool useful, bool erase_if_last_ref);
401
395
 
402
396
  void Ref(ClockHandle& handle);
403
397
 
404
- void Erase(const CacheKeyBytes& key, uint32_t hash);
398
+ void Erase(const UniqueId64x2& hashed_key);
405
399
 
406
400
  void ConstApplyToEntriesRange(std::function<void(const ClockHandle&)> func,
407
- uint32_t index_begin, uint32_t index_end,
401
+ size_t index_begin, size_t index_end,
408
402
  bool apply_if_will_be_deleted) const;
409
403
 
410
404
  void EraseUnRefEntries();
411
405
 
412
- uint32_t GetTableSize() const { return uint32_t{1} << length_bits_; }
406
+ size_t GetTableSize() const { return size_t{1} << length_bits_; }
413
407
 
414
408
  int GetLengthBits() const { return length_bits_; }
415
409
 
416
- uint32_t GetOccupancyLimit() const { return occupancy_limit_; }
410
+ size_t GetOccupancyLimit() const { return occupancy_limit_; }
417
411
 
418
- uint32_t GetOccupancy() const {
412
+ size_t GetOccupancy() const {
419
413
  return occupancy_.load(std::memory_order_relaxed);
420
414
  }
421
415
 
@@ -431,13 +425,15 @@ class ClockHandleTable {
431
425
 
432
426
  private: // functions
433
427
  // Returns x mod 2^{length_bits_}.
434
- uint32_t ModTableSize(uint32_t x) { return x & length_bits_mask_; }
428
+ inline size_t ModTableSize(uint64_t x) {
429
+ return static_cast<size_t>(x) & length_bits_mask_;
430
+ }
435
431
 
436
432
  // Runs the clock eviction algorithm trying to reclaim at least
437
433
  // requested_charge. Returns how much is evicted, which could be less
438
434
  // if it appears impossible to evict the requested amount without blocking.
439
435
  void Evict(size_t requested_charge, size_t* freed_charge,
440
- uint32_t* freed_count);
436
+ size_t* freed_count);
441
437
 
442
438
  // Returns the first slot in the probe sequence, starting from the given
443
439
  // probe number, with a handle e such that match(e) is true. At every
@@ -450,15 +446,15 @@ class ClockHandleTable {
450
446
  // value of probe is one more than the last non-aborting probe during the
451
447
  // call. This is so that that the variable can be used to keep track of
452
448
  // progress across consecutive calls to FindSlot.
453
- inline ClockHandle* FindSlot(uint32_t hash,
449
+ inline ClockHandle* FindSlot(const UniqueId64x2& hashed_key,
454
450
  std::function<bool(ClockHandle*)> match,
455
451
  std::function<bool(ClockHandle*)> stop,
456
452
  std::function<void(ClockHandle*)> update,
457
- uint32_t& probe);
453
+ size_t& probe);
458
454
 
459
455
  // Re-decrement all displacements in probe path starting from beginning
460
456
  // until (not including) the given handle
461
- void Rollback(uint32_t hash, const ClockHandle* h);
457
+ void Rollback(const UniqueId64x2& hashed_key, const ClockHandle* h);
462
458
 
463
459
  private: // data
464
460
  // Number of hash bits used for table index.
@@ -466,10 +462,10 @@ class ClockHandleTable {
466
462
  const int length_bits_;
467
463
 
468
464
  // For faster computation of ModTableSize.
469
- const uint32_t length_bits_mask_;
465
+ const size_t length_bits_mask_;
470
466
 
471
467
  // Maximum number of elements the user can store in the table.
472
- const uint32_t occupancy_limit_;
468
+ const size_t occupancy_limit_;
473
469
 
474
470
  // Array of slots comprising the hash table.
475
471
  const std::unique_ptr<ClockHandle[]> array_;
@@ -484,7 +480,7 @@ class ClockHandleTable {
484
480
 
485
481
  ALIGN_AS(CACHE_LINE_SIZE)
486
482
  // Number of elements in the table.
487
- std::atomic<uint32_t> occupancy_{};
483
+ std::atomic<size_t> occupancy_{};
488
484
 
489
485
  // Memory usage by entries tracked by the cache (including detached)
490
486
  std::atomic<size_t> usage_{};
@@ -494,78 +490,107 @@ class ClockHandleTable {
494
490
  }; // class ClockHandleTable
495
491
 
496
492
  // A single shard of sharded cache.
497
- class ALIGN_AS(CACHE_LINE_SIZE) ClockCacheShard final : public CacheShard {
493
+ class ALIGN_AS(CACHE_LINE_SIZE) ClockCacheShard final : public CacheShardBase {
498
494
  public:
499
495
  ClockCacheShard(size_t capacity, size_t estimated_value_size,
500
496
  bool strict_capacity_limit,
501
497
  CacheMetadataChargePolicy metadata_charge_policy);
502
- ~ClockCacheShard() override = default;
503
498
 
504
- // TODO: document limitations
505
- void SetCapacity(size_t capacity) override;
499
+ // For CacheShard concept
500
+ using HandleImpl = ClockHandle;
501
+ // Hash is lossless hash of 128-bit key
502
+ using HashVal = UniqueId64x2;
503
+ using HashCref = const HashVal&;
504
+ static inline uint32_t HashPieceForSharding(HashCref hash) {
505
+ return Upper32of64(hash[0]);
506
+ }
507
+ static inline HashVal ComputeHash(const Slice& key) {
508
+ assert(key.size() == kCacheKeySize);
509
+ HashVal in;
510
+ HashVal out;
511
+ // NOTE: endian dependence
512
+ // TODO: use GetUnaligned?
513
+ std::memcpy(&in, key.data(), kCacheKeySize);
514
+ BijectiveHash2x64(in[1], in[0], &out[1], &out[0]);
515
+ return out;
516
+ }
517
+
518
+ // For reconstructing key from hashed_key. Requires the caller to provide
519
+ // backing storage for the Slice in `unhashed`
520
+ static inline Slice ReverseHash(const UniqueId64x2& hashed,
521
+ UniqueId64x2* unhashed) {
522
+ BijectiveUnhash2x64(hashed[1], hashed[0], &(*unhashed)[1], &(*unhashed)[0]);
523
+ // NOTE: endian dependence
524
+ return Slice(reinterpret_cast<const char*>(unhashed), kCacheKeySize);
525
+ }
526
+
527
+ // Although capacity is dynamically changeable, the number of table slots is
528
+ // not, so growing capacity substantially could lead to hitting occupancy
529
+ // limit.
530
+ void SetCapacity(size_t capacity);
506
531
 
507
- void SetStrictCapacityLimit(bool strict_capacity_limit) override;
532
+ void SetStrictCapacityLimit(bool strict_capacity_limit);
508
533
 
509
- Status Insert(const Slice& key, uint32_t hash, void* value, size_t charge,
510
- Cache::DeleterFn deleter, Cache::Handle** handle,
511
- Cache::Priority priority) override;
534
+ Status Insert(const Slice& key, const UniqueId64x2& hashed_key, void* value,
535
+ size_t charge, Cache::DeleterFn deleter, ClockHandle** handle,
536
+ Cache::Priority priority);
512
537
 
513
- Cache::Handle* Lookup(const Slice& key, uint32_t hash) override;
538
+ ClockHandle* Lookup(const Slice& key, const UniqueId64x2& hashed_key);
514
539
 
515
- bool Release(Cache::Handle* handle, bool useful,
516
- bool erase_if_last_ref) override;
540
+ bool Release(ClockHandle* handle, bool useful, bool erase_if_last_ref);
517
541
 
518
- bool Release(Cache::Handle* handle, bool erase_if_last_ref = false) override;
542
+ bool Release(ClockHandle* handle, bool erase_if_last_ref = false);
519
543
 
520
- bool Ref(Cache::Handle* handle) override;
544
+ bool Ref(ClockHandle* handle);
521
545
 
522
- void Erase(const Slice& key, uint32_t hash) override;
546
+ void Erase(const Slice& key, const UniqueId64x2& hashed_key);
523
547
 
524
- size_t GetUsage() const override;
548
+ size_t GetUsage() const;
525
549
 
526
- size_t GetPinnedUsage() const override;
550
+ size_t GetPinnedUsage() const;
527
551
 
528
- size_t GetOccupancyCount() const override;
552
+ size_t GetOccupancyCount() const;
529
553
 
530
- size_t GetTableAddressCount() const override;
554
+ size_t GetTableAddressCount() const;
531
555
 
532
556
  void ApplyToSomeEntries(
533
557
  const std::function<void(const Slice& key, void* value, size_t charge,
534
558
  DeleterFn deleter)>& callback,
535
- uint32_t average_entries_per_lock, uint32_t* state) override;
559
+ size_t average_entries_per_lock, size_t* state);
536
560
 
537
- void EraseUnRefEntries() override;
561
+ void EraseUnRefEntries();
538
562
 
539
- std::string GetPrintableOptions() const override { return std::string{}; }
563
+ std::string GetPrintableOptions() const { return std::string{}; }
540
564
 
541
565
  // SecondaryCache not yet supported
542
- Status Insert(const Slice& key, uint32_t hash, void* value,
566
+ Status Insert(const Slice& key, const UniqueId64x2& hashed_key, void* value,
543
567
  const Cache::CacheItemHelper* helper, size_t charge,
544
- Cache::Handle** handle, Cache::Priority priority) override {
545
- return Insert(key, hash, value, charge, helper->del_cb, handle, priority);
568
+ ClockHandle** handle, Cache::Priority priority) {
569
+ return Insert(key, hashed_key, value, charge, helper->del_cb, handle,
570
+ priority);
546
571
  }
547
572
 
548
- Cache::Handle* Lookup(const Slice& key, uint32_t hash,
549
- const Cache::CacheItemHelper* /*helper*/,
550
- const Cache::CreateCallback& /*create_cb*/,
551
- Cache::Priority /*priority*/, bool /*wait*/,
552
- Statistics* /*stats*/) override {
553
- return Lookup(key, hash);
573
+ ClockHandle* Lookup(const Slice& key, const UniqueId64x2& hashed_key,
574
+ const Cache::CacheItemHelper* /*helper*/,
575
+ const Cache::CreateCallback& /*create_cb*/,
576
+ Cache::Priority /*priority*/, bool /*wait*/,
577
+ Statistics* /*stats*/) {
578
+ return Lookup(key, hashed_key);
554
579
  }
555
580
 
556
- bool IsReady(Cache::Handle* /*handle*/) override { return true; }
581
+ bool IsReady(ClockHandle* /*handle*/) { return true; }
557
582
 
558
- void Wait(Cache::Handle* /*handle*/) override {}
583
+ void Wait(ClockHandle* /*handle*/) {}
559
584
 
560
585
  // Acquire/release N references
561
- void TEST_RefN(Cache::Handle* handle, size_t n);
562
- void TEST_ReleaseN(Cache::Handle* handle, size_t n);
586
+ void TEST_RefN(ClockHandle* handle, size_t n);
587
+ void TEST_ReleaseN(ClockHandle* handle, size_t n);
563
588
 
564
589
  private: // functions
565
590
  friend class ClockCache;
566
591
  friend class ClockCacheTest;
567
592
 
568
- ClockHandle* DetachedInsert(const ClockHandleMoreData& h);
593
+ ClockHandle* DetachedInsert(const ClockHandleBasicData& h);
569
594
 
570
595
  // Returns the number of bits used to hash an element in the hash
571
596
  // table.
@@ -586,35 +611,20 @@ class HyperClockCache
586
611
  #ifdef NDEBUG
587
612
  final
588
613
  #endif
589
- : public ShardedCache {
614
+ : public ShardedCache<ClockCacheShard> {
590
615
  public:
591
616
  HyperClockCache(size_t capacity, size_t estimated_value_size,
592
617
  int num_shard_bits, bool strict_capacity_limit,
593
- CacheMetadataChargePolicy metadata_charge_policy =
594
- kDontChargeCacheMetadata);
595
-
596
- ~HyperClockCache() override;
618
+ CacheMetadataChargePolicy metadata_charge_policy,
619
+ std::shared_ptr<MemoryAllocator> memory_allocator);
597
620
 
598
621
  const char* Name() const override { return "HyperClockCache"; }
599
622
 
600
- CacheShard* GetShard(uint32_t shard) override;
601
-
602
- const CacheShard* GetShard(uint32_t shard) const override;
603
-
604
623
  void* Value(Handle* handle) override;
605
624
 
606
625
  size_t GetCharge(Handle* handle) const override;
607
626
 
608
- uint32_t GetHash(Handle* handle) const override;
609
-
610
627
  DeleterFn GetDeleter(Handle* handle) const override;
611
-
612
- void DisownData() override;
613
-
614
- private:
615
- ClockCacheShard* shards_ = nullptr;
616
-
617
- int num_shards_;
618
628
  }; // class HyperClockCache
619
629
 
620
630
  } // namespace hyper_clock_cache
@@ -178,6 +178,19 @@ Status CompressedSecondaryCache::Insert(const Slice& key, void* value,
178
178
 
179
179
  void CompressedSecondaryCache::Erase(const Slice& key) { cache_->Erase(key); }
180
180
 
181
+ Status CompressedSecondaryCache::SetCapacity(size_t capacity) {
182
+ MutexLock l(&capacity_mutex_);
183
+ cache_options_.capacity = capacity;
184
+ cache_->SetCapacity(capacity);
185
+ return Status::OK();
186
+ }
187
+
188
+ Status CompressedSecondaryCache::GetCapacity(size_t& capacity) {
189
+ MutexLock l(&capacity_mutex_);
190
+ capacity = cache_options_.capacity;
191
+ return Status::OK();
192
+ }
193
+
181
194
  std::string CompressedSecondaryCache::GetPrintableOptions() const {
182
195
  std::string ret;
183
196
  ret.reserve(20000);
@@ -194,9 +207,9 @@ std::string CompressedSecondaryCache::GetPrintableOptions() const {
194
207
  }
195
208
 
196
209
  CompressedSecondaryCache::CacheValueChunk*
197
- CompressedSecondaryCache::SplitValueIntoChunks(
198
- const Slice& value, const CompressionType compression_type,
199
- size_t& charge) {
210
+ CompressedSecondaryCache::SplitValueIntoChunks(const Slice& value,
211
+ CompressionType compression_type,
212
+ size_t& charge) {
200
213
  assert(!value.empty());
201
214
  const char* src_ptr = value.data();
202
215
  size_t src_size{value.size()};
@@ -15,6 +15,7 @@
15
15
  #include "rocksdb/slice.h"
16
16
  #include "rocksdb/status.h"
17
17
  #include "util/compression.h"
18
+ #include "util/mutexlock.h"
18
19
 
19
20
  namespace ROCKSDB_NAMESPACE {
20
21
 
@@ -22,7 +23,7 @@ class CompressedSecondaryCacheResultHandle : public SecondaryCacheResultHandle {
22
23
  public:
23
24
  CompressedSecondaryCacheResultHandle(void* value, size_t size)
24
25
  : value_(value), size_(size) {}
25
- virtual ~CompressedSecondaryCacheResultHandle() override = default;
26
+ ~CompressedSecondaryCacheResultHandle() override = default;
26
27
 
27
28
  CompressedSecondaryCacheResultHandle(
28
29
  const CompressedSecondaryCacheResultHandle&) = delete;
@@ -78,7 +79,7 @@ class CompressedSecondaryCache : public SecondaryCache {
78
79
  CompressionType compression_type = CompressionType::kLZ4Compression,
79
80
  uint32_t compress_format_version = 2,
80
81
  bool enable_custom_split_merge = false);
81
- virtual ~CompressedSecondaryCache() override;
82
+ ~CompressedSecondaryCache() override;
82
83
 
83
84
  const char* Name() const override { return "CompressedSecondaryCache"; }
84
85
 
@@ -95,6 +96,10 @@ class CompressedSecondaryCache : public SecondaryCache {
95
96
 
96
97
  void WaitAll(std::vector<SecondaryCacheResultHandle*> /*handles*/) override {}
97
98
 
99
+ Status SetCapacity(size_t capacity) override;
100
+
101
+ Status GetCapacity(size_t& capacity) override;
102
+
98
103
  std::string GetPrintableOptions() const override;
99
104
 
100
105
  private:
@@ -116,7 +121,7 @@ class CompressedSecondaryCache : public SecondaryCache {
116
121
  // are stored in CacheValueChunk and extra charge is needed for each chunk,
117
122
  // so the cache charge is recalculated here.
118
123
  CacheValueChunk* SplitValueIntoChunks(const Slice& value,
119
- const CompressionType compression_type,
124
+ CompressionType compression_type,
120
125
  size_t& charge);
121
126
 
122
127
  // After merging chunks, the extra charge for each chunk is removed, so
@@ -128,6 +133,7 @@ class CompressedSecondaryCache : public SecondaryCache {
128
133
  static Cache::DeleterFn GetDeletionCallback(bool enable_custom_split_merge);
129
134
  std::shared_ptr<Cache> cache_;
130
135
  CompressedSecondaryCacheOptions cache_options_;
136
+ mutable port::Mutex capacity_mutex_;
131
137
  };
132
138
 
133
139
  } // namespace ROCKSDB_NAMESPACE
@@ -5,28 +5,21 @@
5
5
 
6
6
  #include "cache/compressed_secondary_cache.h"
7
7
 
8
- #include <algorithm>
9
- #include <cstdint>
10
8
  #include <iterator>
9
+ #include <memory>
11
10
  #include <tuple>
12
11
 
13
- #include "cache/lru_cache.h"
14
12
  #include "memory/jemalloc_nodump_allocator.h"
15
- #include "memory/memory_allocator.h"
16
- #include "rocksdb/compression_type.h"
17
13
  #include "rocksdb/convenience.h"
18
- #include "rocksdb/secondary_cache.h"
19
14
  #include "test_util/testharness.h"
20
15
  #include "test_util/testutil.h"
21
- #include "util/compression.h"
22
- #include "util/random.h"
23
16
 
24
17
  namespace ROCKSDB_NAMESPACE {
25
18
 
26
19
  class CompressedSecondaryCacheTest : public testing::Test {
27
20
  public:
28
21
  CompressedSecondaryCacheTest() : fail_create_(false) {}
29
- ~CompressedSecondaryCacheTest() {}
22
+ ~CompressedSecondaryCacheTest() override = default;
30
23
 
31
24
  protected:
32
25
  class TestItem {
@@ -34,10 +27,10 @@ class CompressedSecondaryCacheTest : public testing::Test {
34
27
  TestItem(const char* buf, size_t size) : buf_(new char[size]), size_(size) {
35
28
  memcpy(buf_.get(), buf, size);
36
29
  }
37
- ~TestItem() {}
30
+ ~TestItem() = default;
38
31
 
39
32
  char* Buf() { return buf_.get(); }
40
- size_t Size() { return size_; }
33
+ [[nodiscard]] size_t Size() const { return size_; }
41
34
 
42
35
  private:
43
36
  std::unique_ptr<char[]> buf_;
@@ -50,7 +43,7 @@ class CompressedSecondaryCacheTest : public testing::Test {
50
43
 
51
44
  static Status SaveToCallback(void* from_obj, size_t from_offset,
52
45
  size_t length, void* out) {
53
- TestItem* item = reinterpret_cast<TestItem*>(from_obj);
46
+ auto item = reinterpret_cast<TestItem*>(from_obj);
54
47
  const char* buf = item->Buf();
55
48
  EXPECT_EQ(length, item->Size());
56
49
  EXPECT_EQ(from_offset, 0);
@@ -315,12 +308,12 @@ class CompressedSecondaryCacheTest : public testing::Test {
315
308
  get_perf_context()->Reset();
316
309
  Random rnd(301);
317
310
  std::string str1 = rnd.RandomString(1001);
318
- TestItem* item1_1 = new TestItem(str1.data(), str1.length());
311
+ auto item1_1 = new TestItem(str1.data(), str1.length());
319
312
  ASSERT_OK(cache->Insert(
320
313
  "k1", item1_1, &CompressedSecondaryCacheTest::helper_, str1.length()));
321
314
 
322
315
  std::string str2 = rnd.RandomString(1012);
323
- TestItem* item2_1 = new TestItem(str2.data(), str2.length());
316
+ auto item2_1 = new TestItem(str2.data(), str2.length());
324
317
  // After this Insert, primary cache contains k2 and secondary cache contains
325
318
  // k1's dummy item.
326
319
  ASSERT_OK(cache->Insert(
@@ -330,7 +323,7 @@ class CompressedSecondaryCacheTest : public testing::Test {
330
323
  ASSERT_EQ(get_perf_context()->compressed_sec_cache_compressed_bytes, 0);
331
324
 
332
325
  std::string str3 = rnd.RandomString(1024);
333
- TestItem* item3_1 = new TestItem(str3.data(), str3.length());
326
+ auto item3_1 = new TestItem(str3.data(), str3.length());
334
327
  // After this Insert, primary cache contains k3 and secondary cache contains
335
328
  // k1's dummy item and k2's dummy item.
336
329
  ASSERT_OK(cache->Insert(
@@ -339,14 +332,14 @@ class CompressedSecondaryCacheTest : public testing::Test {
339
332
 
340
333
  // After this Insert, primary cache contains k1 and secondary cache contains
341
334
  // k1's dummy item, k2's dummy item, and k3's dummy item.
342
- TestItem* item1_2 = new TestItem(str1.data(), str1.length());
335
+ auto item1_2 = new TestItem(str1.data(), str1.length());
343
336
  ASSERT_OK(cache->Insert(
344
337
  "k1", item1_2, &CompressedSecondaryCacheTest::helper_, str1.length()));
345
338
  ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 3);
346
339
 
347
340
  // After this Insert, primary cache contains k2 and secondary cache contains
348
341
  // k1's item, k2's dummy item, and k3's dummy item.
349
- TestItem* item2_2 = new TestItem(str2.data(), str2.length());
342
+ auto item2_2 = new TestItem(str2.data(), str2.length());
350
343
  ASSERT_OK(cache->Insert(
351
344
  "k2", item2_2, &CompressedSecondaryCacheTest::helper_, str2.length()));
352
345
  ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 1);
@@ -362,7 +355,7 @@ class CompressedSecondaryCacheTest : public testing::Test {
362
355
 
363
356
  // After this Insert, primary cache contains k3 and secondary cache contains
364
357
  // k1's item and k2's item.
365
- TestItem* item3_2 = new TestItem(str3.data(), str3.length());
358
+ auto item3_2 = new TestItem(str3.data(), str3.length());
366
359
  ASSERT_OK(cache->Insert(
367
360
  "k3", item3_2, &CompressedSecondaryCacheTest::helper_, str3.length()));
368
361
  ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 2);
@@ -381,7 +374,7 @@ class CompressedSecondaryCacheTest : public testing::Test {
381
374
  test_item_creator, Cache::Priority::LOW, true,
382
375
  stats.get());
383
376
  ASSERT_NE(handle, nullptr);
384
- TestItem* val3 = static_cast<TestItem*>(cache->Value(handle));
377
+ auto val3 = static_cast<TestItem*>(cache->Value(handle));
385
378
  ASSERT_NE(val3, nullptr);
386
379
  ASSERT_EQ(memcmp(val3->Buf(), item3_2->Buf(), item3_2->Size()), 0);
387
380
  cache->Release(handle);
@@ -399,18 +392,20 @@ class CompressedSecondaryCacheTest : public testing::Test {
399
392
  stats.get());
400
393
  ASSERT_NE(handle, nullptr);
401
394
  ASSERT_EQ(get_perf_context()->block_cache_standalone_handle_count, 1);
402
- TestItem* val1_1 = static_cast<TestItem*>(cache->Value(handle));
395
+ auto val1_1 = static_cast<TestItem*>(cache->Value(handle));
403
396
  ASSERT_NE(val1_1, nullptr);
404
397
  ASSERT_EQ(memcmp(val1_1->Buf(), str1.data(), str1.size()), 0);
405
398
  cache->Release(handle);
406
399
 
407
400
  // This Lookup should erase k1 from the secondary cache and insert
408
401
  // it into primary cache; then k3 is demoted.
402
+ // k2 and k3 are in secondary cache.
409
403
  handle = cache->Lookup("k1", &CompressedSecondaryCacheTest::helper_,
410
404
  test_item_creator, Cache::Priority::LOW, true,
411
405
  stats.get());
412
406
  ASSERT_NE(handle, nullptr);
413
407
  ASSERT_EQ(get_perf_context()->block_cache_standalone_handle_count, 1);
408
+ ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 3);
414
409
  cache->Release(handle);
415
410
 
416
411
  // k2 is still in secondary cache.
@@ -421,6 +416,54 @@ class CompressedSecondaryCacheTest : public testing::Test {
421
416
  ASSERT_EQ(get_perf_context()->block_cache_standalone_handle_count, 2);
422
417
  cache->Release(handle);
423
418
 
419
+ // Testing SetCapacity().
420
+ ASSERT_OK(secondary_cache->SetCapacity(0));
421
+ handle = cache->Lookup("k3", &CompressedSecondaryCacheTest::helper_,
422
+ test_item_creator, Cache::Priority::LOW, true,
423
+ stats.get());
424
+ ASSERT_EQ(handle, nullptr);
425
+
426
+ ASSERT_OK(secondary_cache->SetCapacity(7000));
427
+ size_t capacity;
428
+ ASSERT_OK(secondary_cache->GetCapacity(capacity));
429
+ ASSERT_EQ(capacity, 7000);
430
+ auto item1_3 = new TestItem(str1.data(), str1.length());
431
+ // After this Insert, primary cache contains k1.
432
+ ASSERT_OK(cache->Insert(
433
+ "k1", item1_3, &CompressedSecondaryCacheTest::helper_, str2.length()));
434
+ ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 3);
435
+ ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 4);
436
+
437
+ auto item2_3 = new TestItem(str2.data(), str2.length());
438
+ // After this Insert, primary cache contains k2 and secondary cache contains
439
+ // k1's dummy item.
440
+ ASSERT_OK(cache->Insert(
441
+ "k2", item2_3, &CompressedSecondaryCacheTest::helper_, str1.length()));
442
+ ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 4);
443
+
444
+ auto item1_4 = new TestItem(str1.data(), str1.length());
445
+ // After this Insert, primary cache contains k1 and secondary cache contains
446
+ // k1's dummy item and k2's dummy item.
447
+ ASSERT_OK(cache->Insert(
448
+ "k1", item1_4, &CompressedSecondaryCacheTest::helper_, str2.length()));
449
+ ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 5);
450
+
451
+ auto item2_4 = new TestItem(str2.data(), str2.length());
452
+ // After this Insert, primary cache contains k2 and secondary cache contains
453
+ // k1's real item and k2's dummy item.
454
+ ASSERT_OK(cache->Insert(
455
+ "k2", item2_4, &CompressedSecondaryCacheTest::helper_, str2.length()));
456
+ ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 5);
457
+ // This Lookup should just insert a dummy handle in the primary cache
458
+ // and the k1 is still in the secondary cache.
459
+ handle = cache->Lookup("k1", &CompressedSecondaryCacheTest::helper_,
460
+ test_item_creator, Cache::Priority::LOW, true,
461
+ stats.get());
462
+
463
+ ASSERT_NE(handle, nullptr);
464
+ cache->Release(handle);
465
+ ASSERT_EQ(get_perf_context()->block_cache_standalone_handle_count, 3);
466
+
424
467
  cache.reset();
425
468
  secondary_cache.reset();
426
469
  }
@@ -452,8 +495,7 @@ class CompressedSecondaryCacheTest : public testing::Test {
452
495
 
453
496
  Random rnd(301);
454
497
  std::string str1 = rnd.RandomString(1001);
455
- auto item1 =
456
- std::unique_ptr<TestItem>(new TestItem(str1.data(), str1.length()));
498
+ auto item1 = std::make_unique<TestItem>(str1.data(), str1.length());
457
499
  ASSERT_NOK(cache->Insert("k1", item1.get(), nullptr, str1.length()));
458
500
  ASSERT_OK(cache->Insert("k1", item1.get(),
459
501
  &CompressedSecondaryCacheTest::helper_,
@@ -500,13 +542,13 @@ class CompressedSecondaryCacheTest : public testing::Test {
500
542
 
501
543
  Random rnd(301);
502
544
  std::string str1 = rnd.RandomString(1001);
503
- TestItem* item1 = new TestItem(str1.data(), str1.length());
545
+ auto item1 = new TestItem(str1.data(), str1.length());
504
546
  ASSERT_OK(cache->Insert("k1", item1,
505
547
  &CompressedSecondaryCacheTest::helper_fail_,
506
548
  str1.length()));
507
549
 
508
550
  std::string str2 = rnd.RandomString(1002);
509
- TestItem* item2 = new TestItem(str2.data(), str2.length());
551
+ auto item2 = new TestItem(str2.data(), str2.length());
510
552
  // k1 should be demoted to the secondary cache.
511
553
  ASSERT_OK(cache->Insert("k2", item2,
512
554
  &CompressedSecondaryCacheTest::helper_fail_,
@@ -559,12 +601,12 @@ class CompressedSecondaryCacheTest : public testing::Test {
559
601
 
560
602
  Random rnd(301);
561
603
  std::string str1 = rnd.RandomString(1001);
562
- TestItem* item1 = new TestItem(str1.data(), str1.length());
604
+ auto item1 = new TestItem(str1.data(), str1.length());
563
605
  ASSERT_OK(cache->Insert("k1", item1, &CompressedSecondaryCacheTest::helper_,
564
606
  str1.length()));
565
607
 
566
608
  std::string str2 = rnd.RandomString(1002);
567
- TestItem* item2 = new TestItem(str2.data(), str2.length());
609
+ auto item2 = new TestItem(str2.data(), str2.length());
568
610
  // k1 should be demoted to the secondary cache.
569
611
  ASSERT_OK(cache->Insert("k2", item2, &CompressedSecondaryCacheTest::helper_,
570
612
  str2.length()));
@@ -617,13 +659,13 @@ class CompressedSecondaryCacheTest : public testing::Test {
617
659
 
618
660
  Random rnd(301);
619
661
  std::string str1 = rnd.RandomString(1001);
620
- TestItem* item1_1 = new TestItem(str1.data(), str1.length());
662
+ auto item1_1 = new TestItem(str1.data(), str1.length());
621
663
  ASSERT_OK(cache->Insert(
622
664
  "k1", item1_1, &CompressedSecondaryCacheTest::helper_, str1.length()));
623
665
 
624
666
  std::string str2 = rnd.RandomString(1002);
625
667
  std::string str2_clone{str2};
626
- TestItem* item2 = new TestItem(str2.data(), str2.length());
668
+ auto item2 = new TestItem(str2.data(), str2.length());
627
669
  // After this Insert, primary cache contains k2 and secondary cache contains
628
670
  // k1's dummy item.
629
671
  ASSERT_OK(cache->Insert("k2", item2, &CompressedSecondaryCacheTest::helper_,
@@ -631,11 +673,11 @@ class CompressedSecondaryCacheTest : public testing::Test {
631
673
 
632
674
  // After this Insert, primary cache contains k1 and secondary cache contains
633
675
  // k1's dummy item and k2's dummy item.
634
- TestItem* item1_2 = new TestItem(str1.data(), str1.length());
676
+ auto item1_2 = new TestItem(str1.data(), str1.length());
635
677
  ASSERT_OK(cache->Insert(
636
678
  "k1", item1_2, &CompressedSecondaryCacheTest::helper_, str1.length()));
637
679
 
638
- TestItem* item2_2 = new TestItem(str2.data(), str2.length());
680
+ auto item2_2 = new TestItem(str2.data(), str2.length());
639
681
  // After this Insert, primary cache contains k2 and secondary cache contains
640
682
  // k1's item and k2's dummy item.
641
683
  ASSERT_OK(cache->Insert(
@@ -957,6 +999,7 @@ TEST_F(CompressedSecondaryCacheTest, SplictValueAndMergeChunksTest) {
957
999
  } // namespace ROCKSDB_NAMESPACE
958
1000
 
959
1001
  int main(int argc, char** argv) {
1002
+ ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
960
1003
  ::testing::InitGoogleTest(&argc, argv);
961
1004
  return RUN_ALL_TESTS();
962
1005
  }