@nxtedition/rocksdb 13.1.4 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/binding.cc +43 -16
  2. package/deps/rocksdb/rocksdb/{TARGETS → BUCK} +27 -0
  3. package/deps/rocksdb/rocksdb/CMakeLists.txt +3 -1
  4. package/deps/rocksdb/rocksdb/Makefile +2 -2
  5. package/deps/rocksdb/rocksdb/cache/cache.cc +3 -1
  6. package/deps/rocksdb/rocksdb/db/arena_wrapped_db_iter.h +2 -0
  7. package/deps/rocksdb/rocksdb/db/attribute_group_iterator_impl.h +34 -9
  8. package/deps/rocksdb/rocksdb/db/blob/blob_source.cc +7 -6
  9. package/deps/rocksdb/rocksdb/db/blob/blob_source.h +5 -1
  10. package/deps/rocksdb/rocksdb/db/blob/blob_source_test.cc +22 -14
  11. package/deps/rocksdb/rocksdb/db/blob/db_blob_basic_test.cc +149 -0
  12. package/deps/rocksdb/rocksdb/db/builder.cc +13 -24
  13. package/deps/rocksdb/rocksdb/db/coalescing_iterator.h +35 -10
  14. package/deps/rocksdb/rocksdb/db/column_family.cc +21 -10
  15. package/deps/rocksdb/rocksdb/db/column_family.h +15 -8
  16. package/deps/rocksdb/rocksdb/db/column_family_test.cc +98 -7
  17. package/deps/rocksdb/rocksdb/db/compaction/compaction.cc +126 -16
  18. package/deps/rocksdb/rocksdb/db/compaction/compaction.h +51 -5
  19. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +2 -2
  20. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +2 -8
  21. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator_test.cc +24 -0
  22. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +52 -22
  23. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +9 -7
  24. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +36 -9
  25. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +6 -0
  26. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.cc +30 -17
  27. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.h +26 -23
  28. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.cc +43 -33
  29. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.h +6 -5
  30. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.cc +19 -9
  31. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.h +6 -5
  32. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +632 -411
  33. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.cc +171 -51
  34. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.h +7 -5
  35. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_job.cc +37 -10
  36. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_test.cc +51 -11
  37. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.cc +10 -3
  38. package/deps/rocksdb/rocksdb/db/compaction/tiered_compaction_test.cc +350 -154
  39. package/deps/rocksdb/rocksdb/db/convenience.cc +1 -1
  40. package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +62 -27
  41. package/deps/rocksdb/rocksdb/db/db_bloom_filter_test.cc +68 -1
  42. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +91 -0
  43. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +134 -70
  44. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +71 -23
  45. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +43 -16
  46. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_debug.cc +47 -33
  47. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +27 -19
  48. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +38 -25
  49. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_readonly.cc +3 -3
  50. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +7 -4
  51. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_write.cc +258 -42
  52. package/deps/rocksdb/rocksdb/db/db_io_failure_test.cc +161 -9
  53. package/deps/rocksdb/rocksdb/db/db_iter.cc +118 -86
  54. package/deps/rocksdb/rocksdb/db/db_iter.h +44 -17
  55. package/deps/rocksdb/rocksdb/db/db_options_test.cc +27 -6
  56. package/deps/rocksdb/rocksdb/db/db_test.cc +48 -16
  57. package/deps/rocksdb/rocksdb/db/db_test2.cc +60 -15
  58. package/deps/rocksdb/rocksdb/db/db_test_util.cc +97 -44
  59. package/deps/rocksdb/rocksdb/db/db_test_util.h +7 -1
  60. package/deps/rocksdb/rocksdb/db/dbformat.cc +15 -5
  61. package/deps/rocksdb/rocksdb/db/dbformat.h +137 -55
  62. package/deps/rocksdb/rocksdb/db/event_helpers.cc +1 -0
  63. package/deps/rocksdb/rocksdb/db/experimental.cc +54 -0
  64. package/deps/rocksdb/rocksdb/db/external_sst_file_basic_test.cc +663 -8
  65. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +152 -91
  66. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.h +134 -11
  67. package/deps/rocksdb/rocksdb/db/external_sst_file_test.cc +55 -9
  68. package/deps/rocksdb/rocksdb/db/flush_job.cc +52 -29
  69. package/deps/rocksdb/rocksdb/db/flush_job.h +5 -3
  70. package/deps/rocksdb/rocksdb/db/flush_job_test.cc +18 -12
  71. package/deps/rocksdb/rocksdb/db/forward_iterator.cc +23 -29
  72. package/deps/rocksdb/rocksdb/db/import_column_family_job.cc +3 -2
  73. package/deps/rocksdb/rocksdb/db/import_column_family_test.cc +2 -0
  74. package/deps/rocksdb/rocksdb/db/internal_stats.cc +9 -6
  75. package/deps/rocksdb/rocksdb/db/internal_stats.h +54 -0
  76. package/deps/rocksdb/rocksdb/db/job_context.h +1 -1
  77. package/deps/rocksdb/rocksdb/db/log_reader.cc +6 -7
  78. package/deps/rocksdb/rocksdb/db/manifest_ops.cc +47 -0
  79. package/deps/rocksdb/rocksdb/db/manifest_ops.h +20 -0
  80. package/deps/rocksdb/rocksdb/db/memtable.cc +165 -64
  81. package/deps/rocksdb/rocksdb/db/memtable.h +422 -243
  82. package/deps/rocksdb/rocksdb/db/memtable_list.cc +99 -68
  83. package/deps/rocksdb/rocksdb/db/memtable_list.h +63 -38
  84. package/deps/rocksdb/rocksdb/db/memtable_list_test.cc +28 -25
  85. package/deps/rocksdb/rocksdb/db/multi_cf_iterator_impl.h +118 -60
  86. package/deps/rocksdb/rocksdb/db/multi_cf_iterator_test.cc +344 -89
  87. package/deps/rocksdb/rocksdb/db/range_tombstone_fragmenter.h +2 -3
  88. package/deps/rocksdb/rocksdb/db/repair.cc +15 -14
  89. package/deps/rocksdb/rocksdb/db/repair_test.cc +0 -13
  90. package/deps/rocksdb/rocksdb/db/snapshot_checker.h +7 -0
  91. package/deps/rocksdb/rocksdb/db/table_cache.cc +62 -65
  92. package/deps/rocksdb/rocksdb/db/table_cache.h +70 -76
  93. package/deps/rocksdb/rocksdb/db/table_cache_sync_and_async.h +5 -6
  94. package/deps/rocksdb/rocksdb/db/table_properties_collector_test.cc +1 -1
  95. package/deps/rocksdb/rocksdb/db/transaction_log_impl.cc +8 -7
  96. package/deps/rocksdb/rocksdb/db/version_builder.cc +17 -19
  97. package/deps/rocksdb/rocksdb/db/version_builder.h +13 -12
  98. package/deps/rocksdb/rocksdb/db/version_edit.h +30 -0
  99. package/deps/rocksdb/rocksdb/db/version_edit_handler.cc +3 -5
  100. package/deps/rocksdb/rocksdb/db/version_set.cc +89 -129
  101. package/deps/rocksdb/rocksdb/db/version_set.h +12 -4
  102. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +1 -2
  103. package/deps/rocksdb/rocksdb/db/version_set_test.cc +12 -8
  104. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.cc +0 -15
  105. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization.h +0 -2
  106. package/deps/rocksdb/rocksdb/db/wide/wide_column_serialization_test.cc +9 -7
  107. package/deps/rocksdb/rocksdb/db/wide/wide_columns_helper.cc +0 -8
  108. package/deps/rocksdb/rocksdb/db/wide/wide_columns_helper.h +28 -2
  109. package/deps/rocksdb/rocksdb/db/write_batch.cc +32 -10
  110. package/deps/rocksdb/rocksdb/db/write_batch_internal.h +9 -0
  111. package/deps/rocksdb/rocksdb/db/write_batch_test.cc +2 -1
  112. package/deps/rocksdb/rocksdb/db/write_thread.cc +3 -1
  113. package/deps/rocksdb/rocksdb/db/write_thread.h +6 -2
  114. package/deps/rocksdb/rocksdb/db_stress_tool/batched_ops_stress.cc +15 -0
  115. package/deps/rocksdb/rocksdb/db_stress_tool/cf_consistency_stress.cc +7 -0
  116. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +4 -0
  117. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +18 -2
  118. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +100 -22
  119. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.h +15 -4
  120. package/deps/rocksdb/rocksdb/db_stress_tool/multi_ops_txns_stress.cc +34 -8
  121. package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +223 -78
  122. package/deps/rocksdb/rocksdb/env/file_system.cc +6 -1
  123. package/deps/rocksdb/rocksdb/env/fs_posix.cc +53 -0
  124. package/deps/rocksdb/rocksdb/env/io_posix.cc +63 -17
  125. package/deps/rocksdb/rocksdb/env/io_posix.h +30 -1
  126. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +132 -48
  127. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +92 -24
  128. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +727 -109
  129. package/deps/rocksdb/rocksdb/file/random_access_file_reader.cc +3 -4
  130. package/deps/rocksdb/rocksdb/file/random_access_file_reader.h +1 -1
  131. package/deps/rocksdb/rocksdb/file/writable_file_writer.cc +8 -0
  132. package/deps/rocksdb/rocksdb/include/rocksdb/attribute_groups.h +20 -1
  133. package/deps/rocksdb/rocksdb/include/rocksdb/compaction_job_stats.h +9 -0
  134. package/deps/rocksdb/rocksdb/include/rocksdb/configurable.h +9 -5
  135. package/deps/rocksdb/rocksdb/include/rocksdb/convenience.h +2 -0
  136. package/deps/rocksdb/rocksdb/include/rocksdb/db.h +10 -2
  137. package/deps/rocksdb/rocksdb/include/rocksdb/env.h +1 -0
  138. package/deps/rocksdb/rocksdb/include/rocksdb/experimental.h +7 -0
  139. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +34 -37
  140. package/deps/rocksdb/rocksdb/include/rocksdb/iterator_base.h +21 -0
  141. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +56 -28
  142. package/deps/rocksdb/rocksdb/include/rocksdb/sst_file_writer.h +3 -0
  143. package/deps/rocksdb/rocksdb/include/rocksdb/table.h +36 -28
  144. package/deps/rocksdb/rocksdb/include/rocksdb/table_properties.h +11 -0
  145. package/deps/rocksdb/rocksdb/include/rocksdb/thread_status.h +1 -0
  146. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/options_type.h +84 -60
  147. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/secondary_index.h +102 -0
  148. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/table_properties_collectors.h +89 -2
  149. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/transaction.h +32 -0
  150. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/transaction_db.h +30 -1
  151. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/write_batch_with_index.h +23 -2
  152. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +2 -2
  153. package/deps/rocksdb/rocksdb/include/rocksdb/write_batch.h +2 -0
  154. package/deps/rocksdb/rocksdb/memtable/inlineskiplist.h +79 -21
  155. package/deps/rocksdb/rocksdb/memtable/skiplist.h +41 -18
  156. package/deps/rocksdb/rocksdb/memtable/skiplistrep.cc +1 -5
  157. package/deps/rocksdb/rocksdb/memtable/wbwi_memtable.cc +169 -0
  158. package/deps/rocksdb/rocksdb/memtable/wbwi_memtable.h +400 -0
  159. package/deps/rocksdb/rocksdb/monitoring/thread_status_util_debug.cc +2 -0
  160. package/deps/rocksdb/rocksdb/options/cf_options.cc +137 -82
  161. package/deps/rocksdb/rocksdb/options/cf_options.h +18 -6
  162. package/deps/rocksdb/rocksdb/options/configurable.cc +31 -17
  163. package/deps/rocksdb/rocksdb/options/configurable_helper.h +7 -6
  164. package/deps/rocksdb/rocksdb/options/options_helper.cc +10 -8
  165. package/deps/rocksdb/rocksdb/options/options_parser.cc +74 -54
  166. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +89 -0
  167. package/deps/rocksdb/rocksdb/options/options_test.cc +112 -26
  168. package/deps/rocksdb/rocksdb/port/port.h +5 -9
  169. package/deps/rocksdb/rocksdb/src.mk +8 -0
  170. package/deps/rocksdb/rocksdb/table/adaptive/adaptive_table_factory.h +4 -0
  171. package/deps/rocksdb/rocksdb/table/block_based/block.h +1 -7
  172. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +2 -0
  173. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.cc +62 -80
  174. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.h +13 -3
  175. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.cc +16 -5
  176. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.h +38 -7
  177. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +12 -4
  178. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +4 -1
  179. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +4 -1
  180. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +204 -1
  181. package/deps/rocksdb/rocksdb/table/block_based/data_block_hash_index_test.cc +3 -3
  182. package/deps/rocksdb/rocksdb/table/block_fetcher_test.cc +2 -1
  183. package/deps/rocksdb/rocksdb/table/cuckoo/cuckoo_table_factory.h +4 -0
  184. package/deps/rocksdb/rocksdb/table/format.cc +3 -3
  185. package/deps/rocksdb/rocksdb/table/meta_blocks.cc +4 -1
  186. package/deps/rocksdb/rocksdb/table/mock_table.cc +0 -50
  187. package/deps/rocksdb/rocksdb/table/mock_table.h +53 -0
  188. package/deps/rocksdb/rocksdb/table/plain/plain_table_factory.h +4 -0
  189. package/deps/rocksdb/rocksdb/table/sst_file_dumper.cc +1 -1
  190. package/deps/rocksdb/rocksdb/table/sst_file_writer.cc +10 -5
  191. package/deps/rocksdb/rocksdb/table/table_builder.h +3 -1
  192. package/deps/rocksdb/rocksdb/table/table_properties.cc +181 -0
  193. package/deps/rocksdb/rocksdb/table/table_reader_bench.cc +5 -5
  194. package/deps/rocksdb/rocksdb/table/table_test.cc +71 -64
  195. package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_pysim.py +45 -45
  196. package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_pysim_test.py +35 -35
  197. package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer_plot.py +43 -43
  198. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +41 -4
  199. package/deps/rocksdb/rocksdb/tools/ldb_cmd.cc +1 -0
  200. package/deps/rocksdb/rocksdb/tools/sst_dump_test.cc +1 -1
  201. package/deps/rocksdb/rocksdb/unreleased_history/add.sh +13 -0
  202. package/deps/rocksdb/rocksdb/util/aligned_buffer.h +24 -5
  203. package/deps/rocksdb/rocksdb/util/compaction_job_stats_impl.cc +7 -0
  204. package/deps/rocksdb/rocksdb/util/file_checksum_helper.cc +0 -52
  205. package/deps/rocksdb/rocksdb/util/file_checksum_helper.h +1 -10
  206. package/deps/rocksdb/rocksdb/util/file_reader_writer_test.cc +92 -0
  207. package/deps/rocksdb/rocksdb/util/thread_operation.h +1 -0
  208. package/deps/rocksdb/rocksdb/util/udt_util.cc +50 -4
  209. package/deps/rocksdb/rocksdb/util/udt_util.h +24 -11
  210. package/deps/rocksdb/rocksdb/util/udt_util_test.cc +26 -13
  211. package/deps/rocksdb/rocksdb/utilities/memory/memory_test.cc +1 -16
  212. package/deps/rocksdb/rocksdb/utilities/options/options_util_test.cc +2 -0
  213. package/deps/rocksdb/rocksdb/utilities/secondary_index/faiss_ivf_index.cc +214 -0
  214. package/deps/rocksdb/rocksdb/utilities/secondary_index/faiss_ivf_index.h +60 -0
  215. package/deps/rocksdb/rocksdb/utilities/secondary_index/faiss_ivf_index_test.cc +124 -0
  216. package/deps/rocksdb/rocksdb/utilities/secondary_index/secondary_index_mixin.h +441 -0
  217. package/deps/rocksdb/rocksdb/utilities/table_properties_collectors/compact_for_tiering_collector.cc +34 -3
  218. package/deps/rocksdb/rocksdb/utilities/table_properties_collectors/compact_for_tiering_collector.h +7 -2
  219. package/deps/rocksdb/rocksdb/utilities/transactions/optimistic_transaction_test.cc +437 -0
  220. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction.cc +34 -11
  221. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction.h +14 -7
  222. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction_db.cc +7 -1
  223. package/deps/rocksdb/rocksdb/utilities/transactions/snapshot_checker.cc +17 -0
  224. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_base.cc +69 -0
  225. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_base.h +20 -0
  226. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.cc +1290 -0
  227. package/deps/rocksdb/rocksdb/utilities/transactions/write_committed_transaction_ts_test.cc +324 -0
  228. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_txn.cc +18 -1
  229. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_txn.h +8 -1
  230. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index.cc +57 -12
  231. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_internal.cc +32 -3
  232. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_internal.h +33 -2
  233. package/deps/rocksdb/rocksdb/utilities/write_batch_with_index/write_batch_with_index_test.cc +721 -9
  234. package/deps/rocksdb/rocksdb.gyp +2 -0
  235. package/package.json +1 -1
  236. package/prebuilds/darwin-arm64/@nxtedition+rocksdb.node +0 -0
  237. package/prebuilds/linux-x64/@nxtedition+rocksdb.node +0 -0
