@nxtedition/rocksdb 11.0.3 → 11.0.4

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 (134) hide show
  1. package/binding.cc +133 -122
  2. package/deps/rocksdb/rocksdb/db/column_family_test.cc +15 -7
  3. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +4 -2
  4. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.cc +8 -4
  5. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +11 -7
  6. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_job.cc +17 -11
  7. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_test.cc +15 -0
  8. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +155 -0
  9. package/deps/rocksdb/rocksdb/db/db_bloom_filter_test.cc +564 -461
  10. package/deps/rocksdb/rocksdb/db/db_follower_test.cc +8 -4
  11. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +40 -24
  12. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +8 -1
  13. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +7 -4
  14. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_debug.cc +5 -0
  15. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +3 -1
  16. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +19 -1
  17. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_write.cc +20 -16
  18. package/deps/rocksdb/rocksdb/db/db_io_failure_test.cc +27 -0
  19. package/deps/rocksdb/rocksdb/db/db_kv_checksum_test.cc +10 -2
  20. package/deps/rocksdb/rocksdb/db/db_memtable_test.cc +85 -0
  21. package/deps/rocksdb/rocksdb/db/db_sst_test.cc +55 -2
  22. package/deps/rocksdb/rocksdb/db/db_test2.cc +231 -0
  23. package/deps/rocksdb/rocksdb/db/db_test_util.cc +5 -0
  24. package/deps/rocksdb/rocksdb/db/db_test_util.h +10 -1
  25. package/deps/rocksdb/rocksdb/db/db_universal_compaction_test.cc +0 -1
  26. package/deps/rocksdb/rocksdb/db/db_wal_test.cc +175 -1
  27. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +64 -0
  28. package/deps/rocksdb/rocksdb/db/dbformat.h +5 -6
  29. package/deps/rocksdb/rocksdb/db/dbformat_test.cc +8 -8
  30. package/deps/rocksdb/rocksdb/db/experimental.cc +3 -2
  31. package/deps/rocksdb/rocksdb/db/external_sst_file_test.cc +2 -4
  32. package/deps/rocksdb/rocksdb/db/flush_job.cc +7 -2
  33. package/deps/rocksdb/rocksdb/db/flush_job_test.cc +4 -2
  34. package/deps/rocksdb/rocksdb/db/listener_test.cc +5 -5
  35. package/deps/rocksdb/rocksdb/db/log_writer.cc +12 -3
  36. package/deps/rocksdb/rocksdb/db/memtable.cc +83 -23
  37. package/deps/rocksdb/rocksdb/db/memtable.h +11 -3
  38. package/deps/rocksdb/rocksdb/db/memtable_list.cc +7 -5
  39. package/deps/rocksdb/rocksdb/db/memtable_list_test.cc +21 -0
  40. package/deps/rocksdb/rocksdb/db/version_builder.cc +462 -33
  41. package/deps/rocksdb/rocksdb/db/version_builder.h +70 -23
  42. package/deps/rocksdb/rocksdb/db/version_edit_handler.cc +95 -207
  43. package/deps/rocksdb/rocksdb/db/version_edit_handler.h +54 -35
  44. package/deps/rocksdb/rocksdb/db/version_set.cc +13 -11
  45. package/deps/rocksdb/rocksdb/db/version_set_test.cc +313 -59
  46. package/deps/rocksdb/rocksdb/db/write_batch.cc +124 -64
  47. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +2 -3
  48. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_compaction_filter.h +1 -1
  49. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_driver.cc +4 -1
  50. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +9 -0
  51. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_listener.h +4 -32
  52. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_shared_state.h +7 -3
  53. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +60 -172
  54. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.h +57 -2
  55. package/deps/rocksdb/rocksdb/db_stress_tool/expected_state.cc +23 -15
  56. package/deps/rocksdb/rocksdb/db_stress_tool/expected_state.h +2 -3
  57. package/deps/rocksdb/rocksdb/db_stress_tool/expected_value.cc +1 -1
  58. package/deps/rocksdb/rocksdb/db_stress_tool/expected_value.h +4 -1
  59. package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +200 -92
  60. package/deps/rocksdb/rocksdb/env/file_system.cc +3 -3
  61. package/deps/rocksdb/rocksdb/file/delete_scheduler.cc +124 -23
  62. package/deps/rocksdb/rocksdb/file/delete_scheduler.h +61 -8
  63. package/deps/rocksdb/rocksdb/file/delete_scheduler_test.cc +141 -2
  64. package/deps/rocksdb/rocksdb/file/file_util.cc +17 -2
  65. package/deps/rocksdb/rocksdb/file/file_util.h +10 -0
  66. package/deps/rocksdb/rocksdb/file/filename.cc +11 -3
  67. package/deps/rocksdb/rocksdb/file/filename.h +2 -1
  68. package/deps/rocksdb/rocksdb/file/sst_file_manager_impl.cc +18 -0
  69. package/deps/rocksdb/rocksdb/file/sst_file_manager_impl.h +27 -4
  70. package/deps/rocksdb/rocksdb/file/writable_file_writer.h +8 -1
  71. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +8 -13
  72. package/deps/rocksdb/rocksdb/include/rocksdb/env.h +4 -0
  73. package/deps/rocksdb/rocksdb/include/rocksdb/experimental.h +5 -0
  74. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +5 -2
  75. package/deps/rocksdb/rocksdb/include/rocksdb/filter_policy.h +2 -1
  76. package/deps/rocksdb/rocksdb/include/rocksdb/memtablerep.h +34 -0
  77. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +25 -1
  78. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
  79. package/deps/rocksdb/rocksdb/include/rocksdb/table.h +27 -9
  80. package/deps/rocksdb/rocksdb/include/rocksdb/table_properties.h +2 -0
  81. package/deps/rocksdb/rocksdb/include/rocksdb/types.h +12 -0
  82. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/transaction_db.h +21 -0
  83. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +2 -2
  84. package/deps/rocksdb/rocksdb/include/rocksdb/write_batch.h +29 -1
  85. package/deps/rocksdb/rocksdb/memtable/inlineskiplist.h +102 -33
  86. package/deps/rocksdb/rocksdb/memtable/skiplistrep.cc +46 -3
  87. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +4 -0
  88. package/deps/rocksdb/rocksdb/options/cf_options.cc +6 -0
  89. package/deps/rocksdb/rocksdb/options/cf_options.h +2 -0
  90. package/deps/rocksdb/rocksdb/options/db_options.cc +15 -1
  91. package/deps/rocksdb/rocksdb/options/db_options.h +2 -0
  92. package/deps/rocksdb/rocksdb/options/options_helper.cc +10 -0
  93. package/deps/rocksdb/rocksdb/options/options_parser.cc +3 -2
  94. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +9 -2
  95. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +75 -35
  96. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.cc +6 -0
  97. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +4 -0
  98. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +8 -1
  99. package/deps/rocksdb/rocksdb/table/block_based/filter_block.h +40 -15
  100. package/deps/rocksdb/rocksdb/table/block_based/filter_policy.cc +98 -17
  101. package/deps/rocksdb/rocksdb/table/block_based/filter_policy_internal.h +14 -2
  102. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.cc +21 -91
  103. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block.h +13 -21
  104. package/deps/rocksdb/rocksdb/table/block_based/full_filter_block_test.cc +14 -5
  105. package/deps/rocksdb/rocksdb/table/block_based/index_builder.cc +62 -53
  106. package/deps/rocksdb/rocksdb/table/block_based/index_builder.h +60 -38
  107. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +175 -78
  108. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.h +65 -36
  109. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block_test.cc +25 -15
  110. package/deps/rocksdb/rocksdb/table/block_fetcher.cc +13 -1
  111. package/deps/rocksdb/rocksdb/table/meta_blocks.cc +18 -4
  112. package/deps/rocksdb/rocksdb/table/meta_blocks.h +4 -0
  113. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +11 -0
  114. package/deps/rocksdb/rocksdb/utilities/blob_db/blob_db_test.cc +2 -2
  115. package/deps/rocksdb/rocksdb/utilities/checkpoint/checkpoint_impl.cc +47 -18
  116. package/deps/rocksdb/rocksdb/utilities/checkpoint/checkpoint_impl.h +1 -2
  117. package/deps/rocksdb/rocksdb/utilities/checkpoint/checkpoint_test.cc +95 -0
  118. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.cc +26 -15
  119. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.h +62 -19
  120. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction.cc +73 -34
  121. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction.h +5 -0
  122. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction_db.cc +10 -3
  123. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction_db.h +2 -1
  124. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_util.cc +8 -5
  125. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_util.h +7 -4
  126. package/deps/rocksdb/rocksdb/utilities/transactions/write_committed_transaction_ts_test.cc +225 -0
  127. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_txn.cc +2 -1
  128. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_txn_db.h +17 -0
  129. package/deps/rocksdb/rocksdb/utilities/transactions/write_unprepared_txn.cc +5 -2
  130. package/index.js +5 -17
  131. package/iterator.js +1 -1
  132. package/package.json +1 -1
  133. package/prebuilds/darwin-arm64/@nxtedition+rocksdb.node +0 -0
  134. package/prebuilds/linux-x64/@nxtedition+rocksdb.node +0 -0
