@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
@@ -30,6 +30,7 @@ class NonBatchedOpsStressTest : public StressTest {
30
30
  ts = ts_str;
31
31
  options.timestamp = &ts;
32
32
  }
33
+
33
34
  auto shared = thread->shared;
34
35
  const int64_t max_key = shared->GetMaxKey();
35
36
  const int64_t keys_per_thread = max_key / shared->GetNumThreads();
@@ -37,44 +38,83 @@ class NonBatchedOpsStressTest : public StressTest {
37
38
  int64_t end = start + keys_per_thread;
38
39
  uint64_t prefix_to_use =
39
40
  (FLAGS_prefix_size < 0) ? 1 : static_cast<size_t>(FLAGS_prefix_size);
41
+
40
42
  if (thread->tid == shared->GetNumThreads() - 1) {
41
43
  end = max_key;
42
44
  }
45
+
43
46
  for (size_t cf = 0; cf < column_families_.size(); ++cf) {
44
47
  if (thread->shared->HasVerificationFailedYet()) {
45
48
  break;
46
49
  }
47
- if (thread->rand.OneIn(4)) {
48
- // 1/4 chance use iterator to verify this range
49
- Slice prefix;
50
- std::string seek_key = Key(start);
50
+
51
+ enum class VerificationMethod {
52
+ kIterator,
53
+ kGet,
54
+ kMultiGet,
55
+ kGetMergeOperands,
56
+ // Add any new items above kNumberOfMethods
57
+ kNumberOfMethods
58
+ };
59
+
60
+ constexpr int num_methods =
61
+ static_cast<int>(VerificationMethod::kNumberOfMethods);
62
+
63
+ // Note: Merge/GetMergeOperands is currently not supported for wide-column
64
+ // entities
65
+ const VerificationMethod method =
66
+ static_cast<VerificationMethod>(thread->rand.Uniform(
67
+ FLAGS_use_put_entity_one_in > 0 ? num_methods - 1 : num_methods));
68
+
69
+ if (method == VerificationMethod::kIterator) {
51
70
  std::unique_ptr<Iterator> iter(
52
71
  db_->NewIterator(options, column_families_[cf]));
72
+
73
+ std::string seek_key = Key(start);
53
74
  iter->Seek(seek_key);
54
- prefix = Slice(seek_key.data(), prefix_to_use);
55
- for (auto i = start; i < end; i++) {
75
+
76
+ Slice prefix(seek_key.data(), prefix_to_use);
77
+
78
+ for (int64_t i = start; i < end; ++i) {
56
79
  if (thread->shared->HasVerificationFailedYet()) {
57
80
  break;
58
81
  }
59
- std::string from_db;
60
- std::string keystr = Key(i);
61
- Slice k = keystr;
62
- Slice pfx = Slice(keystr.data(), prefix_to_use);
82
+
83
+ const std::string key = Key(i);
84
+ const Slice k(key);
85
+ const Slice pfx(key.data(), prefix_to_use);
86
+
63
87
  // Reseek when the prefix changes
64
88
  if (prefix_to_use > 0 && prefix.compare(pfx) != 0) {
65
89
  iter->Seek(k);
66
- seek_key = keystr;
90
+ seek_key = key;
67
91
  prefix = Slice(seek_key.data(), prefix_to_use);
68
92
  }
93
+
69
94
  Status s = iter->status();
95
+
96
+ std::string from_db;
97
+
70
98
  if (iter->Valid()) {
71
- Slice iter_key = iter->key();
72
- if (iter->key().compare(k) > 0) {
73
- s = Status::NotFound(Slice());
74
- } else if (iter->key().compare(k) == 0) {
99
+ const int diff = iter->key().compare(k);
100
+
101
+ if (diff > 0) {
102
+ s = Status::NotFound();
103
+ } else if (diff == 0) {
104
+ const WideColumns expected_columns = GenerateExpectedWideColumns(
105
+ GetValueBase(iter->value()), iter->value());
106
+ if (iter->columns() != expected_columns) {
107
+ VerificationAbort(shared, static_cast<int>(cf), i,
108
+ iter->value(), iter->columns(),
109
+ expected_columns);
110
+ break;
111
+ }
112
+
75
113
  from_db = iter->value().ToString();
76
114
  iter->Next();
77
- } else if (iter_key.compare(k) < 0) {
115
+ } else {
116
+ assert(diff < 0);
117
+
78
118
  VerificationAbort(shared, "An out of range key was found",
79
119
  static_cast<int>(cf), i);
80
120
  }
@@ -83,80 +123,95 @@ class NonBatchedOpsStressTest : public StressTest {
83
123
  // move to the next item in the iterator
84
124
  s = Status::NotFound();
85
125
  }
126
+
86
127
  VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
87
- s, true);
88
- if (from_db.length()) {
128
+ s, /* strict */ true);
129
+
130
+ if (!from_db.empty()) {
89
131
  PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
90
- from_db.data(), from_db.length());
132
+ from_db.data(), from_db.size());
91
133
  }
92
134
  }
93
- } else if (thread->rand.OneIn(3)) {
94
- // 1/4 chance use Get to verify this range
95
- for (auto i = start; i < end; i++) {
135
+ } else if (method == VerificationMethod::kGet) {
136
+ for (int64_t i = start; i < end; ++i) {
96
137
  if (thread->shared->HasVerificationFailedYet()) {
97
138
  break;
98
139
  }
140
+
141
+ const std::string key = Key(i);
99
142
  std::string from_db;
100
- std::string keystr = Key(i);
101
- Slice k = keystr;
102
- Status s = db_->Get(options, column_families_[cf], k, &from_db);
143
+
144
+ Status s = db_->Get(options, column_families_[cf], key, &from_db);
145
+
103
146
  VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
104
- s, true);
105
- if (from_db.length()) {
147
+ s, /* strict */ true);
148
+
149
+ if (!from_db.empty()) {
106
150
  PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
107
- from_db.data(), from_db.length());
151
+ from_db.data(), from_db.size());
108
152
  }
109
153
  }
110
- } else if (thread->rand.OneIn(2)) {
111
- // 1/4 chance use MultiGet to verify this range
112
- for (auto i = start; i < end;) {
154
+ } else if (method == VerificationMethod::kMultiGet) {
155
+ for (int64_t i = start; i < end;) {
113
156
  if (thread->shared->HasVerificationFailedYet()) {
114
157
  break;
115
158
  }
159
+
116
160
  // Keep the batch size to some reasonable value
117
161
  size_t batch_size = thread->rand.Uniform(128) + 1;
118
162
  batch_size = std::min<size_t>(batch_size, end - i);
163
+
119
164
  std::vector<std::string> keystrs(batch_size);
120
165
  std::vector<Slice> keys(batch_size);
121
166
  std::vector<PinnableSlice> values(batch_size);
122
167
  std::vector<Status> statuses(batch_size);
168
+
123
169
  for (size_t j = 0; j < batch_size; ++j) {
124
170
  keystrs[j] = Key(i + j);
125
- keys[j] = Slice(keystrs[j].data(), keystrs[j].length());
171
+ keys[j] = Slice(keystrs[j].data(), keystrs[j].size());
126
172
  }
173
+
127
174
  db_->MultiGet(options, column_families_[cf], batch_size, keys.data(),
128
175
  values.data(), statuses.data());
176
+
129
177
  for (size_t j = 0; j < batch_size; ++j) {
130
- Status s = statuses[j];
131
- std::string from_db = values[j].ToString();
178
+ const std::string from_db = values[j].ToString();
179
+
132
180
  VerifyOrSyncValue(static_cast<int>(cf), i + j, options, shared,
133
- from_db, s, true);
134
- if (from_db.length()) {
181
+ from_db, statuses[j], /* strict */ true);
182
+
183
+ if (!from_db.empty()) {
135
184
  PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i + j),
136
- from_db.data(), from_db.length());
185
+ from_db.data(), from_db.size());
137
186
  }
138
187
  }
139
188
 
140
189
  i += batch_size;
141
190
  }
