@nxtedition/rocksdb 15.4.1 → 16.0.0

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 (401) hide show
  1. package/binding.cc +70 -23
  2. package/deps/rocksdb/rocksdb/.clang-tidy +86 -0
  3. package/deps/rocksdb/rocksdb/BUCK +42 -0
  4. package/deps/rocksdb/rocksdb/CMakeLists.txt +11 -0
  5. package/deps/rocksdb/rocksdb/Makefile +59 -32
  6. package/deps/rocksdb/rocksdb/cache/cache.cc +0 -5
  7. package/deps/rocksdb/rocksdb/cache/cache_entry_stats.h +9 -9
  8. package/deps/rocksdb/rocksdb/cache/cache_key.cc +3 -3
  9. package/deps/rocksdb/rocksdb/cache/cache_key.h +5 -5
  10. package/deps/rocksdb/rocksdb/cache/cache_reservation_manager.h +16 -16
  11. package/deps/rocksdb/rocksdb/cache/cache_test.cc +1 -1
  12. package/deps/rocksdb/rocksdb/cache/clock_cache.cc +258 -294
  13. package/deps/rocksdb/rocksdb/cache/clock_cache.h +98 -49
  14. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.cc +1 -5
  15. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache_test.cc +2 -3
  16. package/deps/rocksdb/rocksdb/cache/lru_cache_test.cc +18 -18
  17. package/deps/rocksdb/rocksdb/crash_test.mk +5 -1
  18. package/deps/rocksdb/rocksdb/db/blob/blob_file_builder.cc +23 -22
  19. package/deps/rocksdb/rocksdb/db/blob/blob_file_builder.h +6 -1
  20. package/deps/rocksdb/rocksdb/db/blob/blob_file_builder_test.cc +14 -16
  21. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader.cc +38 -26
  22. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader.h +5 -1
  23. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader_test.cc +101 -18
  24. package/deps/rocksdb/rocksdb/db/blob/blob_index.h +12 -0
  25. package/deps/rocksdb/rocksdb/db/blob/blob_source_test.cc +6 -9
  26. package/deps/rocksdb/rocksdb/db/builder.cc +23 -0
  27. package/deps/rocksdb/rocksdb/db/builder.h +7 -0
  28. package/deps/rocksdb/rocksdb/db/c.cc +373 -57
  29. package/deps/rocksdb/rocksdb/db/c_test.c +101 -1
  30. package/deps/rocksdb/rocksdb/db/column_family.cc +31 -3
  31. package/deps/rocksdb/rocksdb/db/column_family_test.cc +10 -13
  32. package/deps/rocksdb/rocksdb/db/compact_files_test.cc +35 -48
  33. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +13 -5
  34. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +201 -39
  35. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +15 -10
  36. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_stats_test.cc +7 -7
  37. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +2 -455
  38. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.cc +4 -2
  39. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +19 -0
  40. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.cc +72 -9
  41. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.h +12 -10
  42. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.cc +405 -83
  43. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.h +25 -1
  44. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.cc +23 -10
  45. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.h +1 -0
  46. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +1410 -106
  47. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.cc +12 -5
  48. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.h +2 -1
  49. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_job.cc +19 -10
  50. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_test.cc +505 -45
  51. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.cc +2 -2
  52. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.h +9 -1
  53. package/deps/rocksdb/rocksdb/db/compaction/tiered_compaction_test.cc +4 -4
  54. package/deps/rocksdb/rocksdb/db/comparator_db_test.cc +7 -9
  55. package/deps/rocksdb/rocksdb/db/convenience.cc +4 -4
  56. package/deps/rocksdb/rocksdb/db/convenience_impl.h +2 -1
  57. package/deps/rocksdb/rocksdb/db/corruption_test.cc +60 -88
  58. package/deps/rocksdb/rocksdb/db/cuckoo_table_db_test.cc +10 -12
  59. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +471 -40
  60. package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +116 -2
  61. package/deps/rocksdb/rocksdb/db/db_bloom_filter_test.cc +5 -15
  62. package/deps/rocksdb/rocksdb/db/db_compaction_abort_test.cc +993 -0
  63. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +329 -29
  64. package/deps/rocksdb/rocksdb/db/db_flush_test.cc +155 -13
  65. package/deps/rocksdb/rocksdb/db/db_impl/compacted_db_impl.cc +54 -31
  66. package/deps/rocksdb/rocksdb/db/db_impl/compacted_db_impl.h +1 -0
  67. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +232 -70
  68. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +57 -9
  69. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +224 -31
  70. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_debug.cc +5 -0
  71. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_experimental.cc +4 -2
  72. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +1 -1
  73. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_follower.cc +1 -0
  74. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +164 -8
  75. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.cc +6 -0
  76. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.h +5 -0
  77. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +47 -35
  78. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +22 -9
  79. package/deps/rocksdb/rocksdb/db/db_iter.cc +9 -0
  80. package/deps/rocksdb/rocksdb/db/db_iterator_test.cc +371 -6
  81. package/deps/rocksdb/rocksdb/db/db_log_iter_test.cc +7 -5
  82. package/deps/rocksdb/rocksdb/db/db_logical_block_size_cache_test.cc +22 -23
  83. package/deps/rocksdb/rocksdb/db/db_memtable_test.cc +0 -2
  84. package/deps/rocksdb/rocksdb/db/db_merge_operator_test.cc +4 -4
  85. package/deps/rocksdb/rocksdb/db/db_options_test.cc +40 -0
  86. package/deps/rocksdb/rocksdb/db/db_properties_test.cc +32 -13
  87. package/deps/rocksdb/rocksdb/db/db_range_del_test.cc +1 -1
  88. package/deps/rocksdb/rocksdb/db/db_readonly_with_timestamp_test.cc +4 -4
  89. package/deps/rocksdb/rocksdb/db/db_secondary_test.cc +68 -15
  90. package/deps/rocksdb/rocksdb/db/db_sst_test.cc +1 -1
  91. package/deps/rocksdb/rocksdb/db/db_statistics_test.cc +2 -3
  92. package/deps/rocksdb/rocksdb/db/db_table_properties_test.cc +6 -21
  93. package/deps/rocksdb/rocksdb/db/db_test.cc +644 -128
  94. package/deps/rocksdb/rocksdb/db/db_test2.cc +198 -81
  95. package/deps/rocksdb/rocksdb/db/db_test_util.cc +35 -10
  96. package/deps/rocksdb/rocksdb/db/db_test_util.h +8 -2
  97. package/deps/rocksdb/rocksdb/db/db_wal_test.cc +36 -32
  98. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +11 -7
  99. package/deps/rocksdb/rocksdb/db/db_with_timestamp_compaction_test.cc +499 -0
  100. package/deps/rocksdb/rocksdb/db/db_write_buffer_manager_test.cc +284 -20
  101. package/deps/rocksdb/rocksdb/db/db_write_test.cc +3 -3
  102. package/deps/rocksdb/rocksdb/db/dbformat.h +0 -5
  103. package/deps/rocksdb/rocksdb/db/error_handler.cc +24 -0
  104. package/deps/rocksdb/rocksdb/db/error_handler_fs_test.cc +12 -14
  105. package/deps/rocksdb/rocksdb/db/experimental.cc +13 -10
  106. package/deps/rocksdb/rocksdb/db/external_sst_file_basic_test.cc +1 -1
  107. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +22 -3
  108. package/deps/rocksdb/rocksdb/db/external_sst_file_test.cc +21 -15
  109. package/deps/rocksdb/rocksdb/db/fault_injection_test.cc +4 -6
  110. package/deps/rocksdb/rocksdb/db/flush_job.cc +11 -3
  111. package/deps/rocksdb/rocksdb/db/forward_iterator_bench.cc +5 -6
  112. package/deps/rocksdb/rocksdb/db/import_column_family_job.cc +4 -2
  113. package/deps/rocksdb/rocksdb/db/import_column_family_test.cc +17 -17
  114. package/deps/rocksdb/rocksdb/db/internal_stats.cc +13 -0
  115. package/deps/rocksdb/rocksdb/db/internal_stats.h +2 -0
  116. package/deps/rocksdb/rocksdb/db/listener_test.cc +154 -27
  117. package/deps/rocksdb/rocksdb/db/manual_compaction_test.cc +6 -6
  118. package/deps/rocksdb/rocksdb/db/memtable.cc +197 -51
  119. package/deps/rocksdb/rocksdb/db/memtable.h +6 -0
  120. package/deps/rocksdb/rocksdb/db/memtable_list_test.cc +3 -4
  121. package/deps/rocksdb/rocksdb/db/merge_test.cc +37 -35
  122. package/deps/rocksdb/rocksdb/db/obsolete_files_test.cc +2 -1
  123. package/deps/rocksdb/rocksdb/db/options_file_test.cc +4 -4
  124. package/deps/rocksdb/rocksdb/db/perf_context_test.cc +9 -11
  125. package/deps/rocksdb/rocksdb/db/periodic_task_scheduler.cc +10 -1
  126. package/deps/rocksdb/rocksdb/db/periodic_task_scheduler_test.cc +292 -15
  127. package/deps/rocksdb/rocksdb/db/plain_table_db_test.cc +10 -17
  128. package/deps/rocksdb/rocksdb/db/prefix_test.cc +6 -8
  129. package/deps/rocksdb/rocksdb/db/repair.cc +10 -10
  130. package/deps/rocksdb/rocksdb/db/seqno_time_test.cc +5 -5
  131. package/deps/rocksdb/rocksdb/db/table_cache.cc +142 -135
  132. package/deps/rocksdb/rocksdb/db/table_cache.h +30 -6
  133. package/deps/rocksdb/rocksdb/db/table_cache_sync_and_async.h +7 -7
  134. package/deps/rocksdb/rocksdb/db/version_builder.cc +11 -50
  135. package/deps/rocksdb/rocksdb/db/version_builder.h +2 -1
  136. package/deps/rocksdb/rocksdb/db/version_builder_test.cc +2 -1
  137. package/deps/rocksdb/rocksdb/db/version_edit.cc +51 -2
  138. package/deps/rocksdb/rocksdb/db/version_edit.h +91 -29
  139. package/deps/rocksdb/rocksdb/db/version_edit_handler.h +7 -7
  140. package/deps/rocksdb/rocksdb/db/version_set.cc +211 -50
  141. package/deps/rocksdb/rocksdb/db/version_set.h +40 -3
  142. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +5 -0
  143. package/deps/rocksdb/rocksdb/db/version_set_test.cc +294 -21
  144. package/deps/rocksdb/rocksdb/db/version_util.cc +96 -0
  145. package/deps/rocksdb/rocksdb/db/version_util.h +24 -0
  146. package/deps/rocksdb/rocksdb/db/wide/db_wide_basic_test.cc +5 -5
  147. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.cc +647 -31
  148. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.h +219 -1
  149. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization_test.cc +549 -12
  150. package/deps/rocksdb/rocksdb/db/write_callback_test.cc +3 -3
  151. package/deps/rocksdb/rocksdb/db_stress_tool/cf_consistency_stress.cc +1 -1
  152. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.cc +19 -0
  153. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +21 -4
  154. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_env_wrapper.h +32 -0
  155. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +74 -22
  156. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_listener.h +9 -0
  157. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +143 -61
  158. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.h +15 -2
  159. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_tool.cc +76 -2
  160. package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +92 -72
  161. package/deps/rocksdb/rocksdb/env/env.cc +1 -0
  162. package/deps/rocksdb/rocksdb/env/env_test.cc +365 -2
  163. package/deps/rocksdb/rocksdb/env/fs_posix.cc +31 -30
  164. package/deps/rocksdb/rocksdb/env/io_posix.cc +8 -11
  165. package/deps/rocksdb/rocksdb/env/io_posix.h +30 -1
  166. package/deps/rocksdb/rocksdb/env/io_posix_test.cc +43 -0
  167. package/deps/rocksdb/rocksdb/file/delete_scheduler.cc +1 -1
  168. package/deps/rocksdb/rocksdb/file/delete_scheduler_test.cc +108 -0
  169. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +32 -4
  170. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +4 -4
  171. package/deps/rocksdb/rocksdb/file/file_util.cc +8 -2
  172. package/deps/rocksdb/rocksdb/file/file_util.h +2 -1
  173. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +331 -12
  174. package/deps/rocksdb/rocksdb/file/random_access_file_reader.cc +52 -35
  175. package/deps/rocksdb/rocksdb/folly.mk +22 -5
  176. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_cache.h +1 -1
  177. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_compression.h +100 -54
  178. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +67 -2
  179. package/deps/rocksdb/rocksdb/include/rocksdb/c.h +149 -13
  180. package/deps/rocksdb/rocksdb/include/rocksdb/cache.h +1 -12
  181. package/deps/rocksdb/rocksdb/include/rocksdb/db.h +78 -97
  182. package/deps/rocksdb/rocksdb/include/rocksdb/experimental.h +3 -3
  183. package/deps/rocksdb/rocksdb/include/rocksdb/external_table.h +2 -2
  184. package/deps/rocksdb/rocksdb/include/rocksdb/file_checksum.h +5 -0
  185. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +17 -2
  186. package/deps/rocksdb/rocksdb/include/rocksdb/functor_wrapper.h +1 -1
  187. package/deps/rocksdb/rocksdb/include/rocksdb/io_dispatcher.h +358 -0
  188. package/deps/rocksdb/rocksdb/include/rocksdb/iostats_context.h +13 -0
  189. package/deps/rocksdb/rocksdb/include/rocksdb/listener.h +43 -0
  190. package/deps/rocksdb/rocksdb/include/rocksdb/memtablerep.h +20 -0
  191. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +63 -21
  192. package/deps/rocksdb/rocksdb/include/rocksdb/perf_context.h +10 -1
  193. package/deps/rocksdb/rocksdb/include/rocksdb/rate_limiter.h +1 -1
  194. package/deps/rocksdb/rocksdb/include/rocksdb/slice_transform.h +2 -7
  195. package/deps/rocksdb/rocksdb/include/rocksdb/sst_file_reader.h +13 -0
  196. package/deps/rocksdb/rocksdb/include/rocksdb/sst_file_writer.h +3 -14
  197. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +49 -9
  198. package/deps/rocksdb/rocksdb/include/rocksdb/status.h +8 -0
  199. package/deps/rocksdb/rocksdb/include/rocksdb/table.h +77 -6
  200. package/deps/rocksdb/rocksdb/include/rocksdb/table_properties.h +15 -0
  201. package/deps/rocksdb/rocksdb/include/rocksdb/tool_hooks.h +16 -10
  202. package/deps/rocksdb/rocksdb/include/rocksdb/unique_id.h +5 -5
  203. package/deps/rocksdb/rocksdb/include/rocksdb/universal_compaction.h +2 -4
  204. package/deps/rocksdb/rocksdb/include/rocksdb/user_defined_index.h +106 -46
  205. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/db_ttl.h +1 -1
  206. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/ldb_cmd.h +14 -1
  207. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/memory_util.h +5 -1
  208. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/optimistic_transaction_db.h +2 -1
  209. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/stackable_db.h +7 -9
  210. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +2 -2
  211. package/deps/rocksdb/rocksdb/logging/auto_roll_logger_test.cc +1 -2
  212. package/deps/rocksdb/rocksdb/memory/memory_allocator_test.cc +2 -2
  213. package/deps/rocksdb/rocksdb/memtable/inlineskiplist.h +226 -8
  214. package/deps/rocksdb/rocksdb/memtable/inlineskiplist_test.cc +490 -0
  215. package/deps/rocksdb/rocksdb/memtable/skiplist.h +3 -3
  216. package/deps/rocksdb/rocksdb/memtable/skiplistrep.cc +11 -0
  217. package/deps/rocksdb/rocksdb/microbench/db_basic_bench.cc +4 -12
  218. package/deps/rocksdb/rocksdb/microbench/ribbon_bench.cc +5 -5
  219. package/deps/rocksdb/rocksdb/monitoring/file_read_sample.h +21 -4
  220. package/deps/rocksdb/rocksdb/monitoring/perf_context.cc +9 -3
  221. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +21 -2
  222. package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +2 -2
  223. package/deps/rocksdb/rocksdb/options/cf_options.cc +21 -1
  224. package/deps/rocksdb/rocksdb/options/cf_options.h +2 -0
  225. package/deps/rocksdb/rocksdb/options/customizable_test.cc +0 -2
  226. package/deps/rocksdb/rocksdb/options/db_options.cc +26 -5
  227. package/deps/rocksdb/rocksdb/options/db_options.h +3 -1
  228. package/deps/rocksdb/rocksdb/options/options.cc +5 -1
  229. package/deps/rocksdb/rocksdb/options/options_helper.cc +7 -2
  230. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +109 -103
  231. package/deps/rocksdb/rocksdb/options/options_test.cc +14 -0
  232. package/deps/rocksdb/rocksdb/port/jemalloc_helper.h +15 -17
  233. package/deps/rocksdb/rocksdb/port/lang.h +4 -0
  234. package/deps/rocksdb/rocksdb/port/port_example.h +0 -23
  235. package/deps/rocksdb/rocksdb/port/stack_trace.cc +36 -0
  236. package/deps/rocksdb/rocksdb/port/stack_trace.h +9 -0
  237. package/deps/rocksdb/rocksdb/src.mk +12 -0
  238. package/deps/rocksdb/rocksdb/table/adaptive/adaptive_table_factory.cc +1 -2
  239. package/deps/rocksdb/rocksdb/table/block_based/binary_search_index_reader.cc +2 -1
  240. package/deps/rocksdb/rocksdb/table/block_based/block.cc +571 -292
  241. package/deps/rocksdb/rocksdb/table/block_based/block.h +143 -53
  242. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +154 -90
  243. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.h +5 -1
  244. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.cc +51 -14
  245. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.h +0 -2
  246. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.cc +147 -734
  247. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.h +30 -233
  248. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +178 -108
  249. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +13 -0
  250. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_impl.h +17 -4
  251. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +5 -2
  252. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +70 -0
  253. package/deps/rocksdb/rocksdb/table/block_based/block_builder.cc +168 -24
  254. package/deps/rocksdb/rocksdb/table/block_based/block_builder.h +25 -9
  255. package/deps/rocksdb/rocksdb/table/block_based/block_cache.cc +7 -4
  256. package/deps/rocksdb/rocksdb/table/block_based/block_cache.h +9 -2
  257. package/deps/rocksdb/rocksdb/table/block_based/block_test.cc +548 -169
  258. package/deps/rocksdb/rocksdb/table/block_based/block_type.h +30 -0
  259. package/deps/rocksdb/rocksdb/table/block_based/block_util.h +156 -0
  260. package/deps/rocksdb/rocksdb/table/block_based/data_block_footer.cc +73 -30
  261. package/deps/rocksdb/rocksdb/table/block_based/data_block_footer.h +74 -7
  262. package/deps/rocksdb/rocksdb/table/block_based/data_block_hash_index.h +1 -1
  263. package/deps/rocksdb/rocksdb/table/block_based/index_builder.cc +20 -14
  264. package/deps/rocksdb/rocksdb/table/block_based/index_builder.h +22 -12
  265. package/deps/rocksdb/rocksdb/table/block_based/mock_block_based_table.h +1 -1
  266. package/deps/rocksdb/rocksdb/table/block_based/multi_scan_index_iterator.cc +332 -0
  267. package/deps/rocksdb/rocksdb/table/block_based/multi_scan_index_iterator.h +133 -0
  268. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +4 -2
  269. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block_test.cc +1 -1
  270. package/deps/rocksdb/rocksdb/table/block_based/reader_common.cc +3 -2
  271. package/deps/rocksdb/rocksdb/table/block_based/reader_common.h +4 -1
  272. package/deps/rocksdb/rocksdb/table/block_based/uncompression_dict_reader.h +0 -1
  273. package/deps/rocksdb/rocksdb/table/block_based/user_defined_index_wrapper.h +126 -46
  274. package/deps/rocksdb/rocksdb/table/block_fetcher.cc +31 -3
  275. package/deps/rocksdb/rocksdb/table/block_fetcher_test.cc +1 -2
  276. package/deps/rocksdb/rocksdb/table/cleanable_test.cc +3 -1
  277. package/deps/rocksdb/rocksdb/table/external_table.cc +25 -4
  278. package/deps/rocksdb/rocksdb/table/format.cc +27 -15
  279. package/deps/rocksdb/rocksdb/table/format.h +41 -15
  280. package/deps/rocksdb/rocksdb/table/merging_iterator.cc +1 -0
  281. package/deps/rocksdb/rocksdb/table/meta_blocks.cc +22 -12
  282. package/deps/rocksdb/rocksdb/table/meta_blocks.h +0 -1
  283. package/deps/rocksdb/rocksdb/table/sst_file_dumper.cc +7 -21
  284. package/deps/rocksdb/rocksdb/table/sst_file_dumper.h +0 -1
  285. package/deps/rocksdb/rocksdb/table/sst_file_reader.cc +88 -13
  286. package/deps/rocksdb/rocksdb/table/sst_file_reader_test.cc +53 -42
  287. package/deps/rocksdb/rocksdb/table/sst_file_writer.cc +3 -12
  288. package/deps/rocksdb/rocksdb/table/table_builder.h +0 -4
  289. package/deps/rocksdb/rocksdb/table/table_properties.cc +18 -0
  290. package/deps/rocksdb/rocksdb/table/table_reader_bench.cc +2 -3
  291. package/deps/rocksdb/rocksdb/table/table_test.cc +848 -172
  292. package/deps/rocksdb/rocksdb/table/unique_id.cc +24 -20
  293. package/deps/rocksdb/rocksdb/table/unique_id_impl.h +8 -8
  294. package/deps/rocksdb/rocksdb/test_util/sync_point.h +5 -4
  295. package/deps/rocksdb/rocksdb/test_util/testutil.cc +2 -1
  296. package/deps/rocksdb/rocksdb/test_util/testutil.h +2 -2
  297. package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer_test.cc +2 -1
  298. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +238 -120
  299. package/deps/rocksdb/rocksdb/tools/db_repl_stress.cc +2 -2
  300. package/deps/rocksdb/rocksdb/tools/db_sanity_test.cc +2 -4
  301. package/deps/rocksdb/rocksdb/tools/dump/db_dump_tool.cc +4 -8
  302. package/deps/rocksdb/rocksdb/tools/dump/rocksdb_undump.cc +1 -1
  303. package/deps/rocksdb/rocksdb/tools/io_tracer_parser_test.cc +2 -3
  304. package/deps/rocksdb/rocksdb/tools/ldb_cmd.cc +82 -20
  305. package/deps/rocksdb/rocksdb/tools/ldb_cmd_test.cc +41 -47
  306. package/deps/rocksdb/rocksdb/tools/ldb_tool.cc +9 -0
  307. package/deps/rocksdb/rocksdb/tools/reduce_levels_test.cc +5 -6
  308. package/deps/rocksdb/rocksdb/tools/sst_dump_tool.cc +1 -1
  309. package/deps/rocksdb/rocksdb/tools/tool_hooks.cc +6 -5
  310. package/deps/rocksdb/rocksdb/tools/trace_analyzer_test.cc +4 -4
  311. package/deps/rocksdb/rocksdb/tools/write_stress.cc +1 -3
  312. package/deps/rocksdb/rocksdb/util/atomic.h +30 -23
  313. package/deps/rocksdb/rocksdb/util/auto_tune_compressor.cc +6 -7
  314. package/deps/rocksdb/rocksdb/util/auto_tune_compressor.h +3 -3
  315. package/deps/rocksdb/rocksdb/util/bit_fields.h +68 -46
  316. package/deps/rocksdb/rocksdb/util/bloom_impl.h +16 -16
  317. package/deps/rocksdb/rocksdb/util/coding.h +14 -27
  318. package/deps/rocksdb/rocksdb/util/compression.cc +365 -207
  319. package/deps/rocksdb/rocksdb/util/compression.h +16 -1298
  320. package/deps/rocksdb/rocksdb/util/compression_test.cc +347 -61
  321. package/deps/rocksdb/rocksdb/util/crc32c_arm64.cc +8 -9
  322. package/deps/rocksdb/rocksdb/util/crc32c_arm64.h +1 -1
  323. package/deps/rocksdb/rocksdb/util/crc32c_ppc.h +1 -1
  324. package/deps/rocksdb/rocksdb/util/dynamic_bloom_test.cc +3 -3
  325. package/deps/rocksdb/rocksdb/util/filter_bench.cc +18 -18
  326. package/deps/rocksdb/rocksdb/util/gflags_compat.h +3 -3
  327. package/deps/rocksdb/rocksdb/util/hash_test.cc +19 -7
  328. package/deps/rocksdb/rocksdb/util/io_dispatcher_imp.cc +1099 -0
  329. package/deps/rocksdb/rocksdb/util/io_dispatcher_imp.h +36 -0
  330. package/deps/rocksdb/rocksdb/util/io_dispatcher_test.cc +1919 -0
  331. package/deps/rocksdb/rocksdb/util/math.h +3 -1
  332. package/deps/rocksdb/rocksdb/util/mutexlock.h +19 -19
  333. package/deps/rocksdb/rocksdb/util/ribbon_alg.h +25 -25
  334. package/deps/rocksdb/rocksdb/util/simple_mixed_compressor.cc +5 -7
  335. package/deps/rocksdb/rocksdb/util/simple_mixed_compressor.h +4 -5
  336. package/deps/rocksdb/rocksdb/util/slice.cc +0 -10
  337. package/deps/rocksdb/rocksdb/util/slice_test.cc +35 -1
  338. package/deps/rocksdb/rocksdb/util/slice_transform_test.cc +5 -7
  339. package/deps/rocksdb/rocksdb/util/status.cc +3 -1
  340. package/deps/rocksdb/rocksdb/util/stop_watch.h +2 -0
  341. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine.cc +4 -1
  342. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine_test.cc +123 -78
  343. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_compaction_filter.cc +12 -93
  344. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_compaction_filter.h +1 -4
  345. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db.cc +0 -21
  346. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db.h +6 -48
  347. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db_impl.cc +94 -307
  348. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db_impl.h +12 -58
  349. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db_impl_filesnapshot.cc +2 -8
  350. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db_listener.h +2 -3
  351. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db_test.cc +205 -811
  352. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_dump_tool.cc +18 -9
  353. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_file.cc +2 -7
  354. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_file.h +1 -9
  355. package/deps/rocksdb/rocksdb/utilities/cassandra/cassandra_functional_test.cc +17 -11
  356. package/deps/rocksdb/rocksdb/utilities/cassandra/test_utils.cc +1 -1
  357. package/deps/rocksdb/rocksdb/utilities/cassandra/test_utils.h +1 -1
  358. package/deps/rocksdb/rocksdb/utilities/checkpoint/checkpoint_impl.cc +1 -1
  359. package/deps/rocksdb/rocksdb/utilities/checkpoint/checkpoint_test.cc +68 -61
  360. package/deps/rocksdb/rocksdb/utilities/debug.cc +2 -1
  361. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.cc +105 -59
  362. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.h +274 -7
  363. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs_test.cc +94 -0
  364. package/deps/rocksdb/rocksdb/utilities/memory/memory_test.cc +13 -17
  365. package/deps/rocksdb/rocksdb/utilities/memory/memory_util.cc +16 -3
  366. package/deps/rocksdb/rocksdb/utilities/merge_operators/string_append/stringappend_test.cc +25 -25
  367. package/deps/rocksdb/rocksdb/utilities/object_registry.cc +40 -40
  368. package/deps/rocksdb/rocksdb/utilities/option_change_migration/option_change_migration.cc +2 -5
  369. package/deps/rocksdb/rocksdb/utilities/options/options_util_test.cc +17 -19
  370. package/deps/rocksdb/rocksdb/utilities/persistent_cache/block_cache_tier_file.cc +2 -2
  371. package/deps/rocksdb/rocksdb/utilities/persistent_cache/block_cache_tier_file.h +2 -2
  372. package/deps/rocksdb/rocksdb/utilities/persistent_cache/volatile_tier_impl.cc +1 -1
  373. package/deps/rocksdb/rocksdb/utilities/transactions/optimistic_transaction_db_impl.cc +2 -2
  374. package/deps/rocksdb/rocksdb/utilities/transactions/optimistic_transaction_db_impl.h +4 -13
  375. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.cc +3 -3
  376. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.h +6 -0
  377. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_transaction_seqno_test.cc +431 -0
  378. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_transaction_test.cc +1 -2
  379. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_txn.h +91 -0
  380. package/deps/rocksdb/rocksdb/utilities/trie_index/bitvector.cc +562 -0
  381. package/deps/rocksdb/rocksdb/utilities/trie_index/bitvector.h +615 -0
  382. package/deps/rocksdb/rocksdb/utilities/trie_index/louds_trie.cc +2575 -0
  383. package/deps/rocksdb/rocksdb/utilities/trie_index/louds_trie.h +685 -0
  384. package/deps/rocksdb/rocksdb/utilities/trie_index/trie_index_db_test.cc +2843 -0
  385. package/deps/rocksdb/rocksdb/utilities/trie_index/trie_index_factory.cc +567 -0
  386. package/deps/rocksdb/rocksdb/utilities/trie_index/trie_index_factory.h +275 -0
  387. package/deps/rocksdb/rocksdb/utilities/trie_index/trie_index_test.cc +5183 -0
  388. package/deps/rocksdb/rocksdb/utilities/ttl/db_ttl_impl.cc +4 -3
  389. package/deps/rocksdb/rocksdb/utilities/ttl/db_ttl_impl.h +1 -1
  390. package/deps/rocksdb/rocksdb/utilities/ttl/ttl_test.cc +2 -2
  391. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_internal.h +3 -3
  392. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_test.cc +93 -88
  393. package/deps/rocksdb/rocksdb.gyp +7 -0
  394. package/index.js +70 -10
  395. package/iterator.js +25 -3
  396. package/max_rev_operator.h +9 -5
  397. package/package.json +1 -1
  398. package/prebuilds/darwin-arm64/@nxtedition+rocksdb.node +0 -0
  399. package/prebuilds/linux-x64/@nxtedition+rocksdb.node +0 -0
  400. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/lua/rocks_lua_custom_library.h +0 -43
  401. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/lua/rocks_lua_util.h +0 -55