@@ -632,7 +632,6 @@ void StressTest::PreloadDbAndReopenAsReadOnly(int64_t number_of_keys,
632
632
  for (auto cfh : column_families_) {
633
633
  for (int64_t k = 0; k != number_of_keys; ++k) {
634
634
  const std::string key = Key(k);
635
-
636
635
  PendingExpectedValue pending_expected_value =
637
636
  shared->PreparePut(cf_idx, k);
638
637
  const uint32_t value_base = pending_expected_value.GetFinalValueBase();
@@ -1011,26 +1010,12 @@ void StressTest::OperateDb(ThreadState* thread) {
1011
1010
  thread->rand.OneIn(FLAGS_verify_db_one_in)) {
1012
1011
  // Temporarily disable error injection for verification
1013
1012
  if (fault_fs_guard) {
1014
- fault_fs_guard->DisableThreadLocalErrorInjection(
1015
- FaultInjectionIOType::kRead);
1016
- fault_fs_guard->DisableThreadLocalErrorInjection(
1017
- FaultInjectionIOType::kWrite);
1018
- fault_fs_guard->DisableThreadLocalErrorInjection(
1019
- FaultInjectionIOType::kMetadataRead);
1020
- fault_fs_guard->DisableThreadLocalErrorInjection(
1021
- FaultInjectionIOType::kMetadataWrite);
1013
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1022
1014
  }
1023
1015
  ContinuouslyVerifyDb(thread);
1024
1016
  // Enable back error injection disabled for verification
1025
1017
  if (fault_fs_guard) {
1026
- fault_fs_guard->EnableThreadLocalErrorInjection(
1027
- FaultInjectionIOType::kRead);
1028
- fault_fs_guard->EnableThreadLocalErrorInjection(
1029
- FaultInjectionIOType::kWrite);
1030
- fault_fs_guard->EnableThreadLocalErrorInjection(
1031
- FaultInjectionIOType::kMetadataRead);
1032
- fault_fs_guard->EnableThreadLocalErrorInjection(
1033
- FaultInjectionIOType::kMetadataWrite);
1018
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
1034
1019
  }
1035
1020
  if (thread->shared->ShouldStopTest()) {
1036
1021
  break;
@@ -1056,14 +1041,7 @@ void StressTest::OperateDb(ThreadState* thread) {
1056
1041
  } else if (s.ok()) {
1057
1042
  // Temporarily disable error injection for verification
1058
1043
  if (fault_fs_guard) {
1059
- fault_fs_guard->DisableThreadLocalErrorInjection(
1060
- FaultInjectionIOType::kRead);
1061
- fault_fs_guard->DisableThreadLocalErrorInjection(
1062
- FaultInjectionIOType::kMetadataRead);
1063
- fault_fs_guard->DisableThreadLocalErrorInjection(
1064
- FaultInjectionIOType::kWrite);
1065
- fault_fs_guard->DisableThreadLocalErrorInjection(
1066
- FaultInjectionIOType::kMetadataWrite);
1044
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1067
1045
  }
1068
1046
 
1069
1047
  // Verify no writes during LockWAL
@@ -1118,14 +1096,7 @@ void StressTest::OperateDb(ThreadState* thread) {
1118
1096
 
1119
1097
  // Enable back error injection disabled for verification
1120
1098
  if (fault_fs_guard) {
1121
- fault_fs_guard->EnableThreadLocalErrorInjection(
1122
- FaultInjectionIOType::kRead);
1123
- fault_fs_guard->EnableThreadLocalErrorInjection(
1124
- FaultInjectionIOType::kMetadataRead);
1125
- fault_fs_guard->EnableThreadLocalErrorInjection(
1126
- FaultInjectionIOType::kWrite);
1127
- fault_fs_guard->EnableThreadLocalErrorInjection(
1128
- FaultInjectionIOType::kMetadataWrite);
1099
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
1129
1100
  }
1130
1101
  }
1131
1102
  }
@@ -1238,27 +1209,13 @@ void StressTest::OperateDb(ThreadState* thread) {
1238
1209
  // failed due to injected error. So we disable fault injection to avoid
1239
1210
  // false positive
1240
1211
  if (fault_fs_guard) {
1241
- fault_fs_guard->DisableThreadLocalErrorInjection(
1242
- FaultInjectionIOType::kMetadataRead);
1243
- fault_fs_guard->DisableThreadLocalErrorInjection(
1244
- FaultInjectionIOType::kMetadataWrite);
1245
- fault_fs_guard->DisableThreadLocalErrorInjection(
1246
- FaultInjectionIOType::kRead);
1247
- fault_fs_guard->DisableThreadLocalErrorInjection(
1248
- FaultInjectionIOType::kWrite);
1212
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1249
1213
  }
1250
1214
 
1251
1215
  TestGetProperty(thread);
1252
1216
 
1253
1217
  if (fault_fs_guard) {
1254
- fault_fs_guard->EnableThreadLocalErrorInjection(
1255
- FaultInjectionIOType::kMetadataWrite);
1256
- fault_fs_guard->EnableThreadLocalErrorInjection(
1257
- FaultInjectionIOType::kMetadataRead);
1258
- fault_fs_guard->EnableThreadLocalErrorInjection(
1259
- FaultInjectionIOType::kRead);
1260
- fault_fs_guard->EnableThreadLocalErrorInjection(
1261
- FaultInjectionIOType::kWrite);
1218
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
1262
1219
  }
1263
1220
  }
1264
1221
 
@@ -1289,25 +1246,11 @@ void StressTest::OperateDb(ThreadState* thread) {
1289
1246
  // TODO(hx235): enable error injection with
1290
1247
  // backup/restore after fixing the various issues it surfaces
1291
1248
  if (fault_fs_guard) {
1292
- fault_fs_guard->DisableThreadLocalErrorInjection(
1293
- FaultInjectionIOType::kMetadataRead);
1294
- fault_fs_guard->DisableThreadLocalErrorInjection(
1295
- FaultInjectionIOType::kMetadataWrite);
1296
- fault_fs_guard->DisableThreadLocalErrorInjection(
1297
- FaultInjectionIOType::kRead);
1298
- fault_fs_guard->DisableThreadLocalErrorInjection(
1299
- FaultInjectionIOType::kWrite);
1249
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1300
1250
  }
1301
1251
  Status s = TestBackupRestore(thread, rand_column_families, rand_keys);
1302
1252
  if (fault_fs_guard) {
1303
- fault_fs_guard->EnableThreadLocalErrorInjection(
1304
- FaultInjectionIOType::kMetadataWrite);
1305
- fault_fs_guard->EnableThreadLocalErrorInjection(
1306
- FaultInjectionIOType::kMetadataRead);
1307
- fault_fs_guard->EnableThreadLocalErrorInjection(
1308
- FaultInjectionIOType::kRead);
1309
- fault_fs_guard->EnableThreadLocalErrorInjection(
1310
- FaultInjectionIOType::kWrite);
1253
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
1311
1254
  }
1312
1255
  ProcessStatus(shared, "Backup/restore", s);
1313
1256
  }
@@ -1344,7 +1287,13 @@ void StressTest::OperateDb(ThreadState* thread) {
1344
1287
  if (thread->rand.OneInOpt(FLAGS_key_may_exist_one_in)) {
1345
1288
  TestKeyMayExist(thread, read_opts, rand_column_families, rand_keys);
1346
1289
  }
1347
-
1290
+ // Prefix-recoverability relies on tracing successful user writes.
1291
+ // Currently we trace all user writes regardless of whether it later
1292
+ // succeeds or not. To simplify, we disable any fault injection during
1293
+ // user write.
1294
+ // TODO(hx235): support tracing user writes with fault injection.
1295
+ bool disable_fault_injection_during_user_write =
1296
+ fault_fs_guard && MightHaveUnsyncedDataLoss();
1348
1297
  int prob_op = thread->rand.Uniform(100);
1349
1298
  // Reset this in case we pick something other than a read op. We don't
1350
1299
  // want to use a stale value when deciding at the beginning of the loop
@@ -1403,16 +1352,34 @@ void StressTest::OperateDb(ThreadState* thread) {
1403
1352
  } else if (prob_op < write_bound) {
1404
1353
  assert(prefix_bound <= prob_op);
1405
1354
  // OPERATION write
1355
+ if (disable_fault_injection_during_user_write) {
1356
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1357
+ }
1406
1358
  TestPut(thread, write_opts, read_opts, rand_column_families, rand_keys,
1407
1359
  value);
1360
+ if (disable_fault_injection_during_user_write) {
1361
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
1362
+ }
1408
1363
  } else if (prob_op < del_bound) {
1409
1364
  assert(write_bound <= prob_op);
1410
1365
  // OPERATION delete
1366
+ if (disable_fault_injection_during_user_write) {
1367
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1368
+ }
1411
1369
  TestDelete(thread, write_opts, rand_column_families, rand_keys);
1370
+ if (disable_fault_injection_during_user_write) {
1371
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
1372
+ }
1412
1373
  } else if (prob_op < delrange_bound) {
1413
1374
  assert(del_bound <= prob_op);
1414
1375
  // OPERATION delete range
1376
+ if (disable_fault_injection_during_user_write) {
1377
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1378
+ }
1415
1379
  TestDeleteRange(thread, write_opts, rand_column_families, rand_keys);
1380
+ if (disable_fault_injection_during_user_write) {
1381
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
1382
+ }
1416
1383
  } else if (prob_op < iterate_bound) {
1417
1384
  assert(delrange_bound <= prob_op);
1418
1385
  // OPERATION iterate
@@ -1456,14 +1423,7 @@ void StressTest::OperateDb(ThreadState* thread) {
1456
1423
 
1457
1424
  #ifndef NDEBUG
1458
1425
  if (fault_fs_guard) {
1459
- fault_fs_guard->DisableThreadLocalErrorInjection(
1460
- FaultInjectionIOType::kRead);
1461
- fault_fs_guard->DisableThreadLocalErrorInjection(
1462
- FaultInjectionIOType::kWrite);
1463
- fault_fs_guard->DisableThreadLocalErrorInjection(
1464
- FaultInjectionIOType::kMetadataRead);
1465
- fault_fs_guard->DisableThreadLocalErrorInjection(
1466
- FaultInjectionIOType::kMetadataWrite);
1426
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
1467
1427
  }
1468
1428
  #endif // NDEBUG
1469
1429
  }
@@ -2344,14 +2304,7 @@ Status StressTest::TestBackupRestore(
2344
2304
 
2345
2305
  // Temporarily disable error injection for clean up
2346
2306
  if (fault_fs_guard) {
2347
- fault_fs_guard->DisableThreadLocalErrorInjection(
2348
- FaultInjectionIOType::kRead);
2349
- fault_fs_guard->DisableThreadLocalErrorInjection(
2350
- FaultInjectionIOType::kWrite);
2351
- fault_fs_guard->DisableThreadLocalErrorInjection(
2352
- FaultInjectionIOType::kMetadataRead);
2353
- fault_fs_guard->DisableThreadLocalErrorInjection(
2354
- FaultInjectionIOType::kMetadataWrite);
2307
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
2355
2308
  }
2356
2309
 
2357
2310
  if (s.ok() || IsErrorInjectedAndRetryable(s)) {
@@ -2373,14 +2326,7 @@ Status StressTest::TestBackupRestore(
2373
2326
 
2374
2327
  // Enable back error injection disabled for clean up
2375
2328
  if (fault_fs_guard) {
2376
- fault_fs_guard->EnableThreadLocalErrorInjection(
2377
- FaultInjectionIOType::kRead);
2378
- fault_fs_guard->EnableThreadLocalErrorInjection(
2379
- FaultInjectionIOType::kWrite);
2380
- fault_fs_guard->EnableThreadLocalErrorInjection(
2381
- FaultInjectionIOType::kMetadataRead);
2382
- fault_fs_guard->EnableThreadLocalErrorInjection(
2383
- FaultInjectionIOType::kMetadataWrite);
2329
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
2384
2330
  }
2385
2331
 
2386
2332
  if (!s.ok() && !IsErrorInjectedAndRetryable(s)) {
@@ -2520,26 +2466,12 @@ Status StressTest::TestCheckpoint(ThreadState* thread,
2520
2466
  tmp_opts.sst_file_manager.reset();
2521
2467
  // Temporarily disable error injection for clean-up
2522
2468
  if (fault_fs_guard) {
2523
- fault_fs_guard->DisableThreadLocalErrorInjection(
2524
- FaultInjectionIOType::kRead);
2525
- fault_fs_guard->DisableThreadLocalErrorInjection(
2526
- FaultInjectionIOType::kWrite);
2527
- fault_fs_guard->DisableThreadLocalErrorInjection(
2528
- FaultInjectionIOType::kMetadataRead);
2529
- fault_fs_guard->DisableThreadLocalErrorInjection(
2530
- FaultInjectionIOType::kMetadataWrite);
2469
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
2531
2470
  }
2532
2471
  DestroyDB(checkpoint_dir, tmp_opts);
2533
2472
  // Enable back error injection disabled for clean-up
2534
2473
  if (fault_fs_guard) {
2535
- fault_fs_guard->EnableThreadLocalErrorInjection(
2536
- FaultInjectionIOType::kRead);
2537
- fault_fs_guard->EnableThreadLocalErrorInjection(
2538
- FaultInjectionIOType::kWrite);
2539
- fault_fs_guard->EnableThreadLocalErrorInjection(
2540
- FaultInjectionIOType::kMetadataRead);
2541
- fault_fs_guard->EnableThreadLocalErrorInjection(
2542
- FaultInjectionIOType::kMetadataWrite);
2474
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
2543
2475
  }
2544
2476
  Checkpoint* checkpoint = nullptr;
2545
2477
  Status s = Checkpoint::Create(db_, &checkpoint);
@@ -2647,14 +2579,7 @@ Status StressTest::TestCheckpoint(ThreadState* thread,
2647
2579
 
2648
2580
  // Temporarily disable error injection for clean-up
2649
2581
  if (fault_fs_guard) {
2650
- fault_fs_guard->DisableThreadLocalErrorInjection(
2651
- FaultInjectionIOType::kRead);
2652
- fault_fs_guard->DisableThreadLocalErrorInjection(
2653
- FaultInjectionIOType::kWrite);
2654
- fault_fs_guard->DisableThreadLocalErrorInjection(
2655
- FaultInjectionIOType::kMetadataRead);
2656
- fault_fs_guard->DisableThreadLocalErrorInjection(
2657
- FaultInjectionIOType::kMetadataWrite);
2582
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
2658
2583
  }
2659
2584
 
2660
2585
  if (!s.ok() && !IsErrorInjectedAndRetryable(s)) {
@@ -2666,14 +2591,7 @@ Status StressTest::TestCheckpoint(ThreadState* thread,
2666
2591
 
2667
2592
  // Enable back error injection disabled for clean-up
2668
2593
  if (fault_fs_guard) {
2669
- fault_fs_guard->EnableThreadLocalErrorInjection(
2670
- FaultInjectionIOType::kRead);
2671
- fault_fs_guard->EnableThreadLocalErrorInjection(
2672
- FaultInjectionIOType::kWrite);
2673
- fault_fs_guard->EnableThreadLocalErrorInjection(
2674
- FaultInjectionIOType::kMetadataRead);
2675
- fault_fs_guard->EnableThreadLocalErrorInjection(
2676
- FaultInjectionIOType::kMetadataWrite);
2594
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
2677
2595
  }
2678
2596
  return s;
2679
2597
  }
@@ -3048,14 +2966,7 @@ void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,
3048
2966
  if (thread->rand.OneIn(2)) {
3049
2967
  // Temporarily disable error injection to for validation
3050
2968
  if (fault_fs_guard) {
3051
- fault_fs_guard->DisableThreadLocalErrorInjection(
3052
- FaultInjectionIOType::kMetadataRead);
3053
- fault_fs_guard->DisableThreadLocalErrorInjection(
3054
- FaultInjectionIOType::kRead);
3055
- fault_fs_guard->DisableThreadLocalErrorInjection(
3056
- FaultInjectionIOType::kMetadataWrite);
3057
- fault_fs_guard->DisableThreadLocalErrorInjection(
3058
- FaultInjectionIOType::kWrite);
2969
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
3059
2970
  }
3060
2971
 
3061
2972
  // Declare a snapshot and compare the data before and after the compaction
@@ -3065,14 +2976,7 @@ void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,
3065
2976
 
3066
2977
  // Enable back error injection disabled for validation
3067
2978
  if (fault_fs_guard) {
3068
- fault_fs_guard->EnableThreadLocalErrorInjection(
3069
- FaultInjectionIOType::kMetadataRead);
3070
- fault_fs_guard->EnableThreadLocalErrorInjection(
3071
- FaultInjectionIOType::kRead);
3072
- fault_fs_guard->EnableThreadLocalErrorInjection(
3073
- FaultInjectionIOType::kMetadataWrite);
3074
- fault_fs_guard->EnableThreadLocalErrorInjection(
3075
- FaultInjectionIOType::kWrite);
2979
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
3076
2980
  }
3077
2981
  }
3078
2982
  std::ostringstream compact_range_opt_oss;
@@ -3110,14 +3014,7 @@ void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,
3110
3014
  if (pre_snapshot != nullptr) {
3111
3015
  // Temporarily disable error injection for validation
3112
3016
  if (fault_fs_guard) {
3113
- fault_fs_guard->DisableThreadLocalErrorInjection(
3114
- FaultInjectionIOType::kMetadataRead);
3115
- fault_fs_guard->DisableThreadLocalErrorInjection(
3116
- FaultInjectionIOType::kRead);
3117
- fault_fs_guard->DisableThreadLocalErrorInjection(
3118
- FaultInjectionIOType::kMetadataWrite);
3119
- fault_fs_guard->DisableThreadLocalErrorInjection(
3120
- FaultInjectionIOType::kWrite);
3017
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
3121
3018
  }
3122
3019
  uint32_t post_hash =
3123
3020
  GetRangeHash(thread, pre_snapshot, column_family, start_key, end_key);
@@ -3136,14 +3033,7 @@ void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,
3136
3033
  db_->ReleaseSnapshot(pre_snapshot);
3137
3034
  if (fault_fs_guard) {
3138
3035
  // Enable back error injection disabled for validation
3139
- fault_fs_guard->EnableThreadLocalErrorInjection(
3140
- FaultInjectionIOType::kMetadataRead);
3141
- fault_fs_guard->EnableThreadLocalErrorInjection(
3142
- FaultInjectionIOType::kRead);
3143
- fault_fs_guard->EnableThreadLocalErrorInjection(
3144
- FaultInjectionIOType::kMetadataWrite);
3145
- fault_fs_guard->EnableThreadLocalErrorInjection(
3146
- FaultInjectionIOType::kWrite);
3036
+ fault_fs_guard->EnableAllThreadLocalErrorInjection();
3147
3037
  }
3148
3038
  }
3149
3039
  }
@@ -3523,14 +3413,7 @@ void StressTest::Open(SharedState* shared, bool reopen) {
3523
3413
  // If this is for DB reopen, error injection may have been enabled.
3524
3414
  // Disable it here in case there is no open fault injection.
3525
3415
  if (fault_fs_guard) {
3526
- fault_fs_guard->DisableThreadLocalErrorInjection(
3527
- FaultInjectionIOType::kRead);
3528
- fault_fs_guard->DisableThreadLocalErrorInjection(
3529
- FaultInjectionIOType::kWrite);
3530
- fault_fs_guard->DisableThreadLocalErrorInjection(
3531
- FaultInjectionIOType::kMetadataRead);
3532
- fault_fs_guard->DisableThreadLocalErrorInjection(
3533
- FaultInjectionIOType::kMetadataWrite);
3416
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
3534
3417
  }
3535
3418
  // TODO; test transaction DB Open with fault injection
3536
3419
  if (!FLAGS_use_txn) {
@@ -3611,14 +3494,7 @@ void StressTest::Open(SharedState* shared, bool reopen) {
3611
3494
  if (inject_sync_fault || inject_open_meta_read_error ||
3612
3495
  inject_open_meta_write_error || inject_open_read_error ||
3613
3496
  inject_open_write_error) {
3614
- fault_fs_guard->DisableThreadLocalErrorInjection(
3615
- FaultInjectionIOType::kRead);
3616
- fault_fs_guard->DisableThreadLocalErrorInjection(
3617
- FaultInjectionIOType::kWrite);
3618
- fault_fs_guard->DisableThreadLocalErrorInjection(
3619
- FaultInjectionIOType::kMetadataRead);
3620
- fault_fs_guard->DisableThreadLocalErrorInjection(
3621
- FaultInjectionIOType::kMetadataWrite);
3497
+ fault_fs_guard->DisableAllThreadLocalErrorInjection();
3622
3498
 
3623
3499
  if (s.ok()) {
3624
3500
  // Injected errors might happen in background compactions. We
@@ -3798,7 +3674,7 @@ void StressTest::Reopen(ThreadState* thread) {
3798
3674
  // crash-recovery verification does. Therefore it always expects no data loss
3799
3675
  // and we should ensure no data loss in testing.
3800
3676
  // TODO(hx235): eliminate the FlushWAL(true /* sync */)/SyncWAL() below
3801
- if (!FLAGS_disable_wal && !FLAGS_avoid_flush_during_shutdown) {
3677
+ if (!FLAGS_disable_wal && FLAGS_avoid_flush_during_shutdown) {
3802
3678
  Status s;
3803
3679
  if (FLAGS_manual_wal_flush_one_in > 0) {
3804
3680
  s = db_->FlushWAL(/*sync=*/true);
@@ -3956,6 +3832,10 @@ void CheckAndSetOptionsForUserTimestamp(Options& options) {
3956
3832
  FLAGS_persist_user_defined_timestamps;
3957
3833
  }
3958
3834
 
3835
+ bool ShouldDisableAutoCompactionsBeforeVerifyDb() {
3836
+ return !FLAGS_disable_auto_compactions && FLAGS_enable_compaction_filter;
3837
+ }
3838
+
3959
3839
  bool InitializeOptionsFromFile(Options& options) {
3960
3840
  DBOptions db_options;
3961
3841
  ConfigOptions config_options;
@@ -3983,6 +3863,8 @@ void InitializeOptionsFromFlags(
3983
3863
  const std::shared_ptr<const FilterPolicy>& filter_policy,
3984
3864
  Options& options) {
3985
3865
  BlockBasedTableOptions block_based_options;
3866
+ block_based_options.decouple_partitioned_filters =
3867
+ FLAGS_decouple_partitioned_filters;
3986
3868
  block_based_options.block_cache = cache;
3987
3869
  block_based_options.cache_index_and_filter_blocks =
3988
3870
  FLAGS_cache_index_and_filter_blocks;
@@ -4069,7 +3951,11 @@ void InitializeOptionsFromFlags(
4069
3951
  new WriteBufferManager(FLAGS_db_write_buffer_size, block_cache));
4070
3952
  }
4071
3953
  options.memtable_whole_key_filtering = FLAGS_memtable_whole_key_filtering;
4072
- options.disable_auto_compactions = FLAGS_disable_auto_compactions;
3954
+ if (ShouldDisableAutoCompactionsBeforeVerifyDb()) {
3955
+ options.disable_auto_compactions = true;
3956
+ } else {
3957
+ options.disable_auto_compactions = FLAGS_disable_auto_compactions;
3958
+ }
4073
3959
  options.max_background_compactions = FLAGS_max_background_compactions;
4074
3960
  options.max_background_flushes = FLAGS_max_background_flushes;
4075
3961
  options.compaction_style =
@@ -4169,6 +4055,7 @@ void InitializeOptionsFromFlags(
4169
4055
  options.memtable_protection_bytes_per_key =
4170
4056
  FLAGS_memtable_protection_bytes_per_key;
4171
4057
  options.block_protection_bytes_per_key = FLAGS_block_protection_bytes_per_key;
4058
+ options.paranoid_memory_checks = FLAGS_paranoid_memory_checks;
4172
4059
 
4173
4060
  // Integrated BlobDB
4174
4061
  options.enable_blob_files = FLAGS_enable_blob_files;
@@ -4384,6 +4271,7 @@ void InitializeOptionsGeneral(
4384
4271
  options.disable_auto_compactions = true;
4385
4272
  }
4386
4273
 
4274
+ options.table_properties_collector_factories.clear();
4387
4275
  options.table_properties_collector_factories.emplace_back(
4388
4276
  std::make_shared<DbStressTablePropertiesCollectorFactory>());
4389
4277
 
@@ -48,7 +48,11 @@ class StressTest {
48
48
  return FLAGS_sync_fault_injection || FLAGS_disable_wal ||
49
49
  FLAGS_manual_wal_flush_one_in > 0;
50
50
  }
51
-
51
+ Status EnableAutoCompaction() {
52
+ assert(options_.disable_auto_compactions);
53
+ Status s = db_->EnableAutoCompaction(column_families_);
54
+ return s;
55
+ }
52
56
  void CleanUp();
53
57
 
54
58
  protected:
@@ -63,6 +67,55 @@ class StressTest {
63
67
  return 0;
64
68
  }
65
69
  }
70
+
71
+ void UpdateIfInitialWriteFails(Env* db_stress_env, const Status& write_s,
72
+ Status* initial_write_s,
73
+ bool* initial_wal_write_may_succeed,
74
+ uint64_t* wait_for_recover_start_time) {
75
+ assert(db_stress_env && initial_write_s && initial_wal_write_may_succeed &&
76
+ wait_for_recover_start_time);
77
+ // Only update `initial_write_s`, `initial_wal_write_may_succeed` when the
78
+ // first write fails
79
+ if (!write_s.ok() && (*initial_write_s).ok()) {
80
+ *initial_write_s = write_s;
81
+ *initial_wal_write_may_succeed =
82
+ !FaultInjectionTestFS::IsFailedToWriteToWALError(*initial_write_s);
83
+ *wait_for_recover_start_time = db_stress_env->NowMicros();
84
+ }
85
+ }
86
+
87
+ void PrintWriteRecoveryWaitTimeIfNeeded(Env* db_stress_env,
88
+ const Status& initial_write_s,
89
+ bool initial_wal_write_may_succeed,
90
+ uint64_t wait_for_recover_start_time,
91
+ const std::string& thread_name) {
92
+ assert(db_stress_env);
93
+ bool waited_for_recovery = !initial_write_s.ok() &&
94
+ IsErrorInjectedAndRetryable(initial_write_s) &&
95
+ initial_wal_write_may_succeed;
96
+ if (waited_for_recovery) {
97
+ uint64_t elapsed_sec =
98
+ (db_stress_env->NowMicros() - wait_for_recover_start_time) / 1000000;
99
+ if (elapsed_sec > 10) {
100
+ fprintf(stdout,
101
+ "%s thread slept to wait for write recovery for "
102
+ "%" PRIu64 " seconds\n",
103
+ thread_name.c_str(), elapsed_sec);
104
+ }
105
+ }
106
+ }
107
+ void GetDeleteRangeKeyLocks(
108
+ ThreadState* thread, int rand_column_family, int64_t rand_key,
109
+ std::vector<std::unique_ptr<MutexLock>>* range_locks) {
110
+ for (int j = 0; j < FLAGS_range_deletion_width; ++j) {
111
+ if (j == 0 ||
112
+ ((rand_key + j) & ((1 << FLAGS_log2_keys_per_lock) - 1)) == 0) {
113
+ range_locks->emplace_back(new MutexLock(
114
+ thread->shared->GetMutexForKey(rand_column_family, rand_key + j)));
115
+ }
116
+ }
117
+ }
118
+
66
119
  Status AssertSame(DB* db, ColumnFamilyHandle* cf,
67
120
  ThreadState::SnapshotState& snap_state);
68
121
 
@@ -283,7 +336,8 @@ class StressTest {
283
336
 
284
337
  bool IsErrorInjectedAndRetryable(const Status& error_s) const {
285
338
  assert(!error_s.ok());
286
- return error_s.getState() && std::strstr(error_s.getState(), "inject") &&
339
+ return error_s.getState() &&
340
+ FaultInjectionTestFS::IsInjectedError(error_s) &&
287
341
  !status_to_io_status(Status(error_s)).GetDataLoss();
288
342
  }
289
343
 
@@ -397,5 +451,6 @@ void InitializeOptionsGeneral(
397
451
  // user-defined timestamp.
398
452
  void CheckAndSetOptionsForUserTimestamp(Options& options);
399
453
 
454
+ bool ShouldDisableAutoCompactionsBeforeVerifyDb();
400
455
  } // namespace ROCKSDB_NAMESPACE
401
456
  #endif // GFLAGS
@@ -34,11 +34,19 @@ void ExpectedState::Precommit(int cf, int64_t key, const ExpectedValue& value) {
34
34
 
35
35
  PendingExpectedValue ExpectedState::PreparePut(int cf, int64_t key) {
36
36
  ExpectedValue expected_value = Load(cf, key);
37
+
38
+ // Calculate the original expected value
37
39
  const ExpectedValue orig_expected_value = expected_value;
40
+
41
+ // Calculate the pending expected value
38
42
  expected_value.Put(true /* pending */);
39
43
  const ExpectedValue pending_expected_value = expected_value;
44
+
45
+ // Calculate the final expected value
40
46
  expected_value.Put(false /* pending */);
41
47
  const ExpectedValue final_expected_value = expected_value;
48
+
49
+ // Precommit
42
50
  Precommit(cf, key, pending_expected_value);
43
51
  return PendingExpectedValue(&Value(cf, key), orig_expected_value,
44
52
  final_expected_value);
@@ -46,21 +54,26 @@ PendingExpectedValue ExpectedState::PreparePut(int cf, int64_t key) {
46
54
 
47
55
  ExpectedValue ExpectedState::Get(int cf, int64_t key) { return Load(cf, key); }
48
56
 
49
- PendingExpectedValue ExpectedState::PrepareDelete(int cf, int64_t key,
50
- bool* prepared) {
57
+ PendingExpectedValue ExpectedState::PrepareDelete(int cf, int64_t key) {
51
58
  ExpectedValue expected_value = Load(cf, key);
59
+
60
+ // Calculate the original expected value
52
61
  const ExpectedValue orig_expected_value = expected_value;
62
+
63
+ // Calculate the pending expected value
53
64
  bool res = expected_value.Delete(true /* pending */);
54
- if (prepared) {
55
- *prepared = res;
56
- }
57
65
  if (!res) {
58
- return PendingExpectedValue(&Value(cf, key), orig_expected_value,
59
- orig_expected_value);
66
+ PendingExpectedValue ret = PendingExpectedValue(
67
+ &Value(cf, key), orig_expected_value, orig_expected_value);
68
+ return ret;
60
69
  }
61
70
  const ExpectedValue pending_expected_value = expected_value;
71
+
72
+ // Calculate the final expected value
62
73
  expected_value.Delete(false /* pending */);
63
74
  const ExpectedValue final_expected_value = expected_value;
75
+
76
+ // Precommit
64
77
  Precommit(cf, key, pending_expected_value);
65
78
  return PendingExpectedValue(&Value(cf, key), orig_expected_value,
66
79
  final_expected_value);
@@ -73,16 +86,11 @@ PendingExpectedValue ExpectedState::PrepareSingleDelete(int cf, int64_t key) {
73
86
  std::vector<PendingExpectedValue> ExpectedState::PrepareDeleteRange(
74
87
  int cf, int64_t begin_key, int64_t end_key) {
75
88
  std::vector<PendingExpectedValue> pending_expected_values;
89
+
76
90
  for (int64_t key = begin_key; key < end_key; ++key) {
77
- bool prepared = false;
78
- PendingExpectedValue pending_expected_value =
79
- PrepareDelete(cf, key, &prepared);
80
- if (prepared) {
81
- pending_expected_values.push_back(pending_expected_value);
82
- } else {
83
- pending_expected_value.PermitUnclosedPendingState();
84
- }
91
+ pending_expected_values.push_back(PrepareDelete(cf, key));
85
92
  }
93
+
86
94
  return pending_expected_values;
87
95
  }
88
96
 
@@ -49,14 +49,13 @@ class ExpectedState {
49
49
  // Does not requires external locking.
50
50
  ExpectedValue Get(int cf, int64_t key);
51
51
 
52
- // Prepare a Delete that will be started but not finished yet
52
+ // Prepare a Delete that will be started but not finished yet.
53
53
  // This is useful for crash-recovery testing when the process may crash
54
54
  // before updating the corresponding expected value
55
55
  //
56
56
  // Requires external locking covering `key` in `cf` to prevent concurrent
57
57
  // write or delete to the same `key`.
58
- PendingExpectedValue PrepareDelete(int cf, int64_t key,
59
- bool* prepared = nullptr);
58
+ PendingExpectedValue PrepareDelete(int cf, int64_t key);
60
59
 
61
60
  // Requires external locking covering `key` in `cf` to prevent concurrent
62
61
  // write or delete to the same `key`.
@@ -21,7 +21,7 @@ void ExpectedValue::Put(bool pending) {
21
21
  }
22
22
 
23
23
  bool ExpectedValue::Delete(bool pending) {
24
- if (!Exists()) {
24
+ if (pending && !Exists()) {
25
25
  return false;
26
26
  }
27
27
  if (pending) {
@@ -37,7 +37,10 @@ class ExpectedValue {
37
37
  explicit ExpectedValue(uint32_t expected_value)
38
38
  : expected_value_(expected_value) {}
39
39
 
40
- bool Exists() const { return PendingWrite() || !IsDeleted(); }
40
+ bool Exists() const {
41
+ assert(!PendingWrite() && !PendingDelete());
42
+ return !IsDeleted();
43
+ }
41
44
 
42
45
  uint32_t Read() const { return expected_value_; }
43
46