@@ -418,6 +418,21 @@ TEST_P(WriteCommittedTxnWithTsTest, RecoverFromWal) {
418
418
  ASSERT_OK(txn3->Prepare());
419
419
  txn3.reset();
420
420
 
421
+ std::unique_ptr<Transaction> txn4(
422
+ NewTxn(WriteOptions(), TransactionOptions()));
423
+ assert(txn4);
424
+ ASSERT_OK(txn4->SetName("no_op_txn"));
425
+ txn4.reset();
426
+
427
+ std::unique_ptr<Transaction> rolled_back_txn(
428
+ NewTxn(write_opts, TransactionOptions()));
429
+ ASSERT_NE(nullptr, rolled_back_txn);
430
+ ASSERT_OK(rolled_back_txn->Put("non_exist0", "donotcare"));
431
+ ASSERT_OK(rolled_back_txn->Put(handles_[1], "non_exist1", "donotcare"));
432
+ ASSERT_OK(rolled_back_txn->SetName("rolled_back_txn"));
433
+ ASSERT_OK(rolled_back_txn->Rollback());
434
+ rolled_back_txn.reset();
435
+
421
436
  ASSERT_OK(ReOpenNoDelete(cf_descs, &handles_));
422
437
 
423
438
  {
@@ -452,9 +467,318 @@ TEST_P(WriteCommittedTxnWithTsTest, RecoverFromWal) {
452
467
 
453
468
  s = GetFromDb(ReadOptions(), handles_[1], "baz", /*ts=*/24, &value);
454
469
  ASSERT_TRUE(s.IsNotFound());
470
+
471
+ Transaction* no_op_txn = db->GetTransactionByName("no_op_txn");
472
+ ASSERT_EQ(nullptr, no_op_txn);
473
+
474
+ s = db->Get(ReadOptions(), handles_[0], "non_exist0", &value);
475
+ ASSERT_TRUE(s.IsNotFound());
476
+
477
+ s = GetFromDb(ReadOptions(), handles_[1], "non_exist1", /*ts=*/24, &value);
478
+ ASSERT_TRUE(s.IsNotFound());
479
+ }
480
+ }
481
+
482
+ TEST_P(WriteCommittedTxnWithTsTest, EnabledUDTDisabledRecoverFromWal) {
483
+ // This feature is not compatible with UDT in memtable only.
484
+ options.allow_concurrent_memtable_write = false;
485
+ ASSERT_OK(ReOpenNoDelete());
486
+
487
+ ColumnFamilyOptions cf_opts;
488
+ cf_opts.comparator = test::BytewiseComparatorWithU64TsWrapper();
489
+ cf_opts.persist_user_defined_timestamps = false;
490
+ const std::string test_cf_name = "test_cf";
491
+ ColumnFamilyHandle* cfh = nullptr;
492
+ assert(db);
493
+ ASSERT_OK(db->CreateColumnFamily(cf_opts, test_cf_name, &cfh));
494
+ delete cfh;
495
+ cfh = nullptr;
496
+
497
+ std::vector<ColumnFamilyDescriptor> cf_descs;
498
+ cf_descs.emplace_back(kDefaultColumnFamilyName, options);
499
+ cf_descs.emplace_back(test_cf_name, cf_opts);
500
+ options.avoid_flush_during_shutdown = true;
501
+ ASSERT_OK(ReOpenNoDelete(cf_descs, &handles_));
502
+
503
+ std::unique_ptr<Transaction> no_op_txn(
504
+ NewTxn(WriteOptions(), TransactionOptions()));
505
+ ASSERT_NE(nullptr, no_op_txn);
506
+ ASSERT_OK(no_op_txn->SetName("no_op_txn"));
507
+ no_op_txn.reset();
508
+
509
+ std::unique_ptr<Transaction> prepared_but_uncommitted_txn(
510
+ NewTxn(WriteOptions(), TransactionOptions()));
511
+ ASSERT_NE(nullptr, prepared_but_uncommitted_txn);
512
+ ASSERT_OK(prepared_but_uncommitted_txn->Put("foo0", "foo_value_0"));
513
+ ASSERT_OK(
514
+ prepared_but_uncommitted_txn->Put(handles_[1], "foo1", "foo_value_1"));
515
+ ASSERT_OK(
516
+ prepared_but_uncommitted_txn->SetName("prepared_but_uncommitted_txn"));
517
+ ASSERT_OK(prepared_but_uncommitted_txn->Prepare());
518
+
519
+ prepared_but_uncommitted_txn.reset();
520
+
521
+ WriteOptions write_opts;
522
+ write_opts.sync = true;
523
+ std::unique_ptr<Transaction> committed_txn(
524
+ NewTxn(write_opts, TransactionOptions()));
525
+ ASSERT_NE(nullptr, committed_txn);
526
+ ASSERT_OK(committed_txn->Put("bar0", "bar_value_0"));
527
+ ASSERT_OK(committed_txn->Put(handles_[1], "bar1", "bar_value_1"));
528
+ ASSERT_OK(committed_txn->SetName("committed_txn"));
529
+ ASSERT_OK(committed_txn->Prepare());
530
+ ASSERT_OK(committed_txn->SetCommitTimestamp(/*ts=*/23));
531
+ ASSERT_OK(committed_txn->Commit());
532
+ committed_txn.reset();
533
+
534
+ std::unique_ptr<Transaction> committed_without_prepare_txn(
535
+ NewTxn(write_opts, TransactionOptions()));
536
+ ASSERT_NE(nullptr, committed_without_prepare_txn);
537
+ ASSERT_OK(committed_without_prepare_txn->Put("baz0", "baz_value_0"));
538
+ ASSERT_OK(
539
+ committed_without_prepare_txn->Put(handles_[1], "baz1", "baz_value_1"));
540
+ ASSERT_OK(
541
+ committed_without_prepare_txn->SetName("committed_without_prepare_txn"));
542
+ ASSERT_OK(committed_without_prepare_txn->SetCommitTimestamp(/*ts=*/24));
543
+ ASSERT_OK(committed_without_prepare_txn->Commit());
544
+ committed_without_prepare_txn.reset();
545
+
546
+ std::unique_ptr<Transaction> rolled_back_txn(
547
+ NewTxn(write_opts, TransactionOptions()));
548
+ assert(rolled_back_txn);
549
+ ASSERT_OK(rolled_back_txn->Put("non_exist0", "donotcare"));
550
+ ASSERT_OK(rolled_back_txn->Put(handles_[1], "non_exist1", "donotcare"));
551
+ ASSERT_OK(rolled_back_txn->SetName("rolled_back_txn"));
552
+ ASSERT_OK(rolled_back_txn->Rollback());
553
+ rolled_back_txn.reset();
554
+
555
+ // Reopen and disable UDT to replay WAL entries.
556
+ cf_descs[1].options.comparator = BytewiseComparator();
557
+ ASSERT_OK(ReOpenNoDelete(cf_descs, &handles_));
558
+
559
+ {
560
+ Transaction* recovered_txn0 = db->GetTransactionByName("no_op_txn");
561
+ ASSERT_EQ(nullptr, recovered_txn0);
562
+
563
+ Transaction* recovered_txn1 =
564
+ db->GetTransactionByName("prepared_but_uncommitted_txn");
565
+ ASSERT_NE(nullptr, recovered_txn1);
566
+ std::string value;
567
+ ASSERT_OK(recovered_txn1->Commit());
568
+ Status s = db->Get(ReadOptions(), handles_[0], "foo0", &value);
569
+ ASSERT_OK(s);
570
+ ASSERT_EQ("foo_value_0", value);
571
+ s = db->Get(ReadOptions(), handles_[1], "foo1", &value);
572
+ ASSERT_OK(s);
573
+ ASSERT_EQ("foo_value_1", value);
574
+ delete recovered_txn1;
575
+
576
+ ASSERT_EQ(nullptr, db->GetTransactionByName("committed_txn"));
577
+ s = db->Get(ReadOptions(), handles_[0], "bar0", &value);
578
+ ASSERT_OK(s);
579
+ ASSERT_EQ("bar_value_0", value);
580
+ s = db->Get(ReadOptions(), handles_[1], "bar1", &value);
581
+ ASSERT_OK(s);
582
+ ASSERT_EQ("bar_value_1", value);
583
+
584
+ ASSERT_EQ(nullptr,
585
+ db->GetTransactionByName("committed_without_prepare_txn"));
586
+ s = db->Get(ReadOptions(), handles_[0], "baz0", &value);
587
+ ASSERT_OK(s);
588
+ ASSERT_EQ("baz_value_0", value);
589
+ s = db->Get(ReadOptions(), handles_[1], "baz1", &value);
590
+ ASSERT_OK(s);
591
+ ASSERT_EQ("baz_value_1", value);
592
+
593
+ ASSERT_EQ(nullptr, db->GetTransactionByName("rolled_back_txn"));
594
+ s = db->Get(ReadOptions(), handles_[0], "non_exist0", &value);
595
+ ASSERT_TRUE(s.IsNotFound());
596
+ s = db->Get(ReadOptions(), handles_[1], "non_exist1", &value);
597
+ ASSERT_TRUE(s.IsNotFound());
598
+ }
599
+ }
600
+
601
+ TEST_P(WriteCommittedTxnWithTsTest, UDTNewlyEnabledRecoverFromWal) {
602
+ ASSERT_OK(ReOpenNoDelete());
603
+
604
+ ColumnFamilyOptions cf_opts;
605
+ const std::string test_cf_name = "test_cf";
606
+ ColumnFamilyHandle* cfh = nullptr;
607
+ assert(db);
608
+ ASSERT_OK(db->CreateColumnFamily(cf_opts, test_cf_name, &cfh));
609
+ delete cfh;
610
+ cfh = nullptr;
611
+
612
+ std::vector<ColumnFamilyDescriptor> cf_descs;
613
+ cf_descs.emplace_back(kDefaultColumnFamilyName, options);
614
+ cf_descs.emplace_back(test_cf_name, cf_opts);
615
+ options.avoid_flush_during_shutdown = true;
616
+ ASSERT_OK(ReOpenNoDelete(cf_descs, &handles_));
617
+
618
+ std::unique_ptr<Transaction> no_op_txn(
619
+ NewTxn(WriteOptions(), TransactionOptions()));
620
+ ASSERT_NE(nullptr, no_op_txn);
621
+ ASSERT_OK(no_op_txn->SetName("no_op_txn"));
622
+ no_op_txn.reset();
623
+
624
+ std::unique_ptr<Transaction> prepared_but_uncommitted_txn(
625
+ NewTxn(WriteOptions(), TransactionOptions()));
626
+ ASSERT_NE(nullptr, prepared_but_uncommitted_txn);
627
+ ASSERT_OK(
628
+ prepared_but_uncommitted_txn->Put(handles_[0], "foo0", "foo_value_0"));
629
+ ASSERT_OK(
630
+ prepared_but_uncommitted_txn->Put(handles_[1], "foo1", "foo_value_1"));
631
+ ASSERT_OK(
632
+ prepared_but_uncommitted_txn->SetName("prepared_but_uncommitted_txn"));
633
+ ASSERT_OK(prepared_but_uncommitted_txn->Prepare());
634
+
635
+ prepared_but_uncommitted_txn.reset();
636
+
637
+ WriteOptions write_opts;
638
+ write_opts.sync = true;
639
+ std::unique_ptr<Transaction> committed_txn(
640
+ NewTxn(write_opts, TransactionOptions()));
641
+ ASSERT_NE(nullptr, committed_txn);
642
+ ASSERT_OK(committed_txn->Put("bar0", "bar_value_0"));
643
+ ASSERT_OK(committed_txn->Put(handles_[1], "bar1", "bar_value_1"));
644
+ ASSERT_OK(committed_txn->SetName("committed_txn"));
645
+ ASSERT_OK(committed_txn->Prepare());
646
+ ASSERT_OK(committed_txn->Commit());
647
+ committed_txn.reset();
648
+
649
+ std::unique_ptr<Transaction> committed_without_prepare_txn(
650
+ NewTxn(write_opts, TransactionOptions()));
651
+ assert(committed_without_prepare_txn);
652
+ ASSERT_OK(committed_without_prepare_txn->Put("baz0", "baz_value_0"));
653
+ ASSERT_OK(
654
+ committed_without_prepare_txn->Put(handles_[1], "baz1", "baz_value_1"));
655
+ ASSERT_OK(
656
+ committed_without_prepare_txn->SetName("committed_without_prepare_txn"));
657
+ ASSERT_OK(committed_without_prepare_txn->Commit());
658
+ committed_without_prepare_txn.reset();
659
+
660
+ std::unique_ptr<Transaction> rolled_back_txn(
661
+ NewTxn(write_opts, TransactionOptions()));
662
+ ASSERT_NE(nullptr, rolled_back_txn);
663
+ ASSERT_OK(rolled_back_txn->Put("non_exist0", "donotcare"));
664
+ ASSERT_OK(rolled_back_txn->Put(handles_[1], "non_exist1", "donotcare"));
665
+ ASSERT_OK(rolled_back_txn->SetName("rolled_back_txn"));
666
+ ASSERT_OK(rolled_back_txn->Rollback());
667
+ rolled_back_txn.reset();
668
+
669
+ // Reopen and enable UDT to replay WAL entries.
670
+ options.allow_concurrent_memtable_write = false;
671
+ cf_descs[1].options.comparator = test::BytewiseComparatorWithU64TsWrapper();
672
+ cf_descs[1].options.persist_user_defined_timestamps = false;
673
+ ASSERT_OK(ReOpenNoDelete(cf_descs, &handles_));
674
+
675
+ {
676
+ Transaction* recovered_txn1 =
677
+ db->GetTransactionByName("prepared_but_uncommitted_txn");
678
+ ASSERT_NE(nullptr, recovered_txn1);
679
+ std::string value;
680
+ ASSERT_OK(recovered_txn1->SetCommitTimestamp(23));
681
+ ASSERT_OK(recovered_txn1->Commit());
682
+ Status s = db->Get(ReadOptions(), handles_[0], "foo0", &value);
683
+ ASSERT_OK(s);
684
+ ASSERT_EQ("foo_value_0", value);
685
+ s = GetFromDb(ReadOptions(), handles_[1], "foo1", /*ts=*/23, &value);
686
+ ASSERT_OK(s);
687
+ ASSERT_EQ("foo_value_1", value);
688
+ delete recovered_txn1;
689
+
690
+ ASSERT_EQ(nullptr, db->GetTransactionByName("committed_txn"));
691
+ s = db->Get(ReadOptions(), handles_[0], "bar0", &value);
692
+ ASSERT_OK(s);
693
+ ASSERT_EQ("bar_value_0", value);
694
+ s = GetFromDb(ReadOptions(), handles_[1], "bar1", /*ts=*/23, &value);
695
+ ASSERT_OK(s);
696
+ ASSERT_EQ("bar_value_1", value);
697
+
698
+ ASSERT_EQ(nullptr,
699
+ db->GetTransactionByName("committed_without_prepare_txn"));
700
+ s = db->Get(ReadOptions(), handles_[0], "baz0", &value);
701
+ ASSERT_OK(s);
702
+ ASSERT_EQ("baz_value_0", value);
703
+ s = GetFromDb(ReadOptions(), handles_[1], "baz1", /*ts=*/23, &value);
704
+ ASSERT_OK(s);
705
+ ASSERT_EQ("baz_value_1", value);
706
+
707
+ ASSERT_EQ(nullptr, db->GetTransactionByName("rolled_back_txn"));
708
+ s = db->Get(ReadOptions(), handles_[0], "non_exist0", &value);
709
+ ASSERT_TRUE(s.IsNotFound());
710
+ s = GetFromDb(ReadOptions(), handles_[1], "non_exist1", /*ts=*/23, &value);
711
+ ASSERT_TRUE(s.IsNotFound());
455
712
  }
456
713
  }
457
714
 
715
+ TEST_P(WriteCommittedTxnWithTsTest, ChangeFromWriteCommittedAndDisableUDT) {
716
+ // This feature is not compatible with UDT in memtable only.
717
+ options.allow_concurrent_memtable_write = false;
718
+ ASSERT_OK(ReOpenNoDelete());
719
+
720
+ ColumnFamilyOptions cf_opts;
721
+ cf_opts.comparator = test::BytewiseComparatorWithU64TsWrapper();
722
+ cf_opts.persist_user_defined_timestamps = false;
723
+ const std::string test_cf_name = "test_cf";
724
+ ColumnFamilyHandle* cfh = nullptr;
725
+ assert(db);
726
+ ASSERT_OK(db->CreateColumnFamily(cf_opts, test_cf_name, &cfh));
727
+ delete cfh;
728
+ cfh = nullptr;
729
+
730
+ std::vector<ColumnFamilyDescriptor> cf_descs;
731
+ cf_descs.emplace_back(kDefaultColumnFamilyName, options);
732
+ cf_descs.emplace_back(test_cf_name, cf_opts);
733
+ options.avoid_flush_during_shutdown = true;
734
+ ASSERT_OK(ReOpenNoDelete(cf_descs, &handles_));
735
+
736
+ std::unique_ptr<Transaction> prepared_but_uncommitted_txn(
737
+ NewTxn(WriteOptions(), TransactionOptions()));
738
+ assert(prepared_but_uncommitted_txn);
739
+ ASSERT_OK(prepared_but_uncommitted_txn->Put("foo0", "foo_value_0"));
740
+ ASSERT_OK(
741
+ prepared_but_uncommitted_txn->Put(handles_[1], "foo1", "foo_value_1"));
742
+ ASSERT_OK(
743
+ prepared_but_uncommitted_txn->SetName("prepared_but_uncommitted_txn"));
744
+ ASSERT_OK(prepared_but_uncommitted_txn->Prepare());
745
+
746
+ prepared_but_uncommitted_txn.reset();
747
+
748
+ WriteOptions write_opts;
749
+ write_opts.sync = true;
750
+ std::unique_ptr<Transaction> committed_txn(
751
+ NewTxn(write_opts, TransactionOptions()));
752
+ assert(committed_txn);
753
+ ASSERT_OK(committed_txn->Put("bar0", "bar_value_0"));
754
+ ASSERT_OK(committed_txn->Put(handles_[1], "bar1", "bar_value_1"));
755
+ ASSERT_OK(committed_txn->SetName("committed_txn"));
756
+ ASSERT_OK(committed_txn->Prepare());
757
+ ASSERT_OK(committed_txn->SetCommitTimestamp(/*ts=*/23));
758
+ ASSERT_OK(committed_txn->Commit());
759
+ committed_txn.reset();
760
+
761
+ std::unique_ptr<Transaction> committed_without_prepare_txn(
762
+ NewTxn(write_opts, TransactionOptions()));
763
+ assert(committed_without_prepare_txn);
764
+ ASSERT_OK(committed_without_prepare_txn->Put("baz0", "baz_value_0"));
765
+ ASSERT_OK(
766
+ committed_without_prepare_txn->Put(handles_[1], "baz1", "baz_value_1"));
767
+ ASSERT_OK(
768
+ committed_without_prepare_txn->SetName("committed_without_prepare_txn"));
769
+ ASSERT_OK(committed_without_prepare_txn->SetCommitTimestamp(/*ts=*/24));
770
+ ASSERT_OK(committed_without_prepare_txn->Commit());
771
+ committed_without_prepare_txn.reset();
772
+
773
+ // Disable UDT and change write policy.
774
+ cf_descs[1].options.comparator = BytewiseComparator();
775
+ txn_db_options.write_policy = TxnDBWritePolicy::WRITE_PREPARED;
776
+ ASSERT_NOK(ReOpenNoDelete(cf_descs, &handles_));
777
+
778
+ txn_db_options.write_policy = TxnDBWritePolicy::WRITE_UNPREPARED;
779
+ ASSERT_NOK(ReOpenNoDelete(cf_descs, &handles_));
780
+ }
781
+
458
782
  TEST_P(WriteCommittedTxnWithTsTest, TransactionDbLevelApi) {
459
783
  ASSERT_OK(ReOpenNoDelete());
460
784
 
@@ -3,13 +3,13 @@
3
3
  // COPYING file in the root directory) and Apache 2.0 License
4
4
  // (found in the LICENSE.Apache file in the root directory).
5
5
 
6
-
7
6
  #include "utilities/transactions/write_prepared_txn.h"
8
7
 
9
8
  #include <cinttypes>
10
9
  #include <map>
11
10
  #include <set>
12
11
 
12
+ #include "db/attribute_group_iterator_impl.h"
13
13
  #include "db/column_family.h"
14
14
  #include "db/db_impl/db_impl.h"
15
15
  #include "rocksdb/db.h"
@@ -135,6 +135,23 @@ Iterator* WritePreparedTxn::GetIterator(const ReadOptions& options,
135
135
  return write_batch_.NewIteratorWithBase(column_family, db_iter, &options);
136
136
  }
137
137
 
138
+ std::unique_ptr<Iterator> WritePreparedTxn::GetCoalescingIterator(
139
+ const ReadOptions& /* read_options */,
140
+ const std::vector<ColumnFamilyHandle*>& /* column_families */) {
141
+ return std::unique_ptr<Iterator>(NewErrorIterator(
142
+ Status::NotSupported("GetCoalescingIterator not supported for "
143
+ "write-prepared/write-unprepared transactions")));
144
+ }
145
+
146
+ std::unique_ptr<AttributeGroupIterator>
147
+ WritePreparedTxn::GetAttributeGroupIterator(
148
+ const ReadOptions& /* read_options */,
149
+ const std::vector<ColumnFamilyHandle*>& /* column_families */) {
150
+ return NewAttributeGroupErrorIterator(
151
+ Status::NotSupported("GetAttributeGroupIterator not supported for "
152
+ "write-prepared/write-unprepared transactions"));
153
+ }
154
+
138
155
  Status WritePreparedTxn::PrepareInternal() {
139
156
  WriteOptions write_options = write_options_;
140
157
  write_options.disableWAL = false;
@@ -5,7 +5,6 @@
5
5
 
6
6
  #pragma once
7
7
 
8
-
9
8
  #include <algorithm>
10
9
  #include <atomic>
11
10
  #include <mutex>
@@ -71,6 +70,14 @@ class WritePreparedTxn : public PessimisticTransaction {
71
70
  Iterator* GetIterator(const ReadOptions& options,
72
71
  ColumnFamilyHandle* column_family) override;
73
72
 
73
+ std::unique_ptr<Iterator> GetCoalescingIterator(
74
+ const ReadOptions& read_options,
75
+ const std::vector<ColumnFamilyHandle*>& column_families) override;
76
+
77
+ std::unique_ptr<AttributeGroupIterator> GetAttributeGroupIterator(
78
+ const ReadOptions& read_options,
79
+ const std::vector<ColumnFamilyHandle*>& column_families) override;
80
+
74
81
  void SetSnapshot() override;
75
82
 
76
83
  protected:
@@ -35,7 +35,8 @@ struct WriteBatchWithIndex::Rep {
35
35
  overwrite_key(_overwrite_key),
36
36
  last_entry_offset(0),
37
37
  last_sub_batch_offset(0),
38
- sub_batch_cnt(1) {}
38
+ sub_batch_cnt(1),
39
+ track_cf_stat(false) {}
39
40
  ReadableWriteBatch write_batch;
40
41
  WriteBatchEntryComparator comparator;
41
42
  Arena arena;
@@ -49,6 +50,11 @@ struct WriteBatchWithIndex::Rep {
49
50
  // Total number of sub-batches in the write batch. Default is 1.
50
51
  size_t sub_batch_cnt;
51
52
 
53
+ bool track_cf_stat;
54
+ // Tracks ids of CFs that have updates in this WBWI, number of updates and
55
+ // number of overwritten single deletions per cf.
56
+ std::unordered_map<uint32_t, CFStat> cf_id_to_stat;
57
+
52
58
  // Remember current offset of internal write batch, which is used as
53
59
  // the starting offset of the next record.
54
60
  void SetLastEntryOffset() { last_entry_offset = write_batch.GetDataSize(); }
@@ -69,7 +75,7 @@ struct WriteBatchWithIndex::Rep {
69
75
 
70
76
  // Allocate an index entry pointing to the last entry in the write batch and
71
77
  // put it to skip list.
72
- void AddNewEntry(uint32_t column_family_id);
78
+ void AddNewEntry(uint32_t column_family_id, WriteType type);
73
79
 
74
80
  // Clear all updates buffered in this batch.
75
81
  void Clear();
@@ -114,6 +120,16 @@ bool WriteBatchWithIndex::Rep::UpdateExistingEntryWithCfId(
114
120
  last_sub_batch_offset = last_entry_offset;
115
121
  sub_batch_cnt++;
116
122
  }
123
+ if (track_cf_stat) {
124
+ if (non_const_entry->has_single_del &&
125
+ !non_const_entry->has_overwritten_single_del) {
126
+ cf_id_to_stat[column_family_id].overwritten_sd_count++;
127
+ non_const_entry->has_overwritten_single_del = true;
128
+ }
129
+ if (type == kSingleDeleteRecord) {
130
+ non_const_entry->has_single_del = true;
131
+ }
132
+ }
117
133
  if (type == kMergeRecord) {
118
134
  return false;
119
135
  } else {
@@ -130,18 +146,19 @@ void WriteBatchWithIndex::Rep::AddOrUpdateIndex(
130
146
  if (cf_cmp != nullptr) {
131
147
  comparator.SetComparatorForCF(cf_id, cf_cmp);
132
148
  }
133
- AddNewEntry(cf_id);
149
+ AddNewEntry(cf_id, type);
134
150
  }
135
151
  }
136
152
 
137
153
  void WriteBatchWithIndex::Rep::AddOrUpdateIndex(const Slice& key,
138
154
  WriteType type) {
139
155
  if (!UpdateExistingEntryWithCfId(0, key, type)) {
140
- AddNewEntry(0);
156
+ AddNewEntry(0, type);
141
157
  }
142
158
  }
143
159
 
144
- void WriteBatchWithIndex::Rep::AddNewEntry(uint32_t column_family_id) {
160
+ void WriteBatchWithIndex::Rep::AddNewEntry(uint32_t column_family_id,
161
+ WriteType type) {
145
162
  const std::string& wb_data = write_batch.Data();
146
163
  Slice entry_ptr = Slice(wb_data.data() + last_entry_offset,
147
164
  wb_data.size() - last_entry_offset);
@@ -166,10 +183,18 @@ void WriteBatchWithIndex::Rep::AddNewEntry(uint32_t column_family_id) {
166
183
  new (mem) WriteBatchIndexEntry(last_entry_offset, column_family_id,
167
184
  key.data() - wb_data.data(), key.size());
168
185
  skip_list.Insert(index_entry);
186
+
187
+ if (track_cf_stat) {
188
+ if (type == kSingleDeleteRecord) {
189
+ index_entry->has_single_del = true;
190
+ }
191
+ cf_id_to_stat[column_family_id].entry_count++;
192
+ }
169
193
  }
170
194
 
171
195
  void WriteBatchWithIndex::Rep::Clear() {
172
196
  write_batch.Clear();
197
+ cf_id_to_stat.clear();
173
198
  ClearIndex();
174
199
  }
175
200
 
@@ -220,7 +245,7 @@ Status WriteBatchWithIndex::Rep::ReBuildIndex() {
220
245
  case kTypeValue:
221
246
  found++;
222
247
  if (!UpdateExistingEntryWithCfId(column_family_id, key, kPutRecord)) {
223
- AddNewEntry(column_family_id);
248
+ AddNewEntry(column_family_id, kPutRecord);
224
249
  }
225
250
  break;
226
251
  case kTypeColumnFamilyDeletion:
@@ -228,7 +253,7 @@ Status WriteBatchWithIndex::Rep::ReBuildIndex() {
228
253
  found++;
229
254
  if (!UpdateExistingEntryWithCfId(column_family_id, key,
230
255
  kDeleteRecord)) {
231
- AddNewEntry(column_family_id);
256
+ AddNewEntry(column_family_id, kDeleteRecord);
232
257
  }
233
258
  break;
234
259
  case kTypeColumnFamilySingleDeletion:
@@ -236,14 +261,14 @@ Status WriteBatchWithIndex::Rep::ReBuildIndex() {
236
261
  found++;
237
262
  if (!UpdateExistingEntryWithCfId(column_family_id, key,
238
263
  kSingleDeleteRecord)) {
239
- AddNewEntry(column_family_id);
264
+ AddNewEntry(column_family_id, kSingleDeleteRecord);
240
265
  }
241
266
  break;
242
267
  case kTypeColumnFamilyMerge:
243
268
  case kTypeMerge:
244
269
  found++;
245
270
  if (!UpdateExistingEntryWithCfId(column_family_id, key, kMergeRecord)) {
246
- AddNewEntry(column_family_id);
271
+ AddNewEntry(column_family_id, kMergeRecord);
247
272
  }
248
273
  break;
249
274
  case kTypeLogData:
@@ -261,7 +286,7 @@ Status WriteBatchWithIndex::Rep::ReBuildIndex() {
261
286
  found++;
262
287
  if (!UpdateExistingEntryWithCfId(column_family_id, key,
263
288
  kPutEntityRecord)) {
264
- AddNewEntry(column_family_id);
289
+ AddNewEntry(column_family_id, kPutEntityRecord);
265
290
  }
266
291
  break;
267
292
  case kTypeColumnFamilyValuePreferredSeqno:
@@ -313,6 +338,11 @@ WBWIIterator* WriteBatchWithIndex::NewIterator(
313
338
  &(rep->comparator));
314
339
  }
315
340
 
341
+ WBWIIterator* WriteBatchWithIndex::NewIterator(uint32_t cf_id) const {
342
+ return new WBWIIteratorImpl(cf_id, &(rep->skip_list), &rep->write_batch,
343
+ &(rep->comparator));
344
+ }
345
+
316
346
  Iterator* WriteBatchWithIndex::NewIteratorWithBase(
317
347
  ColumnFamilyHandle* column_family, Iterator* base_iterator,
318
348
  const ReadOptions* read_options) {
@@ -329,7 +359,8 @@ Iterator* WriteBatchWithIndex::NewIteratorWithBase(
329
359
  }
330
360
 
331
361
  return new BaseDeltaIterator(column_family, base_iterator, wbwiii,
332
- GetColumnFamilyUserComparator(column_family));
362
+ GetColumnFamilyUserComparator(column_family),
363
+ read_options);
333
364
  }
334
365
 
335
366
  Iterator* WriteBatchWithIndex::NewIteratorWithBase(Iterator* base_iterator) {
@@ -337,7 +368,8 @@ Iterator* WriteBatchWithIndex::NewIteratorWithBase(Iterator* base_iterator) {
337
368
  auto wbwiii = new WBWIIteratorImpl(0, &(rep->skip_list), &rep->write_batch,
338
369
  &rep->comparator);
339
370
  return new BaseDeltaIterator(nullptr, base_iterator, wbwiii,
340
- rep->comparator.default_comparator());
371
+ rep->comparator.default_comparator(),
372
+ /* read_options */ nullptr);
341
373
  }
342
374
 
343
375
  Status WriteBatchWithIndex::Put(ColumnFamilyHandle* column_family,
@@ -1131,4 +1163,17 @@ const Comparator* WriteBatchWithIndexInternal::GetUserComparator(
1131
1163
  return ucmps.GetComparator(cf_id);
1132
1164
  }
1133
1165
 
1166
+ void WriteBatchWithIndex::SetTrackPerCFStat(bool track) {
1167
+ // Should be set when the wbwi contains no update.
1168
+ assert(GetWriteBatch()->Count() == 0);
1169
+ rep->track_cf_stat = track;
1170
+ }
1171
+
1172
+ const std::unordered_map<uint32_t, WriteBatchWithIndex::CFStat>&
1173
+ WriteBatchWithIndex::GetCFStats() const {
1174
+ assert(rep->track_cf_stat);
1175
+ return rep->cf_id_to_stat;
1176
+ }
1177
+
1178
+ bool WriteBatchWithIndex::GetOverwriteKey() const { return rep->overwrite_key; }
1134
1179
  } // namespace ROCKSDB_NAMESPACE
@@ -22,10 +22,13 @@ namespace ROCKSDB_NAMESPACE {
22
22
  BaseDeltaIterator::BaseDeltaIterator(ColumnFamilyHandle* column_family,
23
23
  Iterator* base_iterator,
24
24
  WBWIIteratorImpl* delta_iterator,
25
- const Comparator* comparator)
25
+ const Comparator* comparator,
26
+ const ReadOptions* read_options)
26
27
  : forward_(true),
27
28
  current_at_base_(true),
28
29
  equal_keys_(false),
30
+ allow_unprepared_value_(
31
+ read_options ? read_options->allow_unprepared_value : false),
29
32
  status_(Status::OK()),
30
33
  column_family_(column_family),
31
34
  base_iterator_(base_iterator),
@@ -262,6 +265,17 @@ void BaseDeltaIterator::SetValueAndColumnsFromBase() {
262
265
  assert(value_.empty());
263
266
  assert(columns_.empty());
264
267
 
268
+ if (!base_iterator_->PrepareValue()) {
269
+ assert(!BaseValid());
270
+ assert(!base_iterator_->status().ok());
271
+
272
+ Invalidate(base_iterator_->status());
273
+
274
+ assert(!Valid());
275
+ assert(!status().ok());
276
+ return;
277
+ }
278
+
265
279
  value_ = base_iterator_->value();
266
280
  columns_ = base_iterator_->columns();
267
281
  }
@@ -314,6 +328,17 @@ void BaseDeltaIterator::SetValueAndColumnsFromDelta() {
314
328
  /* result_operand */ nullptr, &result_type);
315
329
  } else if (delta_entry.type == kMergeRecord) {
316
330
  if (equal_keys_) {
331
+ if (!base_iterator_->PrepareValue()) {
332
+ assert(!BaseValid());
333
+ assert(!base_iterator_->status().ok());
334
+
335
+ Invalidate(base_iterator_->status());
336
+
337
+ assert(!Valid());
338
+ assert(!status().ok());
339
+ return;
340
+ }
341
+
317
342
  if (WideColumnsHelper::HasDefaultColumnOnly(base_iterator_->columns())) {
318
343
  status_ = WriteBatchWithIndexInternal::MergeKeyWithBaseValue(
319
344
  column_family_, delta_entry.key, MergeHelper::kPlainBaseValue,
@@ -402,7 +427,9 @@ void BaseDeltaIterator::UpdateCurrent() {
402
427
  } else if (!DeltaValid()) {
403
428
  // Delta has finished.
404
429
  current_at_base_ = true;
405
- SetValueAndColumnsFromBase();
430
+ if (!allow_unprepared_value_) {
431
+ SetValueAndColumnsFromBase();
432
+ }
406
433
  return;
407
434
  } else {
408
435
  int compare =
@@ -426,7 +453,9 @@ void BaseDeltaIterator::UpdateCurrent() {
426
453
  }
427
454
  } else {
428
455
  current_at_base_ = true;
429
- SetValueAndColumnsFromBase();
456
+ if (!allow_unprepared_value_) {
457
+ SetValueAndColumnsFromBase();
458
+ }
430
459
  return;
431
460
  }
432
461
  }