@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
@@ -67,7 +67,7 @@ class LRUCacheTest : public testing::Test {
67
67
  bool Lookup(const std::string& key) {
68
68
  auto handle = cache_->Lookup(key, 0 /*hash*/);
69
69
  if (handle) {
70
- cache_->Release(handle);
70
+ cache_->Release(handle, true /*useful*/, false /*erase*/);
71
71
  return true;
72
72
  }
73
73
  return false;
@@ -529,22 +529,27 @@ class ClockCacheTest : public testing::Test {
529
529
  kDontChargeCacheMetadata);
530
530
  }
531
531
 
532
- Status Insert(const std::string& key,
532
+ Status Insert(const UniqueId64x2& hashed_key,
533
533
  Cache::Priority priority = Cache::Priority::LOW) {
534
- return shard_->Insert(key, 0 /*hash*/, nullptr /*value*/, 1 /*charge*/,
535
- nullptr /*deleter*/, nullptr /*handle*/, priority);
534
+ return shard_->Insert(TestKey(hashed_key), hashed_key, nullptr /*value*/,
535
+ 1 /*charge*/, nullptr /*deleter*/, nullptr /*handle*/,
536
+ priority);
536
537
  }
537
538
 
538
539
  Status Insert(char key, Cache::Priority priority = Cache::Priority::LOW) {
539
- return Insert(std::string(kCacheKeySize, key), priority);
540
+ return Insert(TestHashedKey(key), priority);
540
541
  }
541
542
 
542
543
  Status InsertWithLen(char key, size_t len) {
543
- return Insert(std::string(len, key));
544
+ std::string skey(len, key);
545
+ return shard_->Insert(skey, TestHashedKey(key), nullptr /*value*/,
546
+ 1 /*charge*/, nullptr /*deleter*/, nullptr /*handle*/,
547
+ Cache::Priority::LOW);
544
548
  }
545
549
 
546
- bool Lookup(const std::string& key, bool useful = true) {
547
- auto handle = shard_->Lookup(key, 0 /*hash*/);
550
+ bool Lookup(const Slice& key, const UniqueId64x2& hashed_key,
551
+ bool useful = true) {
552
+ auto handle = shard_->Lookup(key, hashed_key);
548
553
  if (handle) {
549
554
  shard_->Release(handle, useful, /*erase_if_last_ref=*/false);
550
555
  return true;
@@ -552,43 +557,28 @@ class ClockCacheTest : public testing::Test {
552
557
  return false;
553
558
  }
554
559
 
555
- bool Lookup(char key, bool useful = true) {
556
- return Lookup(std::string(kCacheKeySize, key), useful);
560
+ bool Lookup(const UniqueId64x2& hashed_key, bool useful = true) {
561
+ return Lookup(TestKey(hashed_key), hashed_key, useful);
557
562
  }
558
563
 
559
- void Erase(const std::string& key) { shard_->Erase(key, 0 /*hash*/); }
560
-
561
- #if 0 // FIXME
562
- size_t CalcEstimatedHandleChargeWrapper(
563
- size_t estimated_value_size,
564
- CacheMetadataChargePolicy metadata_charge_policy) {
565
- return ClockCacheShard::CalcEstimatedHandleCharge(estimated_value_size,
566
- metadata_charge_policy);
564
+ bool Lookup(char key, bool useful = true) {
565
+ return Lookup(TestHashedKey(key), useful);
567
566
  }
568
567
 
569
- int CalcHashBitsWrapper(size_t capacity, size_t estimated_value_size,
570
- CacheMetadataChargePolicy metadata_charge_policy) {
571
- return ClockCacheShard::CalcHashBits(capacity, estimated_value_size,
572
- metadata_charge_policy);
568
+ void Erase(char key) {
569
+ UniqueId64x2 hashed_key = TestHashedKey(key);
570
+ shard_->Erase(TestKey(hashed_key), hashed_key);
573
571
  }
574
572
 
575
- // Maximum number of items that a shard can hold.
576
- double CalcMaxOccupancy(size_t capacity, size_t estimated_value_size,
577
- CacheMetadataChargePolicy metadata_charge_policy) {
578
- size_t handle_charge = ClockCacheShard::CalcEstimatedHandleCharge(
579
- estimated_value_size, metadata_charge_policy);
580
- return capacity / (kLoadFactor * handle_charge);
573
+ static inline Slice TestKey(const UniqueId64x2& hashed_key) {
574
+ return Slice(reinterpret_cast<const char*>(&hashed_key), 16U);
581
575
  }
582
576
 
583
- bool TableSizeIsAppropriate(int hash_bits, double max_occupancy) {
584
- if (hash_bits == 0) {
585
- return max_occupancy <= 1;
586
- } else {
587
- return (1 << hash_bits >= max_occupancy) &&
588
- (1 << (hash_bits - 1) <= max_occupancy);
589
- }
577
+ static inline UniqueId64x2 TestHashedKey(char key) {
578
+ // For testing hash near-collision behavior, put the variance in
579
+ // hashed_key in bits that are unlikely to be used as hash bits.
580
+ return {(static_cast<uint64_t>(key) << 56) + 1234U, 5678U};
590
581
  }
591
- #endif
592
582
 
593
583
  ClockCacheShard* shard_ = nullptr;
594
584
  };
@@ -607,10 +597,10 @@ TEST_F(ClockCacheTest, Misc) {
607
597
 
608
598
  // Some of this is motivated by code coverage
609
599
  std::string wrong_size_key(15, 'x');
610
- EXPECT_FALSE(Lookup(wrong_size_key));
600
+ EXPECT_FALSE(Lookup(wrong_size_key, TestHashedKey('x')));
611
601
  EXPECT_FALSE(shard_->Ref(nullptr));
612
602
  EXPECT_FALSE(shard_->Release(nullptr));
613
- shard_->Erase(wrong_size_key, /*hash*/ 42); // no-op
603
+ shard_->Erase(wrong_size_key, TestHashedKey('x')); // no-op
614
604
  }
615
605
 
616
606
  TEST_F(ClockCacheTest, Limits) {
@@ -622,11 +612,11 @@ TEST_F(ClockCacheTest, Limits) {
622
612
  // Also tests switching between strict limit and not
623
613
  shard_->SetStrictCapacityLimit(strict_capacity_limit);
624
614
 
625
- std::string key(16, 'x');
615
+ UniqueId64x2 hkey = TestHashedKey('x');
626
616
 
627
617
  // Single entry charge beyond capacity
628
618
  {
629
- Status s = shard_->Insert(key, 0 /*hash*/, nullptr /*value*/,
619
+ Status s = shard_->Insert(TestKey(hkey), hkey, nullptr /*value*/,
630
620
  5 /*charge*/, nullptr /*deleter*/,
631
621
  nullptr /*handle*/, Cache::Priority::LOW);
632
622
  if (strict_capacity_limit) {
@@ -638,9 +628,10 @@ TEST_F(ClockCacheTest, Limits) {
638
628
 
639
629
  // Single entry fills capacity
640
630
  {
641
- Cache::Handle* h;
642
- ASSERT_OK(shard_->Insert(key, 0 /*hash*/, nullptr /*value*/, 3 /*charge*/,
643
- nullptr /*deleter*/, &h, Cache::Priority::LOW));
631
+ ClockHandle* h;
632
+ ASSERT_OK(shard_->Insert(TestKey(hkey), hkey, nullptr /*value*/,
633
+ 3 /*charge*/, nullptr /*deleter*/, &h,
634
+ Cache::Priority::LOW));
644
635
  // Try to insert more
645
636
  Status s = Insert('a');
646
637
  if (strict_capacity_limit) {
@@ -657,11 +648,11 @@ TEST_F(ClockCacheTest, Limits) {
657
648
  // entries) to exceed occupancy limit.
658
649
  {
659
650
  size_t n = shard_->GetTableAddressCount() + 1;
660
- std::unique_ptr<Cache::Handle* []> ha { new Cache::Handle* [n] {} };
651
+ std::unique_ptr<ClockHandle* []> ha { new ClockHandle* [n] {} };
661
652
  Status s;
662
653
  for (size_t i = 0; i < n && s.ok(); ++i) {
663
- EncodeFixed64(&key[0], i);
664
- s = shard_->Insert(key, 0 /*hash*/, nullptr /*value*/, 0 /*charge*/,
654
+ hkey[1] = i;
655
+ s = shard_->Insert(TestKey(hkey), hkey, nullptr /*value*/, 0 /*charge*/,
665
656
  nullptr /*deleter*/, &ha[i], Cache::Priority::LOW);
666
657
  if (i == 0) {
667
658
  EXPECT_OK(s);
@@ -807,12 +798,11 @@ void IncrementIntDeleter(const Slice& /*key*/, void* value) {
807
798
  // Testing calls to CorrectNearOverflow in Release
808
799
  TEST_F(ClockCacheTest, ClockCounterOverflowTest) {
809
800
  NewShard(6, /*strict_capacity_limit*/ false);
810
- Cache::Handle* h;
801
+ ClockHandle* h;
811
802
  int deleted = 0;
812
- std::string my_key(kCacheKeySize, 'x');
813
- uint32_t my_hash = 42;
814
- ASSERT_OK(shard_->Insert(my_key, my_hash, &deleted, 1, IncrementIntDeleter,
815
- &h, Cache::Priority::HIGH));
803
+ UniqueId64x2 hkey = TestHashedKey('x');
804
+ ASSERT_OK(shard_->Insert(TestKey(hkey), hkey, &deleted, 1,
805
+ IncrementIntDeleter, &h, Cache::Priority::HIGH));
816
806
 
817
807
  // Some large number outstanding
818
808
  shard_->TEST_RefN(h, 123456789);
@@ -822,7 +812,7 @@ TEST_F(ClockCacheTest, ClockCounterOverflowTest) {
822
812
  shard_->TEST_ReleaseN(h, 1234567);
823
813
  }
824
814
  // Mark it invisible (to reach a different CorrectNearOverflow() in Release)
825
- shard_->Erase(my_key, my_hash);
815
+ shard_->Erase(TestKey(hkey), hkey);
826
816
  // Simulate many more lookup/ref + release (one-by-one would be too
827
817
  // expensive for unit test)
828
818
  for (int i = 0; i < 10000; ++i) {
@@ -844,63 +834,65 @@ TEST_F(ClockCacheTest, ClockCounterOverflowTest) {
844
834
  TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
845
835
  NewShard(6, /*strict_capacity_limit*/ false);
846
836
  int deleted = 0;
847
- std::string key1(kCacheKeySize, 'x');
848
- std::string key2(kCacheKeySize, 'y');
849
- std::string key3(kCacheKeySize, 'z');
850
- uint32_t my_hash = 42;
851
- Cache::Handle* h1;
852
- ASSERT_OK(shard_->Insert(key1, my_hash, &deleted, 1, IncrementIntDeleter, &h1,
837
+ UniqueId64x2 hkey1 = TestHashedKey('x');
838
+ Slice key1 = TestKey(hkey1);
839
+ UniqueId64x2 hkey2 = TestHashedKey('y');
840
+ Slice key2 = TestKey(hkey2);
841
+ UniqueId64x2 hkey3 = TestHashedKey('z');
842
+ Slice key3 = TestKey(hkey3);
843
+ ClockHandle* h1;
844
+ ASSERT_OK(shard_->Insert(key1, hkey1, &deleted, 1, IncrementIntDeleter, &h1,
853
845
  Cache::Priority::HIGH));
854
- Cache::Handle* h2;
855
- ASSERT_OK(shard_->Insert(key2, my_hash, &deleted, 1, IncrementIntDeleter, &h2,
846
+ ClockHandle* h2;
847
+ ASSERT_OK(shard_->Insert(key2, hkey2, &deleted, 1, IncrementIntDeleter, &h2,
856
848
  Cache::Priority::HIGH));
857
- Cache::Handle* h3;
858
- ASSERT_OK(shard_->Insert(key3, my_hash, &deleted, 1, IncrementIntDeleter, &h3,
849
+ ClockHandle* h3;
850
+ ASSERT_OK(shard_->Insert(key3, hkey3, &deleted, 1, IncrementIntDeleter, &h3,
859
851
  Cache::Priority::HIGH));
860
852
 
861
853
  // Can repeatedly lookup+release despite the hash collision
862
- Cache::Handle* tmp_h;
854
+ ClockHandle* tmp_h;
863
855
  for (bool erase_if_last_ref : {true, false}) { // but not last ref
864
- tmp_h = shard_->Lookup(key1, my_hash);
856
+ tmp_h = shard_->Lookup(key1, hkey1);
865
857
  ASSERT_EQ(h1, tmp_h);
866
858
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
867
859
 
868
- tmp_h = shard_->Lookup(key2, my_hash);
860
+ tmp_h = shard_->Lookup(key2, hkey2);
869
861
  ASSERT_EQ(h2, tmp_h);
870
862
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
871
863
 
872
- tmp_h = shard_->Lookup(key3, my_hash);
864
+ tmp_h = shard_->Lookup(key3, hkey3);
873
865
  ASSERT_EQ(h3, tmp_h);
874
866
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
875
867
  }
876
868
 
877
869
  // Make h1 invisible
878
- shard_->Erase(key1, my_hash);
870
+ shard_->Erase(key1, hkey1);
879
871
  // Redundant erase
880
- shard_->Erase(key1, my_hash);
872
+ shard_->Erase(key1, hkey1);
881
873
 
882
874
  // All still alive
883
875
  ASSERT_EQ(deleted, 0);
884
876
 
885
877
  // Invisible to Lookup
886
- tmp_h = shard_->Lookup(key1, my_hash);
878
+ tmp_h = shard_->Lookup(key1, hkey1);
887
879
  ASSERT_EQ(nullptr, tmp_h);
888
880
 
889
881
  // Can still find h2, h3
890
882
  for (bool erase_if_last_ref : {true, false}) { // but not last ref
891
- tmp_h = shard_->Lookup(key2, my_hash);
883
+ tmp_h = shard_->Lookup(key2, hkey2);
892
884
  ASSERT_EQ(h2, tmp_h);
893
885
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
894
886
 
895
- tmp_h = shard_->Lookup(key3, my_hash);
887
+ tmp_h = shard_->Lookup(key3, hkey3);
896
888
  ASSERT_EQ(h3, tmp_h);
897
889
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
898
890
  }
899
891
 
900
892
  // Also Insert with invisible entry there
901
- ASSERT_OK(shard_->Insert(key1, my_hash, &deleted, 1, IncrementIntDeleter,
893
+ ASSERT_OK(shard_->Insert(key1, hkey1, &deleted, 1, IncrementIntDeleter,
902
894
  nullptr, Cache::Priority::HIGH));
903
- tmp_h = shard_->Lookup(key1, my_hash);
895
+ tmp_h = shard_->Lookup(key1, hkey1);
904
896
  // Found but distinct handle
905
897
  ASSERT_NE(nullptr, tmp_h);
906
898
  ASSERT_NE(h1, tmp_h);
@@ -918,11 +910,11 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
918
910
 
919
911
  // Can still find h2, h3
920
912
  for (bool erase_if_last_ref : {true, false}) { // but not last ref
921
- tmp_h = shard_->Lookup(key2, my_hash);
913
+ tmp_h = shard_->Lookup(key2, hkey2);
922
914
  ASSERT_EQ(h2, tmp_h);
923
915
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
924
916
 
925
- tmp_h = shard_->Lookup(key3, my_hash);
917
+ tmp_h = shard_->Lookup(key3, hkey3);
926
918
  ASSERT_EQ(h3, tmp_h);
927
919
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
928
920
  }
@@ -934,7 +926,7 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
934
926
  ASSERT_EQ(deleted, 0);
935
927
 
936
928
  // Can still find it
937
- tmp_h = shard_->Lookup(key2, my_hash);
929
+ tmp_h = shard_->Lookup(key2, hkey2);
938
930
  ASSERT_EQ(h2, tmp_h);
939
931
 
940
932
  // Release last ref on h2, with erase
@@ -942,12 +934,12 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
942
934
 
943
935
  // h2 deleted
944
936
  ASSERT_EQ(deleted--, 1);
945
- tmp_h = shard_->Lookup(key2, my_hash);
937
+ tmp_h = shard_->Lookup(key2, hkey2);
946
938
  ASSERT_EQ(nullptr, tmp_h);
947
939
 
948
940
  // Can still find h3
949
941
  for (bool erase_if_last_ref : {true, false}) { // but not last ref
950
- tmp_h = shard_->Lookup(key3, my_hash);
942
+ tmp_h = shard_->Lookup(key3, hkey3);
951
943
  ASSERT_EQ(h3, tmp_h);
952
944
  ASSERT_FALSE(shard_->Release(tmp_h, erase_if_last_ref));
953
945
  }
@@ -959,11 +951,11 @@ TEST_F(ClockCacheTest, CollidingInsertEraseTest) {
959
951
  ASSERT_EQ(deleted, 0);
960
952
 
961
953
  // Explicit erase
962
- shard_->Erase(key3, my_hash);
954
+ shard_->Erase(key3, hkey3);
963
955
 
964
956
  // h3 deleted
965
957
  ASSERT_EQ(deleted--, 1);
966
- tmp_h = shard_->Lookup(key3, my_hash);
958
+ tmp_h = shard_->Lookup(key3, hkey3);
967
959
  ASSERT_EQ(nullptr, tmp_h);
968
960
  }
969
961
 
@@ -1371,9 +1363,11 @@ TEST_F(LRUCacheSecondaryCacheTest, SaveFailTest) {
1371
1363
  std::string str2 = rnd.RandomString(1020);
1372
1364
  TestItem* item2 = new TestItem(str2.data(), str2.length());
1373
1365
  // k1 should be demoted to NVM
1366
+ ASSERT_EQ(secondary_cache->num_inserts(), 0u);
1374
1367
  ASSERT_OK(cache->Insert(k2.AsSlice(), item2,
1375
1368
  &LRUCacheSecondaryCacheTest::helper_fail_,
1376
1369
  str2.length()));
1370
+ ASSERT_EQ(secondary_cache->num_inserts(), 1u);
1377
1371
 
1378
1372
  Cache::Handle* handle;
1379
1373
  handle =
@@ -2703,6 +2697,7 @@ TEST_F(DBSecondaryCacheTest, TestSecondaryCacheOptionTwoDB) {
2703
2697
  } // namespace ROCKSDB_NAMESPACE
2704
2698
 
2705
2699
  int main(int argc, char** argv) {
2700
+ ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
2706
2701
  ::testing::InitGoogleTest(&argc, argv);
2707
2702
  return RUN_ALL_TESTS();
2708
2703
  }
@@ -19,184 +19,49 @@
19
19
 
20
20
  namespace ROCKSDB_NAMESPACE {
21
21
 
22
- namespace {
23
-
24
- inline uint32_t HashSlice(const Slice& s) {
25
- return Lower32of64(GetSliceNPHash64(s));
26
- }
27
-
28
- } // namespace
29
-
30
- ShardedCache::ShardedCache(size_t capacity, int num_shard_bits,
31
- bool strict_capacity_limit,
32
- std::shared_ptr<MemoryAllocator> allocator)
22
+ ShardedCacheBase::ShardedCacheBase(size_t capacity, int num_shard_bits,
23
+ bool strict_capacity_limit,
24
+ std::shared_ptr<MemoryAllocator> allocator)
33
25
  : Cache(std::move(allocator)),
26
+ last_id_(1),
34
27
  shard_mask_((uint32_t{1} << num_shard_bits) - 1),
35
- capacity_(capacity),
36
28
  strict_capacity_limit_(strict_capacity_limit),
37
- last_id_(1) {}
29
+ capacity_(capacity) {}
38
30
 
39
- void ShardedCache::SetCapacity(size_t capacity) {
31
+ size_t ShardedCacheBase::ComputePerShardCapacity(size_t capacity) const {
40
32
  uint32_t num_shards = GetNumShards();
41
- const size_t per_shard = (capacity + (num_shards - 1)) / num_shards;
42
- MutexLock l(&capacity_mutex_);
43
- for (uint32_t s = 0; s < num_shards; s++) {
44
- GetShard(s)->SetCapacity(per_shard);
45
- }
46
- capacity_ = capacity;
47
- }
48
-
49
- void ShardedCache::SetStrictCapacityLimit(bool strict_capacity_limit) {
50
- uint32_t num_shards = GetNumShards();
51
- MutexLock l(&capacity_mutex_);
52
- for (uint32_t s = 0; s < num_shards; s++) {
53
- GetShard(s)->SetStrictCapacityLimit(strict_capacity_limit);
54
- }
55
- strict_capacity_limit_ = strict_capacity_limit;
56
- }
57
-
58
- Status ShardedCache::Insert(const Slice& key, void* value, size_t charge,
59
- DeleterFn deleter, Handle** handle,
60
- Priority priority) {
61
- uint32_t hash = HashSlice(key);
62
- return GetShard(Shard(hash))
63
- ->Insert(key, hash, value, charge, deleter, handle, priority);
64
- }
65
-
66
- Status ShardedCache::Insert(const Slice& key, void* value,
67
- const CacheItemHelper* helper, size_t charge,
68
- Handle** handle, Priority priority) {
69
- uint32_t hash = HashSlice(key);
70
- if (!helper) {
71
- return Status::InvalidArgument();
72
- }
73
- return GetShard(Shard(hash))
74
- ->Insert(key, hash, value, helper, charge, handle, priority);
75
- }
76
-
77
- Cache::Handle* ShardedCache::Lookup(const Slice& key, Statistics* /*stats*/) {
78
- uint32_t hash = HashSlice(key);
79
- return GetShard(Shard(hash))->Lookup(key, hash);
80
- }
81
-
82
- Cache::Handle* ShardedCache::Lookup(const Slice& key,
83
- const CacheItemHelper* helper,
84
- const CreateCallback& create_cb,
85
- Priority priority, bool wait,
86
- Statistics* stats) {
87
- uint32_t hash = HashSlice(key);
88
- return GetShard(Shard(hash))
89
- ->Lookup(key, hash, helper, create_cb, priority, wait, stats);
90
- }
91
-
92
- bool ShardedCache::IsReady(Handle* handle) {
93
- uint32_t hash = GetHash(handle);
94
- return GetShard(Shard(hash))->IsReady(handle);
95
- }
96
-
97
- void ShardedCache::Wait(Handle* handle) {
98
- uint32_t hash = GetHash(handle);
99
- GetShard(Shard(hash))->Wait(handle);
100
- }
101
-
102
- bool ShardedCache::Ref(Handle* handle) {
103
- uint32_t hash = GetHash(handle);
104
- return GetShard(Shard(hash))->Ref(handle);
105
- }
106
-
107
- bool ShardedCache::Release(Handle* handle, bool erase_if_last_ref) {
108
- uint32_t hash = GetHash(handle);
109
- return GetShard(Shard(hash))->Release(handle, erase_if_last_ref);
33
+ return (capacity + (num_shards - 1)) / num_shards;
110
34
  }
111
35
 
112
- bool ShardedCache::Release(Handle* handle, bool useful,
113
- bool erase_if_last_ref) {
114
- uint32_t hash = GetHash(handle);
115
- return GetShard(Shard(hash))->Release(handle, useful, erase_if_last_ref);
36
+ size_t ShardedCacheBase::GetPerShardCapacity() const {
37
+ return ComputePerShardCapacity(GetCapacity());
116
38
  }
117
39
 
118
- void ShardedCache::Erase(const Slice& key) {
119
- uint32_t hash = HashSlice(key);
120
- GetShard(Shard(hash))->Erase(key, hash);
121
- }
122
-
123
- uint64_t ShardedCache::NewId() {
40
+ uint64_t ShardedCacheBase::NewId() {
124
41
  return last_id_.fetch_add(1, std::memory_order_relaxed);
125
42
  }
126
43
 
127
- size_t ShardedCache::GetCapacity() const {
128
- MutexLock l(&capacity_mutex_);
44
+ size_t ShardedCacheBase::GetCapacity() const {
45
+ MutexLock l(&config_mutex_);
129
46
  return capacity_;
130
47
  }
131
48
 
132
- bool ShardedCache::HasStrictCapacityLimit() const {
133
- MutexLock l(&capacity_mutex_);
49
+ bool ShardedCacheBase::HasStrictCapacityLimit() const {
50
+ MutexLock l(&config_mutex_);
134
51
  return strict_capacity_limit_;
135
52
  }
136
53
 
137
- size_t ShardedCache::GetUsage() const {
138
- // We will not lock the cache when getting the usage from shards.
139
- uint32_t num_shards = GetNumShards();
140
- size_t usage = 0;
141
- for (uint32_t s = 0; s < num_shards; s++) {
142
- usage += GetShard(s)->GetUsage();
143
- }
144
- return usage;
145
- }
146
-
147
- size_t ShardedCache::GetUsage(Handle* handle) const {
54
+ size_t ShardedCacheBase::GetUsage(Handle* handle) const {
148
55
  return GetCharge(handle);
149
56
  }
150
57
 
151
- size_t ShardedCache::GetPinnedUsage() const {
152
- // We will not lock the cache when getting the usage from shards.
153
- uint32_t num_shards = GetNumShards();
154
- size_t usage = 0;
155
- for (uint32_t s = 0; s < num_shards; s++) {
156
- usage += GetShard(s)->GetPinnedUsage();
157
- }
158
- return usage;
159
- }
160
-
161
- void ShardedCache::ApplyToAllEntries(
162
- const std::function<void(const Slice& key, void* value, size_t charge,
163
- DeleterFn deleter)>& callback,
164
- const ApplyToAllEntriesOptions& opts) {
165
- uint32_t num_shards = GetNumShards();
166
- // Iterate over part of each shard, rotating between shards, to
167
- // minimize impact on latency of concurrent operations.
168
- std::unique_ptr<uint32_t[]> states(new uint32_t[num_shards]{});
169
-
170
- uint32_t aepl_in_32 = static_cast<uint32_t>(
171
- std::min(size_t{UINT32_MAX}, opts.average_entries_per_lock));
172
- aepl_in_32 = std::min(aepl_in_32, uint32_t{1});
173
-
174
- bool remaining_work;
175
- do {
176
- remaining_work = false;
177
- for (uint32_t s = 0; s < num_shards; s++) {
178
- if (states[s] != UINT32_MAX) {
179
- GetShard(s)->ApplyToSomeEntries(callback, aepl_in_32, &states[s]);
180
- remaining_work |= states[s] != UINT32_MAX;
181
- }
182
- }
183
- } while (remaining_work);
184
- }
185
-
186
- void ShardedCache::EraseUnRefEntries() {
187
- uint32_t num_shards = GetNumShards();
188
- for (uint32_t s = 0; s < num_shards; s++) {
189
- GetShard(s)->EraseUnRefEntries();
190
- }
191
- }
192
-
193
- std::string ShardedCache::GetPrintableOptions() const {
58
+ std::string ShardedCacheBase::GetPrintableOptions() const {
194
59
  std::string ret;
195
60
  ret.reserve(20000);
196
61
  const int kBufferSize = 200;
197
62
  char buffer[kBufferSize];
198
63
  {
199
- MutexLock l(&capacity_mutex_);
64
+ MutexLock l(&config_mutex_);
200
65
  snprintf(buffer, kBufferSize, " capacity : %" ROCKSDB_PRIszt "\n",
201
66
  capacity_);
202
67
  ret.append(buffer);
@@ -210,7 +75,7 @@ std::string ShardedCache::GetPrintableOptions() const {
210
75
  snprintf(buffer, kBufferSize, " memory_allocator : %s\n",
211
76
  memory_allocator() ? memory_allocator()->Name() : "None");
212
77
  ret.append(buffer);
213
- ret.append(GetShard(0)->GetPrintableOptions());
78
+ AppendPrintableOptions(ret);
214
79
  return ret;
215
80
  }
216
81
 
@@ -226,25 +91,10 @@ int GetDefaultCacheShardBits(size_t capacity, size_t min_shard_size) {
226
91
  return num_shard_bits;
227
92
  }
228
93
 
229
- int ShardedCache::GetNumShardBits() const { return BitsSetToOne(shard_mask_); }
230
-
231
- uint32_t ShardedCache::GetNumShards() const { return shard_mask_ + 1; }
232
-
233
- size_t ShardedCache::GetOccupancyCount() const {
234
- size_t oc = 0;
235
- uint32_t num_shards = GetNumShards();
236
- for (uint32_t s = 0; s < num_shards; s++) {
237
- oc += GetShard(s)->GetOccupancyCount();
238
- }
239
- return oc;
240
- }
241
- size_t ShardedCache::GetTableAddressCount() const {
242
- size_t tac = 0;
243
- uint32_t num_shards = GetNumShards();
244
- for (uint32_t s = 0; s < num_shards; s++) {
245
- tac += GetShard(s)->GetTableAddressCount();
246
- }
247
- return tac;
94
+ int ShardedCacheBase::GetNumShardBits() const {
95
+ return BitsSetToOne(shard_mask_);
248
96
  }
249
97
 
98
+ uint32_t ShardedCacheBase::GetNumShards() const { return shard_mask_ + 1; }
99
+
250
100
  } // namespace ROCKSDB_NAMESPACE