@nxtedition/rocksdb 6.0.2 → 7.0.0-alpha.2

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 (259) hide show
  1. package/BUILDING.md +12 -4
  2. package/binding.cc +589 -128
  3. package/chained-batch.js +6 -6
  4. package/deps/rocksdb/rocksdb/CMakeLists.txt +9 -0
  5. package/deps/rocksdb/rocksdb/Makefile +16 -5
  6. package/deps/rocksdb/rocksdb/TARGETS +23 -2
  7. package/deps/rocksdb/rocksdb/cmake/modules/CxxFlags.cmake +7 -0
  8. package/deps/rocksdb/rocksdb/cmake/modules/FindJeMalloc.cmake +29 -0
  9. package/deps/rocksdb/rocksdb/cmake/modules/FindNUMA.cmake +29 -0
  10. package/deps/rocksdb/rocksdb/cmake/modules/FindSnappy.cmake +29 -0
  11. package/deps/rocksdb/rocksdb/cmake/modules/FindTBB.cmake +33 -0
  12. package/deps/rocksdb/rocksdb/cmake/modules/Findgflags.cmake +29 -0
  13. package/deps/rocksdb/rocksdb/cmake/modules/Findlz4.cmake +29 -0
  14. package/deps/rocksdb/rocksdb/cmake/modules/Finduring.cmake +26 -0
  15. package/deps/rocksdb/rocksdb/cmake/modules/Findzstd.cmake +29 -0
  16. package/deps/rocksdb/rocksdb/cmake/modules/ReadVersion.cmake +10 -0
  17. package/deps/rocksdb/rocksdb/db/builder.cc +12 -4
  18. package/deps/rocksdb/rocksdb/db/c.cc +26 -0
  19. package/deps/rocksdb/rocksdb/db/c_test.c +3 -0
  20. package/deps/rocksdb/rocksdb/db/column_family.cc +8 -2
  21. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +29 -6
  22. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +8 -2
  23. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +16 -4
  24. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +2 -1
  25. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_test.cc +16 -0
  26. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +402 -30
  27. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +2 -12
  28. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +14 -0
  29. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +7 -5
  30. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_experimental.cc +1 -1
  31. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +33 -7
  32. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.cc +54 -23
  33. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.h +3 -0
  34. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +8 -1
  35. package/deps/rocksdb/rocksdb/db/db_options_test.cc +16 -0
  36. package/deps/rocksdb/rocksdb/db/db_rate_limiter_test.cc +14 -15
  37. package/deps/rocksdb/rocksdb/db/db_readonly_with_timestamp_test.cc +331 -0
  38. package/deps/rocksdb/rocksdb/db/db_secondary_test.cc +5 -0
  39. package/deps/rocksdb/rocksdb/db/db_test.cc +16 -0
  40. package/deps/rocksdb/rocksdb/db/db_test2.cc +221 -92
  41. package/deps/rocksdb/rocksdb/db/db_test_util.cc +6 -2
  42. package/deps/rocksdb/rocksdb/db/db_test_util.h +4 -2
  43. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +1 -171
  44. package/deps/rocksdb/rocksdb/db/db_with_timestamp_test_util.cc +96 -0
  45. package/deps/rocksdb/rocksdb/db/db_with_timestamp_test_util.h +126 -0
  46. package/deps/rocksdb/rocksdb/db/experimental.cc +1 -1
  47. package/deps/rocksdb/rocksdb/db/external_sst_file_basic_test.cc +57 -0
  48. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +13 -2
  49. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.h +2 -0
  50. package/deps/rocksdb/rocksdb/db/flush_job.cc +10 -11
  51. package/deps/rocksdb/rocksdb/db/import_column_family_job.cc +11 -1
  52. package/deps/rocksdb/rocksdb/db/import_column_family_test.cc +6 -0
  53. package/deps/rocksdb/rocksdb/db/repair.cc +12 -1
  54. package/deps/rocksdb/rocksdb/db/repair_test.cc +32 -10
  55. package/deps/rocksdb/rocksdb/db/snapshot_impl.h +3 -1
  56. package/deps/rocksdb/rocksdb/db/table_cache.cc +19 -127
  57. package/deps/rocksdb/rocksdb/db/table_cache.h +3 -2
  58. package/deps/rocksdb/rocksdb/db/table_cache_sync_and_async.h +140 -0
  59. package/deps/rocksdb/rocksdb/db/version_builder_test.cc +130 -128
  60. package/deps/rocksdb/rocksdb/db/version_edit.cc +20 -0
  61. package/deps/rocksdb/rocksdb/db/version_edit.h +13 -4
  62. package/deps/rocksdb/rocksdb/db/version_edit_test.cc +14 -14
  63. package/deps/rocksdb/rocksdb/db/version_set.cc +205 -212
  64. package/deps/rocksdb/rocksdb/db/version_set.h +11 -0
  65. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +154 -0
  66. package/deps/rocksdb/rocksdb/db/version_set_test.cc +10 -9
  67. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +2 -0
  68. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +13 -0
  69. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +15 -0
  70. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +159 -65
  71. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +43 -21
  72. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +142 -17
  73. package/deps/rocksdb/rocksdb/file/writable_file_writer.cc +23 -27
  74. package/deps/rocksdb/rocksdb/file/writable_file_writer.h +2 -3
  75. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +23 -5
  76. package/deps/rocksdb/rocksdb/include/rocksdb/c.h +14 -1
  77. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +2 -0
  78. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +17 -0
  79. package/deps/rocksdb/rocksdb/include/rocksdb/perf_context.h +2 -0
  80. package/deps/rocksdb/rocksdb/include/rocksdb/snapshot.h +4 -1
  81. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +3 -0
  82. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/options_type.h +189 -0
  83. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  84. package/deps/rocksdb/rocksdb/monitoring/perf_context.cc +5 -0
  85. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +1 -1
  86. package/deps/rocksdb/rocksdb/options/cf_options.cc +13 -0
  87. package/deps/rocksdb/rocksdb/options/db_options.cc +8 -0
  88. package/deps/rocksdb/rocksdb/options/db_options.h +1 -0
  89. package/deps/rocksdb/rocksdb/options/options.cc +7 -0
  90. package/deps/rocksdb/rocksdb/options/options_helper.cc +4 -0
  91. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +6 -4
  92. package/deps/rocksdb/rocksdb/options/options_test.cc +107 -9
  93. package/deps/rocksdb/rocksdb/src.mk +4 -1
  94. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +9 -4
  95. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.cc +80 -6
  96. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.h +8 -2
  97. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +81 -757
  98. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +21 -15
  99. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_impl.h +9 -3
  100. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +754 -0
  101. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +2 -1
  102. package/deps/rocksdb/rocksdb/table/block_based/block_prefetcher.cc +8 -0
  103. package/deps/rocksdb/rocksdb/table/block_based/filter_block.h +1 -10
  104. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.cc +59 -1
  105. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.h +18 -0
  106. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.cc +0 -61
  107. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.h +0 -13
  108. package/deps/rocksdb/rocksdb/table/block_based/index_reader_common.cc +1 -1
  109. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +3 -2
  110. package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_iterator.cc +2 -2
  111. package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_reader.cc +2 -1
  112. package/deps/rocksdb/rocksdb/table/block_based/uncompression_dict_reader.cc +2 -1
  113. package/deps/rocksdb/rocksdb/table/block_fetcher.cc +60 -2
  114. package/deps/rocksdb/rocksdb/table/block_fetcher.h +2 -0
  115. package/deps/rocksdb/rocksdb/table/merging_iterator.cc +39 -0
  116. package/deps/rocksdb/rocksdb/table/multiget_context.h +46 -2
  117. package/deps/rocksdb/rocksdb/table/sst_file_dumper.cc +2 -1
  118. package/deps/rocksdb/rocksdb/table/sst_file_dumper.h +1 -1
  119. package/deps/rocksdb/rocksdb/table/table_reader.h +13 -0
  120. package/deps/rocksdb/rocksdb/table/unique_id.cc +27 -0
  121. package/deps/rocksdb/rocksdb/table/unique_id_impl.h +3 -0
  122. package/deps/rocksdb/rocksdb/test_util/testutil.cc +2 -0
  123. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +23 -7
  124. package/deps/rocksdb/rocksdb/tools/sst_dump_tool.cc +9 -1
  125. package/deps/rocksdb/rocksdb/util/async_file_reader.cc +72 -0
  126. package/deps/rocksdb/rocksdb/util/async_file_reader.h +144 -0
  127. package/deps/rocksdb/rocksdb/util/compression.h +49 -0
  128. package/deps/rocksdb/rocksdb/util/coro_utils.h +111 -0
  129. package/deps/rocksdb/rocksdb/util/single_thread_executor.h +55 -0
  130. package/deps/rocksdb/rocksdb.gyp +16 -15
  131. package/index.js +186 -3
  132. package/iterator.js +1 -0
  133. package/package-lock.json +23687 -0
  134. package/package.json +2 -30
  135. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  136. package/deps/liburing/liburing/README +0 -46
  137. package/deps/liburing/liburing/test/232c93d07b74-test.c +0 -305
  138. package/deps/liburing/liburing/test/35fa71a030ca-test.c +0 -329
  139. package/deps/liburing/liburing/test/500f9fbadef8-test.c +0 -89
  140. package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +0 -93
  141. package/deps/liburing/liburing/test/8a9973408177-test.c +0 -106
  142. package/deps/liburing/liburing/test/917257daa0fe-test.c +0 -53
  143. package/deps/liburing/liburing/test/Makefile +0 -312
  144. package/deps/liburing/liburing/test/a0908ae19763-test.c +0 -58
  145. package/deps/liburing/liburing/test/a4c0b3decb33-test.c +0 -180
  146. package/deps/liburing/liburing/test/accept-link.c +0 -251
  147. package/deps/liburing/liburing/test/accept-reuse.c +0 -164
  148. package/deps/liburing/liburing/test/accept-test.c +0 -79
  149. package/deps/liburing/liburing/test/accept.c +0 -476
  150. package/deps/liburing/liburing/test/across-fork.c +0 -283
  151. package/deps/liburing/liburing/test/b19062a56726-test.c +0 -53
  152. package/deps/liburing/liburing/test/b5837bd5311d-test.c +0 -77
  153. package/deps/liburing/liburing/test/ce593a6c480a-test.c +0 -135
  154. package/deps/liburing/liburing/test/close-opath.c +0 -122
  155. package/deps/liburing/liburing/test/config +0 -10
  156. package/deps/liburing/liburing/test/connect.c +0 -398
  157. package/deps/liburing/liburing/test/cq-full.c +0 -96
  158. package/deps/liburing/liburing/test/cq-overflow.c +0 -294
  159. package/deps/liburing/liburing/test/cq-peek-batch.c +0 -102
  160. package/deps/liburing/liburing/test/cq-ready.c +0 -94
  161. package/deps/liburing/liburing/test/cq-size.c +0 -58
  162. package/deps/liburing/liburing/test/d4ae271dfaae-test.c +0 -96
  163. package/deps/liburing/liburing/test/d77a67ed5f27-test.c +0 -65
  164. package/deps/liburing/liburing/test/defer.c +0 -307
  165. package/deps/liburing/liburing/test/double-poll-crash.c +0 -186
  166. package/deps/liburing/liburing/test/eeed8b54e0df-test.c +0 -114
  167. package/deps/liburing/liburing/test/empty-eownerdead.c +0 -42
  168. package/deps/liburing/liburing/test/eventfd-disable.c +0 -151
  169. package/deps/liburing/liburing/test/eventfd-ring.c +0 -97
  170. package/deps/liburing/liburing/test/eventfd.c +0 -112
  171. package/deps/liburing/liburing/test/fadvise.c +0 -202
  172. package/deps/liburing/liburing/test/fallocate.c +0 -249
  173. package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +0 -138
  174. package/deps/liburing/liburing/test/file-register.c +0 -843
  175. package/deps/liburing/liburing/test/file-update.c +0 -173
  176. package/deps/liburing/liburing/test/files-exit-hang-poll.c +0 -128
  177. package/deps/liburing/liburing/test/files-exit-hang-timeout.c +0 -134
  178. package/deps/liburing/liburing/test/fixed-link.c +0 -90
  179. package/deps/liburing/liburing/test/fsync.c +0 -224
  180. package/deps/liburing/liburing/test/hardlink.c +0 -136
  181. package/deps/liburing/liburing/test/helpers.c +0 -135
  182. package/deps/liburing/liburing/test/helpers.h +0 -67
  183. package/deps/liburing/liburing/test/io-cancel.c +0 -537
  184. package/deps/liburing/liburing/test/io_uring_enter.c +0 -296
  185. package/deps/liburing/liburing/test/io_uring_register.c +0 -664
  186. package/deps/liburing/liburing/test/io_uring_setup.c +0 -192
  187. package/deps/liburing/liburing/test/iopoll.c +0 -366
  188. package/deps/liburing/liburing/test/lfs-openat-write.c +0 -117
  189. package/deps/liburing/liburing/test/lfs-openat.c +0 -273
  190. package/deps/liburing/liburing/test/link-timeout.c +0 -1107
  191. package/deps/liburing/liburing/test/link.c +0 -496
  192. package/deps/liburing/liburing/test/link_drain.c +0 -229
  193. package/deps/liburing/liburing/test/madvise.c +0 -195
  194. package/deps/liburing/liburing/test/mkdir.c +0 -108
  195. package/deps/liburing/liburing/test/multicqes_drain.c +0 -383
  196. package/deps/liburing/liburing/test/nop-all-sizes.c +0 -107
  197. package/deps/liburing/liburing/test/nop.c +0 -115
  198. package/deps/liburing/liburing/test/open-close.c +0 -146
  199. package/deps/liburing/liburing/test/openat2.c +0 -240
  200. package/deps/liburing/liburing/test/personality.c +0 -204
  201. package/deps/liburing/liburing/test/pipe-eof.c +0 -81
  202. package/deps/liburing/liburing/test/pipe-reuse.c +0 -105
  203. package/deps/liburing/liburing/test/poll-cancel-ton.c +0 -139
  204. package/deps/liburing/liburing/test/poll-cancel.c +0 -135
  205. package/deps/liburing/liburing/test/poll-link.c +0 -227
  206. package/deps/liburing/liburing/test/poll-many.c +0 -208
  207. package/deps/liburing/liburing/test/poll-mshot-update.c +0 -273
  208. package/deps/liburing/liburing/test/poll-ring.c +0 -48
  209. package/deps/liburing/liburing/test/poll-v-poll.c +0 -353
  210. package/deps/liburing/liburing/test/poll.c +0 -109
  211. package/deps/liburing/liburing/test/probe.c +0 -137
  212. package/deps/liburing/liburing/test/read-write.c +0 -876
  213. package/deps/liburing/liburing/test/register-restrictions.c +0 -633
  214. package/deps/liburing/liburing/test/rename.c +0 -134
  215. package/deps/liburing/liburing/test/ring-leak.c +0 -173
  216. package/deps/liburing/liburing/test/ring-leak2.c +0 -249
  217. package/deps/liburing/liburing/test/rsrc_tags.c +0 -449
  218. package/deps/liburing/liburing/test/runtests-loop.sh +0 -16
  219. package/deps/liburing/liburing/test/runtests.sh +0 -170
  220. package/deps/liburing/liburing/test/rw_merge_test.c +0 -97
  221. package/deps/liburing/liburing/test/self.c +0 -91
  222. package/deps/liburing/liburing/test/send_recv.c +0 -291
  223. package/deps/liburing/liburing/test/send_recvmsg.c +0 -345
  224. package/deps/liburing/liburing/test/sendmsg_fs_cve.c +0 -198
  225. package/deps/liburing/liburing/test/shared-wq.c +0 -84
  226. package/deps/liburing/liburing/test/short-read.c +0 -75
  227. package/deps/liburing/liburing/test/shutdown.c +0 -163
  228. package/deps/liburing/liburing/test/sigfd-deadlock.c +0 -74
  229. package/deps/liburing/liburing/test/socket-rw-eagain.c +0 -156
  230. package/deps/liburing/liburing/test/socket-rw.c +0 -147
  231. package/deps/liburing/liburing/test/splice.c +0 -511
  232. package/deps/liburing/liburing/test/sq-full-cpp.cc +0 -45
  233. package/deps/liburing/liburing/test/sq-full.c +0 -45
  234. package/deps/liburing/liburing/test/sq-poll-dup.c +0 -200
  235. package/deps/liburing/liburing/test/sq-poll-kthread.c +0 -168
  236. package/deps/liburing/liburing/test/sq-poll-share.c +0 -137
  237. package/deps/liburing/liburing/test/sq-space_left.c +0 -159
  238. package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +0 -159
  239. package/deps/liburing/liburing/test/sqpoll-disable-exit.c +0 -195
  240. package/deps/liburing/liburing/test/sqpoll-exit-hang.c +0 -77
  241. package/deps/liburing/liburing/test/sqpoll-sleep.c +0 -68
  242. package/deps/liburing/liburing/test/statx.c +0 -172
  243. package/deps/liburing/liburing/test/stdout.c +0 -232
  244. package/deps/liburing/liburing/test/submit-link-fail.c +0 -154
  245. package/deps/liburing/liburing/test/submit-reuse.c +0 -239
  246. package/deps/liburing/liburing/test/symlink.c +0 -116
  247. package/deps/liburing/liburing/test/teardowns.c +0 -58
  248. package/deps/liburing/liburing/test/thread-exit.c +0 -131
  249. package/deps/liburing/liburing/test/timeout-new.c +0 -246
  250. package/deps/liburing/liburing/test/timeout-overflow.c +0 -204
  251. package/deps/liburing/liburing/test/timeout.c +0 -1354
  252. package/deps/liburing/liburing/test/unlink.c +0 -111
  253. package/deps/liburing/liburing/test/wakeup-hang.c +0 -162
  254. package/deps/rocksdb/rocksdb/README.md +0 -32
  255. package/deps/rocksdb/rocksdb/microbench/README.md +0 -60
  256. package/deps/rocksdb/rocksdb/plugin/README.md +0 -43
  257. package/deps/rocksdb/rocksdb/port/README +0 -10
  258. package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_tree/lib/README +0 -13
  259. package/prebuilds/linux-x64/node.napi.node +0 -0