142
191
  } else {
143
- // 1/4 chance use GetMergeOperand to verify this range
192
+ assert(method == VerificationMethod::kGetMergeOperands);
193
+
144
194
  // Start off with small size that will be increased later if necessary
145
195
  std::vector<PinnableSlice> values(4);
196
+
146
197
  GetMergeOperandsOptions merge_operands_info;
147
198
  merge_operands_info.expected_max_number_of_operands =
148
199
  static_cast<int>(values.size());
149
- for (auto i = start; i < end; i++) {
200
+
201
+ for (int64_t i = start; i < end; ++i) {
150
202
  if (thread->shared->HasVerificationFailedYet()) {
151
203
  break;
152
204
  }
205
+
206
+ const std::string key = Key(i);
207
+ const Slice k(key);
153
208
  std::string from_db;
154
- std::string keystr = Key(i);
155
- Slice k = keystr;
156
209
  int number_of_operands = 0;
210
+
157
211
  Status s = db_->GetMergeOperands(options, column_families_[cf], k,
158
212
  values.data(), &merge_operands_info,
159
213
  &number_of_operands);
214
+
160
215
  if (s.IsIncomplete()) {
161
216
  // Need to resize values as there are more than values.size() merge
162
217
  // operands on this key. Should only happen a few times when we
@@ -173,11 +228,13 @@ class NonBatchedOpsStressTest : public StressTest {
173
228
  if (number_of_operands) {
174
229
  from_db = values[number_of_operands - 1].ToString();
175
230
  }
231
+
176
232
  VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
177
- s, true);
178
- if (from_db.length()) {
233
+ s, /* strict */ true);
234
+
235
+ if (!from_db.empty()) {
179
236
  PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
180
- from_db.data(), from_db.length());
237
+ from_db.data(), from_db.size());
181
238
  }
182
239
  }
183
240
  }
