@nxtedition/rocksdb 6.0.2 → 6.0.3

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 (257) hide show
  1. package/BUILDING.md +12 -4
  2. package/binding.cc +2 -0
  3. package/deps/rocksdb/rocksdb/CMakeLists.txt +9 -0
  4. package/deps/rocksdb/rocksdb/Makefile +16 -5
  5. package/deps/rocksdb/rocksdb/TARGETS +23 -2
  6. package/deps/rocksdb/rocksdb/cmake/modules/CxxFlags.cmake +7 -0
  7. package/deps/rocksdb/rocksdb/cmake/modules/FindJeMalloc.cmake +29 -0
  8. package/deps/rocksdb/rocksdb/cmake/modules/FindNUMA.cmake +29 -0
  9. package/deps/rocksdb/rocksdb/cmake/modules/FindSnappy.cmake +29 -0
  10. package/deps/rocksdb/rocksdb/cmake/modules/FindTBB.cmake +33 -0
  11. package/deps/rocksdb/rocksdb/cmake/modules/Findgflags.cmake +29 -0
  12. package/deps/rocksdb/rocksdb/cmake/modules/Findlz4.cmake +29 -0
  13. package/deps/rocksdb/rocksdb/cmake/modules/Finduring.cmake +26 -0
  14. package/deps/rocksdb/rocksdb/cmake/modules/Findzstd.cmake +29 -0
  15. package/deps/rocksdb/rocksdb/cmake/modules/ReadVersion.cmake +10 -0
  16. package/deps/rocksdb/rocksdb/db/builder.cc +12 -4
  17. package/deps/rocksdb/rocksdb/db/c.cc +26 -0
  18. package/deps/rocksdb/rocksdb/db/c_test.c +3 -0
  19. package/deps/rocksdb/rocksdb/db/column_family.cc +8 -2
  20. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +29 -6
  21. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +8 -2
  22. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +16 -4
  23. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +2 -1
  24. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_test.cc +16 -0
  25. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +402 -30
  26. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +2 -12
  27. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +14 -0
  28. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +7 -5
  29. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_experimental.cc +1 -1
  30. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +33 -7
  31. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.cc +54 -23
  32. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.h +3 -0
  33. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +8 -1
  34. package/deps/rocksdb/rocksdb/db/db_options_test.cc +16 -0
  35. package/deps/rocksdb/rocksdb/db/db_rate_limiter_test.cc +14 -15
  36. package/deps/rocksdb/rocksdb/db/db_readonly_with_timestamp_test.cc +331 -0
  37. package/deps/rocksdb/rocksdb/db/db_secondary_test.cc +5 -0
  38. package/deps/rocksdb/rocksdb/db/db_test.cc +16 -0
  39. package/deps/rocksdb/rocksdb/db/db_test2.cc +221 -92
  40. package/deps/rocksdb/rocksdb/db/db_test_util.cc +6 -2
  41. package/deps/rocksdb/rocksdb/db/db_test_util.h +4 -2
  42. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +1 -171
  43. package/deps/rocksdb/rocksdb/db/db_with_timestamp_test_util.cc +96 -0
  44. package/deps/rocksdb/rocksdb/db/db_with_timestamp_test_util.h +126 -0
  45. package/deps/rocksdb/rocksdb/db/experimental.cc +1 -1
  46. package/deps/rocksdb/rocksdb/db/external_sst_file_basic_test.cc +57 -0
  47. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +13 -2
  48. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.h +2 -0
  49. package/deps/rocksdb/rocksdb/db/flush_job.cc +10 -11
  50. package/deps/rocksdb/rocksdb/db/import_column_family_job.cc +11 -1
  51. package/deps/rocksdb/rocksdb/db/import_column_family_test.cc +6 -0
  52. package/deps/rocksdb/rocksdb/db/repair.cc +12 -1
  53. package/deps/rocksdb/rocksdb/db/repair_test.cc +32 -10
  54. package/deps/rocksdb/rocksdb/db/snapshot_impl.h +3 -1
  55. package/deps/rocksdb/rocksdb/db/table_cache.cc +19 -127
  56. package/deps/rocksdb/rocksdb/db/table_cache.h +3 -2
  57. package/deps/rocksdb/rocksdb/db/table_cache_sync_and_async.h +140 -0
  58. package/deps/rocksdb/rocksdb/db/version_builder_test.cc +130 -128
  59. package/deps/rocksdb/rocksdb/db/version_edit.cc +20 -0
  60. package/deps/rocksdb/rocksdb/db/version_edit.h +13 -4
  61. package/deps/rocksdb/rocksdb/db/version_edit_test.cc +14 -14
  62. package/deps/rocksdb/rocksdb/db/version_set.cc +205 -212
  63. package/deps/rocksdb/rocksdb/db/version_set.h +11 -0
  64. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +154 -0
  65. package/deps/rocksdb/rocksdb/db/version_set_test.cc +10 -9
  66. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +2 -0
  67. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +13 -0
  68. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +15 -0
  69. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +159 -65
  70. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +43 -21
  71. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +142 -17
  72. package/deps/rocksdb/rocksdb/file/writable_file_writer.cc +23 -27
  73. package/deps/rocksdb/rocksdb/file/writable_file_writer.h +2 -3
  74. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +23 -5
  75. package/deps/rocksdb/rocksdb/include/rocksdb/c.h +14 -1
  76. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +2 -0
  77. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +17 -0
  78. package/deps/rocksdb/rocksdb/include/rocksdb/perf_context.h +2 -0
  79. package/deps/rocksdb/rocksdb/include/rocksdb/snapshot.h +4 -1
  80. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +3 -0
  81. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/options_type.h +189 -0
  82. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  83. package/deps/rocksdb/rocksdb/monitoring/perf_context.cc +5 -0
  84. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +1 -1
  85. package/deps/rocksdb/rocksdb/options/cf_options.cc +13 -0
  86. package/deps/rocksdb/rocksdb/options/db_options.cc +8 -0
  87. package/deps/rocksdb/rocksdb/options/db_options.h +1 -0
  88. package/deps/rocksdb/rocksdb/options/options.cc +7 -0
  89. package/deps/rocksdb/rocksdb/options/options_helper.cc +4 -0
  90. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +6 -4
  91. package/deps/rocksdb/rocksdb/options/options_test.cc +107 -9
  92. package/deps/rocksdb/rocksdb/src.mk +4 -1
  93. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +9 -4
  94. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.cc +80 -6
  95. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.h +8 -2
  96. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +81 -757
  97. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +21 -15
  98. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_impl.h +9 -3
  99. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +754 -0
  100. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +2 -1
  101. package/deps/rocksdb/rocksdb/table/block_based/block_prefetcher.cc +8 -0
  102. package/deps/rocksdb/rocksdb/table/block_based/filter_block.h +1 -10
  103. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.cc +59 -1
  104. package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.h +18 -0
  105. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.cc +0 -61
  106. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.h +0 -13
  107. package/deps/rocksdb/rocksdb/table/block_based/index_reader_common.cc +1 -1
  108. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +3 -2
  109. package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_iterator.cc +2 -2
  110. package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_reader.cc +2 -1
  111. package/deps/rocksdb/rocksdb/table/block_based/uncompression_dict_reader.cc +2 -1
  112. package/deps/rocksdb/rocksdb/table/block_fetcher.cc +60 -2
  113. package/deps/rocksdb/rocksdb/table/block_fetcher.h +2 -0
  114. package/deps/rocksdb/rocksdb/table/merging_iterator.cc +39 -0
  115. package/deps/rocksdb/rocksdb/table/multiget_context.h +46 -2
  116. package/deps/rocksdb/rocksdb/table/sst_file_dumper.cc +2 -1
  117. package/deps/rocksdb/rocksdb/table/sst_file_dumper.h +1 -1
  118. package/deps/rocksdb/rocksdb/table/table_reader.h +13 -0
  119. package/deps/rocksdb/rocksdb/table/unique_id.cc +27 -0
  120. package/deps/rocksdb/rocksdb/table/unique_id_impl.h +3 -0
  121. package/deps/rocksdb/rocksdb/test_util/testutil.cc +2 -0
  122. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +23 -7
  123. package/deps/rocksdb/rocksdb/tools/sst_dump_tool.cc +9 -1
  124. package/deps/rocksdb/rocksdb/util/async_file_reader.cc +72 -0
  125. package/deps/rocksdb/rocksdb/util/async_file_reader.h +144 -0
  126. package/deps/rocksdb/rocksdb/util/compression.h +49 -0
  127. package/deps/rocksdb/rocksdb/util/coro_utils.h +111 -0
  128. package/deps/rocksdb/rocksdb/util/single_thread_executor.h +55 -0
  129. package/deps/rocksdb/rocksdb.gyp +16 -15
  130. package/package-lock.json +23687 -0
  131. package/package.json +2 -30
  132. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  133. package/prebuilds/darwin-x64/node.napi.node +0 -0
  134. package/prebuilds/linux-x64/node.napi.node +0 -0
  135. package/deps/liburing/liburing/README +0 -46
  136. package/deps/liburing/liburing/test/232c93d07b74-test.c +0 -305
  137. package/deps/liburing/liburing/test/35fa71a030ca-test.c +0 -329
  138. package/deps/liburing/liburing/test/500f9fbadef8-test.c +0 -89
  139. package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +0 -93
  140. package/deps/liburing/liburing/test/8a9973408177-test.c +0 -106
  141. package/deps/liburing/liburing/test/917257daa0fe-test.c +0 -53
  142. package/deps/liburing/liburing/test/Makefile +0 -312
  143. package/deps/liburing/liburing/test/a0908ae19763-test.c +0 -58
  144. package/deps/liburing/liburing/test/a4c0b3decb33-test.c +0 -180
  145. package/deps/liburing/liburing/test/accept-link.c +0 -251
  146. package/deps/liburing/liburing/test/accept-reuse.c +0 -164
  147. package/deps/liburing/liburing/test/accept-test.c +0 -79
  148. package/deps/liburing/liburing/test/accept.c +0 -476
  149. package/deps/liburing/liburing/test/across-fork.c +0 -283
  150. package/deps/liburing/liburing/test/b19062a56726-test.c +0 -53
  151. package/deps/liburing/liburing/test/b5837bd5311d-test.c +0 -77
  152. package/deps/liburing/liburing/test/ce593a6c480a-test.c +0 -135
  153. package/deps/liburing/liburing/test/close-opath.c +0 -122
  154. package/deps/liburing/liburing/test/config +0 -10
  155. package/deps/liburing/liburing/test/connect.c +0 -398
  156. package/deps/liburing/liburing/test/cq-full.c +0 -96
  157. package/deps/liburing/liburing/test/cq-overflow.c +0 -294
  158. package/deps/liburing/liburing/test/cq-peek-batch.c +0 -102
  159. package/deps/liburing/liburing/test/cq-ready.c +0 -94
  160. package/deps/liburing/liburing/test/cq-size.c +0 -58
  161. package/deps/liburing/liburing/test/d4ae271dfaae-test.c +0 -96
  162. package/deps/liburing/liburing/test/d77a67ed5f27-test.c +0 -65
  163. package/deps/liburing/liburing/test/defer.c +0 -307
  164. package/deps/liburing/liburing/test/double-poll-crash.c +0 -186
  165. package/deps/liburing/liburing/test/eeed8b54e0df-test.c +0 -114
  166. package/deps/liburing/liburing/test/empty-eownerdead.c +0 -42
  167. package/deps/liburing/liburing/test/eventfd-disable.c +0 -151
  168. package/deps/liburing/liburing/test/eventfd-ring.c +0 -97
  169. package/deps/liburing/liburing/test/eventfd.c +0 -112
  170. package/deps/liburing/liburing/test/fadvise.c +0 -202
  171. package/deps/liburing/liburing/test/fallocate.c +0 -249
  172. package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +0 -138
  173. package/deps/liburing/liburing/test/file-register.c +0 -843
  174. package/deps/liburing/liburing/test/file-update.c +0 -173
  175. package/deps/liburing/liburing/test/files-exit-hang-poll.c +0 -128
  176. package/deps/liburing/liburing/test/files-exit-hang-timeout.c +0 -134
  177. package/deps/liburing/liburing/test/fixed-link.c +0 -90
  178. package/deps/liburing/liburing/test/fsync.c +0 -224
  179. package/deps/liburing/liburing/test/hardlink.c +0 -136
  180. package/deps/liburing/liburing/test/helpers.c +0 -135
  181. package/deps/liburing/liburing/test/helpers.h +0 -67
  182. package/deps/liburing/liburing/test/io-cancel.c +0 -537
  183. package/deps/liburing/liburing/test/io_uring_enter.c +0 -296
  184. package/deps/liburing/liburing/test/io_uring_register.c +0 -664
  185. package/deps/liburing/liburing/test/io_uring_setup.c +0 -192
  186. package/deps/liburing/liburing/test/iopoll.c +0 -366
  187. package/deps/liburing/liburing/test/lfs-openat-write.c +0 -117
  188. package/deps/liburing/liburing/test/lfs-openat.c +0 -273
  189. package/deps/liburing/liburing/test/link-timeout.c +0 -1107
  190. package/deps/liburing/liburing/test/link.c +0 -496
  191. package/deps/liburing/liburing/test/link_drain.c +0 -229
  192. package/deps/liburing/liburing/test/madvise.c +0 -195
  193. package/deps/liburing/liburing/test/mkdir.c +0 -108
  194. package/deps/liburing/liburing/test/multicqes_drain.c +0 -383
  195. package/deps/liburing/liburing/test/nop-all-sizes.c +0 -107
  196. package/deps/liburing/liburing/test/nop.c +0 -115
  197. package/deps/liburing/liburing/test/open-close.c +0 -146
  198. package/deps/liburing/liburing/test/openat2.c +0 -240
  199. package/deps/liburing/liburing/test/personality.c +0 -204
  200. package/deps/liburing/liburing/test/pipe-eof.c +0 -81
  201. package/deps/liburing/liburing/test/pipe-reuse.c +0 -105
  202. package/deps/liburing/liburing/test/poll-cancel-ton.c +0 -139
  203. package/deps/liburing/liburing/test/poll-cancel.c +0 -135
  204. package/deps/liburing/liburing/test/poll-link.c +0 -227
  205. package/deps/liburing/liburing/test/poll-many.c +0 -208
  206. package/deps/liburing/liburing/test/poll-mshot-update.c +0 -273
  207. package/deps/liburing/liburing/test/poll-ring.c +0 -48
  208. package/deps/liburing/liburing/test/poll-v-poll.c +0 -353
  209. package/deps/liburing/liburing/test/poll.c +0 -109
  210. package/deps/liburing/liburing/test/probe.c +0 -137
  211. package/deps/liburing/liburing/test/read-write.c +0 -876
  212. package/deps/liburing/liburing/test/register-restrictions.c +0 -633
  213. package/deps/liburing/liburing/test/rename.c +0 -134
  214. package/deps/liburing/liburing/test/ring-leak.c +0 -173
  215. package/deps/liburing/liburing/test/ring-leak2.c +0 -249
  216. package/deps/liburing/liburing/test/rsrc_tags.c +0 -449
  217. package/deps/liburing/liburing/test/runtests-loop.sh +0 -16
  218. package/deps/liburing/liburing/test/runtests.sh +0 -170
  219. package/deps/liburing/liburing/test/rw_merge_test.c +0 -97
  220. package/deps/liburing/liburing/test/self.c +0 -91
  221. package/deps/liburing/liburing/test/send_recv.c +0 -291
  222. package/deps/liburing/liburing/test/send_recvmsg.c +0 -345
  223. package/deps/liburing/liburing/test/sendmsg_fs_cve.c +0 -198
  224. package/deps/liburing/liburing/test/shared-wq.c +0 -84
  225. package/deps/liburing/liburing/test/short-read.c +0 -75
  226. package/deps/liburing/liburing/test/shutdown.c +0 -163
  227. package/deps/liburing/liburing/test/sigfd-deadlock.c +0 -74
  228. package/deps/liburing/liburing/test/socket-rw-eagain.c +0 -156
  229. package/deps/liburing/liburing/test/socket-rw.c +0 -147
  230. package/deps/liburing/liburing/test/splice.c +0 -511
  231. package/deps/liburing/liburing/test/sq-full-cpp.cc +0 -45
  232. package/deps/liburing/liburing/test/sq-full.c +0 -45
  233. package/deps/liburing/liburing/test/sq-poll-dup.c +0 -200
  234. package/deps/liburing/liburing/test/sq-poll-kthread.c +0 -168
  235. package/deps/liburing/liburing/test/sq-poll-share.c +0 -137
  236. package/deps/liburing/liburing/test/sq-space_left.c +0 -159
  237. package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +0 -159
  238. package/deps/liburing/liburing/test/sqpoll-disable-exit.c +0 -195
  239. package/deps/liburing/liburing/test/sqpoll-exit-hang.c +0 -77
  240. package/deps/liburing/liburing/test/sqpoll-sleep.c +0 -68
  241. package/deps/liburing/liburing/test/statx.c +0 -172
  242. package/deps/liburing/liburing/test/stdout.c +0 -232
  243. package/deps/liburing/liburing/test/submit-link-fail.c +0 -154
  244. package/deps/liburing/liburing/test/submit-reuse.c +0 -239
  245. package/deps/liburing/liburing/test/symlink.c +0 -116
  246. package/deps/liburing/liburing/test/teardowns.c +0 -58
  247. package/deps/liburing/liburing/test/thread-exit.c +0 -131
  248. package/deps/liburing/liburing/test/timeout-new.c +0 -246
  249. package/deps/liburing/liburing/test/timeout-overflow.c +0 -204
  250. package/deps/liburing/liburing/test/timeout.c +0 -1354
  251. package/deps/liburing/liburing/test/unlink.c +0 -111
  252. package/deps/liburing/liburing/test/wakeup-hang.c +0 -162
  253. package/deps/rocksdb/rocksdb/README.md +0 -32
  254. package/deps/rocksdb/rocksdb/microbench/README.md +0 -60
  255. package/deps/rocksdb/rocksdb/plugin/README.md +0 -43
  256. package/deps/rocksdb/rocksdb/port/README +0 -10
  257. package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_tree/lib/README +0 -13