@@ -10,49 +10,14 @@
10
10
  #pragma once
11
11
 
12
12
  #include <algorithm>
13
- #include <limits>
14
-
15
- #ifdef ROCKSDB_MALLOC_USABLE_SIZE
16
- #ifdef OS_FREEBSD
17
- #include <malloc_np.h>
18
- #else // OS_FREEBSD
19
- #include <malloc.h>
20
- #endif // OS_FREEBSD
21
- #endif // ROCKSDB_MALLOC_USABLE_SIZE
22
- #include <string>
23
13
 
24
14
  #include "memory/memory_allocator_impl.h"
25
- #include "port/likely.h"
26
15
  #include "rocksdb/advanced_compression.h"
27
16
  #include "rocksdb/options.h"
28
17
  #include "table/block_based/block_type.h"
29
- #include "test_util/sync_point.h"
30
- #include "util/atomic.h"
31
- #include "util/cast_util.h"
18
+ #include "util/aligned_buffer.h"
32
19
  #include "util/coding.h"
33
20
  #include "util/compression_context_cache.h"
34
- #include "util/string_util.h"
35
-
36
- #ifdef SNAPPY
37
- #include <snappy-sinksource.h>
38
- #include <snappy.h>
39
- #endif
40
-
41
- #ifdef ZLIB
42
- #include <zlib.h>
43
- #endif
44
-
45
- #ifdef BZIP2
46
- #include <bzlib.h>
47
- #endif
48
-
49
- #if defined(LZ4)
50
- #include <lz4.h>
51
- #include <lz4hc.h>
52
- #if LZ4_VERSION_NUMBER < 10700 // < r129
53
- #error "LZ4 support requires version >= 1.7.0 (lz4-devel)"
54
- #endif
55
- #endif
56
21
 