@@ -342,8 +399,8 @@ class NonBatchedOpsStressTest : public StressTest {
342
399
  ReadOptions read_opts_copy = read_opts;
343
400
  std::string read_ts_str;
344
401
  Slice read_ts_slice;
345
- MaybeUseOlderTimestampForPointLookup(thread, read_ts_str, read_ts_slice,
346
- read_opts_copy);
402
+ bool read_older_ts = MaybeUseOlderTimestampForPointLookup(
403
+ thread, read_ts_str, read_ts_slice, read_opts_copy);
347
404
 
348
405
  Status s = db_->Get(read_opts_copy, cfh, key, &from_db);
349
406
  if (fault_fs_guard) {
@@ -376,7 +433,7 @@ class NonBatchedOpsStressTest : public StressTest {
376
433
  } else if (s.IsNotFound()) {
377
434
  // not found case
378
435
  thread->stats.AddGets(1, 0);
379
- if (!FLAGS_skip_verifydb && !read_opts_copy.timestamp) {
436
+ if (!FLAGS_skip_verifydb && !read_older_ts) {
380
437
  auto expected =
381
438
  thread->shared->Get(rand_column_families[0], rand_keys[0]);
382
439
  if (expected != SharedState::DELETION_SENTINEL &&
@@ -568,7 +625,8 @@ class NonBatchedOpsStressTest : public StressTest {
568
625
  keys[i].ToString(true).c_str());
569
626
  fprintf(stderr, "MultiGet returned value %s\n",
570
627
  values[i].ToString(true).c_str());
571
- fprintf(stderr, "Get returned value %s\n", value.c_str());
628
+ fprintf(stderr, "Get returned value %s\n",
629
+ Slice(value).ToString(true /* hex */).c_str());
572
630
  is_consistent = false;
573
631
  }
574
632
  }
@@ -613,14 +671,19 @@ class NonBatchedOpsStressTest : public StressTest {
613
671
  Status TestPrefixScan(ThreadState* thread, const ReadOptions& read_opts,
614
672
  const std::vector<int>& rand_column_families,
615
673
  const std::vector<int64_t>& rand_keys) override {
616
- auto cfh = column_families_[rand_column_families[0]];
617
- std::string key_str = Key(rand_keys[0]);
618
- Slice key = key_str;
619
- Slice prefix = Slice(key.data(), FLAGS_prefix_size);
674
+ assert(!rand_column_families.empty());
675
+ assert(!rand_keys.empty());
676
+
677
+ ColumnFamilyHandle* const cfh = column_families_[rand_column_families[0]];
678
+ assert(cfh);
679
+
680
+ const std::string key = Key(rand_keys[0]);
681
+ const Slice prefix(key.data(), FLAGS_prefix_size);
620
682
 
621
683
  std::string upper_bound;
622
684
  Slice ub_slice;
623
685
  ReadOptions ro_copy = read_opts;
686
+
624
687
  // Get the next prefix first and then see if we want to set upper bound.
625
688
  // We'll use the next prefix in an assertion later on
626
689
  if (GetNextPrefix(prefix, &upper_bound) && thread->rand.OneIn(2)) {
@@ -634,26 +697,54 @@ class NonBatchedOpsStressTest : public StressTest {
634
697
  MaybeUseOlderTimestampForRangeScan(thread, read_ts_str, read_ts_slice,
635
698
  ro_copy);
636
699
 
637
- Iterator* iter = db_->NewIterator(ro_copy, cfh);
638
- unsigned long count = 0;
700
+ std::unique_ptr<Iterator> iter(db_->NewIterator(ro_copy, cfh));
701
+
702
+ uint64_t count = 0;
703
+ Status s;
704
+
639
705
  for (iter->Seek(prefix); iter->Valid() && iter->key().starts_with(prefix);
640
706
  iter->Next()) {
641
707
  ++count;
708
+
709
+ // When iter_start_ts is set, iterator exposes internal keys, including
710
+ // tombstones; however, we want to perform column validation only for
711
+ // value-like types.
712
+ if (ro_copy.iter_start_ts) {
713
+ const ValueType value_type = ExtractValueType(iter->key());
714
+ if (value_type != kTypeValue && value_type != kTypeBlobIndex &&
715
+ value_type != kTypeWideColumnEntity) {
716
+ continue;
717
+ }
718
+ }
719
+
720
+ const WideColumns expected_columns = GenerateExpectedWideColumns(
721
+ GetValueBase(iter->value()), iter->value());
722
+ if (iter->columns() != expected_columns) {
723
+ s = Status::Corruption(
724
+ "Value and columns inconsistent",
725
+ DebugString(iter->value(), iter->columns(), expected_columns));
726
+ break;
727
+ }
642
728
  }
643
729
 
644
730
  if (ro_copy.iter_start_ts == nullptr) {
645
731
  assert(count <= GetPrefixKeyCount(prefix.ToString(), upper_bound));
646
732
  }
647
733
 
648
- Status s = iter->status();
649
- if (iter->status().ok()) {
650
- thread->stats.AddPrefixes(1, count);
651
- } else {
734
+ if (s.ok()) {
735
+ s = iter->status();
736
+ }
737
+
738
+ if (!s.ok()) {
652
739
  fprintf(stderr, "TestPrefixScan error: %s\n", s.ToString().c_str());
653
740
  thread->stats.AddErrors(1);
741
+
742
+ return s;
654
743
  }
655
- delete iter;
656
- return s;
744
+
745
+ thread->stats.AddPrefixes(1, count);
746
+
747
+ return Status::OK();
657
748
  }
658
749
 
659
750
  Status TestPut(ThreadState* thread, WriteOptions& write_opts,
@@ -661,78 +752,92 @@ class NonBatchedOpsStressTest : public StressTest {
661
752
  const std::vector<int>& rand_column_families,
662
753
  const std::vector<int64_t>& rand_keys,
663
754
  char (&value)[100]) override {
755
+ assert(!rand_column_families.empty());
756
+ assert(!rand_keys.empty());
757
+
664
758
  auto shared = thread->shared;
665
- int64_t max_key = shared->GetMaxKey();
759
+ assert(shared);
760
+
761
+ const int64_t max_key = shared->GetMaxKey();
762
+
666
763
  int64_t rand_key = rand_keys[0];
667
764
  int rand_column_family = rand_column_families[0];
668
- std::string write_ts_str;
669
- Slice write_ts;
765
+ std::string write_ts;
766
+
670
767
  std::unique_ptr<MutexLock> lock(
671
768
  new MutexLock(shared->GetMutexForKey(rand_column_family, rand_key)));
672
769
  while (!shared->AllowsOverwrite(rand_key) &&
673
770
  (FLAGS_use_merge || shared->Exists(rand_column_family, rand_key))) {
674
771
  lock.reset();
772
+
675
773
  rand_key = thread->rand.Next() % max_key;
676
774
  rand_column_family = thread->rand.Next() % FLAGS_column_families;
775
+
677
776
  lock.reset(
678
777
  new MutexLock(shared->GetMutexForKey(rand_column_family, rand_key)));
679
778
  if (FLAGS_user_timestamp_size > 0) {
680
- write_ts_str = GetNowNanos();
681
- write_ts = write_ts_str;
779
+ write_ts = GetNowNanos();
682
780
  }
683
781
  }
684
- if (write_ts.size() == 0 && FLAGS_user_timestamp_size) {
685
- write_ts_str = GetNowNanos();
686
- write_ts = write_ts_str;
782
+
783
+ if (write_ts.empty() && FLAGS_user_timestamp_size) {
784
+ write_ts = GetNowNanos();
687
785
  }
688
786
 
689
- std::string key_str = Key(rand_key);
690
- Slice key = key_str;
691
- ColumnFamilyHandle* cfh = column_families_[rand_column_family];
787
+ const std::string k = Key(rand_key);
788
+
789
+ ColumnFamilyHandle* const cfh = column_families_[rand_column_family];
790
+ assert(cfh);
692
791
 
693
792
  if (FLAGS_verify_before_write) {
694
- std::string key_str2 = Key(rand_key);
695
- Slice k = key_str2;
696
793
  std::string from_db;
697
794
  Status s = db_->Get(read_opts, cfh, k, &from_db);
698
795
  if (!VerifyOrSyncValue(rand_column_family, rand_key, read_opts, shared,
699
- from_db, s, true)) {
796
+ from_db, s, /* strict */ true)) {
700
797
  return s;
701
798
  }
702
799
  }
703
- uint32_t value_base = thread->rand.Next() % shared->UNKNOWN_SENTINEL;
704
- size_t sz = GenerateValue(value_base, value, sizeof(value));
705
- Slice v(value, sz);
800
+
801
+ const uint32_t value_base = thread->rand.Next() % shared->UNKNOWN_SENTINEL;
802
+ const size_t sz = GenerateValue(value_base, value, sizeof(value));
803
+ const Slice v(value, sz);
804
+
706
805
  shared->Put(rand_column_family, rand_key, value_base, true /* pending */);
806
+
707
807
  Status s;
808
+
708
809
  if (FLAGS_use_merge) {
709
810
  if (!FLAGS_use_txn) {
710
- s = db_->Merge(write_opts, cfh, key, v);
811
+ s = db_->Merge(write_opts, cfh, k, v);
711
812
  } else {
712
813
  #ifndef ROCKSDB_LITE
713
814
  Transaction* txn;
714
815
  s = NewTxn(write_opts, &txn);
715
816
  if (s.ok()) {
716
- s = txn->Merge(cfh, key, v);
817
+ s = txn->Merge(cfh, k, v);
717
818
  if (s.ok()) {
718
819
  s = CommitTxn(txn, thread);
719
820
  }
720
821
  }
721
822
  #endif
722
823
  }
824
+ } else if (FLAGS_use_put_entity_one_in > 0 &&
825
+ (value_base % FLAGS_use_put_entity_one_in) == 0) {
826
+ s = db_->PutEntity(write_opts, cfh, k,
827
+ GenerateWideColumns(value_base, v));
723
828
  } else {
724
829
  if (!FLAGS_use_txn) {
725
830
  if (FLAGS_user_timestamp_size == 0) {
726
- s = db_->Put(write_opts, cfh, key, v);
831
+ s = db_->Put(write_opts, cfh, k, v);
727
832
  } else {
728
- s = db_->Put(write_opts, cfh, key, write_ts, v);
833
+ s = db_->Put(write_opts, cfh, k, write_ts, v);
729
834
  }
730
835
  } else {
731
836
  #ifndef ROCKSDB_LITE
732
837
  Transaction* txn;
733
838
  s = NewTxn(write_opts, &txn);
734
839
  if (s.ok()) {
735
- s = txn->Put(cfh, key, v);
840
+ s = txn->Put(cfh, k, v);
736
841
  if (s.ok()) {
737
842
  s = CommitTxn(txn, thread);
738
843
  }
@@ -740,7 +845,9 @@ class NonBatchedOpsStressTest : public StressTest {
740
845
  #endif
741
846
  }
742
847
  }
848
+
743
849
  shared->Put(rand_column_family, rand_key, value_base, false /* pending */);
850
+
744
851
  if (!s.ok()) {
745
852
  if (FLAGS_injest_error_severity >= 2) {
746
853
  if (!is_db_stopped_ && s.severity() >= Status::Severity::kFatalError) {
@@ -755,6 +862,7 @@ class NonBatchedOpsStressTest : public StressTest {
755
862
  std::terminate();
756
863
  }
757
864
  }
865
+
758
866
  thread->stats.AddBytesForWrites(1, sz);
759
867
  PrintKeyValue(rand_column_family, static_cast<uint32_t>(rand_key), value,
760
868
  sz);
@@ -893,7 +1001,16 @@ class NonBatchedOpsStressTest : public StressTest {
893
1001
  auto cfh = column_families_[rand_column_family];
894
1002
  std::string end_keystr = Key(rand_key + FLAGS_range_deletion_width);
895
1003
  Slice end_key = end_keystr;
896
- Status s = db_->DeleteRange(write_opts, cfh, key, end_key);
1004
+ std::string write_ts_str;
1005
+ Slice write_ts;
1006
+ Status s;
1007
+ if (FLAGS_user_timestamp_size) {
1008
+ write_ts_str = GetNowNanos();
1009
+ write_ts = write_ts_str;
1010
+ s = db_->DeleteRange(write_opts, cfh, key, end_key, write_ts);
1011
+ } else {
1012
+ s = db_->DeleteRange(write_opts, cfh, key, end_key);
1013
+ }
897
1014
  if (!s.ok()) {
898
1015
  if (FLAGS_injest_error_severity >= 2) {
899
1016
  if (!is_db_stopped_ && s.severity() >= Status::Severity::kFatalError) {
@@ -982,6 +1099,10 @@ class NonBatchedOpsStressTest : public StressTest {
982
1099
  s = sst_file_writer.Put(Slice(key_str), Slice(value, value_len));
983
1100
  }
984
1101
 
1102
+ if (s.ok() && keys.empty()) {
1103
+ return;
1104
+ }
1105
+
985
1106
  if (s.ok()) {
986
1107
  s = sst_file_writer.Finish();
987
1108
  }
@@ -1006,33 +1127,41 @@ class NonBatchedOpsStressTest : public StressTest {
1006
1127
  ThreadState* thread, const ReadOptions& read_opts,
1007
1128
  const std::vector<int>& rand_column_families,
1008
1129
  const std::vector<int64_t>& rand_keys) override {
1009
- // Lock the whole range over which we might iterate to ensure it doesn't
1010
- // change under us.
1011
- std::vector<std::unique_ptr<MutexLock>> range_locks;
1012
- int64_t lb = rand_keys[0];
1013
- int rand_column_family = rand_column_families[0];
1130
+ assert(thread);
1131
+ assert(!rand_column_families.empty());
1132
+ assert(!rand_keys.empty());
1133
+
1014
1134
  auto shared = thread->shared;
1135
+ assert(shared);
1136
+
1015
1137
  int64_t max_key = shared->GetMaxKey();
1016
- if (static_cast<uint64_t>(lb) > max_key - FLAGS_num_iterations) {
1017
- lb = thread->rand.Next() % (max_key - FLAGS_num_iterations + 1);
1018
- }
1019
- for (int j = 0; j < static_cast<int>(FLAGS_num_iterations); ++j) {
1020
- if (j == 0 || ((lb + j) & ((1 << FLAGS_log2_keys_per_lock) - 1)) == 0) {
1021
- range_locks.emplace_back(
1022
- new MutexLock(shared->GetMutexForKey(rand_column_family, lb + j)));
1023
- }
1138
+
1139
+ const int64_t num_iter = static_cast<int64_t>(FLAGS_num_iterations);
1140
+
1141
+ int64_t lb = rand_keys[0];
1142
+ if (lb > max_key - num_iter) {
1143
+ lb = thread->rand.Next() % (max_key - num_iter + 1);
1024
1144
  }
1025
- int64_t ub = lb + FLAGS_num_iterations;
1026
- // Locks acquired for [lb, ub)
1027
- ReadOptions readoptscopy(read_opts);
1145
+
1146
+ const int64_t ub = lb + num_iter;
1147
+
1148
+ // Lock the whole range over which we might iterate to ensure it doesn't
1149
+ // change under us.
1150
+ const int rand_column_family = rand_column_families[0];
1151
+ std::vector<std::unique_ptr<MutexLock>> range_locks =
1152
+ shared->GetLocksForKeyRange(rand_column_family, lb, ub);
1153
+
1154
+ ReadOptions ro(read_opts);
1155
+ ro.total_order_seek = true;
1156
+
1028
1157
  std::string read_ts_str;
1029
1158
  Slice read_ts;
1030
1159
  if (FLAGS_user_timestamp_size > 0) {
1031
1160
  read_ts_str = GetNowNanos();
1032
1161
  read_ts = read_ts_str;
1033
- readoptscopy.timestamp = &read_ts;
1162
+ ro.timestamp = &read_ts;
1034
1163
  }
1035
- readoptscopy.total_order_seek = true;
1164
+
1036
1165
  std::string max_key_str;
1037
1166
  Slice max_key_slice;
1038
1167
  if (!FLAGS_destroy_db_initially) {
@@ -1041,11 +1170,41 @@ class NonBatchedOpsStressTest : public StressTest {
1041
1170
  // to restrict iterator from reading keys written in batched_op_stress
1042
1171
  // that do not have expected state updated and may not be parseable by
1043
1172
  // GetIntVal().
1044
- readoptscopy.iterate_upper_bound = &max_key_slice;
1173
+ ro.iterate_upper_bound = &max_key_slice;
1045
1174
  }
1046
- auto cfh = column_families_[rand_column_family];
1175
+
1176
+ ColumnFamilyHandle* const cfh = column_families_[rand_column_family];
1177
+ assert(cfh);
1178
+
1179
+ std::unique_ptr<Iterator> iter(db_->NewIterator(ro, cfh));
1180
+
1047
1181
  std::string op_logs;
1048
- std::unique_ptr<Iterator> iter(db_->NewIterator(readoptscopy, cfh));
1182
+
1183
+ auto check_columns = [&]() {
1184
+ assert(iter);
1185
+ assert(iter->Valid());
1186
+
1187
+ const WideColumns expected_columns = GenerateExpectedWideColumns(
1188
+ GetValueBase(iter->value()), iter->value());
1189
+ if (iter->columns() != expected_columns) {
1190
+ shared->SetVerificationFailure();
1191
+
1192
+ fprintf(stderr,
1193
+ "Verification failed for key %s: "
1194
+ "Value and columns inconsistent: %s\n",
1195
+ Slice(iter->key()).ToString(/* hex */ true).c_str(),
1196
+ DebugString(iter->value(), iter->columns(), expected_columns)
1197
+ .c_str());
1198
+ fprintf(stderr, "Column family: %s, op_logs: %s\n",
1199
+ cfh->GetName().c_str(), op_logs.c_str());
1200
+
1201
+ thread->stats.AddErrors(1);
1202
+
1203
+ return false;
1204
+ }
1205
+
1206
+ return true;
1207
+ };
1049
1208
 
1050
1209
  auto check_no_key_in_range = [&](int64_t start, int64_t end) {
1051
1210
  for (auto j = std::max(start, lb); j < std::min(end, ub); ++j) {
@@ -1077,10 +1236,13 @@ class NonBatchedOpsStressTest : public StressTest {
1077
1236
  // The random sequence Next and Prev test below tends to be very short
1078
1237
  // ranged.
1079
1238
  int64_t last_key = lb - 1;
1239
+
1080
1240
  std::string key_str = Key(lb);
1081
- iter->Seek(Slice(key_str));
1241
+ iter->Seek(key_str);
1242
+
1082
1243
  op_logs += "S " + Slice(key_str).ToString(true) + " ";
1083
- uint64_t curr;
1244
+
1245
+ uint64_t curr = 0;
1084
1246
  while (true) {
1085
1247
  if (!iter->Valid()) {
1086
1248
  if (!iter->status().ok()) {
@@ -1092,29 +1254,38 @@ class NonBatchedOpsStressTest : public StressTest {
1092
1254
  thread->stats.AddErrors(1);
1093
1255
  return iter->status();
1094
1256
  }
1095
- if (!check_no_key_in_range(last_key + 1, static_cast<int64_t>(ub))) {
1096
- // error reported in check_no_key_in_range()
1257
+ if (!check_no_key_in_range(last_key + 1, ub)) {
1097
1258
  return Status::OK();
1098
1259
  }
1099
1260
  break;
1100
1261
  }
1262
+
1263
+ if (!check_columns()) {
1264
+ return Status::OK();
1265
+ }
1266
+
1101
1267
  // iter is valid, the range (last_key, current key) was skipped
1102
1268
  GetIntVal(iter->key().ToString(), &curr);
1103
1269
  if (!check_no_key_in_range(last_key + 1, static_cast<int64_t>(curr))) {
1104
1270
  return Status::OK();
1105
1271
  }
1272
+
1106
1273
  last_key = static_cast<int64_t>(curr);
1107
1274
  if (last_key >= ub - 1) {
1108
1275
  break;
1109
1276
  }
1277
+
1110
1278
  iter->Next();
1279
+
1111
1280
  op_logs += "N";
1112
1281
  }
1113
1282
 
1114
1283
  // backward scan
1115
1284
  key_str = Key(ub - 1);
1116
- iter->SeekForPrev(Slice(key_str));
1285
+ iter->SeekForPrev(key_str);
1286
+
1117
1287
  op_logs += " SFP " + Slice(key_str).ToString(true) + " ";
1288
+
1118
1289
  last_key = ub;
1119
1290
  while (true) {
1120
1291
  if (!iter->Valid()) {
@@ -1132,24 +1303,40 @@ class NonBatchedOpsStressTest : public StressTest {
1132
1303
  }
1133
1304
  break;
1134
1305
  }
1306
+
1307
+ if (!check_columns()) {
1308
+ return Status::OK();
1309
+ }
1310
+
1135
1311
  // the range (current key, last key) was skipped
1136
1312
  GetIntVal(iter->key().ToString(), &curr);
1137
1313
  if (!check_no_key_in_range(static_cast<int64_t>(curr + 1), last_key)) {
1138
1314
  return Status::OK();
1139
1315
  }
1316
+
1140
1317
  last_key = static_cast<int64_t>(curr);
1141
1318
  if (last_key <= lb) {
1142
1319
  break;
1143
1320
  }
1321
+
1144
1322
  iter->Prev();
1323
+
1145
1324
  op_logs += "P";
1146
1325
  }
1147
1326
 
1327
+ if (thread->rand.OneIn(2)) {
1328
+ // Refresh after forward/backward scan to allow higher chance of SV
1329
+ // change. It is safe to refresh since the testing key range is locked.
1330
+ iter->Refresh();
1331
+ }
1332
+
1148
1333
  // start from middle of [lb, ub) otherwise it is easy to iterate out of
1149
1334
  // locked range
1150
- int64_t mid = lb + static_cast<int64_t>(FLAGS_num_iterations / 2);
1335
+ const int64_t mid = lb + num_iter / 2;
1336
+
1151
1337
  key_str = Key(mid);
1152
- Slice key = key_str;
1338
+ const Slice key(key_str);
1339
+
1153
1340
  if (thread->rand.OneIn(2)) {
1154
1341
  iter->Seek(key);
1155
1342
  op_logs += " S " + key.ToString(true) + " ";
@@ -1169,16 +1356,20 @@ class NonBatchedOpsStressTest : public StressTest {
1169
1356
  }
1170
1357
  }
1171
1358
 
1172
- for (uint64_t i = 0; i < FLAGS_num_iterations && iter->Valid(); i++) {
1359
+ for (int64_t i = 0; i < num_iter && iter->Valid(); ++i) {
1360
+ if (!check_columns()) {
1361
+ return Status::OK();
1362
+ }
1363
+
1173
1364
  GetIntVal(iter->key().ToString(), &curr);
1174
- if (curr < static_cast<uint64_t>(lb)) {
1365
+ if (static_cast<int64_t>(curr) < lb) {
1175
1366
  iter->Next();
1176
1367
  op_logs += "N";
1177
- } else if (curr >= static_cast<uint64_t>(ub)) {
1368
+ } else if (static_cast<int64_t>(curr) >= ub) {
1178
1369
  iter->Prev();
1179
1370
  op_logs += "P";
1180
1371
  } else {
1181
- uint32_t expected_value =
1372
+ const uint32_t expected_value =
1182
1373
  shared->Get(rand_column_family, static_cast<int64_t>(curr));
1183
1374
  if (expected_value == shared->DELETION_SENTINEL) {
1184
1375
  // Fail fast to preserve the DB state.
@@ -1190,13 +1381,14 @@ class NonBatchedOpsStressTest : public StressTest {
1190
1381
  thread->stats.AddErrors(1);
1191
1382
  break;
1192
1383
  }
1384
+
1193
1385
  if (thread->rand.OneIn(2)) {
1194
1386
  iter->Next();
1195
1387
  op_logs += "N";
1196
1388
  if (!iter->Valid()) {
1197
1389
  break;
1198
1390
  }
1199
- uint64_t next;
1391
+ uint64_t next = 0;
1200
1392
  GetIntVal(iter->key().ToString(), &next);
1201
1393
  if (!check_no_key_in_range(static_cast<int64_t>(curr + 1),
1202
1394
  static_cast<int64_t>(next))) {
@@ -1208,7 +1400,7 @@ class NonBatchedOpsStressTest : public StressTest {
1208
1400
  if (!iter->Valid()) {
1209
1401
  break;
1210
1402
  }
1211
- uint64_t prev;
1403
+ uint64_t prev = 0;
1212
1404
  GetIntVal(iter->key().ToString(), &prev);
1213
1405
  if (!check_no_key_in_range(static_cast<int64_t>(prev + 1),
1214
1406
  static_cast<int64_t>(curr))) {
@@ -1217,6 +1409,7 @@ class NonBatchedOpsStressTest : public StressTest {
1217
1409
  }
1218
1410
  }
1219
1411
  }
1412
+
1220
1413
  if (!iter->status().ok()) {
1221
1414
  thread->shared->SetVerificationFailure();
1222
1415
  fprintf(stderr, "TestIterate against expected state error: %s\n",
@@ -1226,7 +1419,9 @@ class NonBatchedOpsStressTest : public StressTest {
1226
1419
  thread->stats.AddErrors(1);
1227
1420
  return iter->status();
1228
1421
  }
1422
+
1229
1423
  thread->stats.AddIterations(1);
1424
+
1230
1425
  return Status::OK();
1231
1426
  }
1232
1427