@@ -74,6 +74,31 @@
74
74
  #include "util/stop_watch.h"
75
75
  #include "util/string_util.h"
76
76
 
77
+ namespace ROCKSDB_NAMESPACE {
78
+ namespace {
79
+
80
+ CacheAllocationPtr CopyBufferToHeap(MemoryAllocator* allocator, Slice& buf) {
81
+ CacheAllocationPtr heap_buf;
82
+ heap_buf = AllocateBlock(buf.size(), allocator);
83
+ memcpy(heap_buf.get(), buf.data(), buf.size());
84
+ return heap_buf;
85
+ }
86
+ } // namespace
87
+ } // namespace ROCKSDB_NAMESPACE
88
+
89
+ // Generate the regular and coroutine versions of some methods by
90
+ // including block_based_table_reader_sync_and_async.h twice
91
+ // Macros in the header will expand differently based on whether
92
+ // WITH_COROUTINES or WITHOUT_COROUTINES is defined
93
+ // clang-format off
94
+ #define WITHOUT_COROUTINES
95
+ #include "table/block_based/block_based_table_reader_sync_and_async.h"
96
+ #undef WITHOUT_COROUTINES
97
+ #define WITH_COROUTINES
98
+ #include "table/block_based/block_based_table_reader_sync_and_async.h"
99
+ #undef WITH_COROUTINES
100
+ // clang-format on
101
+
77
102
  namespace ROCKSDB_NAMESPACE {
78
103
 
79
104
  extern const uint64_t kBlockBasedTableMagicNumber;
@@ -100,7 +125,7 @@ Status ReadBlockFromFile(
100
125
  const UncompressionDict& uncompression_dict,
101
126
  const PersistentCacheOptions& cache_options, size_t read_amp_bytes_per_bit,
102
127
  MemoryAllocator* memory_allocator, bool for_compaction, bool using_zstd,
103
- const FilterPolicy* filter_policy) {
128
+ const FilterPolicy* filter_policy, bool async_read) {
104
129
  assert(result);
105
130
 
106
131
  BlockContents contents;
@@ -108,7 +133,17 @@ Status ReadBlockFromFile(
108
133
  file, prefetch_buffer, footer, options, handle, &contents, ioptions,
109
134
  do_uncompress, maybe_compressed, block_type, uncompression_dict,
110
135
  cache_options, memory_allocator, nullptr, for_compaction);
111
- Status s = block_fetcher.ReadBlockContents();
136
+ Status s;
137
+ // If prefetch_buffer is not allocated, it will fallback to synchronous
138
+ // reading of block contents.
139
+ if (async_read && prefetch_buffer != nullptr) {
140
+ s = block_fetcher.ReadAsyncBlockContents();
141
+ if (!s.ok()) {
142
+ return s;
143
+ }
144
+ } else {
145
+ s = block_fetcher.ReadBlockContents();
146
+ }
112
147
  if (s.ok()) {
113
148
  result->reset(BlocklikeTraits<TBlocklike>::Create(
114
149
  std::move(contents), read_amp_bytes_per_bit, ioptions.stats, using_zstd,
@@ -139,12 +174,6 @@ inline bool PrefixExtractorChangedHelper(
139
174
  }
140
175
  }
141
176
 
142
- CacheAllocationPtr CopyBufferToHeap(MemoryAllocator* allocator, Slice& buf) {
143
- CacheAllocationPtr heap_buf;
144
- heap_buf = AllocateBlock(buf.size(), allocator);
145
- memcpy(heap_buf.get(), buf.data(), buf.size());
146
- return heap_buf;
147
- }
148
177
  } // namespace
149
178
 
150
179
  void BlockBasedTable::UpdateCacheHitMetrics(BlockType block_type,
@@ -885,10 +914,12 @@ Status BlockBasedTable::ReadRangeDelBlock(
885
914
  "Error when seeking to range delete tombstones block from file: %s",
886
915
  s.ToString().c_str());
887
916
  } else if (!range_del_handle.IsNull()) {
917
+ Status tmp_status;
888
918
  std::unique_ptr<InternalIterator> iter(NewDataBlockIterator<DataBlockIter>(
889
919
  read_options, range_del_handle,
890
920
  /*input_iter=*/nullptr, BlockType::kRangeDeletion,
891
- /*get_context=*/nullptr, lookup_context, Status(), prefetch_buffer));
921
+ /*get_context=*/nullptr, lookup_context, prefetch_buffer,
922
+ /*for_compaction= */ false, /*async_read= */ false, tmp_status));
892
923
  assert(iter != nullptr);
893
924
  s = iter->status();
894
925
  if (!s.ok()) {
@@ -1158,7 +1189,7 @@ Status BlockBasedTable::ReadMetaIndexBlock(
1158
1189
  UncompressionDict::GetEmptyDict(), rep_->persistent_cache_options,
1159
1190
  0 /* read_amp_bytes_per_bit */, GetMemoryAllocator(rep_->table_options),
1160
1191
  false /* for_compaction */, rep_->blocks_definitely_zstd_compressed,
1161
- nullptr /* filter_policy */);
1192
+ nullptr /* filter_policy */, false /* async_read */);
1162
1193
 
1163
1194
  if (!s.ok()) {
1164
1195
  ROCKS_LOG_ERROR(rep_->ioptions.logger,
@@ -1489,7 +1520,7 @@ Status BlockBasedTable::MaybeReadBlockAndLoadToCache(
1489
1520
  const bool wait, const bool for_compaction,
1490
1521
  CachableEntry<TBlocklike>* block_entry, BlockType block_type,
1491
1522
  GetContext* get_context, BlockCacheLookupContext* lookup_context,
1492
- BlockContents* contents) const {
1523
+ BlockContents* contents, bool async_read) const {
1493
1524
  assert(block_entry != nullptr);
1494
1525
  const bool no_io = (ro.read_tier == kBlockCacheTier);
1495
1526
  Cache* block_cache = rep_->table_options.block_cache.get();
@@ -1552,7 +1583,18 @@ Status BlockBasedTable::MaybeReadBlockAndLoadToCache(
1552
1583
  rep_->persistent_cache_options,
1553
1584
  GetMemoryAllocator(rep_->table_options),
1554
1585
  GetMemoryAllocatorForCompressedBlock(rep_->table_options));
1555
- s = block_fetcher.ReadBlockContents();
1586
+
1587
+ // If prefetch_buffer is not allocated, it will fallback to synchronous
1588
+ // reading of block contents.
1589
+ if (async_read && prefetch_buffer != nullptr) {
1590
+ s = block_fetcher.ReadAsyncBlockContents();
1591
+ if (!s.ok()) {
1592
+ return s;
1593
+ }
1594
+ } else {
1595
+ s = block_fetcher.ReadBlockContents();
1596
+ }
1597
+
1556
1598
  raw_block_comp_type = block_fetcher.get_compression_type();
1557
1599
  contents = &raw_block_contents;
1558
1600
  if (get_context) {
@@ -1653,305 +1695,14 @@ Status BlockBasedTable::MaybeReadBlockAndLoadToCache(
1653
1695
  return s;
1654
1696
  }
1655
1697
 
1656
- // This function reads multiple data blocks from disk using Env::MultiRead()
1657
- // and optionally inserts them into the block cache. It uses the scratch
1658
- // buffer provided by the caller, which is contiguous. If scratch is a nullptr
1659
- // it allocates a separate buffer for each block. Typically, if the blocks
1660
- // need to be uncompressed and there is no compressed block cache, callers
1661
- // can allocate a temporary scratch buffer in order to minimize memory
1662
- // allocations.
1663
- // If options.fill_cache is true, it inserts the blocks into cache. If its
1664
- // false and scratch is non-null and the blocks are uncompressed, it copies
1665
- // the buffers to heap. In any case, the CachableEntry<Block> returned will
1666
- // own the data bytes.
1667
- // If compression is enabled and also there is no compressed block cache,
1668
- // the adjacent blocks are read out in one IO (combined read)
1669
- // batch - A MultiGetRange with only those keys with unique data blocks not
1670
- // found in cache
1671
- // handles - A vector of block handles. Some of them me be NULL handles
1672
- // scratch - An optional contiguous buffer to read compressed blocks into
1673
- void BlockBasedTable::RetrieveMultipleBlocks(
1674
- const ReadOptions& options, const MultiGetRange* batch,
1675
- const autovector<BlockHandle, MultiGetContext::MAX_BATCH_SIZE>* handles,
1676
- autovector<Status, MultiGetContext::MAX_BATCH_SIZE>* statuses,
1677
- autovector<CachableEntry<Block>, MultiGetContext::MAX_BATCH_SIZE>* results,
1678
- char* scratch, const UncompressionDict& uncompression_dict) const {
1679
- RandomAccessFileReader* file = rep_->file.get();
1680
- const Footer& footer = rep_->footer;
1681
- const ImmutableOptions& ioptions = rep_->ioptions;
1682
- size_t read_amp_bytes_per_bit = rep_->table_options.read_amp_bytes_per_bit;
1683
- MemoryAllocator* memory_allocator = GetMemoryAllocator(rep_->table_options);
1684
-
1685
- if (ioptions.allow_mmap_reads) {
1686
- size_t idx_in_batch = 0;
1687
- for (auto mget_iter = batch->begin(); mget_iter != batch->end();
1688
- ++mget_iter, ++idx_in_batch) {
1689
- BlockCacheLookupContext lookup_data_block_context(
1690
- TableReaderCaller::kUserMultiGet);
1691
- const BlockHandle& handle = (*handles)[idx_in_batch];
1692
- if (handle.IsNull()) {
1693
- continue;
1694
- }
1695
-
1696
- (*statuses)[idx_in_batch] =
1697
- RetrieveBlock(nullptr, options, handle, uncompression_dict,
1698
- &(*results)[idx_in_batch], BlockType::kData,
1699
- mget_iter->get_context, &lookup_data_block_context,
1700
- /* for_compaction */ false, /* use_cache */ true,
1701
- /* wait_for_cache */ true);
1702
- }
1703
- return;
1704
- }
1705
-
1706
- // In direct IO mode, blocks share the direct io buffer.
1707
- // Otherwise, blocks share the scratch buffer.
1708
- const bool use_shared_buffer = file->use_direct_io() || scratch != nullptr;
1709
-
1710
- autovector<FSReadRequest, MultiGetContext::MAX_BATCH_SIZE> read_reqs;
1711
- size_t buf_offset = 0;
1712
- size_t idx_in_batch = 0;
1713
-
1714
- uint64_t prev_offset = 0;
1715
- size_t prev_len = 0;
1716
- autovector<size_t, MultiGetContext::MAX_BATCH_SIZE> req_idx_for_block;
1717
- autovector<size_t, MultiGetContext::MAX_BATCH_SIZE> req_offset_for_block;
1718
- for (auto mget_iter = batch->begin(); mget_iter != batch->end();
1719
- ++mget_iter, ++idx_in_batch) {
1720
- const BlockHandle& handle = (*handles)[idx_in_batch];
1721
- if (handle.IsNull()) {
1722
- continue;
1723
- }
1724
-
1725
- size_t prev_end = static_cast<size_t>(prev_offset) + prev_len;
1726
-
1727
- // If current block is adjacent to the previous one, at the same time,
1728
- // compression is enabled and there is no compressed cache, we combine
1729
- // the two block read as one.
1730
- // We don't combine block reads here in direct IO mode, because when doing
1731
- // direct IO read, the block requests will be realigned and merged when
1732
- // necessary.
1733
- if (use_shared_buffer && !file->use_direct_io() &&
1734
- prev_end == handle.offset()) {
1735
- req_offset_for_block.emplace_back(prev_len);
1736
- prev_len += BlockSizeWithTrailer(handle);
1737
- } else {
1738
- // No compression or current block and previous one is not adjacent:
1739
- // Step 1, create a new request for previous blocks
1740
- if (prev_len != 0) {
1741
- FSReadRequest req;
1742
- req.offset = prev_offset;
1743
- req.len = prev_len;
1744
- if (file->use_direct_io()) {
1745
- req.scratch = nullptr;
1746
- } else if (use_shared_buffer) {
1747
- req.scratch = scratch + buf_offset;
1748
- buf_offset += req.len;
1749
- } else {
1750
- req.scratch = new char[req.len];
1751
- }
1752
- read_reqs.emplace_back(req);
1753
- }
1754
-
1755
- // Step 2, remeber the previous block info
1756
- prev_offset = handle.offset();
1757
- prev_len = BlockSizeWithTrailer(handle);
1758
- req_offset_for_block.emplace_back(0);
1759
- }
1760
- req_idx_for_block.emplace_back(read_reqs.size());
1761
-
1762
- PERF_COUNTER_ADD(block_read_count, 1);
1763
- PERF_COUNTER_ADD(block_read_byte, BlockSizeWithTrailer(handle));
1764
- }
1765
- // Handle the last block and process the pending last request
1766
- if (prev_len != 0) {
1767
- FSReadRequest req;
1768
- req.offset = prev_offset;
1769
- req.len = prev_len;
1770
- if (file->use_direct_io()) {
1771
- req.scratch = nullptr;
1772
- } else if (use_shared_buffer) {
1773
- req.scratch = scratch + buf_offset;
1774
- } else {
1775
- req.scratch = new char[req.len];
1776
- }
1777
- read_reqs.emplace_back(req);
1778
- }
1779
-
1780
- AlignedBuf direct_io_buf;
1781
- {
1782
- IOOptions opts;
1783
- IOStatus s = file->PrepareIOOptions(options, opts);
1784
- if (s.ok()) {
1785
- s = file->MultiRead(opts, &read_reqs[0], read_reqs.size(), &direct_io_buf,
1786
- options.rate_limiter_priority);
1787
- }
1788
- if (!s.ok()) {
1789
- // Discard all the results in this batch if there is any time out
1790
- // or overall MultiRead error
1791
- for (FSReadRequest& req : read_reqs) {
1792
- req.status = s;
1793
- }
1794
- }
1795
- }
1796
-
1797
- idx_in_batch = 0;
1798
- size_t valid_batch_idx = 0;
1799
- for (auto mget_iter = batch->begin(); mget_iter != batch->end();
1800
- ++mget_iter, ++idx_in_batch) {
1801
- const BlockHandle& handle = (*handles)[idx_in_batch];
1802
-
1803
- if (handle.IsNull()) {
1804
- continue;
1805
- }
1806
-
1807
- assert(valid_batch_idx < req_idx_for_block.size());
1808
- assert(valid_batch_idx < req_offset_for_block.size());
1809
- assert(req_idx_for_block[valid_batch_idx] < read_reqs.size());
1810
- size_t& req_idx = req_idx_for_block[valid_batch_idx];
1811
- size_t& req_offset = req_offset_for_block[valid_batch_idx];
1812
- valid_batch_idx++;
1813
- if (mget_iter->get_context) {
1814
- ++(mget_iter->get_context->get_context_stats_.num_data_read);
1815
- }
1816
- FSReadRequest& req = read_reqs[req_idx];
1817
- Status s = req.status;
1818
- if (s.ok()) {
1819
- if ((req.result.size() != req.len) ||
1820
- (req_offset + BlockSizeWithTrailer(handle) > req.result.size())) {
1821
- s = Status::Corruption("truncated block read from " +
1822
- rep_->file->file_name() + " offset " +
1823
- std::to_string(handle.offset()) + ", expected " +
1824
- std::to_string(req.len) + " bytes, got " +
1825
- std::to_string(req.result.size()));
1826
- }
1827
- }
1828
-
1829
- BlockContents raw_block_contents;
1830
- if (s.ok()) {
1831
- if (!use_shared_buffer) {
1832
- // We allocated a buffer for this block. Give ownership of it to
1833
- // BlockContents so it can free the memory
1834
- assert(req.result.data() == req.scratch);
1835
- assert(req.result.size() == BlockSizeWithTrailer(handle));
1836
- assert(req_offset == 0);
1837
- std::unique_ptr<char[]> raw_block(req.scratch);
1838
- raw_block_contents = BlockContents(std::move(raw_block), handle.size());
1839
- } else {
1840
- // We used the scratch buffer or direct io buffer
1841
- // which are shared by the blocks.
1842
- // raw_block_contents does not have the ownership.
1843
- raw_block_contents =
1844
- BlockContents(Slice(req.result.data() + req_offset, handle.size()));
1845
- }
1846
- #ifndef NDEBUG
1847
- raw_block_contents.is_raw_block = true;
1848
- #endif
1849
-
1850
- if (options.verify_checksums) {
1851
- PERF_TIMER_GUARD(block_checksum_time);
1852
- const char* data = req.result.data();
1853
- // Since the scratch might be shared, the offset of the data block in
1854
- // the buffer might not be 0. req.result.data() only point to the
1855
- // begin address of each read request, we need to add the offset
1856
- // in each read request. Checksum is stored in the block trailer,
1857
- // beyond the payload size.
1858
- s = VerifyBlockChecksum(footer.checksum_type(), data + req_offset,
1859
- handle.size(), rep_->file->file_name(),
1860
- handle.offset());
1861
- TEST_SYNC_POINT_CALLBACK("RetrieveMultipleBlocks:VerifyChecksum", &s);
1862
- }
1863
- } else if (!use_shared_buffer) {
1864
- // Free the allocated scratch buffer.
1865
- delete[] req.scratch;
1866
- }
1867
-
1868
- if (s.ok()) {
1869
- // When the blocks share the same underlying buffer (scratch or direct io
1870
- // buffer), we may need to manually copy the block into heap if the raw
1871
- // block has to be inserted into a cache. That falls into th following
1872
- // cases -
1873
- // 1. Raw block is not compressed, it needs to be inserted into the
1874
- // uncompressed block cache if there is one
1875
- // 2. If the raw block is compressed, it needs to be inserted into the
1876
- // compressed block cache if there is one
1877
- //
1878
- // In all other cases, the raw block is either uncompressed into a heap
1879
- // buffer or there is no cache at all.
1880
- CompressionType compression_type =
1881
- GetBlockCompressionType(raw_block_contents);
1882
- if (use_shared_buffer && (compression_type == kNoCompression ||
1883
- (compression_type != kNoCompression &&
1884
- rep_->table_options.block_cache_compressed))) {
1885
- Slice raw =
1886
- Slice(req.result.data() + req_offset, BlockSizeWithTrailer(handle));
1887
- raw_block_contents = BlockContents(
1888
- CopyBufferToHeap(GetMemoryAllocator(rep_->table_options), raw),
1889
- handle.size());
1890
- #ifndef NDEBUG
1891
- raw_block_contents.is_raw_block = true;
1892
- #endif
1893
- }
1894
- }
1895
-
1896
- if (s.ok()) {
1897
- if (options.fill_cache) {
1898
- BlockCacheLookupContext lookup_data_block_context(
1899
- TableReaderCaller::kUserMultiGet);
1900
- CachableEntry<Block>* block_entry = &(*results)[idx_in_batch];
1901
- // MaybeReadBlockAndLoadToCache will insert into the block caches if
1902
- // necessary. Since we're passing the raw block contents, it will
1903
- // avoid looking up the block cache
1904
- s = MaybeReadBlockAndLoadToCache(
1905
- nullptr, options, handle, uncompression_dict, /*wait=*/true,
1906
- /*for_compaction=*/false, block_entry, BlockType::kData,
1907
- mget_iter->get_context, &lookup_data_block_context,
1908
- &raw_block_contents);
1909
-
1910
- // block_entry value could be null if no block cache is present, i.e
1911
- // BlockBasedTableOptions::no_block_cache is true and no compressed
1912
- // block cache is configured. In that case, fall
1913
- // through and set up the block explicitly
1914
- if (block_entry->GetValue() != nullptr) {
1915
- s.PermitUncheckedError();
1916
- continue;
1917
- }
1918
- }
1919
-
1920
- CompressionType compression_type =
1921
- GetBlockCompressionType(raw_block_contents);
1922
- BlockContents contents;
1923
- if (compression_type != kNoCompression) {
1924
- UncompressionContext context(compression_type);
1925
- UncompressionInfo info(context, uncompression_dict, compression_type);
1926
- s = UncompressBlockContents(
1927
- info, req.result.data() + req_offset, handle.size(), &contents,
1928
- footer.format_version(), rep_->ioptions, memory_allocator);
1929
- } else {
1930
- // There are two cases here:
1931
- // 1) caller uses the shared buffer (scratch or direct io buffer);
1932
- // 2) we use the requst buffer.
1933
- // If scratch buffer or direct io buffer is used, we ensure that
1934
- // all raw blocks are copyed to the heap as single blocks. If scratch
1935
- // buffer is not used, we also have no combined read, so the raw
1936
- // block can be used directly.
1937
- contents = std::move(raw_block_contents);
1938
- }
1939
- if (s.ok()) {
1940
- (*results)[idx_in_batch].SetOwnedValue(new Block(
1941
- std::move(contents), read_amp_bytes_per_bit, ioptions.stats));
1942
- }
1943
- }
1944
- (*statuses)[idx_in_batch] = s;
1945
- }
1946
- }
1947
-
1948
1698
  template <typename TBlocklike>
1949
1699
  Status BlockBasedTable::RetrieveBlock(
1950
1700
  FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro,
1951
1701
  const BlockHandle& handle, const UncompressionDict& uncompression_dict,
1952
1702
  CachableEntry<TBlocklike>* block_entry, BlockType block_type,
1953
1703
  GetContext* get_context, BlockCacheLookupContext* lookup_context,
1954
- bool for_compaction, bool use_cache, bool wait_for_cache) const {
1704
+ bool for_compaction, bool use_cache, bool wait_for_cache,
1705
+ bool async_read) const {
1955
1706
  assert(block_entry);
1956
1707
  assert(block_entry->IsEmpty());
1957
1708
 
@@ -1960,7 +1711,7 @@ Status BlockBasedTable::RetrieveBlock(
1960
1711
  s = MaybeReadBlockAndLoadToCache(
1961
1712
  prefetch_buffer, ro, handle, uncompression_dict, wait_for_cache,
1962
1713
  for_compaction, block_entry, block_type, get_context, lookup_context,
1963
- /*contents=*/nullptr);
1714
+ /*contents=*/nullptr, async_read);
1964
1715
 
1965
1716
  if (!s.ok()) {
1966
1717
  return s;
@@ -2000,7 +1751,7 @@ Status BlockBasedTable::RetrieveBlock(
2000
1751
  : 0,
2001
1752
  GetMemoryAllocator(rep_->table_options), for_compaction,
2002
1753
  rep_->blocks_definitely_zstd_compressed,
2003
- rep_->table_options.filter_policy.get());
1754
+ rep_->table_options.filter_policy.get(), async_read);
2004
1755
 
2005
1756
  if (get_context) {
2006
1757
  switch (block_type) {
@@ -2036,28 +1787,32 @@ template Status BlockBasedTable::RetrieveBlock<BlockContents>(
2036
1787
  const BlockHandle& handle, const UncompressionDict& uncompression_dict,
2037
1788
  CachableEntry<BlockContents>* block_entry, BlockType block_type,
2038
1789
  GetContext* get_context, BlockCacheLookupContext* lookup_context,
2039
- bool for_compaction, bool use_cache, bool wait_for_cache) const;
1790
+ bool for_compaction, bool use_cache, bool wait_for_cache,
1791
+ bool async_read) const;
2040
1792
 
2041
1793
  template Status BlockBasedTable::RetrieveBlock<ParsedFullFilterBlock>(
2042
1794
  FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro,
2043
1795
  const BlockHandle& handle, const UncompressionDict& uncompression_dict,
2044
1796
  CachableEntry<ParsedFullFilterBlock>* block_entry, BlockType block_type,
2045
1797
  GetContext* get_context, BlockCacheLookupContext* lookup_context,
2046
- bool for_compaction, bool use_cache, bool wait_for_cache) const;
1798
+ bool for_compaction, bool use_cache, bool wait_for_cache,
1799
+ bool async_read) const;
2047
1800
 
2048
1801
  template Status BlockBasedTable::RetrieveBlock<Block>(
2049
1802
  FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro,
2050
1803
  const BlockHandle& handle, const UncompressionDict& uncompression_dict,
2051
1804
  CachableEntry<Block>* block_entry, BlockType block_type,
2052
1805
  GetContext* get_context, BlockCacheLookupContext* lookup_context,
2053
- bool for_compaction, bool use_cache, bool wait_for_cache) const;
1806
+ bool for_compaction, bool use_cache, bool wait_for_cache,
1807
+ bool async_read) const;
2054
1808
 
2055
1809
  template Status BlockBasedTable::RetrieveBlock<UncompressionDict>(
2056
1810
  FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro,
2057
1811
  const BlockHandle& handle, const UncompressionDict& uncompression_dict,
2058
1812
  CachableEntry<UncompressionDict>* block_entry, BlockType block_type,
2059
1813
  GetContext* get_context, BlockCacheLookupContext* lookup_context,
2060
- bool for_compaction, bool use_cache, bool wait_for_cache) const;
1814
+ bool for_compaction, bool use_cache, bool wait_for_cache,
1815
+ bool async_read) const;
2061
1816
 
2062
1817
  BlockBasedTable::PartitionedIndexIteratorState::PartitionedIndexIteratorState(
2063
1818
  const BlockBasedTable* table,
@@ -2426,10 +2181,11 @@ Status BlockBasedTable::Get(const ReadOptions& read_options, const Slice& key,
2426
2181
  bool does_referenced_key_exist = false;
2427
2182
  DataBlockIter biter;
2428
2183
  uint64_t referenced_data_size = 0;
2184
+ Status tmp_status;
2429
2185
  NewDataBlockIterator<DataBlockIter>(
2430
2186
  read_options, v.handle, &biter, BlockType::kData, get_context,
2431
- &lookup_data_block_context,
2432
- /*s=*/Status(), /*prefetch_buffer*/ nullptr);
2187
+ &lookup_data_block_context, /*prefetch_buffer=*/nullptr,
2188
+ /*for_compaction=*/false, /*async_read=*/false, tmp_status);
2433
2189
 
2434
2190
  if (no_io && biter.status().IsIncomplete()) {
2435
2191
  // couldn't get block from block_cache
@@ -2525,443 +2281,6 @@ Status BlockBasedTable::Get(const ReadOptions& read_options, const Slice& key,
2525
2281
  return s;
2526
2282
  }
2527
2283
 
2528
- using MultiGetRange = MultiGetContext::Range;
2529
- void BlockBasedTable::MultiGet(const ReadOptions& read_options,
2530
- const MultiGetRange* mget_range,
2531
- const SliceTransform* prefix_extractor,
2532
- bool skip_filters) {
2533
- if (mget_range->empty()) {
2534
- // Caller should ensure non-empty (performance bug)
2535
- assert(false);
2536
- return; // Nothing to do
2537
- }
2538
-
2539
- FilterBlockReader* const filter =
2540
- !skip_filters ? rep_->filter.get() : nullptr;
2541
- MultiGetRange sst_file_range(*mget_range, mget_range->begin(),
2542
- mget_range->end());
2543
-
2544
- // First check the full filter
2545
- // If full filter not useful, Then go into each block
2546
- const bool no_io = read_options.read_tier == kBlockCacheTier;
2547
- uint64_t tracing_mget_id = BlockCacheTraceHelper::kReservedGetId;
2548
- if (sst_file_range.begin()->get_context) {
2549
- tracing_mget_id = sst_file_range.begin()->get_context->get_tracing_get_id();
2550
- }
2551
- BlockCacheLookupContext lookup_context{
2552
- TableReaderCaller::kUserMultiGet, tracing_mget_id,
2553
- /*get_from_user_specified_snapshot=*/read_options.snapshot != nullptr};
2554
- FullFilterKeysMayMatch(filter, &sst_file_range, no_io, prefix_extractor,
2555
- &lookup_context);
2556
-
2557
- if (!sst_file_range.empty()) {
2558
- IndexBlockIter iiter_on_stack;
2559
- // if prefix_extractor found in block differs from options, disable
2560
- // BlockPrefixIndex. Only do this check when index_type is kHashSearch.
2561
- bool need_upper_bound_check = false;
2562
- if (rep_->index_type == BlockBasedTableOptions::kHashSearch) {
2563
- need_upper_bound_check = PrefixExtractorChanged(prefix_extractor);
2564
- }
2565
- auto iiter =
2566
- NewIndexIterator(read_options, need_upper_bound_check, &iiter_on_stack,
2567
- sst_file_range.begin()->get_context, &lookup_context);
2568
- std::unique_ptr<InternalIteratorBase<IndexValue>> iiter_unique_ptr;
2569
- if (iiter != &iiter_on_stack) {
2570
- iiter_unique_ptr.reset(iiter);
2571
- }
2572
-
2573
- uint64_t prev_offset = std::numeric_limits<uint64_t>::max();
2574
- autovector<BlockHandle, MultiGetContext::MAX_BATCH_SIZE> block_handles;
2575
- autovector<CachableEntry<Block>, MultiGetContext::MAX_BATCH_SIZE> results;
2576
- autovector<Status, MultiGetContext::MAX_BATCH_SIZE> statuses;
2577
- MultiGetContext::Mask reused_mask = 0;
2578
- char stack_buf[kMultiGetReadStackBufSize];
2579
- std::unique_ptr<char[]> block_buf;
2580
- {
2581
- MultiGetRange data_block_range(sst_file_range, sst_file_range.begin(),
2582
- sst_file_range.end());
2583
- std::vector<Cache::Handle*> cache_handles;
2584
- bool wait_for_cache_results = false;
2585
-
2586
- CachableEntry<UncompressionDict> uncompression_dict;
2587
- Status uncompression_dict_status;
2588
- uncompression_dict_status.PermitUncheckedError();
2589
- bool uncompression_dict_inited = false;
2590
- size_t total_len = 0;
2591
- ReadOptions ro = read_options;
2592
- ro.read_tier = kBlockCacheTier;
2593
-
2594
- for (auto miter = data_block_range.begin();
2595
- miter != data_block_range.end(); ++miter) {
2596
- const Slice& key = miter->ikey;
2597
- iiter->Seek(miter->ikey);
2598
-
2599
- IndexValue v;
2600
- if (iiter->Valid()) {
2601
- v = iiter->value();
2602
- }
2603
- if (!iiter->Valid() ||
2604
- (!v.first_internal_key.empty() && !skip_filters &&
2605
- UserComparatorWrapper(rep_->internal_comparator.user_comparator())
2606
- .CompareWithoutTimestamp(
2607
- ExtractUserKey(key),
2608
- ExtractUserKey(v.first_internal_key)) < 0)) {
2609
- // The requested key falls between highest key in previous block and
2610
- // lowest key in current block.
2611
- if (!iiter->status().IsNotFound()) {
2612
- *(miter->s) = iiter->status();
2613
- }
2614
- data_block_range.SkipKey(miter);
2615
- sst_file_range.SkipKey(miter);
2616
- continue;
2617
- }
2618
-
2619
- if (!uncompression_dict_inited && rep_->uncompression_dict_reader) {
2620
- uncompression_dict_status =
2621
- rep_->uncompression_dict_reader->GetOrReadUncompressionDictionary(
2622
- nullptr /* prefetch_buffer */, no_io,
2623
- read_options.verify_checksums,
2624
- sst_file_range.begin()->get_context, &lookup_context,
2625
- &uncompression_dict);
2626
- uncompression_dict_inited = true;
2627
- }
2628
-
2629
- if (!uncompression_dict_status.ok()) {
2630
- assert(!uncompression_dict_status.IsNotFound());
2631
- *(miter->s) = uncompression_dict_status;
2632
- data_block_range.SkipKey(miter);
2633
- sst_file_range.SkipKey(miter);
2634
- continue;
2635
- }
2636
-
2637
- statuses.emplace_back();
2638
- results.emplace_back();
2639
- if (v.handle.offset() == prev_offset) {
2640
- // This key can reuse the previous block (later on).
2641
- // Mark previous as "reused"
2642
- reused_mask |= MultiGetContext::Mask{1} << (block_handles.size() - 1);
2643
- // Use null handle to indicate this one reuses same block as
2644
- // previous.
2645
- block_handles.emplace_back(BlockHandle::NullBlockHandle());
2646
- continue;
2647
- }
2648
- // Lookup the cache for the given data block referenced by an index
2649
- // iterator value (i.e BlockHandle). If it exists in the cache,
2650
- // initialize block to the contents of the data block.
2651
- prev_offset = v.handle.offset();
2652
- BlockHandle handle = v.handle;
2653
- BlockCacheLookupContext lookup_data_block_context(
2654
- TableReaderCaller::kUserMultiGet);
2655
- const UncompressionDict& dict = uncompression_dict.GetValue()
2656
- ? *uncompression_dict.GetValue()
2657
- : UncompressionDict::GetEmptyDict();
2658
- Status s = RetrieveBlock(
2659
- nullptr, ro, handle, dict, &(results.back()), BlockType::kData,
2660
- miter->get_context, &lookup_data_block_context,
2661
- /* for_compaction */ false, /* use_cache */ true,
2662
- /* wait_for_cache */ false);
2663
- if (s.IsIncomplete()) {
2664
- s = Status::OK();
2665
- }
2666
- if (s.ok() && !results.back().IsEmpty()) {
2667
- // Since we have a valid handle, check the value. If its nullptr,
2668
- // it means the cache is waiting for the final result and we're
2669
- // supposed to call WaitAll() to wait for the result.
2670
- if (results.back().GetValue() != nullptr) {
2671
- // Found it in the cache. Add NULL handle to indicate there is
2672
- // nothing to read from disk.
2673
- if (results.back().GetCacheHandle()) {
2674
- results.back().UpdateCachedValue();
2675
- }
2676
- block_handles.emplace_back(BlockHandle::NullBlockHandle());
2677
- } else {
2678
- // We have to wait for the cache lookup to finish in the
2679
- // background, and then we may have to read the block from disk
2680
- // anyway
2681
- assert(results.back().GetCacheHandle());
2682
- wait_for_cache_results = true;
2683
- block_handles.emplace_back(handle);
2684
- cache_handles.emplace_back(results.back().GetCacheHandle());
2685
- }
2686
- } else {
2687
- block_handles.emplace_back(handle);
2688
- total_len += BlockSizeWithTrailer(handle);
2689
- }
2690
- }
2691
-
2692
- if (wait_for_cache_results) {
2693
- Cache* block_cache = rep_->table_options.block_cache.get();
2694
- block_cache->WaitAll(cache_handles);
2695
- for (size_t i = 0; i < block_handles.size(); ++i) {
2696
- // If this block was a success or failure or not needed because
2697
- // the corresponding key is in the same block as a prior key, skip
2698
- if (block_handles[i] == BlockHandle::NullBlockHandle() ||
2699
- results[i].IsEmpty()) {
2700
- continue;
2701
- }
2702
- results[i].UpdateCachedValue();
2703
- void* val = results[i].GetValue();
2704
- if (!val) {
2705
- // The async cache lookup failed - could be due to an error
2706
- // or a false positive. We need to read the data block from
2707
- // the SST file
2708
- results[i].Reset();
2709
- total_len += BlockSizeWithTrailer(block_handles[i]);
2710
- } else {
2711
- block_handles[i] = BlockHandle::NullBlockHandle();
2712
- }
2713
- }
2714
- }
2715
-
2716
- if (total_len) {
2717
- char* scratch = nullptr;
2718
- const UncompressionDict& dict = uncompression_dict.GetValue()
2719
- ? *uncompression_dict.GetValue()
2720
- : UncompressionDict::GetEmptyDict();
2721
- assert(uncompression_dict_inited || !rep_->uncompression_dict_reader);
2722
- assert(uncompression_dict_status.ok());
2723
- // If using direct IO, then scratch is not used, so keep it nullptr.
2724
- // If the blocks need to be uncompressed and we don't need the
2725
- // compressed blocks, then we can use a contiguous block of
2726
- // memory to read in all the blocks as it will be temporary
2727
- // storage
2728
- // 1. If blocks are compressed and compressed block cache is there,
2729
- // alloc heap bufs
2730
- // 2. If blocks are uncompressed, alloc heap bufs
2731
- // 3. If blocks are compressed and no compressed block cache, use
2732
- // stack buf
2733
- if (!rep_->file->use_direct_io() &&
2734
- rep_->table_options.block_cache_compressed == nullptr &&
2735
- rep_->blocks_maybe_compressed) {
2736
- if (total_len <= kMultiGetReadStackBufSize) {
2737
- scratch = stack_buf;
2738
- } else {
2739
- scratch = new char[total_len];
2740
- block_buf.reset(scratch);
2741
- }
2742
- }
2743
- RetrieveMultipleBlocks(read_options, &data_block_range, &block_handles,
2744
- &statuses, &results, scratch, dict);
2745
- if (sst_file_range.begin()->get_context) {
2746
- ++(sst_file_range.begin()
2747
- ->get_context->get_context_stats_.num_sst_read);
2748
- }
2749
- }
2750
- }
2751
-
2752
- DataBlockIter first_biter;
2753
- DataBlockIter next_biter;
2754
- size_t idx_in_batch = 0;
2755
- SharedCleanablePtr shared_cleanable;
2756
- for (auto miter = sst_file_range.begin(); miter != sst_file_range.end();
2757
- ++miter) {
2758
- Status s;
2759
- GetContext* get_context = miter->get_context;
2760
- const Slice& key = miter->ikey;
2761
- bool matched = false; // if such user key matched a key in SST
2762
- bool done = false;
2763
- bool first_block = true;
2764
- do {
2765
- DataBlockIter* biter = nullptr;
2766
- bool reusing_prev_block;
2767
- bool later_reused;
2768
- uint64_t referenced_data_size = 0;
2769
- bool does_referenced_key_exist = false;
2770
- BlockCacheLookupContext lookup_data_block_context(
2771
- TableReaderCaller::kUserMultiGet, tracing_mget_id,
2772
- /*get_from_user_specified_snapshot=*/read_options.snapshot !=
2773
- nullptr);
2774
- if (first_block) {
2775
- if (!block_handles[idx_in_batch].IsNull() ||
2776
- !results[idx_in_batch].IsEmpty()) {
2777
- first_biter.Invalidate(Status::OK());
2778
- NewDataBlockIterator<DataBlockIter>(
2779
- read_options, results[idx_in_batch], &first_biter,
2780
- statuses[idx_in_batch]);
2781
- reusing_prev_block = false;
2782
- } else {
2783
- // If handler is null and result is empty, then the status is never
2784
- // set, which should be the initial value: ok().
2785
- assert(statuses[idx_in_batch].ok());
2786
- reusing_prev_block = true;
2787
- }
2788
- biter = &first_biter;
2789
- later_reused =
2790
- (reused_mask & (MultiGetContext::Mask{1} << idx_in_batch)) != 0;
2791
- idx_in_batch++;
2792
- } else {
2793
- IndexValue v = iiter->value();
2794
- if (!v.first_internal_key.empty() && !skip_filters &&
2795
- UserComparatorWrapper(rep_->internal_comparator.user_comparator())
2796
- .CompareWithoutTimestamp(
2797
- ExtractUserKey(key),
2798
- ExtractUserKey(v.first_internal_key)) < 0) {
2799
- // The requested key falls between highest key in previous block and
2800
- // lowest key in current block.
2801
- break;
2802
- }
2803
-
2804
- next_biter.Invalidate(Status::OK());
2805
- NewDataBlockIterator<DataBlockIter>(
2806
- read_options, iiter->value().handle, &next_biter,
2807
- BlockType::kData, get_context, &lookup_data_block_context,
2808
- Status(), nullptr);
2809
- biter = &next_biter;
2810
- reusing_prev_block = false;
2811
- later_reused = false;
2812
- }
2813
-
2814
- if (read_options.read_tier == kBlockCacheTier &&
2815
- biter->status().IsIncomplete()) {
2816
- // couldn't get block from block_cache
2817
- // Update Saver.state to Found because we are only looking for
2818
- // whether we can guarantee the key is not there when "no_io" is set
2819
- get_context->MarkKeyMayExist();
2820
- break;
2821
- }
2822
- if (!biter->status().ok()) {
2823
- s = biter->status();
2824
- break;
2825
- }
2826
-
2827
- bool may_exist = biter->SeekForGet(key);
2828
- if (!may_exist) {
2829
- // HashSeek cannot find the key this block and the the iter is not
2830
- // the end of the block, i.e. cannot be in the following blocks
2831
- // either. In this case, the seek_key cannot be found, so we break
2832
- // from the top level for-loop.
2833
- break;
2834
- }
2835
-
2836
- // Reusing blocks complicates pinning/Cleanable, because the cache
2837
- // entry referenced by biter can only be released once all returned
2838
- // pinned values are released. This code previously did an extra
2839
- // block_cache Ref for each reuse, but that unnecessarily increases
2840
- // block cache contention. Instead we can use a variant of shared_ptr
2841
- // to release in block cache only once.
2842
- //
2843
- // Although the biter loop below might SaveValue multiple times for
2844
- // merges, just one value_pinner suffices, as MultiGet will merge
2845
- // the operands before returning to the API user.
2846
- Cleanable* value_pinner;
2847
- if (biter->IsValuePinned()) {
2848
- if (reusing_prev_block) {
2849
- // Note that we don't yet know if the MultiGet results will need
2850
- // to pin this block, so we might wrap a block for sharing and
2851
- // still end up with 1 (or 0) pinning ref. Not ideal but OK.
2852
- //
2853
- // Here we avoid adding redundant cleanups if we didn't end up
2854
- // delegating the cleanup from last time around.
2855
- if (!biter->HasCleanups()) {
2856
- assert(shared_cleanable.get());
2857
- if (later_reused) {
2858
- shared_cleanable.RegisterCopyWith(biter);
2859
- } else {
2860
- shared_cleanable.MoveAsCleanupTo(biter);
2861
- }
2862
- }
2863
- } else if (later_reused) {
2864
- assert(biter->HasCleanups());
2865
- // Make the existing cleanups on `biter` sharable:
2866
- shared_cleanable.Allocate();
2867
- // Move existing `biter` cleanup(s) to `shared_cleanable`
2868
- biter->DelegateCleanupsTo(&*shared_cleanable);
2869
- // Reference `shared_cleanable` as new cleanup for `biter`
2870
- shared_cleanable.RegisterCopyWith(biter);
2871
- }
2872
- assert(biter->HasCleanups());
2873
- value_pinner = biter;
2874
- } else {
2875
- value_pinner = nullptr;
2876
- }
2877
-
2878
- // Call the *saver function on each entry/block until it returns false
2879
- for (; biter->Valid(); biter->Next()) {
2880
- ParsedInternalKey parsed_key;
2881
- Status pik_status = ParseInternalKey(
2882
- biter->key(), &parsed_key, false /* log_err_key */); // TODO
2883
- if (!pik_status.ok()) {
2884
- s = pik_status;
2885
- }
2886
- if (!get_context->SaveValue(parsed_key, biter->value(), &matched,
2887
- value_pinner)) {
2888
- if (get_context->State() == GetContext::GetState::kFound) {
2889
- does_referenced_key_exist = true;
2890
- referenced_data_size =
2891
- biter->key().size() + biter->value().size();
2892
- }
2893
- done = true;
2894
- break;
2895
- }
2896
- s = biter->status();
2897
- }
2898
- // Write the block cache access.
2899
- // XXX: There appear to be 'break' statements above that bypass this
2900
- // writing of the block cache trace record
2901
- if (block_cache_tracer_ && block_cache_tracer_->is_tracing_enabled() &&
2902
- !reusing_prev_block) {
2903
- // Avoid making copy of block_key, cf_name, and referenced_key when
2904
- // constructing the access record.
2905
- Slice referenced_key;
2906
- if (does_referenced_key_exist) {
2907
- referenced_key = biter->key();
2908
- } else {
2909
- referenced_key = key;
2910
- }
2911
- BlockCacheTraceRecord access_record(
2912
- rep_->ioptions.clock->NowMicros(),
2913
- /*block_key=*/"", lookup_data_block_context.block_type,
2914
- lookup_data_block_context.block_size, rep_->cf_id_for_tracing(),
2915
- /*cf_name=*/"", rep_->level_for_tracing(),
2916
- rep_->sst_number_for_tracing(), lookup_data_block_context.caller,
2917
- lookup_data_block_context.is_cache_hit,
2918
- lookup_data_block_context.no_insert,
2919
- lookup_data_block_context.get_id,
2920
- lookup_data_block_context.get_from_user_specified_snapshot,
2921
- /*referenced_key=*/"", referenced_data_size,
2922
- lookup_data_block_context.num_keys_in_block,
2923
- does_referenced_key_exist);
2924
- // TODO: Should handle status here?
2925
- block_cache_tracer_
2926
- ->WriteBlockAccess(access_record,
2927
- lookup_data_block_context.block_key,
2928
- rep_->cf_name_for_tracing(), referenced_key)
2929
- .PermitUncheckedError();
2930
- }
2931
- s = biter->status();
2932
- if (done) {
2933
- // Avoid the extra Next which is expensive in two-level indexes
2934
- break;
2935
- }
2936
- if (first_block) {
2937
- iiter->Seek(key);
2938
- if (!iiter->Valid()) {
2939
- break;
2940
- }
2941
- }
2942
- first_block = false;
2943
- iiter->Next();
2944
- } while (iiter->Valid());
2945
-
2946
- if (matched && filter != nullptr && !filter->IsBlockBased()) {
2947
- RecordTick(rep_->ioptions.stats, BLOOM_FILTER_FULL_TRUE_POSITIVE);
2948
- PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_full_true_positive, 1,
2949
- rep_->level);
2950
- }
2951
- if (s.ok() && !iiter->status().IsNotFound()) {
2952
- s = iiter->status();
2953
- }
2954
- *(miter->s) = s;
2955
- }
2956
- #ifdef ROCKSDB_ASSERT_STATUS_CHECKED
2957
- // Not sure why we need to do it. Should investigate more.
2958
- for (auto& st : statuses) {
2959
- st.PermitUncheckedError();
2960
- }
2961
- #endif // ROCKSDB_ASSERT_STATUS_CHECKED
2962
- }
2963
- }
2964
-
2965
2284
  Status BlockBasedTable::Prefetch(const Slice* const begin,
2966
2285
  const Slice* const end) {
2967
2286
  auto& comparator = rep_->internal_comparator;
@@ -3007,11 +2326,12 @@ Status BlockBasedTable::Prefetch(const Slice* const begin,
3007
2326
 
3008
2327
  // Load the block specified by the block_handle into the block cache
3009
2328
  DataBlockIter biter;
3010
-
2329
+ Status tmp_status;
3011
2330
  NewDataBlockIterator<DataBlockIter>(
3012
2331
  ReadOptions(), block_handle, &biter, /*type=*/BlockType::kData,
3013
- /*get_context=*/nullptr, &lookup_context, Status(),
3014
- /*prefetch_buffer=*/nullptr);
2332
+ /*get_context=*/nullptr, &lookup_context,
2333
+ /*prefetch_buffer=*/nullptr, /*for_compaction=*/false,
2334
+ /*async_read=*/false, tmp_status);
3015
2335
 
3016
2336
  if (!biter.status().ok()) {
3017
2337
  // there was an unexpected error while pre-fetching
@@ -3406,11 +2726,13 @@ Status BlockBasedTable::GetKVPairsFromDataBlocks(
3406
2726
  }
3407
2727
 
3408
2728
  std::unique_ptr<InternalIterator> datablock_iter;
2729
+ Status tmp_status;
3409
2730
  datablock_iter.reset(NewDataBlockIterator<DataBlockIter>(
3410
2731
  ReadOptions(), blockhandles_iter->value().handle,
3411
2732
  /*input_iter=*/nullptr, /*type=*/BlockType::kData,
3412
- /*get_context=*/nullptr, /*lookup_context=*/nullptr, Status(),
3413
- /*prefetch_buffer=*/nullptr));
2733
+ /*get_context=*/nullptr, /*lookup_context=*/nullptr,
2734
+ /*prefetch_buffer=*/nullptr, /*for_compaction=*/false,
2735
+ /*async_read=*/false, tmp_status));
3414
2736
  s = datablock_iter->status();
3415
2737
 
3416
2738
  if (!s.ok()) {
@@ -3637,11 +2959,13 @@ Status BlockBasedTable::DumpDataBlocks(std::ostream& out_stream) {
3637
2959
  out_stream << "--------------------------------------\n";
3638
2960
 
3639
2961
  std::unique_ptr<InternalIterator> datablock_iter;
2962
+ Status tmp_status;
3640
2963
  datablock_iter.reset(NewDataBlockIterator<DataBlockIter>(
3641
2964
  ReadOptions(), blockhandles_iter->value().handle,
3642
2965
  /*input_iter=*/nullptr, /*type=*/BlockType::kData,
3643
- /*get_context=*/nullptr, /*lookup_context=*/nullptr, Status(),
3644
- /*prefetch_buffer=*/nullptr));
2966
+ /*get_context=*/nullptr, /*lookup_context=*/nullptr,
2967
+ /*prefetch_buffer=*/nullptr, /*for_compaction=*/false,
2968
+ /*async_read=*/false, tmp_status));
3645
2969
  s = datablock_iter->status();
3646
2970
 
3647
2971
  if (!s.ok()) {