57
22
  #ifdef ZSTD
58
23
  #include <zstd.h>
@@ -244,41 +209,7 @@ struct DecompressorDict {
244
209
  size_t ApproximateMemoryUsage() const { return memory_usage_; }
245
210
 
246
211
  private:
247
- void Populate(Decompressor& from_decompressor, Slice dict) {
248
- if (UNLIKELY(dict.empty())) {
249
- dict_str_ = {};
250
- dict_allocation_ = {};
251
- // Appropriately reject bad files with empty dictionary block.
252
- // It is longstanding not to write an empty dictionary block:
253
- // https://github.com/facebook/rocksdb/blame/10.2.fb/table/block_based/block_based_table_builder.cc#L1841
254
- decompressor_ = std::make_unique<FailureDecompressor>(
255
- Status::Corruption("Decompression dictionary is empty"));
256
- } else {
257
- Status s = from_decompressor.MaybeCloneForDict(dict, &decompressor_);
258
- if (decompressor_ == nullptr) {
259
- dict_str_ = {};
260
- dict_allocation_ = {};
261
- assert(!s.ok());
262
- decompressor_ = std::make_unique<FailureDecompressor>(std::move(s));
263
- } else {
264
- assert(s.ok());
265
- assert(decompressor_->GetSerializedDict() == dict);
266
- }
267
- }
268
-
269
- memory_usage_ = sizeof(struct DecompressorDict);
270
- memory_usage_ += dict_str_.size();
271
- if (dict_allocation_) {
272
- auto allocator = dict_allocation_.get_deleter().allocator;
273
- if (allocator) {
274
- memory_usage_ +=
275
- allocator->UsableSize(dict_allocation_.get(), GetRawDict().size());
276
- } else {
277
- memory_usage_ += GetRawDict().size();
278
- }
279
- }
280
- memory_usage_ += decompressor_->ApproximateOwnedMemoryUsage();
281
- }
212
+ void Populate(Decompressor& from_decompressor, Slice dict);
282
213
  };