@@ -0,0 +1,754 @@
1
+ // Copyright (c) Meta Platforms, Inc. and its affiliates. All Rights Reserved.
2
+ // This source code is licensed under both the GPLv2 (found in the
3
+ // COPYING file in the root directory) and Apache 2.0 License
4
+ // (found in the LICENSE.Apache file in the root directory).
5
+
6
+ #include "util/async_file_reader.h"
7
+ #include "util/coro_utils.h"
8
+
9
+ #if defined(WITHOUT_COROUTINES) || \
10
+ (defined(USE_COROUTINES) && defined(WITH_COROUTINES))
11
+
12
+ namespace ROCKSDB_NAMESPACE {
13
+
14
+ // This function reads multiple data blocks from disk using Env::MultiRead()
15
+ // and optionally inserts them into the block cache. It uses the scratch
16
+ // buffer provided by the caller, which is contiguous. If scratch is a nullptr
17
+ // it allocates a separate buffer for each block. Typically, if the blocks
18
+ // need to be uncompressed and there is no compressed block cache, callers
19
+ // can allocate a temporary scratch buffer in order to minimize memory
20
+ // allocations.
21
+ // If options.fill_cache is true, it inserts the blocks into cache. If its
22
+ // false and scratch is non-null and the blocks are uncompressed, it copies
23
+ // the buffers to heap. In any case, the CachableEntry<Block> returned will
24
+ // own the data bytes.
25
+ // If compression is enabled and also there is no compressed block cache,
26
+ // the adjacent blocks are read out in one IO (combined read)
27
+ // batch - A MultiGetRange with only those keys with unique data blocks not
28
+ // found in cache
29
+ // handles - A vector of block handles. Some of them me be NULL handles
30
+ // scratch - An optional contiguous buffer to read compressed blocks into
31
+ DEFINE_SYNC_AND_ASYNC(void, BlockBasedTable::RetrieveMultipleBlocks)
32
+ (const ReadOptions& options, const MultiGetRange* batch,
33
+ const autovector<BlockHandle, MultiGetContext::MAX_BATCH_SIZE>* handles,
34
+ autovector<Status, MultiGetContext::MAX_BATCH_SIZE>* statuses,
35
+ autovector<CachableEntry<Block>, MultiGetContext::MAX_BATCH_SIZE>* results,
36
+ char* scratch, const UncompressionDict& uncompression_dict) const {
37
+ RandomAccessFileReader* file = rep_->file.get();
38
+ const Footer& footer = rep_->footer;
39
+ const ImmutableOptions& ioptions = rep_->ioptions;
40
+ size_t read_amp_bytes_per_bit = rep_->table_options.read_amp_bytes_per_bit;
41
+ MemoryAllocator* memory_allocator = GetMemoryAllocator(rep_->table_options);
42
+
43
+ if (ioptions.allow_mmap_reads) {
44
+ size_t idx_in_batch = 0;
45
+ for (auto mget_iter = batch->begin(); mget_iter != batch->end();
46
+ ++mget_iter, ++idx_in_batch) {
47
+ BlockCacheLookupContext lookup_data_block_context(
48
+ TableReaderCaller::kUserMultiGet);
49
+ const BlockHandle& handle = (*handles)[idx_in_batch];
50
+ if (handle.IsNull()) {
51
+ continue;
52
+ }
53
+
54
+ (*statuses)[idx_in_batch] =
55
+ RetrieveBlock(nullptr, options, handle, uncompression_dict,
56
+ &(*results)[idx_in_batch], BlockType::kData,
57
+ mget_iter->get_context, &lookup_data_block_context,
58
+ /* for_compaction */ false, /* use_cache */ true,
59
+ /* wait_for_cache */ true, /* async_read */ false);
60
+ }
61
+ CO_RETURN;
62
+ }
63
+
64
+ // In direct IO mode, blocks share the direct io buffer.
65
+ // Otherwise, blocks share the scratch buffer.
66
+ const bool use_shared_buffer = file->use_direct_io() || scratch != nullptr;
67
+
68
+ autovector<FSReadRequest, MultiGetContext::MAX_BATCH_SIZE> read_reqs;
69
+ size_t buf_offset = 0;
70
+ size_t idx_in_batch = 0;
71
+
72
+ uint64_t prev_offset = 0;
73
+ size_t prev_len = 0;
74
+ autovector<size_t, MultiGetContext::MAX_BATCH_SIZE> req_idx_for_block;
75
+ autovector<size_t, MultiGetContext::MAX_BATCH_SIZE> req_offset_for_block;
76
+ for (auto mget_iter = batch->begin(); mget_iter != batch->end();
77
+ ++mget_iter, ++idx_in_batch) {
78
+ const BlockHandle& handle = (*handles)[idx_in_batch];
79
+ if (handle.IsNull()) {
80
+ continue;
81
+ }
82
+
83
+ size_t prev_end = static_cast<size_t>(prev_offset) + prev_len;
84
+
85
+ // If current block is adjacent to the previous one, at the same time,
86
+ // compression is enabled and there is no compressed cache, we combine
87
+ // the two block read as one.
88
+ // We don't combine block reads here in direct IO mode, because when doing
89
+ // direct IO read, the block requests will be realigned and merged when
90
+ // necessary.
91
+ if (use_shared_buffer && !file->use_direct_io() &&
92
+ prev_end == handle.offset()) {
93
+ req_offset_for_block.emplace_back(prev_len);
94
+ prev_len += BlockSizeWithTrailer(handle);
95
+ } else {
96
+ // No compression or current block and previous one is not adjacent:
97
+ // Step 1, create a new request for previous blocks
98
+ if (prev_len != 0) {
99
+ FSReadRequest req;
100
+ req.offset = prev_offset;
101
+ req.len = prev_len;
102
+ if (file->use_direct_io()) {
103
+ req.scratch = nullptr;
104
+ } else if (use_shared_buffer) {
105
+ req.scratch = scratch + buf_offset;
106
+ buf_offset += req.len;
107
+ } else {
108
+ req.scratch = new char[req.len];
109
+ }
110
+ read_reqs.emplace_back(req);
111
+ }
112
+
113
+ // Step 2, remeber the previous block info
114
+ prev_offset = handle.offset();
115
+ prev_len = BlockSizeWithTrailer(handle);
116
+ req_offset_for_block.emplace_back(0);
117
+ }
118
+ req_idx_for_block.emplace_back(read_reqs.size());
119
+
120
+ PERF_COUNTER_ADD(block_read_count, 1);
121
+ PERF_COUNTER_ADD(block_read_byte, BlockSizeWithTrailer(handle));
122
+ }
123
+ // Handle the last block and process the pending last request
124
+ if (prev_len != 0) {
125
+ FSReadRequest req;
126
+ req.offset = prev_offset;
127
+ req.len = prev_len;
128
+ if (file->use_direct_io()) {
129
+ req.scratch = nullptr;
130
+ } else if (use_shared_buffer) {
131
+ req.scratch = scratch + buf_offset;
132
+ } else {
133
+ req.scratch = new char[req.len];
134
+ }
135
+ read_reqs.emplace_back(req);
136
+ }
137
+
138
+ AlignedBuf direct_io_buf;
139
+ {
140
+ IOOptions opts;
141
+ IOStatus s = file->PrepareIOOptions(options, opts);
142
+ if (s.ok()) {
143
+ #if defined(WITH_COROUTINES)
144
+ if (file->use_direct_io()) {
145
+ #endif // WITH_COROUTINES
146
+ s = file->MultiRead(opts, &read_reqs[0], read_reqs.size(),
147
+ &direct_io_buf, options.rate_limiter_priority);
148
+ #if defined(WITH_COROUTINES)
149
+ } else {
150
+ co_await batch->context()->reader().MultiReadAsync(
151
+ file, opts, &read_reqs[0], read_reqs.size(), &direct_io_buf);
152
+ }
153
+ #endif // WITH_COROUTINES
154
+ }
155
+ if (!s.ok()) {
156
+ // Discard all the results in this batch if there is any time out
157
+ // or overall MultiRead error
158
+ for (FSReadRequest& req : read_reqs) {
159
+ req.status = s;
160
+ }
161
+ }
162
+ }
163
+
164
+ idx_in_batch = 0;
165
+ size_t valid_batch_idx = 0;
166
+ for (auto mget_iter = batch->begin(); mget_iter != batch->end();
167
+ ++mget_iter, ++idx_in_batch) {
168
+ const BlockHandle& handle = (*handles)[idx_in_batch];
169
+
170
+ if (handle.IsNull()) {
171
+ continue;
172
+ }
173
+
174
+ assert(valid_batch_idx < req_idx_for_block.size());
175
+ assert(valid_batch_idx < req_offset_for_block.size());
176
+ assert(req_idx_for_block[valid_batch_idx] < read_reqs.size());
177
+ size_t& req_idx = req_idx_for_block[valid_batch_idx];
178
+ size_t& req_offset = req_offset_for_block[valid_batch_idx];
179
+ valid_batch_idx++;
180
+ if (mget_iter->get_context) {
181
+ ++(mget_iter->get_context->get_context_stats_.num_data_read);
182
+ }
183
+ FSReadRequest& req = read_reqs[req_idx];
184
+ Status s = req.status;
185
+ if (s.ok()) {
186
+ if ((req.result.size() != req.len) ||
187
+ (req_offset + BlockSizeWithTrailer(handle) > req.result.size())) {
188
+ s = Status::Corruption("truncated block read from " +
189
+ rep_->file->file_name() + " offset " +
190
+ std::to_string(handle.offset()) + ", expected " +
191
+ std::to_string(req.len) + " bytes, got " +
192
+ std::to_string(req.result.size()));
193
+ }
194
+ }
195
+
196
+ BlockContents raw_block_contents;
197
+ if (s.ok()) {
198
+ if (!use_shared_buffer) {
199
+ // We allocated a buffer for this block. Give ownership of it to
200
+ // BlockContents so it can free the memory
201
+ assert(req.result.data() == req.scratch);
202
+ assert(req.result.size() == BlockSizeWithTrailer(handle));
203
+ assert(req_offset == 0);
204
+ std::unique_ptr<char[]> raw_block(req.scratch);
205
+ raw_block_contents = BlockContents(std::move(raw_block), handle.size());
206
+ } else {
207
+ // We used the scratch buffer or direct io buffer
208
+ // which are shared by the blocks.
209
+ // raw_block_contents does not have the ownership.
210
+ raw_block_contents =
211
+ BlockContents(Slice(req.result.data() + req_offset, handle.size()));
212
+ }
213
+ #ifndef NDEBUG
214
+ raw_block_contents.is_raw_block = true;
215
+ #endif
216
+
217
+ if (options.verify_checksums) {
218
+ PERF_TIMER_GUARD(block_checksum_time);
219
+ const char* data = req.result.data();
220
+ // Since the scratch might be shared, the offset of the data block in
221
+ // the buffer might not be 0. req.result.data() only point to the
222
+ // begin address of each read request, we need to add the offset
223
+ // in each read request. Checksum is stored in the block trailer,
224
+ // beyond the payload size.
225
+ s = VerifyBlockChecksum(footer.checksum_type(), data + req_offset,
226
+ handle.size(), rep_->file->file_name(),
227
+ handle.offset());
228
+ TEST_SYNC_POINT_CALLBACK("RetrieveMultipleBlocks:VerifyChecksum", &s);
229
+ }
230
+ } else if (!use_shared_buffer) {
231
+ // Free the allocated scratch buffer.
232
+ delete[] req.scratch;
233
+ }
234
+
235
+ if (s.ok()) {
236
+ // When the blocks share the same underlying buffer (scratch or direct io
237
+ // buffer), we may need to manually copy the block into heap if the raw
238
+ // block has to be inserted into a cache. That falls into th following
239
+ // cases -
240
+ // 1. Raw block is not compressed, it needs to be inserted into the
241
+ // uncompressed block cache if there is one
242
+ // 2. If the raw block is compressed, it needs to be inserted into the
243
+ // compressed block cache if there is one
244
+ //
245
+ // In all other cases, the raw block is either uncompressed into a heap
246
+ // buffer or there is no cache at all.
247
+ CompressionType compression_type =
248
+ GetBlockCompressionType(raw_block_contents);
249
+ if (use_shared_buffer && (compression_type == kNoCompression ||
250
+ (compression_type != kNoCompression &&
251
+ rep_->table_options.block_cache_compressed))) {
252
+ Slice raw =
253
+ Slice(req.result.data() + req_offset, BlockSizeWithTrailer(handle));
254
+ raw_block_contents = BlockContents(
255
+ CopyBufferToHeap(GetMemoryAllocator(rep_->table_options), raw),
256
+ handle.size());
257
+ #ifndef NDEBUG
258
+ raw_block_contents.is_raw_block = true;
259
+ #endif
260
+ }
261
+ }
262
+
263
+ if (s.ok()) {
264
+ if (options.fill_cache) {
265
+ BlockCacheLookupContext lookup_data_block_context(
266
+ TableReaderCaller::kUserMultiGet);
267
+ CachableEntry<Block>* block_entry = &(*results)[idx_in_batch];
268
+ // MaybeReadBlockAndLoadToCache will insert into the block caches if
269
+ // necessary. Since we're passing the raw block contents, it will
270
+ // avoid looking up the block cache
271
+ s = MaybeReadBlockAndLoadToCache(
272
+ nullptr, options, handle, uncompression_dict, /*wait=*/true,
273
+ /*for_compaction=*/false, block_entry, BlockType::kData,
274
+ mget_iter->get_context, &lookup_data_block_context,
275
+ &raw_block_contents, /*async_read=*/false);
276
+
277
+ // block_entry value could be null if no block cache is present, i.e
278
+ // BlockBasedTableOptions::no_block_cache is true and no compressed
279
+ // block cache is configured. In that case, fall
280
+ // through and set up the block explicitly
281
+ if (block_entry->GetValue() != nullptr) {
282
+ s.PermitUncheckedError();
283
+ continue;
284
+ }
285
+ }
286
+
287
+ CompressionType compression_type =
288
+ GetBlockCompressionType(raw_block_contents);
289
+ BlockContents contents;
290
+ if (compression_type != kNoCompression) {
291
+ UncompressionContext context(compression_type);
292
+ UncompressionInfo info(context, uncompression_dict, compression_type);
293
+ s = UncompressBlockContents(
294
+ info, req.result.data() + req_offset, handle.size(), &contents,
295
+ footer.format_version(), rep_->ioptions, memory_allocator);
296
+ } else {
297
+ // There are two cases here:
298
+ // 1) caller uses the shared buffer (scratch or direct io buffer);
299
+ // 2) we use the requst buffer.
300
+ // If scratch buffer or direct io buffer is used, we ensure that
301
+ // all raw blocks are copyed to the heap as single blocks. If scratch
302
+ // buffer is not used, we also have no combined read, so the raw
303
+ // block can be used directly.
304
+ contents = std::move(raw_block_contents);
305
+ }
306
+ if (s.ok()) {
307
+ (*results)[idx_in_batch].SetOwnedValue(new Block(
308
+ std::move(contents), read_amp_bytes_per_bit, ioptions.stats));
309
+ }
310
+ }
311
+ (*statuses)[idx_in_batch] = s;
312
+ }
313
+ }
314
+
315
+ using MultiGetRange = MultiGetContext::Range;
316
+ DEFINE_SYNC_AND_ASYNC(void, BlockBasedTable::MultiGet)
317
+ (const ReadOptions& read_options, const MultiGetRange* mget_range,
318
+ const SliceTransform* prefix_extractor, bool skip_filters) {
319
+ if (mget_range->empty()) {
320
+ // Caller should ensure non-empty (performance bug)
321
+ assert(false);
322
+ CO_RETURN; // Nothing to do
323
+ }
324
+
325
+ FilterBlockReader* const filter =
326
+ !skip_filters ? rep_->filter.get() : nullptr;
327
+ MultiGetRange sst_file_range(*mget_range, mget_range->begin(),
328
+ mget_range->end());
329
+
330
+ // First check the full filter
331
+ // If full filter not useful, Then go into each block
332
+ const bool no_io = read_options.read_tier == kBlockCacheTier;
333
+ uint64_t tracing_mget_id = BlockCacheTraceHelper::kReservedGetId;
334
+ if (sst_file_range.begin()->get_context) {
335
+ tracing_mget_id = sst_file_range.begin()->get_context->get_tracing_get_id();
336
+ }
337
+ BlockCacheLookupContext lookup_context{
338
+ TableReaderCaller::kUserMultiGet, tracing_mget_id,
339
+ /*_get_from_user_specified_snapshot=*/read_options.snapshot != nullptr};
340
+ FullFilterKeysMayMatch(filter, &sst_file_range, no_io, prefix_extractor,
341
+ &lookup_context);
342
+
343
+ if (!sst_file_range.empty()) {
344
+ IndexBlockIter iiter_on_stack;
345
+ // if prefix_extractor found in block differs from options, disable
346
+ // BlockPrefixIndex. Only do this check when index_type is kHashSearch.
347
+ bool need_upper_bound_check = false;
348
+ if (rep_->index_type == BlockBasedTableOptions::kHashSearch) {
349
+ need_upper_bound_check = PrefixExtractorChanged(prefix_extractor);
350
+ }
351
+ auto iiter =
352
+ NewIndexIterator(read_options, need_upper_bound_check, &iiter_on_stack,
353
+ sst_file_range.begin()->get_context, &lookup_context);
354
+ std::unique_ptr<InternalIteratorBase<IndexValue>> iiter_unique_ptr;
355
+ if (iiter != &iiter_on_stack) {
356
+ iiter_unique_ptr.reset(iiter);
357
+ }
358
+
359
+ uint64_t prev_offset = std::numeric_limits<uint64_t>::max();
360
+ autovector<BlockHandle, MultiGetContext::MAX_BATCH_SIZE> block_handles;
361
+ autovector<CachableEntry<Block>, MultiGetContext::MAX_BATCH_SIZE> results;
362
+ autovector<Status, MultiGetContext::MAX_BATCH_SIZE> statuses;
363
+ MultiGetContext::Mask reused_mask = 0;
364
+ char stack_buf[kMultiGetReadStackBufSize];
365
+ std::unique_ptr<char[]> block_buf;
366
+ {
367
+ MultiGetRange data_block_range(sst_file_range, sst_file_range.begin(),
368
+ sst_file_range.end());
369
+ std::vector<Cache::Handle*> cache_handles;
370
+ bool wait_for_cache_results = false;
371
+
372
+ CachableEntry<UncompressionDict> uncompression_dict;
373
+ Status uncompression_dict_status;
374
+ uncompression_dict_status.PermitUncheckedError();
375
+ bool uncompression_dict_inited = false;
376
+ size_t total_len = 0;
377
+ ReadOptions ro = read_options;
378
+ ro.read_tier = kBlockCacheTier;
379
+
380
+ for (auto miter = data_block_range.begin();
381
+ miter != data_block_range.end(); ++miter) {
382
+ const Slice& key = miter->ikey;
383
+ iiter->Seek(miter->ikey);
384
+
385
+ IndexValue v;
386
+ if (iiter->Valid()) {
387
+ v = iiter->value();
388
+ }
389
+ if (!iiter->Valid() ||
390
+ (!v.first_internal_key.empty() && !skip_filters &&
391
+ UserComparatorWrapper(rep_->internal_comparator.user_comparator())
392
+ .CompareWithoutTimestamp(
393
+ ExtractUserKey(key),
394
+ ExtractUserKey(v.first_internal_key)) < 0)) {
395
+ // The requested key falls between highest key in previous block and
396
+ // lowest key in current block.
397
+ if (!iiter->status().IsNotFound()) {
398
+ *(miter->s) = iiter->status();
399
+ }
400
+ data_block_range.SkipKey(miter);
401
+ sst_file_range.SkipKey(miter);
402
+ continue;
403
+ }
404
+
405
+ if (!uncompression_dict_inited && rep_->uncompression_dict_reader) {
406
+ uncompression_dict_status =
407
+ rep_->uncompression_dict_reader->GetOrReadUncompressionDictionary(
408
+ nullptr /* prefetch_buffer */, no_io,
409
+ read_options.verify_checksums,
410
+ sst_file_range.begin()->get_context, &lookup_context,
411
+ &uncompression_dict);
412
+ uncompression_dict_inited = true;
413
+ }
414
+
415
+ if (!uncompression_dict_status.ok()) {
416
+ assert(!uncompression_dict_status.IsNotFound());
417
+ *(miter->s) = uncompression_dict_status;
418
+ data_block_range.SkipKey(miter);
419
+ sst_file_range.SkipKey(miter);
420
+ continue;
421
+ }
422
+
423
+ statuses.emplace_back();
424
+ results.emplace_back();
425
+ if (v.handle.offset() == prev_offset) {
426
+ // This key can reuse the previous block (later on).
427
+ // Mark previous as "reused"
428
+ reused_mask |= MultiGetContext::Mask{1} << (block_handles.size() - 1);
429
+ // Use null handle to indicate this one reuses same block as
430
+ // previous.
431
+ block_handles.emplace_back(BlockHandle::NullBlockHandle());
432
+ continue;
433
+ }
434
+ // Lookup the cache for the given data block referenced by an index
435
+ // iterator value (i.e BlockHandle). If it exists in the cache,
436
+ // initialize block to the contents of the data block.
437
+ prev_offset = v.handle.offset();
438
+ BlockHandle handle = v.handle;
439
+ BlockCacheLookupContext lookup_data_block_context(
440
+ TableReaderCaller::kUserMultiGet);
441
+ const UncompressionDict& dict = uncompression_dict.GetValue()
442
+ ? *uncompression_dict.GetValue()
443
+ : UncompressionDict::GetEmptyDict();
444
+ Status s = RetrieveBlock(
445
+ nullptr, ro, handle, dict, &(results.back()), BlockType::kData,
446
+ miter->get_context, &lookup_data_block_context,
447
+ /* for_compaction */ false, /* use_cache */ true,
448
+ /* wait_for_cache */ false, /* async_read */ false);
449
+ if (s.IsIncomplete()) {
450
+ s = Status::OK();
451
+ }
452
+ if (s.ok() && !results.back().IsEmpty()) {
453
+ // Since we have a valid handle, check the value. If its nullptr,
454
+ // it means the cache is waiting for the final result and we're
455
+ // supposed to call WaitAll() to wait for the result.
456
+ if (results.back().GetValue() != nullptr) {
457
+ // Found it in the cache. Add NULL handle to indicate there is
458
+ // nothing to read from disk.
459
+ if (results.back().GetCacheHandle()) {
460
+ results.back().UpdateCachedValue();
461
+ }
462
+ block_handles.emplace_back(BlockHandle::NullBlockHandle());
463
+ } else {
464
+ // We have to wait for the cache lookup to finish in the
465
+ // background, and then we may have to read the block from disk
466
+ // anyway
467
+ assert(results.back().GetCacheHandle());
468
+ wait_for_cache_results = true;
469
+ block_handles.emplace_back(handle);
470
+ cache_handles.emplace_back(results.back().GetCacheHandle());
471
+ }
472
+ } else {
473
+ block_handles.emplace_back(handle);
474
+ total_len += BlockSizeWithTrailer(handle);
475
+ }
476
+ }
477
+
478
+ if (wait_for_cache_results) {
479
+ Cache* block_cache = rep_->table_options.block_cache.get();
480
+ block_cache->WaitAll(cache_handles);
481
+ for (size_t i = 0; i < block_handles.size(); ++i) {
482
+ // If this block was a success or failure or not needed because
483
+ // the corresponding key is in the same block as a prior key, skip
484
+ if (block_handles[i] == BlockHandle::NullBlockHandle() ||
485
+ results[i].IsEmpty()) {
486
+ continue;
487
+ }
488
+ results[i].UpdateCachedValue();
489
+ void* val = results[i].GetValue();
490
+ if (!val) {
491
+ // The async cache lookup failed - could be due to an error
492
+ // or a false positive. We need to read the data block from
493
+ // the SST file
494
+ results[i].Reset();
495
+ total_len += BlockSizeWithTrailer(block_handles[i]);
496
+ } else {
497
+ block_handles[i] = BlockHandle::NullBlockHandle();
498
+ }
499
+ }
500
+ }
501
+
502
+ if (total_len) {
503
+ char* scratch = nullptr;
504
+ const UncompressionDict& dict = uncompression_dict.GetValue()
505
+ ? *uncompression_dict.GetValue()
506
+ : UncompressionDict::GetEmptyDict();
507
+ assert(uncompression_dict_inited || !rep_->uncompression_dict_reader);
508
+ assert(uncompression_dict_status.ok());
509
+ // If using direct IO, then scratch is not used, so keep it nullptr.
510
+ // If the blocks need to be uncompressed and we don't need the
511
+ // compressed blocks, then we can use a contiguous block of
512
+ // memory to read in all the blocks as it will be temporary
513
+ // storage
514
+ // 1. If blocks are compressed and compressed block cache is there,
515
+ // alloc heap bufs
516
+ // 2. If blocks are uncompressed, alloc heap bufs
517
+ // 3. If blocks are compressed and no compressed block cache, use
518
+ // stack buf
519
+ if (!rep_->file->use_direct_io() &&
520
+ rep_->table_options.block_cache_compressed == nullptr &&
521
+ rep_->blocks_maybe_compressed) {
522
+ if (total_len <= kMultiGetReadStackBufSize) {
523
+ scratch = stack_buf;
524
+ } else {
525
+ scratch = new char[total_len];
526
+ block_buf.reset(scratch);
527
+ }
528
+ }
529
+ CO_AWAIT(RetrieveMultipleBlocks)
530
+ (read_options, &data_block_range, &block_handles, &statuses, &results,
531
+ scratch, dict);
532
+ if (sst_file_range.begin()->get_context) {
533
+ ++(sst_file_range.begin()
534
+ ->get_context->get_context_stats_.num_sst_read);
535
+ }
536
+ }
537
+ }
538
+
539
+ DataBlockIter first_biter;
540
+ DataBlockIter next_biter;
541
+ size_t idx_in_batch = 0;
542
+ SharedCleanablePtr shared_cleanable;
543
+ for (auto miter = sst_file_range.begin(); miter != sst_file_range.end();
544
+ ++miter) {
545
+ Status s;
546
+ GetContext* get_context = miter->get_context;
547
+ const Slice& key = miter->ikey;
548
+ bool matched = false; // if such user key matched a key in SST
549
+ bool done = false;
550
+ bool first_block = true;
551
+ do {
552
+ DataBlockIter* biter = nullptr;
553
+ bool reusing_prev_block;
554
+ bool later_reused;
555
+ uint64_t referenced_data_size = 0;
556
+ bool does_referenced_key_exist = false;
557
+ BlockCacheLookupContext lookup_data_block_context(
558
+ TableReaderCaller::kUserMultiGet, tracing_mget_id,
559
+ /*_get_from_user_specified_snapshot=*/read_options.snapshot !=
560
+ nullptr);
561
+ if (first_block) {
562
+ if (!block_handles[idx_in_batch].IsNull() ||
563
+ !results[idx_in_batch].IsEmpty()) {
564
+ first_biter.Invalidate(Status::OK());
565
+ NewDataBlockIterator<DataBlockIter>(
566
+ read_options, results[idx_in_batch], &first_biter,
567
+ statuses[idx_in_batch]);
568
+ reusing_prev_block = false;
569
+ } else {
570
+ // If handler is null and result is empty, then the status is never
571
+ // set, which should be the initial value: ok().
572
+ assert(statuses[idx_in_batch].ok());
573
+ reusing_prev_block = true;
574
+ }
575
+ biter = &first_biter;
576
+ later_reused =
577
+ (reused_mask & (MultiGetContext::Mask{1} << idx_in_batch)) != 0;
578
+ idx_in_batch++;
579
+ } else {
580
+ IndexValue v = iiter->value();
581
+ if (!v.first_internal_key.empty() && !skip_filters &&
582
+ UserComparatorWrapper(rep_->internal_comparator.user_comparator())
583
+ .CompareWithoutTimestamp(
584
+ ExtractUserKey(key),
585
+ ExtractUserKey(v.first_internal_key)) < 0) {
586
+ // The requested key falls between highest key in previous block and
587
+ // lowest key in current block.
588
+ break;
589
+ }
590
+
591
+ next_biter.Invalidate(Status::OK());
592
+ Status tmp_s;
593
+ NewDataBlockIterator<DataBlockIter>(
594
+ read_options, iiter->value().handle, &next_biter,
595
+ BlockType::kData, get_context, &lookup_data_block_context,
596
+ /* prefetch_buffer= */ nullptr, /* for_compaction = */ false,
597
+ /*async_read = */ false, tmp_s);
598
+ biter = &next_biter;
599
+ reusing_prev_block = false;
600
+ later_reused = false;
601
+ }
602
+
603
+ if (read_options.read_tier == kBlockCacheTier &&
604
+ biter->status().IsIncomplete()) {
605
+ // couldn't get block from block_cache
606
+ // Update Saver.state to Found because we are only looking for
607
+ // whether we can guarantee the key is not there when "no_io" is set
608
+ get_context->MarkKeyMayExist();
609
+ break;
610
+ }
611
+ if (!biter->status().ok()) {
612
+ s = biter->status();
613
+ break;
614
+ }
615
+
616
+ bool may_exist = biter->SeekForGet(key);
617
+ if (!may_exist) {
618
+ // HashSeek cannot find the key this block and the the iter is not
619
+ // the end of the block, i.e. cannot be in the following blocks
620
+ // either. In this case, the seek_key cannot be found, so we break
621
+ // from the top level for-loop.
622
+ break;
623
+ }
624
+
625
+ // Reusing blocks complicates pinning/Cleanable, because the cache
626
+ // entry referenced by biter can only be released once all returned
627
+ // pinned values are released. This code previously did an extra
628
+ // block_cache Ref for each reuse, but that unnecessarily increases
629
+ // block cache contention. Instead we can use a variant of shared_ptr
630
+ // to release in block cache only once.
631
+ //
632
+ // Although the biter loop below might SaveValue multiple times for
633
+ // merges, just one value_pinner suffices, as MultiGet will merge
634
+ // the operands before returning to the API user.
635
+ Cleanable* value_pinner;
636
+ if (biter->IsValuePinned()) {
637
+ if (reusing_prev_block) {
638
+ // Note that we don't yet know if the MultiGet results will need
639
+ // to pin this block, so we might wrap a block for sharing and
640
+ // still end up with 1 (or 0) pinning ref. Not ideal but OK.
641
+ //
642
+ // Here we avoid adding redundant cleanups if we didn't end up
643
+ // delegating the cleanup from last time around.
644
+ if (!biter->HasCleanups()) {
645
+ assert(shared_cleanable.get());
646
+ if (later_reused) {
647
+ shared_cleanable.RegisterCopyWith(biter);
648
+ } else {
649
+ shared_cleanable.MoveAsCleanupTo(biter);
650
+ }
651
+ }
652
+ } else if (later_reused) {
653
+ assert(biter->HasCleanups());
654
+ // Make the existing cleanups on `biter` sharable:
655
+ shared_cleanable.Allocate();
656
+ // Move existing `biter` cleanup(s) to `shared_cleanable`
657
+ biter->DelegateCleanupsTo(&*shared_cleanable);
658
+ // Reference `shared_cleanable` as new cleanup for `biter`
659
+ shared_cleanable.RegisterCopyWith(biter);
660
+ }
661
+ assert(biter->HasCleanups());
662
+ value_pinner = biter;
663
+ } else {
664
+ value_pinner = nullptr;
665
+ }
666
+
667
+ // Call the *saver function on each entry/block until it returns false
668
+ for (; biter->Valid(); biter->Next()) {
669
+ ParsedInternalKey parsed_key;
670
+ Status pik_status = ParseInternalKey(
671
+ biter->key(), &parsed_key, false /* log_err_key */); // TODO
672
+ if (!pik_status.ok()) {
673
+ s = pik_status;
674
+ }
675
+ if (!get_context->SaveValue(parsed_key, biter->value(), &matched,
676
+ value_pinner)) {
677
+ if (get_context->State() == GetContext::GetState::kFound) {
678
+ does_referenced_key_exist = true;
679
+ referenced_data_size =
680
+ biter->key().size() + biter->value().size();
681
+ }
682
+ done = true;
683
+ break;
684
+ }
685
+ s = biter->status();
686
+ }
687
+ // Write the block cache access.
688
+ // XXX: There appear to be 'break' statements above that bypass this
689
+ // writing of the block cache trace record
690
+ if (block_cache_tracer_ && block_cache_tracer_->is_tracing_enabled() &&
691
+ !reusing_prev_block) {
692
+ // Avoid making copy of block_key, cf_name, and referenced_key when
693
+ // constructing the access record.
694
+ Slice referenced_key;
695
+ if (does_referenced_key_exist) {
696
+ referenced_key = biter->key();
697
+ } else {
698
+ referenced_key = key;
699
+ }
700
+ BlockCacheTraceRecord access_record(
701
+ rep_->ioptions.clock->NowMicros(),
702
+ /*_block_key=*/"", lookup_data_block_context.block_type,
703
+ lookup_data_block_context.block_size, rep_->cf_id_for_tracing(),
704
+ /*_cf_name=*/"", rep_->level_for_tracing(),
705
+ rep_->sst_number_for_tracing(), lookup_data_block_context.caller,
706
+ lookup_data_block_context.is_cache_hit,
707
+ lookup_data_block_context.no_insert,
708
+ lookup_data_block_context.get_id,
709
+ lookup_data_block_context.get_from_user_specified_snapshot,
710
+ /*_referenced_key=*/"", referenced_data_size,
711
+ lookup_data_block_context.num_keys_in_block,
712
+ does_referenced_key_exist);
713
+ // TODO: Should handle status here?
714
+ block_cache_tracer_
715
+ ->WriteBlockAccess(access_record,
716
+ lookup_data_block_context.block_key,
717
+ rep_->cf_name_for_tracing(), referenced_key)
718
+ .PermitUncheckedError();
719
+ }
720
+ s = biter->status();
721
+ if (done) {
722
+ // Avoid the extra Next which is expensive in two-level indexes
723
+ break;
724
+ }
725
+ if (first_block) {
726
+ iiter->Seek(key);
727
+ if (!iiter->Valid()) {
728
+ break;
729
+ }
730
+ }
731
+ first_block = false;
732
+ iiter->Next();
733
+ } while (iiter->Valid());
734
+
735
+ if (matched && filter != nullptr && !filter->IsBlockBased()) {
736
+ RecordTick(rep_->ioptions.stats, BLOOM_FILTER_FULL_TRUE_POSITIVE);
737
+ PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_full_true_positive, 1,
738
+ rep_->level);
739
+ }
740
+ if (s.ok() && !iiter->status().IsNotFound()) {
741
+ s = iiter->status();
742
+ }
743
+ *(miter->s) = s;
744
+ }
745
+ #ifdef ROCKSDB_ASSERT_STATUS_CHECKED
746
+ // Not sure why we need to do it. Should investigate more.
747
+ for (auto& st : statuses) {
748
+ st.PermitUncheckedError();
749
+ }
750
+ #endif // ROCKSDB_ASSERT_STATUS_CHECKED
751
+ }
752
+ }
753
+ } // namespace ROCKSDB_NAMESPACE
754
+ #endif