283
214
 
284
215
  // Holds dictionary and related data, like ZSTD's digested compression
@@ -358,140 +289,6 @@ struct CompressionDict {
358
289
  CompressionDict& operator=(const CompressionDict&) = delete;
359
290
  };
360
291
 
361
- // Holds dictionary and related data, like ZSTD's digested uncompression
362
- // dictionary.
363
- struct UncompressionDict {
364
- // Block containing the data for the compression dictionary in case the
365
- // constructor that takes a string parameter is used.
366
- std::string dict_;
367
-
368
- // Block containing the data for the compression dictionary in case the
369
- // constructor that takes a Slice parameter is used and the passed in
370
- // CacheAllocationPtr is not nullptr.
371
- CacheAllocationPtr allocation_;
372
-
373
- // Slice pointing to the compression dictionary data. Can point to
374
- // dict_, allocation_, or some other memory location, depending on how
375
- // the object was constructed.
376
- Slice slice_;
377
-
378
- #ifdef ROCKSDB_ZSTD_DDICT
379
- // Processed version of the contents of slice_ for ZSTD compression.
380
- ZSTD_DDict* zstd_ddict_ = nullptr;
381
- #endif // ROCKSDB_ZSTD_DDICT
382
-
383
- UncompressionDict(std::string&& dict, bool using_zstd)
384
- : dict_(std::move(dict)), slice_(dict_) {
385
- #ifdef ROCKSDB_ZSTD_DDICT
386
- if (!slice_.empty() && using_zstd) {
387
- zstd_ddict_ = ZSTD_createDDict_byReference(slice_.data(), slice_.size());
388
- assert(zstd_ddict_ != nullptr);
389
- }
390
- #else
391
- (void)using_zstd;
392
- #endif // ROCKSDB_ZSTD_DDICT
393
- }
394
-
395
- UncompressionDict(Slice slice, CacheAllocationPtr&& allocation,
396
- bool using_zstd)
397
- : allocation_(std::move(allocation)), slice_(std::move(slice)) {
398
- #ifdef ROCKSDB_ZSTD_DDICT
399
- if (!slice_.empty() && using_zstd) {
400
- zstd_ddict_ = ZSTD_createDDict_byReference(slice_.data(), slice_.size());
401
- assert(zstd_ddict_ != nullptr);
402
- }
403
- #else
404
- (void)using_zstd;
405
- #endif // ROCKSDB_ZSTD_DDICT
406
- }
407
-
408
- UncompressionDict(UncompressionDict&& rhs)
409
- : dict_(std::move(rhs.dict_)),
410
- allocation_(std::move(rhs.allocation_)),
411
- slice_(std::move(rhs.slice_))
412
- #ifdef ROCKSDB_ZSTD_DDICT
413
- ,
414
- zstd_ddict_(rhs.zstd_ddict_)
415
- #endif
416
- {
417
- #ifdef ROCKSDB_ZSTD_DDICT
418
- rhs.zstd_ddict_ = nullptr;
419
- #endif
420
- }
421
-
422
- ~UncompressionDict() {
423
- #ifdef ROCKSDB_ZSTD_DDICT
424
- size_t res = 0;
425
- if (zstd_ddict_ != nullptr) {
426
- res = ZSTD_freeDDict(zstd_ddict_);
427
- }
428
- assert(res == 0); // Last I checked they can't fail
429
- (void)res; // prevent unused var warning
430
- #endif // ROCKSDB_ZSTD_DDICT
431
- }
432
-
433
- UncompressionDict& operator=(UncompressionDict&& rhs) {
434
- if (this == &rhs) {
435
- return *this;
436
- }
437
-
438
- dict_ = std::move(rhs.dict_);
439
- allocation_ = std::move(rhs.allocation_);
440
- slice_ = std::move(rhs.slice_);
441
-
442
- #ifdef ROCKSDB_ZSTD_DDICT
443
- zstd_ddict_ = rhs.zstd_ddict_;
444
- rhs.zstd_ddict_ = nullptr;
445
- #endif
446
-
447
- return *this;
448
- }
449
-
450
- // The object is self-contained if the string constructor is used, or the
451
- // Slice constructor is invoked with a non-null allocation. Otherwise, it
452
- // is the caller's responsibility to ensure that the underlying storage
453
- // outlives this object.
454
- bool own_bytes() const { return !dict_.empty() || allocation_; }
455
-
456
- const Slice& GetRawDict() const { return slice_; }
457
-
458
- // For TypedCacheInterface
459
- const Slice& ContentSlice() const { return slice_; }
460
- static constexpr CacheEntryRole kCacheEntryRole = CacheEntryRole::kOtherBlock;
461
- static constexpr BlockType kBlockType = BlockType::kCompressionDictionary;
462
-
463
- #ifdef ROCKSDB_ZSTD_DDICT
464
- const ZSTD_DDict* GetDigestedZstdDDict() const { return zstd_ddict_; }
465
- #endif // ROCKSDB_ZSTD_DDICT
466
-
467
- static const UncompressionDict& GetEmptyDict() {
468
- static UncompressionDict empty_dict{};
469
- return empty_dict;
470
- }
471
-
472
- size_t ApproximateMemoryUsage() const {
473
- size_t usage = sizeof(struct UncompressionDict);
474
- usage += dict_.size();
475
- if (allocation_) {
476
- auto allocator = allocation_.get_deleter().allocator;
477
- if (allocator) {
478
- usage += allocator->UsableSize(allocation_.get(), slice_.size());
479
- } else {
480
- usage += slice_.size();
481
- }
482
- }
483
- #ifdef ROCKSDB_ZSTD_DDICT
484
- usage += ZSTD_sizeof_DDict(zstd_ddict_);
485
- #endif // ROCKSDB_ZSTD_DDICT
486
- return usage;
487
- }
488
-
489
- UncompressionDict() = default;
490
- // Disable copy
491
- UncompressionDict(const CompressionDict&) = delete;
492
- UncompressionDict& operator=(const CompressionDict&) = delete;
493
- };
494
-
495
292
  class CompressionContext : public Compressor::WorkingArea {
496
293
  private:
497
294
  #ifdef ZSTD
@@ -563,25 +360,6 @@ class CompressionContext : public Compressor::WorkingArea {
563
360
  CompressionContext& operator=(const CompressionContext&) = delete;
564
361
  };
565
362
 
566
- // TODO: rename
567
- class CompressionInfo {
568
- const CompressionOptions& opts_;
569
- const CompressionContext& context_;
570
- const CompressionDict& dict_;
571
- const CompressionType type_;
572
-
573
- public:
574
- CompressionInfo(const CompressionOptions& _opts,
575
- const CompressionContext& _context,
576
- const CompressionDict& _dict, CompressionType _type)
577
- : opts_(_opts), context_(_context), dict_(_dict), type_(_type) {}
578
-
579
- const CompressionOptions& options() const { return opts_; }
580
- const CompressionContext& context() const { return context_; }
581
- const CompressionDict& dict() const { return dict_; }
582
- CompressionType type() const { return type_; }
583
- };
584
-
585
363
  // This is like a working area, reusable for different dicts, etc.
586
364
  // TODO: refactor / consolidate
587
365
  class UncompressionContext : public Decompressor::WorkingArea {
@@ -611,21 +389,6 @@ class UncompressionContext : public Decompressor::WorkingArea {
611
389
  }
612
390
  };
613
391
 
614
- class UncompressionInfo {
615
- const UncompressionContext& context_;
616
- const UncompressionDict& dict_;
617
- const CompressionType type_;
618
-
619
- public:
620
- UncompressionInfo(const UncompressionContext& _context,
621
- const UncompressionDict& _dict, CompressionType _type)
622
- : context_(_context), dict_(_dict), type_(_type) {}
623
-
624
- const UncompressionContext& context() const { return context_; }
625
- const UncompressionDict& dict() const { return dict_; }
626
- CompressionType type() const { return type_; }
627
- };
628
-
629
392
  inline bool Snappy_Supported() {
630
393
  #ifdef SNAPPY
631
394
  return true;
@@ -748,898 +511,13 @@ inline bool DictCompressionTypeSupported(CompressionType compression_type) {
748
511
  }
749
512
 
750
513
  // WART: does not match OptionsHelper::compression_type_string_map
751
- inline std::string CompressionTypeToString(CompressionType compression_type) {
752
- switch (compression_type) {
753
- case kNoCompression:
754
- return "NoCompression";
755
- case kSnappyCompression:
756
- return "Snappy";
757
- case kZlibCompression:
758
- return "Zlib";
759
- case kBZip2Compression:
760
- return "BZip2";
761
- case kLZ4Compression:
762
- return "LZ4";
763
- case kLZ4HCCompression:
764
- return "LZ4HC";
765
- case kXpressCompression:
766
- return "Xpress";
767
- case kZSTD:
768
- return "ZSTD";
769
- case kDisableCompressionOption:
770
- return "DisableOption";
771
- default: {
772
- bool is_custom = compression_type >= kFirstCustomCompression &&
773
- compression_type <= kLastCustomCompression;
774
- unsigned char c = lossless_cast<unsigned char>(compression_type);
775
- return (is_custom ? "Custom" : "Reserved") +
776
- ToBaseCharsString<16>(2, c, /*uppercase=*/true);
777
- }
778
- }
779
- }
514
+ std::string CompressionTypeToString(CompressionType compression_type);
780
515
 
781
516
  // WART: does not match OptionsHelper::compression_type_string_map
782
- inline CompressionType CompressionTypeFromString(
783
- std::string compression_type_str) {
784
- if (!compression_type_str.empty()) {
785
- switch (compression_type_str[0]) {
786
- case 'N':
787
- if (compression_type_str == "NoCompression") {
788
- return kNoCompression;
789
- }
790
- break;
791
- case 'S':
792
- if (compression_type_str == "Snappy") {
793
- return kSnappyCompression;
794
- }
795
- break;
796
- case 'Z':
797
- if (compression_type_str == "ZSTD") {
798
- return kZSTD;
799
- }
800
- if (compression_type_str == "Zlib") {
801
- return kZlibCompression;
802
- }
803
- break;
804
- case 'B':
805
- if (compression_type_str == "BZip2") {
806
- return kBZip2Compression;
807
- }
808
- break;
809
- case 'L':
810
- if (compression_type_str == "LZ4") {
811
- return kLZ4Compression;
812
- }
813
- if (compression_type_str == "LZ4HC") {
814
- return kLZ4HCCompression;
815
- }
816
- break;
817
- case 'X':
818
- if (compression_type_str == "Xpress") {
819
- return kXpressCompression;
820
- }
821
- break;
822
- default:;
823
- }
824
- }
825
- // unrecognized
826
- return kDisableCompressionOption;
827
- }
828
-
829
- inline std::string CompressionOptionsToString(
830
- const CompressionOptions& compression_options) {
831
- std::string result;
832
- result.reserve(512);
833
- result.append("window_bits=")
834
- .append(std::to_string(compression_options.window_bits))
835
- .append("; ");
836
- result.append("level=")
837
- .append(std::to_string(compression_options.level))
838
- .append("; ");
839
- result.append("strategy=")
840
- .append(std::to_string(compression_options.strategy))
841
- .append("; ");
842
- result.append("max_dict_bytes=")
843
- .append(std::to_string(compression_options.max_dict_bytes))
844
- .append("; ");
845
- result.append("zstd_max_train_bytes=")
846
- .append(std::to_string(compression_options.zstd_max_train_bytes))
847
- .append("; ");
848
- // NOTE: parallel_threads is skipped because it doesn't really affect the file
849
- // contents written, arguably doesn't belong in CompressionOptions
850
- result.append("enabled=")
851
- .append(std::to_string(compression_options.enabled))
852
- .append("; ");
853
- result.append("max_dict_buffer_bytes=")
854
- .append(std::to_string(compression_options.max_dict_buffer_bytes))
855
- .append("; ");
856
- result.append("use_zstd_dict_trainer=")
857
- .append(std::to_string(compression_options.use_zstd_dict_trainer))
858
- .append("; ");
859
- result.append("max_compressed_bytes_per_kb=")
860
- .append(std::to_string(compression_options.max_compressed_bytes_per_kb))
861
- .append("; ");
862
- result.append("checksum=")
863
- .append(std::to_string(compression_options.checksum))
864
- .append("; ");
865
- return result;
866
- }
867
-
868
- // compress_format_version can have two values:
869
- // 1 -- decompressed sizes for BZip2 and Zlib are not included in the compressed
870
- // block. Also, decompressed sizes for LZ4 are encoded in platform-dependent
871
- // way.
872
- // 2 -- Zlib, BZip2 and LZ4 encode decompressed size as Varint32 just before the
873
- // start of compressed block. Snappy and XPRESS instead extract the decompressed
874
- // size from the compressed block itself, same as version 1.
875
-
876
- inline bool Snappy_Compress(const CompressionInfo& /*info*/, const char* input,
877
- size_t length, ::std::string* output) {
878
- #ifdef SNAPPY
879
- output->resize(snappy::MaxCompressedLength(length));
880
- size_t outlen;
881
- snappy::RawCompress(input, length, &(*output)[0], &outlen);
882
- output->resize(outlen);
883
- return true;
884
- #else
885
- (void)input;
886
- (void)length;
887
- (void)output;
888
- return false;
889
- #endif
890
- }
891
-
892
- inline CacheAllocationPtr Snappy_Uncompress(
893
- const char* input, size_t length, size_t* uncompressed_size,
894
- MemoryAllocator* allocator = nullptr) {
895
- #ifdef SNAPPY
896
- size_t uncompressed_length = 0;
897
- if (!snappy::GetUncompressedLength(input, length, &uncompressed_length)) {
898
- return nullptr;
899
- }
900
-
901
- CacheAllocationPtr output = AllocateBlock(uncompressed_length, allocator);
902
-
903
- if (!snappy::RawUncompress(input, length, output.get())) {
904
- return nullptr;
905
- }
906
-
907
- *uncompressed_size = uncompressed_length;
908
-
909
- return output;
910
- #else
911
- (void)input;
912
- (void)length;
913
- (void)uncompressed_size;
914
- (void)allocator;
915
- return nullptr;
916
- #endif
917
- }
918
-
919
- namespace compression {
920
- // returns size
921
- inline size_t PutDecompressedSizeInfo(std::string* output, uint32_t length) {
922
- PutVarint32(output, length);
923
- return output->size();
924
- }
925
-
926
- inline bool GetDecompressedSizeInfo(const char** input_data,
927
- size_t* input_length,
928
- uint32_t* output_len) {
929
- auto new_input_data =
930
- GetVarint32Ptr(*input_data, *input_data + *input_length, output_len);
931
- if (new_input_data == nullptr) {
932
- return false;
933
- }
934
- *input_length -= (new_input_data - *input_data);
935
- *input_data = new_input_data;
936
- return true;
937
- }
938
- } // namespace compression
939
-
940
- // compress_format_version == 1 -- decompressed size is not included in the
941
- // block header
942
- // compress_format_version == 2 -- decompressed size is included in the block
943
- // header in varint32 format
944
- // @param compression_dict Data for presetting the compression library's
945
- // dictionary.
946
- inline bool Zlib_Compress(const CompressionInfo& info,
947
- uint32_t compress_format_version, const char* input,
948
- size_t length, ::std::string* output) {
949
- #ifdef ZLIB
950
- if (length > std::numeric_limits<uint32_t>::max()) {
951
- // Can't compress more than 4GB
952
- return false;
953
- }
954
-
955
- size_t output_header_len = 0;
956
- if (compress_format_version == 2) {
957
- output_header_len = compression::PutDecompressedSizeInfo(
958
- output, static_cast<uint32_t>(length));
959
- }
960
-
961
- // The memLevel parameter specifies how much memory should be allocated for
962
- // the internal compression state.
963
- // memLevel=1 uses minimum memory but is slow and reduces compression ratio.
964
- // memLevel=9 uses maximum memory for optimal speed.
965
- // The default value is 8. See zconf.h for more details.
966
- static const int memLevel = 8;
967
- int level;
968
- if (info.options().level == CompressionOptions::kDefaultCompressionLevel) {
969
- level = Z_DEFAULT_COMPRESSION;
970
- } else {
971
- level = info.options().level;
972
- }
973
- z_stream _stream;
974
- memset(&_stream, 0, sizeof(z_stream));
975
- int st = deflateInit2(&_stream, level, Z_DEFLATED, info.options().window_bits,
976
- memLevel, info.options().strategy);
977
- if (st != Z_OK) {
978
- return false;
979
- }
980
-
981
- Slice compression_dict = info.dict().GetRawDict();
982
- if (compression_dict.size()) {
983
- // Initialize the compression library's dictionary
984
- st = deflateSetDictionary(
985
- &_stream, reinterpret_cast<const Bytef*>(compression_dict.data()),
986
- static_cast<unsigned int>(compression_dict.size()));
987
- if (st != Z_OK) {
988
- deflateEnd(&_stream);
989
- return false;
990
- }
991
- }
992
-
993
- // Get an upper bound on the compressed size.
994
- size_t upper_bound =
995
- deflateBound(&_stream, static_cast<unsigned long>(length));
996
- output->resize(output_header_len + upper_bound);
997
-
998
- // Compress the input, and put compressed data in output.
999
- _stream.next_in = (Bytef*)input;
1000
- _stream.avail_in = static_cast<unsigned int>(length);
1001
-
1002
- // Initialize the output size.
1003
- _stream.avail_out = static_cast<unsigned int>(upper_bound);
1004
- _stream.next_out = reinterpret_cast<Bytef*>(&(*output)[output_header_len]);
1005
-
1006
- bool compressed = false;
1007
- st = deflate(&_stream, Z_FINISH);
1008
- if (st == Z_STREAM_END) {
1009
- compressed = true;
1010
- output->resize(output->size() - _stream.avail_out);
1011
- }
1012
- // The only return value we really care about is Z_STREAM_END.
1013
- // Z_OK means insufficient output space. This means the compression is
1014
- // bigger than decompressed size. Just fail the compression in that case.
1015
-
1016
- deflateEnd(&_stream);
1017
- return compressed;
1018
- #else
1019
- (void)info;
1020
- (void)compress_format_version;
1021
- (void)input;
1022
- (void)length;
1023
- (void)output;
1024
- return false;
1025
- #endif
1026
- }
1027
-
1028
- // compress_format_version == 1 -- decompressed size is not included in the
1029
- // block header
1030
- // compress_format_version == 2 -- decompressed size is included in the block
1031
- // header in varint32 format
1032
- // @param compression_dict Data for presetting the compression library's
1033
- // dictionary.
1034
- inline CacheAllocationPtr Zlib_Uncompress(
1035
- const UncompressionInfo& info, const char* input_data, size_t input_length,
1036
- size_t* uncompressed_size, uint32_t compress_format_version,
1037
- MemoryAllocator* allocator = nullptr, int windowBits = -14) {
1038
- #ifdef ZLIB
1039
- uint32_t output_len = 0;
1040
- if (compress_format_version == 2) {
1041
- if (!compression::GetDecompressedSizeInfo(&input_data, &input_length,
1042
- &output_len)) {
1043
- return nullptr;
1044
- }
1045
- } else {
1046
- // Assume the decompressed data size will 5x of compressed size, but round
1047
- // to the page size
1048
- size_t proposed_output_len = ((input_length * 5) & (~(4096 - 1))) + 4096;
1049
- output_len = static_cast<uint32_t>(
1050
- std::min(proposed_output_len,
1051
- static_cast<size_t>(std::numeric_limits<uint32_t>::max())));
1052
- }
1053
-
1054
- z_stream _stream;
1055
- memset(&_stream, 0, sizeof(z_stream));
1056
-
1057
- // For raw inflate, the windowBits should be -8..-15.
1058
- // If windowBits is bigger than zero, it will use either zlib
1059
- // header or gzip header. Adding 32 to it will do automatic detection.
1060
- int st =
1061
- inflateInit2(&_stream, windowBits > 0 ? windowBits + 32 : windowBits);
1062
- if (st != Z_OK) {
1063
- return nullptr;
1064
- }
1065
-
1066
- const Slice& compression_dict = info.dict().GetRawDict();
1067
- if (compression_dict.size()) {
1068
- // Initialize the compression library's dictionary
1069
- st = inflateSetDictionary(
1070
- &_stream, reinterpret_cast<const Bytef*>(compression_dict.data()),
1071
- static_cast<unsigned int>(compression_dict.size()));
1072
- if (st != Z_OK) {
1073
- return nullptr;
1074
- }
1075
- }
1076
-
1077
- _stream.next_in = (Bytef*)input_data;
1078
- _stream.avail_in = static_cast<unsigned int>(input_length);
1079
-
1080
- auto output = AllocateBlock(output_len, allocator);
1081
-
1082
- _stream.next_out = (Bytef*)output.get();
1083
- _stream.avail_out = static_cast<unsigned int>(output_len);
1084
-
1085
- bool done = false;
1086
- while (!done) {
1087
- st = inflate(&_stream, Z_SYNC_FLUSH);
1088
- switch (st) {
1089
- case Z_STREAM_END:
1090
- done = true;
1091
- break;
1092
- case Z_OK: {
1093
- // No output space. Increase the output space by 20%.
1094
- // We should never run out of output space if
1095
- // compress_format_version == 2
1096
- assert(compress_format_version != 2);
1097
- size_t old_sz = output_len;
1098
- uint32_t output_len_delta = output_len / 5;
1099
- output_len += output_len_delta < 10 ? 10 : output_len_delta;
1100
- auto tmp = AllocateBlock(output_len, allocator);
1101
- memcpy(tmp.get(), output.get(), old_sz);
1102
- output = std::move(tmp);
1103
-
1104
- // Set more output.
1105
- _stream.next_out = (Bytef*)(output.get() + old_sz);
1106
- _stream.avail_out = static_cast<unsigned int>(output_len - old_sz);
1107
- break;
1108
- }
1109
- case Z_BUF_ERROR:
1110
- default:
1111
- inflateEnd(&_stream);
1112
- return nullptr;
1113
- }
1114
- }
1115
-
1116
- // If we encoded decompressed block size, we should have no bytes left
1117
- assert(compress_format_version != 2 || _stream.avail_out == 0);
1118
- assert(output_len >= _stream.avail_out);
1119
- *uncompressed_size = output_len - _stream.avail_out;
1120
- inflateEnd(&_stream);
1121
- return output;
1122
- #else
1123
- (void)info;
1124
- (void)input_data;
1125
- (void)input_length;
1126
- (void)uncompressed_size;
1127
- (void)compress_format_version;
1128
- (void)allocator;
1129
- (void)windowBits;
1130
- return nullptr;
1131
- #endif
1132
- }
1133
-
1134
- // compress_format_version == 1 -- decompressed size is not included in the
1135
- // block header
1136
- // compress_format_version == 2 -- decompressed size is included in the block
1137
- // header in varint32 format
1138
- inline bool BZip2_Compress(const CompressionInfo& /*info*/,
1139
- uint32_t compress_format_version, const char* input,
1140
- size_t length, ::std::string* output) {
1141
- #ifdef BZIP2
1142
- if (length > std::numeric_limits<uint32_t>::max()) {
1143
- // Can't compress more than 4GB
1144
- return false;
1145
- }
1146
- size_t output_header_len = 0;
1147
- if (compress_format_version == 2) {
1148
- output_header_len = compression::PutDecompressedSizeInfo(
1149
- output, static_cast<uint32_t>(length));
1150
- }
1151
- // Resize output to be the plain data length.
1152
- // This may not be big enough if the compression actually expands data.
1153
- output->resize(output_header_len + length);
1154
-
1155
- bz_stream _stream;
1156
- memset(&_stream, 0, sizeof(bz_stream));
1157
-
1158
- // Block size 1 is 100K.
1159
- // 0 is for silent.
1160
- // 30 is the default workFactor
1161
- int st = BZ2_bzCompressInit(&_stream, 1, 0, 30);
1162
- if (st != BZ_OK) {
1163
- return false;
1164
- }
1165
-
1166
- // Compress the input, and put compressed data in output.
1167
- _stream.next_in = (char*)input;
1168
- _stream.avail_in = static_cast<unsigned int>(length);
1169
-
1170
- // Initialize the output size.
1171
- _stream.avail_out = static_cast<unsigned int>(length);
1172
- _stream.next_out = output->data() + output_header_len;
1173
-
1174
- bool compressed = false;
1175
- st = BZ2_bzCompress(&_stream, BZ_FINISH);
1176
- if (st == BZ_STREAM_END) {
1177
- compressed = true;
1178
- output->resize(output->size() - _stream.avail_out);
1179
- }
1180
- // The only return value we really care about is BZ_STREAM_END.
1181
- // BZ_FINISH_OK means insufficient output space. This means the compression
1182
- // is bigger than decompressed size. Just fail the compression in that case.
1183
-
1184
- BZ2_bzCompressEnd(&_stream);
1185
- return compressed;
1186
- #else
1187
- (void)compress_format_version;
1188
- (void)input;
1189
- (void)length;
1190
- (void)output;
1191
- return false;
1192
- #endif
1193
- }
1194
-
1195
- // compress_format_version == 1 -- decompressed size is not included in the
1196
- // block header
1197
- // compress_format_version == 2 -- decompressed size is included in the block
1198
- // header in varint32 format
1199
- inline CacheAllocationPtr BZip2_Uncompress(
1200
- const char* input_data, size_t input_length, size_t* uncompressed_size,
1201
- uint32_t compress_format_version, MemoryAllocator* allocator = nullptr) {
1202
- #ifdef BZIP2
1203
- uint32_t output_len = 0;
1204
- if (compress_format_version == 2) {
1205
- if (!compression::GetDecompressedSizeInfo(&input_data, &input_length,
1206
- &output_len)) {
1207
- return nullptr;
1208
- }
1209
- } else {
1210
- // Assume the decompressed data size will 5x of compressed size, but round
1211
- // to the next page size
1212
- size_t proposed_output_len = ((input_length * 5) & (~(4096 - 1))) + 4096;
1213
- output_len = static_cast<uint32_t>(
1214
- std::min(proposed_output_len,
1215
- static_cast<size_t>(std::numeric_limits<uint32_t>::max())));
1216
- }
1217
-
1218
- bz_stream _stream;
1219
- memset(&_stream, 0, sizeof(bz_stream));
1220
-
1221
- int st = BZ2_bzDecompressInit(&_stream, 0, 0);
1222
- if (st != BZ_OK) {
1223
- return nullptr;
1224
- }
1225
-
1226
- _stream.next_in = (char*)input_data;
1227
- _stream.avail_in = static_cast<unsigned int>(input_length);
1228
-
1229
- auto output = AllocateBlock(output_len, allocator);
1230
-
1231
- _stream.next_out = (char*)output.get();
1232
- _stream.avail_out = static_cast<unsigned int>(output_len);
1233
-
1234
- bool done = false;
1235
- while (!done) {
1236
- st = BZ2_bzDecompress(&_stream);
1237
- switch (st) {
1238
- case BZ_STREAM_END:
1239
- done = true;
1240
- break;
1241
- case BZ_OK: {
1242
- // No output space. Increase the output space by 20%.
1243
- // We should never run out of output space if
1244
- // compress_format_version == 2
1245
- assert(compress_format_version != 2);
1246
- uint32_t old_sz = output_len;
1247
- output_len = output_len * 1.2;
1248
- auto tmp = AllocateBlock(output_len, allocator);
1249
- memcpy(tmp.get(), output.get(), old_sz);
1250
- output = std::move(tmp);
1251
-
1252
- // Set more output.
1253
- _stream.next_out = (char*)(output.get() + old_sz);
1254
- _stream.avail_out = static_cast<unsigned int>(output_len - old_sz);
1255
- break;
1256
- }
1257
- default:
1258
- BZ2_bzDecompressEnd(&_stream);
1259
- return nullptr;
1260
- }
1261
- }
1262
-
1263
- // If we encoded decompressed block size, we should have no bytes left
1264
- assert(compress_format_version != 2 || _stream.avail_out == 0);
1265
- assert(output_len >= _stream.avail_out);
1266
- *uncompressed_size = output_len - _stream.avail_out;
1267
- BZ2_bzDecompressEnd(&_stream);
1268
- return output;
1269
- #else
1270
- (void)input_data;
1271
- (void)input_length;
1272
- (void)uncompressed_size;
1273
- (void)compress_format_version;
1274
- (void)allocator;
1275
- return nullptr;
1276
- #endif
1277
- }
1278
-
1279
- // compress_format_version == 1 -- decompressed size is included in the
1280
- // block header using memcpy, which makes database non-portable)
1281
- // compress_format_version == 2 -- decompressed size is included in the block
1282
- // header in varint32 format
1283
- // @param compression_dict Data for presetting the compression library's
1284
- // dictionary.
1285
- inline bool LZ4_Compress(const CompressionInfo& info,
1286
- uint32_t compress_format_version, const char* input,
1287
- size_t length, ::std::string* output) {
1288
- #ifdef LZ4
1289
- if (length > std::numeric_limits<uint32_t>::max()) {
1290
- // Can't compress more than 4GB
1291
- return false;
1292
- }
1293
-
1294
- size_t output_header_len = 0;
1295
- if (compress_format_version == 2) {
1296
- // new encoding, using varint32 to store size information
1297
- output_header_len = compression::PutDecompressedSizeInfo(
1298
- output, static_cast<uint32_t>(length));
1299
- } else {
1300
- // legacy encoding, which is not really portable (depends on big/little
1301
- // endianness)
1302
- output_header_len = 8;
1303
- output->resize(output_header_len);
1304
- char* p = const_cast<char*>(output->c_str());
1305
- memcpy(p, &length, sizeof(length));
1306
- }
1307
- int compress_bound = LZ4_compressBound(static_cast<int>(length));
1308
- output->resize(static_cast<size_t>(output_header_len + compress_bound));
1309
-
1310
- int outlen;
1311
- #if LZ4_VERSION_NUMBER >= 10400 // r124+
1312
- LZ4_stream_t* stream = LZ4_createStream();
1313
- Slice compression_dict = info.dict().GetRawDict();
1314
- if (compression_dict.size()) {
1315
- LZ4_loadDict(stream, compression_dict.data(),
1316
- static_cast<int>(compression_dict.size()));
1317
- }
1318
- #if LZ4_VERSION_NUMBER >= 10700 // r129+
1319
- int acceleration;
1320
- if (info.options().level < 0) {
1321
- acceleration = -info.options().level;
1322
- } else {
1323
- acceleration = 1;
1324
- }
1325
- outlen = LZ4_compress_fast_continue(
1326
- stream, input, &(*output)[output_header_len], static_cast<int>(length),
1327
- compress_bound, acceleration);
1328
- #else // up to r128
1329
- outlen = LZ4_compress_limitedOutput_continue(
1330
- stream, input, &(*output)[output_header_len], static_cast<int>(length),
1331
- compress_bound);
1332
- #endif
1333
- LZ4_freeStream(stream);
1334
- #else // up to r123
1335
- outlen = LZ4_compress_limitedOutput(input, &(*output)[output_header_len],
1336
- static_cast<int>(length), compress_bound);
1337
- #endif // LZ4_VERSION_NUMBER >= 10400
1338
-
1339
- if (outlen == 0) {
1340
- return false;
1341
- }
1342
- output->resize(static_cast<size_t>(output_header_len + outlen));
1343
- return true;
1344
- #else // LZ4
1345
- (void)info;
1346
- (void)compress_format_version;
1347
- (void)input;
1348
- (void)length;
1349
- (void)output;
1350
- return false;
1351
- #endif
1352
- }
1353
-
1354
- // compress_format_version == 1 -- decompressed size is included in the
1355
- // block header using memcpy, which makes database non-portable)
1356
- // compress_format_version == 2 -- decompressed size is included in the block
1357
- // header in varint32 format
1358
- // @param compression_dict Data for presetting the compression library's
1359
- // dictionary.
1360
- inline CacheAllocationPtr LZ4_Uncompress(const UncompressionInfo& info,
1361
- const char* input_data,
1362
- size_t input_length,
1363
- size_t* uncompressed_size,
1364
- uint32_t compress_format_version,
1365
- MemoryAllocator* allocator = nullptr) {
1366
- #ifdef LZ4
1367
- uint32_t output_len = 0;
1368
- if (compress_format_version == 2) {
1369
- // new encoding, using varint32 to store size information
1370
- if (!compression::GetDecompressedSizeInfo(&input_data, &input_length,
1371
- &output_len)) {
1372
- return nullptr;
1373
- }
1374
- } else {
1375
- // legacy encoding, which is not really portable (depends on big/little
1376
- // endianness)
1377
- if (input_length < 8) {
1378
- return nullptr;
1379
- }
1380
- if (port::kLittleEndian) {
1381
- memcpy(&output_len, input_data, sizeof(output_len));
1382
- } else {
1383
- memcpy(&output_len, input_data + 4, sizeof(output_len));
1384
- }
1385
- input_length -= 8;
1386
- input_data += 8;
1387
- }
1388
-
1389
- auto output = AllocateBlock(output_len, allocator);
1390
-
1391
- int decompress_bytes = 0;
1392
-
1393
- #if LZ4_VERSION_NUMBER >= 10400 // r124+
1394
- LZ4_streamDecode_t* stream = LZ4_createStreamDecode();
1395
- const Slice& compression_dict = info.dict().GetRawDict();
1396
- if (compression_dict.size()) {
1397
- LZ4_setStreamDecode(stream, compression_dict.data(),
1398
- static_cast<int>(compression_dict.size()));
1399
- }
1400
- decompress_bytes = LZ4_decompress_safe_continue(
1401
- stream, input_data, output.get(), static_cast<int>(input_length),
1402
- static_cast<int>(output_len));
1403
- LZ4_freeStreamDecode(stream);
1404
- #else // up to r123
1405
- decompress_bytes = LZ4_decompress_safe(input_data, output.get(),
1406
- static_cast<int>(input_length),
1407
- static_cast<int>(output_len));
1408
- #endif // LZ4_VERSION_NUMBER >= 10400
1409
-
1410
- if (decompress_bytes < 0) {
1411
- return nullptr;
1412
- }
1413
- assert(decompress_bytes == static_cast<int>(output_len));
1414
- *uncompressed_size = decompress_bytes;
1415
- return output;
1416
- #else // LZ4
1417
- (void)info;
1418
- (void)input_data;
1419
- (void)input_length;
1420
- (void)uncompressed_size;
1421
- (void)compress_format_version;
1422
- (void)allocator;
1423
- return nullptr;
1424
- #endif
1425
- }
1426
-
1427
- // compress_format_version == 1 -- decompressed size is included in the
1428
- // block header using memcpy, which makes database non-portable)
1429
- // compress_format_version == 2 -- decompressed size is included in the block
1430
- // header in varint32 format
1431
- // @param compression_dict Data for presetting the compression library's
1432
- // dictionary.
1433
- inline bool LZ4HC_Compress(const CompressionInfo& info,
1434
- uint32_t compress_format_version, const char* input,
1435
- size_t length, ::std::string* output) {
1436
- #ifdef LZ4
1437
- if (length > std::numeric_limits<uint32_t>::max()) {
1438
- // Can't compress more than 4GB
1439
- return false;
1440
- }
1441
-
1442
- size_t output_header_len = 0;
1443
- if (compress_format_version == 2) {
1444
- // new encoding, using varint32 to store size information
1445
- output_header_len = compression::PutDecompressedSizeInfo(
1446
- output, static_cast<uint32_t>(length));
1447
- } else {
1448
- // legacy encoding, which is not really portable (depends on big/little
1449
- // endianness)
1450
- output_header_len = 8;
1451
- output->resize(output_header_len);
1452
- char* p = const_cast<char*>(output->c_str());
1453
- memcpy(p, &length, sizeof(length));
1454
- }
1455
- int compress_bound = LZ4_compressBound(static_cast<int>(length));
1456
- output->resize(static_cast<size_t>(output_header_len + compress_bound));
1457
-
1458
- int outlen;
1459
- int level;
1460
- if (info.options().level == CompressionOptions::kDefaultCompressionLevel) {
1461
- level = 0; // lz4hc.h says any value < 1 will be sanitized to default
1462
- } else {
1463
- level = info.options().level;
1464
- }
1465
- #if LZ4_VERSION_NUMBER >= 10400 // r124+
1466
- LZ4_streamHC_t* stream = LZ4_createStreamHC();
1467
- LZ4_resetStreamHC(stream, level);
1468
- Slice compression_dict = info.dict().GetRawDict();
1469
- const char* compression_dict_data =
1470
- compression_dict.size() > 0 ? compression_dict.data() : nullptr;
1471
- size_t compression_dict_size = compression_dict.size();
1472
- if (compression_dict_data != nullptr) {
1473
- LZ4_loadDictHC(stream, compression_dict_data,
1474
- static_cast<int>(compression_dict_size));
1475
- }
1476
-
1477
- #if LZ4_VERSION_NUMBER >= 10700 // r129+
1478
- outlen =
1479
- LZ4_compress_HC_continue(stream, input, &(*output)[output_header_len],
1480
- static_cast<int>(length), compress_bound);
1481
- #else // r124-r128
1482
- outlen = LZ4_compressHC_limitedOutput_continue(
1483
- stream, input, &(*output)[output_header_len], static_cast<int>(length),
1484
- compress_bound);
1485
- #endif // LZ4_VERSION_NUMBER >= 10700
1486
- LZ4_freeStreamHC(stream);
1487
-
1488
- #elif LZ4_VERSION_MAJOR // r113-r123
1489
- outlen = LZ4_compressHC2_limitedOutput(input, &(*output)[output_header_len],
1490
- static_cast<int>(length),
1491
- compress_bound, level);
1492
- #else // up to r112
1493
- outlen =
1494
- LZ4_compressHC_limitedOutput(input, &(*output)[output_header_len],
1495
- static_cast<int>(length), compress_bound);
1496
- #endif // LZ4_VERSION_NUMBER >= 10400
1497
-
1498
- if (outlen == 0) {
1499
- return false;
1500
- }
1501
- output->resize(static_cast<size_t>(output_header_len + outlen));
1502
- return true;
1503
- #else // LZ4
1504
- (void)info;
1505
- (void)compress_format_version;
1506
- (void)input;
1507
- (void)length;
1508
- (void)output;
1509
- return false;
1510
- #endif
1511
- }
517
+ CompressionType CompressionTypeFromString(std::string compression_type_str);
1512
518
 
1513
- #ifdef XPRESS
1514
- inline bool XPRESS_Compress(const char* input, size_t length,
1515
- std::string* output) {
1516
- return port::xpress::Compress(input, length, output);
1517
- }
1518
- #else
1519
- inline bool XPRESS_Compress(const char* /*input*/, size_t /*length*/,
1520
- std::string* /*output*/) {
1521
- return false;
1522
- }
1523
- #endif
1524
-
1525
- #ifdef XPRESS
1526
- inline char* XPRESS_Uncompress(const char* input_data, size_t input_length,
1527
- size_t* uncompressed_size) {
1528
- return port::xpress::Decompress(input_data, input_length, uncompressed_size);
1529
- }
1530
- #else
1531
- inline char* XPRESS_Uncompress(const char* /*input_data*/,
1532
- size_t /*input_length*/,
1533
- size_t* /*uncompressed_size*/) {
1534
- return nullptr;
1535
- }
1536
- #endif
1537
-
1538
- inline bool ZSTD_Compress(const CompressionInfo& info, const char* input,
1539
- size_t length, ::std::string* output) {
1540
- #ifdef ZSTD
1541
- if (length > std::numeric_limits<uint32_t>::max()) {
1542
- // Can't compress more than 4GB
1543
- return false;
1544
- }
1545
-
1546
- size_t output_header_len = compression::PutDecompressedSizeInfo(
1547
- output, static_cast<uint32_t>(length));
1548
-
1549
- size_t compressBound = ZSTD_compressBound(length);
1550
- // TODO: use resize_and_overwrite with c++23
1551
- output->resize(static_cast<size_t>(output_header_len + compressBound));
1552
- size_t outlen = 0;
1553
- ZSTD_CCtx* context = info.context().ZSTDPreallocCtx();
1554
- assert(context != nullptr);
1555
- if (info.dict().GetDigestedZstdCDict() != nullptr) {
1556
- ZSTD_CCtx_refCDict(context, info.dict().GetDigestedZstdCDict());
1557
- } else {
1558
- ZSTD_CCtx_loadDictionary(context, info.dict().GetRawDict().data(),
1559
- info.dict().GetRawDict().size());
1560
- }
1561
-
1562
- // Compression level is set in `contex` during CreateNativeContext()
1563
- outlen = ZSTD_compress2(context, &(*output)[output_header_len], compressBound,
1564
- input, length);
1565
- if (outlen == 0) {
1566
- return false;
1567
- }
1568
- output->resize(output_header_len + outlen);
1569
- return true;
1570
- #else // ZSTD
1571
- (void)info;
1572
- (void)input;
1573
- (void)length;
1574
- (void)output;
1575
- return false;
1576
- #endif
1577
- }
1578
-
1579
- // @param compression_dict Data for presetting the compression library's
1580
- // dictionary.
1581
- // @param error_message If not null, will be set if decompression fails.
1582
- //
1583
- // Returns nullptr if decompression fails.
1584
- inline CacheAllocationPtr ZSTD_Uncompress(
1585
- const UncompressionInfo& info, const char* input_data, size_t input_length,
1586
- size_t* uncompressed_size, MemoryAllocator* allocator = nullptr,
1587
- const char** error_message = nullptr) {
1588
- #ifdef ZSTD
1589
- static const char* const kErrorDecodeOutputSize =
1590
- "Cannot decode output size.";
1591
- static const char* const kErrorOutputLenMismatch =
1592
- "Decompressed size does not match header.";
1593
- uint32_t output_len = 0;
1594
- if (!compression::GetDecompressedSizeInfo(&input_data, &input_length,
1595
- &output_len)) {
1596
- if (error_message) {
1597
- *error_message = kErrorDecodeOutputSize;
1598
- }
1599
- return nullptr;
1600
- }
1601
-
1602
- CacheAllocationPtr output = AllocateBlock(output_len, allocator);
1603
- size_t actual_output_length = 0;
1604
- ZSTD_DCtx* context = info.context().GetZSTDContext();
1605
- assert(context != nullptr);
1606
- #ifdef ROCKSDB_ZSTD_DDICT
1607
- if (info.dict().GetDigestedZstdDDict() != nullptr) {
1608
- actual_output_length = ZSTD_decompress_usingDDict(
1609
- context, output.get(), output_len, input_data, input_length,
1610
- info.dict().GetDigestedZstdDDict());
1611
- } else {
1612
- #endif // ROCKSDB_ZSTD_DDICT
1613
- actual_output_length = ZSTD_decompress_usingDict(
1614
- context, output.get(), output_len, input_data, input_length,
1615
- info.dict().GetRawDict().data(), info.dict().GetRawDict().size());
1616
- #ifdef ROCKSDB_ZSTD_DDICT
1617
- }
1618
- #endif // ROCKSDB_ZSTD_DDICT
1619
- if (ZSTD_isError(actual_output_length)) {
1620
- if (error_message) {
1621
- *error_message = ZSTD_getErrorName(actual_output_length);
1622
- }
1623
- return nullptr;
1624
- } else if (actual_output_length != output_len) {
1625
- if (error_message) {
1626
- *error_message = kErrorOutputLenMismatch;
1627
- }
1628
- return nullptr;
1629
- }
1630
-
1631
- *uncompressed_size = actual_output_length;
1632
- return output;
1633
- #else // ZSTD
1634
- (void)info;
1635
- (void)input_data;
1636
- (void)input_length;
1637
- (void)uncompressed_size;
1638
- (void)allocator;
1639
- (void)error_message;
1640
- return nullptr;
1641
- #endif
1642
- }
519
+ std::string CompressionOptionsToString(
520
+ const CompressionOptions& compression_options);
1643
521
 
1644
522
  inline bool ZSTD_TrainDictionarySupported() {
1645
523
  #ifdef ZSTD
@@ -1652,50 +530,6 @@ inline bool ZSTD_TrainDictionarySupported() {
1652
530
  #endif
1653
531
  }
1654
532
 
1655
- inline std::string ZSTD_TrainDictionary(const std::string& samples,
1656
- const std::vector<size_t>& sample_lens,
1657
- size_t max_dict_bytes) {
1658
- #ifdef ZSTD
1659
- assert(samples.empty() == sample_lens.empty());
1660
- if (samples.empty()) {
1661
- return "";
1662
- }
1663
- std::string dict_data(max_dict_bytes, '\0');
1664
- size_t dict_len = ZDICT_trainFromBuffer(
1665
- &dict_data[0], max_dict_bytes, &samples[0], &sample_lens[0],
1666
- static_cast<unsigned>(sample_lens.size()));
1667
- if (ZDICT_isError(dict_len)) {
1668
- return "";
1669
- }
1670
- assert(dict_len <= max_dict_bytes);
1671
- dict_data.resize(dict_len);
1672
- return dict_data;
1673
- #else
1674
- assert(false);
1675
- (void)samples;
1676
- (void)sample_lens;
1677
- (void)max_dict_bytes;
1678
- return "";
1679
- #endif // ZSTD
1680
- }
1681
-
1682
- inline std::string ZSTD_TrainDictionary(const std::string& samples,
1683
- size_t sample_len_shift,
1684
- size_t max_dict_bytes) {
1685
- #ifdef ZSTD
1686
- // skips potential partial sample at the end of "samples"
1687
- size_t num_samples = samples.size() >> sample_len_shift;
1688
- std::vector<size_t> sample_lens(num_samples, size_t(1) << sample_len_shift);
1689
- return ZSTD_TrainDictionary(samples, sample_lens, max_dict_bytes);
1690
- #else
1691
- assert(false);
1692
- (void)samples;
1693
- (void)sample_len_shift;
1694
- (void)max_dict_bytes;
1695
- return "";
1696
- #endif // ZSTD
1697
- }
1698
-
1699
533
  inline bool ZSTD_FinalizeDictionarySupported() {
1700
534
  #ifdef ROCKSDB_ZDICT_FINALIZE
1701
535
  return true;
@@ -1704,132 +538,16 @@ inline bool ZSTD_FinalizeDictionarySupported() {
1704
538
  #endif
1705
539
  }
1706
540
 
1707
- inline std::string ZSTD_FinalizeDictionary(
1708
- const std::string& samples, const std::vector<size_t>& sample_lens,
1709
- size_t max_dict_bytes, int level) {
1710
- #ifdef ROCKSDB_ZDICT_FINALIZE
1711
- assert(samples.empty() == sample_lens.empty());
1712
- if (samples.empty()) {
1713
- return "";
1714
- }
1715
- if (level == CompressionOptions::kDefaultCompressionLevel) {
1716
- // NB: ZSTD_CLEVEL_DEFAULT is historically == 3
1717
- level = ZSTD_CLEVEL_DEFAULT;
1718
- }
1719
- std::string dict_data(max_dict_bytes, '\0');
1720
- size_t dict_len = ZDICT_finalizeDictionary(
1721
- dict_data.data(), max_dict_bytes, samples.data(),
1722
- std::min(static_cast<size_t>(samples.size()), max_dict_bytes),
1723
- samples.data(), sample_lens.data(),
1724
- static_cast<unsigned>(sample_lens.size()),
1725
- {level, 0 /* notificationLevel */, 0 /* dictID */});
1726
- if (ZDICT_isError(dict_len)) {
1727
- return "";
1728
- } else {
1729
- assert(dict_len <= max_dict_bytes);
1730
- dict_data.resize(dict_len);
1731
- return dict_data;
1732
- }
1733
- #else
1734
- assert(false);
1735
- (void)samples;
1736
- (void)sample_lens;
1737
- (void)max_dict_bytes;
1738
- (void)level;
1739
- return "";
1740
- #endif // ROCKSDB_ZDICT_FINALIZE
1741
- }
1742
-
1743
- inline bool OLD_CompressData(const Slice& raw,
1744
- const CompressionInfo& compression_info,
1745
- uint32_t compress_format_version,
1746
- std::string* compressed_output) {
1747
- bool ret = false;
1748
-
1749
- // Will return compressed block contents if (1) the compression method is
1750
- // supported in this platform and (2) the compression rate is "good enough".
1751
- switch (compression_info.type()) {
1752
- case kSnappyCompression:
1753
- ret = Snappy_Compress(compression_info, raw.data(), raw.size(),
1754
- compressed_output);
1755
- break;
1756
- case kZlibCompression:
1757
- ret = Zlib_Compress(compression_info, compress_format_version, raw.data(),
1758
- raw.size(), compressed_output);
1759
- break;
1760
- case kBZip2Compression:
1761
- ret = BZip2_Compress(compression_info, compress_format_version,
1762
- raw.data(), raw.size(), compressed_output);
1763
- break;
1764
- case kLZ4Compression:
1765
- ret = LZ4_Compress(compression_info, compress_format_version, raw.data(),
1766
- raw.size(), compressed_output);
1767
- break;
1768
- case kLZ4HCCompression:
1769
- ret = LZ4HC_Compress(compression_info, compress_format_version,
1770
- raw.data(), raw.size(), compressed_output);
1771
- break;
1772
- case kXpressCompression:
1773
- ret = XPRESS_Compress(raw.data(), raw.size(), compressed_output);
1774
- break;
1775
- case kZSTD:
1776
- ret = ZSTD_Compress(compression_info, raw.data(), raw.size(),
1777
- compressed_output);
1778
- break;
1779
- default:
1780
- // Do not recognize this compression type
1781
- break;
1782
- }
1783
-
1784
- TEST_SYNC_POINT_CALLBACK("CompressData:TamperWithReturnValue",
1785
- static_cast<void*>(&ret));
1786
-
1787
- return ret;
1788
- }
1789
-
1790
- inline CacheAllocationPtr OLD_UncompressData(
1791
- const UncompressionInfo& uncompression_info, const char* data, size_t n,
1792
- size_t* uncompressed_size, uint32_t compress_format_version,
1793
- MemoryAllocator* allocator = nullptr,
1794
- const char** error_message = nullptr) {
1795
- switch (uncompression_info.type()) {
1796
- case kSnappyCompression:
1797
- return Snappy_Uncompress(data, n, uncompressed_size, allocator);
1798
- case kZlibCompression:
1799
- return Zlib_Uncompress(uncompression_info, data, n, uncompressed_size,
1800
- compress_format_version, allocator);
1801
- case kBZip2Compression:
1802
- return BZip2_Uncompress(data, n, uncompressed_size,
1803
- compress_format_version, allocator);
1804
- case kLZ4Compression:
1805
- case kLZ4HCCompression:
1806
- return LZ4_Uncompress(uncompression_info, data, n, uncompressed_size,
1807
- compress_format_version, allocator);
1808
- case kXpressCompression:
1809
- // XPRESS allocates memory internally, thus no support for custom
1810
- // allocator.
1811
- return CacheAllocationPtr(XPRESS_Uncompress(data, n, uncompressed_size));
1812
- case kZSTD:
1813
- // TODO(cbi): error message handling for other compression algorithms.
1814
- return ZSTD_Uncompress(uncompression_info, data, n, uncompressed_size,
1815
- allocator, error_message);
1816
- default:
1817
- return CacheAllocationPtr();
1818
- }
1819
- }
1820
-
1821
- // ***********************************************************************
1822
- // BEGIN built-in implementation of customization interface
1823
- // ***********************************************************************
1824
-
1825
- // NOTE: to avoid compression API depending on block-based table API, uses
1826
- // its own format version. See internal function GetCompressFormatForVersion()
1827
- const std::shared_ptr<CompressionManager>& GetBuiltinCompressionManager(
1828
- int compression_format_version);
1829
-
1830
- // ***********************************************************************
1831
- // END built-in implementation of customization interface
1832
- // ***********************************************************************
541
+ // The new compression APIs intentionally make it difficult to generate
542
+ // compressed data larger than the original. (It is better to store the
543
+ // uncompressed version in that case.) For legacy cases that must store
544
+ // compressed data even when larger than the uncompressed, this is a convenient
545
+ // wrapper to support that, with a compressor from BuiltinCompressionManager and
546
+ // a GrowableBuffer.
547
+ Status LegacyForceBuiltinCompression(
548
+ Compressor& builtin_compressor,
549
+ Compressor::ManagedWorkingArea* working_area, Slice from,
550
+ GrowableBuffer* to);
1833
551
 
1834
552
  // Records the compression type for subsequent WAL records.
1835
553
  class CompressionTypeRecord {