@nxtedition/rocksdb 7.0.23 → 7.0.26

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 (146) hide show
  1. package/binding.cc +3 -1
  2. package/deps/rocksdb/rocksdb/CMakeLists.txt +5 -0
  3. package/deps/rocksdb/rocksdb/Makefile +6 -2
  4. package/deps/rocksdb/rocksdb/TARGETS +14 -0
  5. package/deps/rocksdb/rocksdb/cache/cache_bench_tool.cc +4 -1
  6. package/deps/rocksdb/rocksdb/cache/cache_helpers.h +20 -0
  7. package/deps/rocksdb/rocksdb/cache/cache_reservation_manager_test.cc +2 -2
  8. package/deps/rocksdb/rocksdb/cache/cache_test.cc +44 -31
  9. package/deps/rocksdb/rocksdb/cache/clock_cache.cc +491 -722
  10. package/deps/rocksdb/rocksdb/cache/clock_cache.h +468 -2
  11. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.cc +1 -1
  12. package/deps/rocksdb/rocksdb/cache/fast_lru_cache.cc +51 -52
  13. package/deps/rocksdb/rocksdb/cache/fast_lru_cache.h +28 -16
  14. package/deps/rocksdb/rocksdb/cache/lru_cache.cc +12 -1
  15. package/deps/rocksdb/rocksdb/cache/lru_cache.h +1 -0
  16. package/deps/rocksdb/rocksdb/cache/lru_cache_test.cc +170 -36
  17. package/deps/rocksdb/rocksdb/db/blob/blob_file_cache_test.cc +1 -1
  18. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader.cc +63 -36
  19. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader.h +4 -6
  20. package/deps/rocksdb/rocksdb/db/blob/blob_file_reader_test.cc +57 -38
  21. package/deps/rocksdb/rocksdb/db/blob/blob_read_request.h +58 -0
  22. package/deps/rocksdb/rocksdb/db/blob/blob_source.cc +164 -74
  23. package/deps/rocksdb/rocksdb/db/blob/blob_source.h +42 -29
  24. package/deps/rocksdb/rocksdb/db/blob/blob_source_test.cc +419 -62
  25. package/deps/rocksdb/rocksdb/db/blob/db_blob_basic_test.cc +208 -8
  26. package/deps/rocksdb/rocksdb/db/c.cc +68 -0
  27. package/deps/rocksdb/rocksdb/db/c_test.c +95 -2
  28. package/deps/rocksdb/rocksdb/db/column_family.cc +12 -3
  29. package/deps/rocksdb/rocksdb/db/compaction/compaction.cc +92 -15
  30. package/deps/rocksdb/rocksdb/db/compaction/compaction.h +76 -4
  31. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +52 -1
  32. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +30 -1
  33. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator_test.cc +126 -0
  34. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +203 -1584
  35. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +93 -26
  36. package/deps/rocksdb/rocksdb/db/compaction/compaction_job_test.cc +87 -1
  37. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.cc +314 -0
  38. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +328 -0
  39. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.cc +32 -6
  40. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.h +4 -1
  41. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.cc +7 -3
  42. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_level.cc +174 -33
  43. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +474 -7
  44. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.cc +5 -2
  45. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_job.cc +825 -0
  46. package/deps/rocksdb/rocksdb/db/compaction/compaction_state.cc +46 -0
  47. package/deps/rocksdb/rocksdb/db/compaction/compaction_state.h +42 -0
  48. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.cc +223 -0
  49. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.h +255 -0
  50. package/deps/rocksdb/rocksdb/db/compaction/tiered_compaction_test.cc +1253 -0
  51. package/deps/rocksdb/rocksdb/db/corruption_test.cc +32 -8
  52. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +3 -1
  53. package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +13 -8
  54. package/deps/rocksdb/rocksdb/db/db_bloom_filter_test.cc +376 -0
  55. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +103 -78
  56. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +4 -6
  57. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +0 -8
  58. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +10 -3
  59. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +21 -6
  60. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +19 -1
  61. package/deps/rocksdb/rocksdb/db/db_iter.cc +91 -14
  62. package/deps/rocksdb/rocksdb/db/db_iter.h +5 -0
  63. package/deps/rocksdb/rocksdb/db/db_kv_checksum_test.cc +33 -0
  64. package/deps/rocksdb/rocksdb/db/db_properties_test.cc +79 -0
  65. package/deps/rocksdb/rocksdb/db/db_range_del_test.cc +2 -0
  66. package/deps/rocksdb/rocksdb/db/db_test2.cc +1 -1
  67. package/deps/rocksdb/rocksdb/db/db_wal_test.cc +5 -2
  68. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +185 -0
  69. package/deps/rocksdb/rocksdb/db/dbformat.cc +1 -4
  70. package/deps/rocksdb/rocksdb/db/dbformat.h +2 -8
  71. package/deps/rocksdb/rocksdb/db/internal_stats.cc +71 -29
  72. package/deps/rocksdb/rocksdb/db/internal_stats.h +160 -5
  73. package/deps/rocksdb/rocksdb/db/log_reader.cc +29 -3
  74. package/deps/rocksdb/rocksdb/db/log_reader.h +12 -3
  75. package/deps/rocksdb/rocksdb/db/repair_test.cc +1 -3
  76. package/deps/rocksdb/rocksdb/db/version_edit.cc +6 -0
  77. package/deps/rocksdb/rocksdb/db/version_set.cc +93 -129
  78. package/deps/rocksdb/rocksdb/db/version_set.h +4 -4
  79. package/deps/rocksdb/rocksdb/db/version_set_sync_and_async.h +2 -2
  80. package/deps/rocksdb/rocksdb/db/version_set_test.cc +42 -35
  81. package/deps/rocksdb/rocksdb/db/write_batch.cc +10 -2
  82. package/deps/rocksdb/rocksdb/db/write_batch_internal.h +4 -1
  83. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.cc +10 -4
  84. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +3 -3
  85. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_driver.cc +3 -2
  86. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +4 -0
  87. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_shared_state.h +5 -1
  88. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +140 -8
  89. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.h +12 -0
  90. package/deps/rocksdb/rocksdb/db_stress_tool/multi_ops_txns_stress.cc +46 -7
  91. package/deps/rocksdb/rocksdb/db_stress_tool/multi_ops_txns_stress.h +7 -0
  92. package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +27 -7
  93. package/deps/rocksdb/rocksdb/env/composite_env_wrapper.h +8 -0
  94. package/deps/rocksdb/rocksdb/env/env_posix.cc +14 -0
  95. package/deps/rocksdb/rocksdb/env/env_test.cc +130 -1
  96. package/deps/rocksdb/rocksdb/env/fs_posix.cc +7 -1
  97. package/deps/rocksdb/rocksdb/env/io_posix.cc +18 -50
  98. package/deps/rocksdb/rocksdb/env/io_posix.h +53 -6
  99. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +8 -10
  100. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +3 -7
  101. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +239 -259
  102. package/deps/rocksdb/rocksdb/file/random_access_file_reader.cc +84 -19
  103. package/deps/rocksdb/rocksdb/file/random_access_file_reader.h +24 -4
  104. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +1 -1
  105. package/deps/rocksdb/rocksdb/include/rocksdb/c.h +31 -1
  106. package/deps/rocksdb/rocksdb/include/rocksdb/cache.h +11 -7
  107. package/deps/rocksdb/rocksdb/include/rocksdb/compaction_job_stats.h +2 -0
  108. package/deps/rocksdb/rocksdb/include/rocksdb/db.h +14 -0
  109. package/deps/rocksdb/rocksdb/include/rocksdb/env.h +20 -0
  110. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +37 -13
  111. package/deps/rocksdb/rocksdb/include/rocksdb/perf_context.h +7 -0
  112. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +14 -0
  113. package/deps/rocksdb/rocksdb/include/rocksdb/threadpool.h +9 -0
  114. package/deps/rocksdb/rocksdb/include/rocksdb/write_batch.h +13 -13
  115. package/deps/rocksdb/rocksdb/logging/auto_roll_logger.cc +12 -2
  116. package/deps/rocksdb/rocksdb/monitoring/perf_context.cc +38 -0
  117. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +7 -1
  118. package/deps/rocksdb/rocksdb/port/win/env_win.cc +17 -0
  119. package/deps/rocksdb/rocksdb/port/win/env_win.h +8 -0
  120. package/deps/rocksdb/rocksdb/port/win/io_win.cc +6 -3
  121. package/deps/rocksdb/rocksdb/src.mk +5 -0
  122. package/deps/rocksdb/rocksdb/table/block_based/block.h +1 -2
  123. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +1 -1
  124. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.cc +5 -2
  125. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +1 -1
  126. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_impl.h +15 -12
  127. package/deps/rocksdb/rocksdb/table/block_based/block_prefetcher.cc +5 -4
  128. package/deps/rocksdb/rocksdb/table/block_based/block_prefetcher.h +2 -1
  129. package/deps/rocksdb/rocksdb/table/block_based/filter_policy.cc +1 -1
  130. package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_iterator.cc +4 -4
  131. package/deps/rocksdb/rocksdb/table/block_fetcher.cc +1 -2
  132. package/deps/rocksdb/rocksdb/table/get_context.cc +1 -0
  133. package/deps/rocksdb/rocksdb/table/sst_file_dumper.cc +1 -2
  134. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +24 -4
  135. package/deps/rocksdb/rocksdb/util/async_file_reader.cc +1 -1
  136. package/deps/rocksdb/rocksdb/util/compression.h +2 -0
  137. package/deps/rocksdb/rocksdb/util/thread_list_test.cc +18 -1
  138. package/deps/rocksdb/rocksdb/util/threadpool_imp.cc +67 -4
  139. package/deps/rocksdb/rocksdb/util/threadpool_imp.h +8 -0
  140. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine.cc +15 -12
  141. package/deps/rocksdb/rocksdb/utilities/backup/backup_engine_test.cc +4 -2
  142. package/deps/rocksdb/rocksdb/utilities/simulator_cache/sim_cache_test.cc +1 -1
  143. package/deps/rocksdb/rocksdb.gyp +5 -1
  144. package/package.json +1 -1
  145. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  146. package/prebuilds/linux-x64/node.napi.node +0 -0
@@ -20,8 +20,6 @@
20
20
  #include "rocksdb/system_clock.h"
21
21
  #include "util/hash_containers.h"
22
22
 
23
- class ColumnFamilyData;
24
-
25
23
  namespace ROCKSDB_NAMESPACE {
26
24
 
27
25
  template <class Stats>
@@ -140,6 +138,23 @@ class InternalStats {
140
138
 
141
139
  InternalStats(int num_levels, SystemClock* clock, ColumnFamilyData* cfd);
142
140
 
141
+ // Per level compaction stats
142
+ struct CompactionOutputsStats {
143
+ uint64_t num_output_records = 0;
144
+ uint64_t bytes_written = 0;
145
+ uint64_t bytes_written_blob = 0;
146
+ uint64_t num_output_files = 0;
147
+ uint64_t num_output_files_blob = 0;
148
+
149
+ void Add(const CompactionOutputsStats& stats) {
150
+ this->num_output_records += stats.num_output_records;
151
+ this->bytes_written += stats.bytes_written;
152
+ this->bytes_written_blob += stats.bytes_written_blob;
153
+ this->num_output_files += stats.num_output_files;
154
+ this->num_output_files_blob += stats.num_output_files_blob;
155
+ }
156
+ };
157
+
143
158
  // Per level compaction stats. comp_stats_[level] stores the stats for
144
159
  // compactions that produced data for the specified "level".
145
160
  struct CompactionStats {
@@ -184,11 +199,14 @@ class InternalStats {
184
199
  // (num input entries - num output entries) for compaction levels N and N+1
185
200
  uint64_t num_dropped_records;
186
201
 
202
+ // Total output entries from compaction
203
+ uint64_t num_output_records;
204
+
187
205
  // Number of compactions done
188
206
  int count;
189
207
 
190
208
  // Number of compactions done per CompactionReason
191
- int counts[static_cast<int>(CompactionReason::kNumOfReasons)];
209
+ int counts[static_cast<int>(CompactionReason::kNumOfReasons)]{};
192
210
 
193
211
  explicit CompactionStats()
194
212
  : micros(0),
@@ -205,6 +223,7 @@ class InternalStats {
205
223
  num_output_files_blob(0),
206
224
  num_input_records(0),
207
225
  num_dropped_records(0),
226
+ num_output_records(0),
208
227
  count(0) {
209
228
  int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
210
229
  for (int i = 0; i < num_of_reasons; i++) {
@@ -227,6 +246,7 @@ class InternalStats {
227
246
  num_output_files_blob(0),
228
247
  num_input_records(0),
229
248
  num_dropped_records(0),
249
+ num_output_records(0),
230
250
  count(c) {
231
251
  int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
232
252
  for (int i = 0; i < num_of_reasons; i++) {
@@ -240,7 +260,7 @@ class InternalStats {
240
260
  }
241
261
  }
242
262
 
243
- explicit CompactionStats(const CompactionStats& c)
263
+ CompactionStats(const CompactionStats& c)
244
264
  : micros(c.micros),
245
265
  cpu_micros(c.cpu_micros),
246
266
  bytes_read_non_output_levels(c.bytes_read_non_output_levels),
@@ -256,6 +276,7 @@ class InternalStats {
256
276
  num_output_files_blob(c.num_output_files_blob),
257
277
  num_input_records(c.num_input_records),
258
278
  num_dropped_records(c.num_dropped_records),
279
+ num_output_records(c.num_output_records),
259
280
  count(c.count) {
260
281
  int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
261
282
  for (int i = 0; i < num_of_reasons; i++) {
@@ -279,6 +300,7 @@ class InternalStats {
279
300
  num_output_files_blob = c.num_output_files_blob;
280
301
  num_input_records = c.num_input_records;
281
302
  num_dropped_records = c.num_dropped_records;
303
+ num_output_records = c.num_output_records;
282
304
  count = c.count;
283
305
 
284
306
  int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
@@ -303,6 +325,7 @@ class InternalStats {
303
325
  this->num_output_files_blob = 0;
304
326
  this->num_input_records = 0;
305
327
  this->num_dropped_records = 0;
328
+ this->num_output_records = 0;
306
329
  this->count = 0;
307
330
  int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
308
331
  for (int i = 0; i < num_of_reasons; i++) {
@@ -327,6 +350,7 @@ class InternalStats {
327
350
  this->num_output_files_blob += c.num_output_files_blob;
328
351
  this->num_input_records += c.num_input_records;
329
352
  this->num_dropped_records += c.num_dropped_records;
353
+ this->num_output_records += c.num_output_records;
330
354
  this->count += c.count;
331
355
  int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
332
356
  for (int i = 0; i< num_of_reasons; i++) {
@@ -334,6 +358,15 @@ class InternalStats {
334
358
  }
335
359
  }
336
360
 
361
+ void Add(const CompactionOutputsStats& stats) {
362
+ this->num_output_files += static_cast<int>(stats.num_output_files);
363
+ this->num_output_records += stats.num_output_records;
364
+ this->bytes_written += stats.bytes_written;
365
+ this->bytes_written_blob += stats.bytes_written_blob;
366
+ this->num_output_files_blob +=
367
+ static_cast<int>(stats.num_output_files_blob);
368
+ }
369
+
337
370
  void Subtract(const CompactionStats& c) {
338
371
  this->micros -= c.micros;
339
372
  this->cpu_micros -= c.cpu_micros;
@@ -351,12 +384,70 @@ class InternalStats {
351
384
  this->num_output_files_blob -= c.num_output_files_blob;
352
385
  this->num_input_records -= c.num_input_records;
353
386
  this->num_dropped_records -= c.num_dropped_records;
387
+ this->num_output_records -= c.num_output_records;
354
388
  this->count -= c.count;
355
389
  int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
356
390
  for (int i = 0; i < num_of_reasons; i++) {
357
391
  counts[i] -= c.counts[i];
358
392
  }
359
393
  }
394
+
395
+ void ResetCompactionReason(CompactionReason reason) {
396
+ int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
397
+ assert(count == 1); // only support update one compaction reason
398
+ for (int i = 0; i < num_of_reasons; i++) {
399
+ counts[i] = 0;
400
+ }
401
+ int r = static_cast<int>(reason);
402
+ assert(r >= 0 && r < num_of_reasons);
403
+ counts[r] = 1;
404
+ }
405
+ };
406
+
407
+ // Compaction stats, for per_key_placement compaction, it includes 2 levels
408
+ // stats: the last level and the penultimate level.
409
+ struct CompactionStatsFull {
410
+ // the stats for the target primary output level
411
+ CompactionStats stats;
412
+
413
+ // stats for penultimate level output if exist
414
+ bool has_penultimate_level_output = false;
415
+ CompactionStats penultimate_level_stats;
416
+
417
+ explicit CompactionStatsFull() : stats(), penultimate_level_stats() {}
418
+
419
+ explicit CompactionStatsFull(CompactionReason reason, int c)
420
+ : stats(reason, c), penultimate_level_stats(reason, c){};
421
+
422
+ uint64_t TotalBytesWritten() const {
423
+ uint64_t bytes_written = stats.bytes_written + stats.bytes_written_blob;
424
+ if (has_penultimate_level_output) {
425
+ bytes_written += penultimate_level_stats.bytes_written +
426
+ penultimate_level_stats.bytes_written_blob;
427
+ }
428
+ return bytes_written;
429
+ }
430
+
431
+ uint64_t DroppedRecords() {
432
+ uint64_t output_records = stats.num_output_records;
433
+ if (has_penultimate_level_output) {
434
+ output_records += penultimate_level_stats.num_output_records;
435
+ }
436
+ if (stats.num_input_records > output_records) {
437
+ return stats.num_input_records - output_records;
438
+ }
439
+ return 0;
440
+ }
441
+
442
+ void SetMicros(uint64_t val) {
443
+ stats.micros = val;
444
+ penultimate_level_stats.micros = val;
445
+ }
446
+
447
+ void AddCpuMicros(uint64_t val) {
448
+ stats.cpu_micros += val;
449
+ penultimate_level_stats.cpu_micros += val;
450
+ }
360
451
  };
361
452
 
362
453
  // For use with CacheEntryStatsCollector
@@ -403,6 +494,7 @@ class InternalStats {
403
494
  for (auto& comp_stat : comp_stats_) {
404
495
  comp_stat.Clear();
405
496
  }
497
+ per_key_placement_comp_stats_.Clear();
406
498
  for (auto& h : file_read_latency_) {
407
499
  h.Clear();
408
500
  }
@@ -419,6 +511,15 @@ class InternalStats {
419
511
  comp_stats_by_pri_[thread_pri].Add(stats);
420
512
  }
421
513
 
514
+ void AddCompactionStats(int level, Env::Priority thread_pri,
515
+ const CompactionStatsFull& comp_stats_full) {
516
+ AddCompactionStats(level, thread_pri, comp_stats_full.stats);
517
+ if (comp_stats_full.has_penultimate_level_output) {
518
+ per_key_placement_comp_stats_.Add(
519
+ comp_stats_full.penultimate_level_stats);
520
+ }
521
+ }
522
+
422
523
  void IncBytesMoved(int level, uint64_t amount) {
423
524
  comp_stats_[level].bytes_moved += amount;
424
525
  }
@@ -479,6 +580,10 @@ class InternalStats {
479
580
  return comp_stats_;
480
581
  }
481
582
 
583
+ const CompactionStats& TEST_GetPerKeyPlacementCompactionStats() const {
584
+ return per_key_placement_comp_stats_;
585
+ }
586
+
482
587
  void TEST_GetCacheEntryRoleStats(CacheEntryRoleStats* stats, bool foreground);
483
588
 
484
589
  // Store a mapping from the user-facing DB::Properties string to our
@@ -500,7 +605,8 @@ class InternalStats {
500
605
  void DumpCFStatsNoFileHistogram(std::string* value);
501
606
  void DumpCFFileHistogram(std::string* value);
502
607
 
503
- bool GetBlockCacheForStats(Cache** block_cache);
608
+ Cache* GetBlockCacheForStats();
609
+ Cache* GetBlobCacheForStats();
504
610
 
505
611
  // Per-DB stats
506
612
  std::atomic<uint64_t> db_stats_[kIntStatsNumMax];
@@ -517,6 +623,7 @@ class InternalStats {
517
623
  // Per-ColumnFamily/level compaction stats
518
624
  std::vector<CompactionStats> comp_stats_;
519
625
  std::vector<CompactionStats> comp_stats_by_pri_;
626
+ CompactionStats per_key_placement_comp_stats_;
520
627
  std::vector<HistogramImpl> file_read_latency_;
521
628
  HistogramImpl blob_file_read_latency_;
522
629
 
@@ -693,6 +800,10 @@ class InternalStats {
693
800
  bool HandleLiveBlobFileSize(uint64_t* value, DBImpl* db, Version* version);
694
801
  bool HandleLiveBlobFileGarbageSize(uint64_t* value, DBImpl* db,
695
802
  Version* version);
803
+ bool HandleBlobCacheCapacity(uint64_t* value, DBImpl* db, Version* version);
804
+ bool HandleBlobCacheUsage(uint64_t* value, DBImpl* db, Version* version);
805
+ bool HandleBlobCachePinnedUsage(uint64_t* value, DBImpl* db,
806
+ Version* version);
696
807
 
697
808
  // Total number of background errors encountered. Every time a flush task
698
809
  // or compaction task fails, this counter is incremented. The failure can
@@ -744,6 +855,23 @@ class InternalStats {
744
855
  InternalStats(int /*num_levels*/, SystemClock* /*clock*/,
745
856
  ColumnFamilyData* /*cfd*/) {}
746
857
 
858
+ // Per level compaction stats
859
+ struct CompactionOutputsStats {
860
+ uint64_t num_output_records = 0;
861
+ uint64_t bytes_written = 0;
862
+ uint64_t bytes_written_blob = 0;
863
+ uint64_t num_output_files = 0;
864
+ uint64_t num_output_files_blob = 0;
865
+
866
+ void Add(const CompactionOutputsStats& stats) {
867
+ this->num_output_records += stats.num_output_records;
868
+ this->bytes_written += stats.bytes_written;
869
+ this->bytes_written_blob += stats.bytes_written_blob;
870
+ this->num_output_files += stats.num_output_files;
871
+ this->num_output_files_blob += stats.num_output_files_blob;
872
+ }
873
+ };
874
+
747
875
  struct CompactionStats {
748
876
  uint64_t micros;
749
877
  uint64_t cpu_micros;
@@ -759,6 +887,7 @@ class InternalStats {
759
887
  int num_output_files_blob;
760
888
  uint64_t num_input_records;
761
889
  uint64_t num_dropped_records;
890
+ uint64_t num_output_records;
762
891
  int count;
763
892
 
764
893
  explicit CompactionStats() {}
@@ -769,12 +898,38 @@ class InternalStats {
769
898
 
770
899
  void Add(const CompactionStats& /*c*/) {}
771
900
 
901
+ void Add(const CompactionOutputsStats& /*c*/) {}
902
+
772
903
  void Subtract(const CompactionStats& /*c*/) {}
773
904
  };
774
905
 
906
+ struct CompactionStatsFull {
907
+ // the stats for the target primary output level (per level stats)
908
+ CompactionStats stats;
909
+
910
+ // stats for output_to_penultimate_level level (per level stats)
911
+ bool has_penultimate_level_output = false;
912
+ CompactionStats penultimate_level_stats;
913
+
914
+ explicit CompactionStatsFull(){};
915
+
916
+ explicit CompactionStatsFull(CompactionReason /*reason*/, int /*c*/){};
917
+
918
+ uint64_t TotalBytesWritten() const { return 0; }
919
+
920
+ uint64_t DroppedRecords() { return 0; }
921
+
922
+ void SetMicros(uint64_t /*val*/){};
923
+
924
+ void AddCpuMicros(uint64_t /*val*/){};
925
+ };
926
+
775
927
  void AddCompactionStats(int /*level*/, Env::Priority /*thread_pri*/,
776
928
  const CompactionStats& /*stats*/) {}
777
929
 
930
+ void AddCompactionStats(int /*level*/, Env::Priority /*thread_pri*/,
931
+ const CompactionStatsFull& /*unmerged_stats*/) {}
932
+
778
933
  void IncBytesMoved(int /*level*/, uint64_t /*amount*/) {}
779
934
 
780
935
  void AddCFStats(InternalCFStatsType /*type*/, uint64_t /*value*/) {}
@@ -43,13 +43,17 @@ Reader::Reader(std::shared_ptr<Logger> info_log,
43
43
  first_record_read_(false),
44
44
  compression_type_(kNoCompression),
45
45
  compression_type_record_read_(false),
46
- uncompress_(nullptr) {}
46
+ uncompress_(nullptr),
47
+ hash_state_(nullptr) {}
47
48
 
48
49
  Reader::~Reader() {
49
50
  delete[] backing_store_;
50
51
  if (uncompress_) {
51
52
  delete uncompress_;
52
53
  }
54
+ if (hash_state_) {
55
+ XXH3_freeState(hash_state_);
56
+ }
53
57
  }
54
58
 
55
59
  // For kAbsoluteConsistency, on clean shutdown we don't expect any error
@@ -60,9 +64,15 @@ Reader::~Reader() {
60
64
  // TODO krad: Evaluate if we need to move to a more strict mode where we
61
65
  // restrict the inconsistency to only the last log
62
66
  bool Reader::ReadRecord(Slice* record, std::string* scratch,
63
- WALRecoveryMode wal_recovery_mode) {
67
+ WALRecoveryMode wal_recovery_mode, uint64_t* checksum) {
64
68
  scratch->clear();
65
69
  record->clear();
70
+ if (checksum != nullptr) {
71
+ if (hash_state_ == nullptr) {
72
+ hash_state_ = XXH3_createState();
73
+ }
74
+ XXH3_64bits_reset(hash_state_);
75
+ }
66
76
  if (uncompress_) {
67
77
  uncompress_->Reset();
68
78
  }
@@ -86,6 +96,10 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
86
96
  // at the beginning of the next block.
87
97
  ReportCorruption(scratch->size(), "partial record without end(1)");
88
98
  }
99
+ if (checksum != nullptr) {
100
+ // No need to stream since the record is a single fragment
101
+ *checksum = XXH3_64bits(fragment.data(), fragment.size());
102
+ }
89
103
  prospective_record_offset = physical_record_offset;
90
104
  scratch->clear();
91
105
  *record = fragment;
@@ -101,6 +115,10 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
101
115
  // of a block followed by a kFullType or kFirstType record
102
116
  // at the beginning of the next block.
103
117
  ReportCorruption(scratch->size(), "partial record without end(2)");
118
+ XXH3_64bits_reset(hash_state_);
119
+ }
120
+ if (checksum != nullptr) {
121
+ XXH3_64bits_update(hash_state_, fragment.data(), fragment.size());
104
122
  }
105
123
  prospective_record_offset = physical_record_offset;
106
124
  scratch->assign(fragment.data(), fragment.size());
@@ -113,6 +131,9 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
113
131
  ReportCorruption(fragment.size(),
114
132
  "missing start of fragmented record(1)");
115
133
  } else {
134
+ if (checksum != nullptr) {
135
+ XXH3_64bits_update(hash_state_, fragment.data(), fragment.size());
136
+ }
116
137
  scratch->append(fragment.data(), fragment.size());
117
138
  }
118
139
  break;
@@ -123,6 +144,10 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
123
144
  ReportCorruption(fragment.size(),
124
145
  "missing start of fragmented record(2)");
125
146
  } else {
147
+ if (checksum != nullptr) {
148
+ XXH3_64bits_update(hash_state_, fragment.data(), fragment.size());
149
+ *checksum = XXH3_64bits_digest(hash_state_);
150
+ }
126
151
  scratch->append(fragment.data(), fragment.size());
127
152
  *record = Slice(*scratch);
128
153
  last_record_offset_ = prospective_record_offset;
@@ -509,7 +534,8 @@ void Reader::InitCompression(const CompressionTypeRecord& compression_record) {
509
534
  }
510
535
 
511
536
  bool FragmentBufferedReader::ReadRecord(Slice* record, std::string* scratch,
512
- WALRecoveryMode /*unused*/) {
537
+ WALRecoveryMode /*unused*/,
538
+ uint64_t* /* checksum */) {
513
539
  assert(record != nullptr);
514
540
  assert(scratch != nullptr);
515
541
  record->clear();
@@ -18,6 +18,7 @@
18
18
  #include "rocksdb/slice.h"
19
19
  #include "rocksdb/status.h"
20
20
  #include "util/compression.h"
21
+ #include "util/xxhash.h"
21
22
 
22
23
  namespace ROCKSDB_NAMESPACE {
23
24
  class Logger;
@@ -61,12 +62,17 @@ class Reader {
61
62
 
62
63
  // Read the next record into *record. Returns true if read
63
64
  // successfully, false if we hit end of the input. May use
64
- // "*scratch" as temporary storage. The contents filled in *record
65
+ // "*scratch" as temporary storage. The contents filled in *record
65
66
  // will only be valid until the next mutating operation on this
66
67
  // reader or the next mutation to *scratch.
68
+ // If record_checksum is not nullptr, then this function will calculate the
69
+ // checksum of the record read and set record_checksum to it. The checksum is
70
+ // calculated from the original buffers that contain the contents of the
71
+ // record.
67
72
  virtual bool ReadRecord(Slice* record, std::string* scratch,
68
73
  WALRecoveryMode wal_recovery_mode =
69
- WALRecoveryMode::kTolerateCorruptedTailRecords);
74
+ WALRecoveryMode::kTolerateCorruptedTailRecords,
75
+ uint64_t* record_checksum = nullptr);
70
76
 
71
77
  // Returns the physical offset of the last record returned by ReadRecord.
72
78
  //
@@ -145,6 +151,8 @@ class Reader {
145
151
  std::unique_ptr<char[]> uncompressed_buffer_;
146
152
  // Reusable uncompressed record
147
153
  std::string uncompressed_record_;
154
+ // Used for stream hashing log record
155
+ XXH3_state_t* hash_state_;
148
156
 
149
157
  // Extend record types with the following special values
150
158
  enum {
@@ -191,7 +199,8 @@ class FragmentBufferedReader : public Reader {
191
199
  ~FragmentBufferedReader() override {}
192
200
  bool ReadRecord(Slice* record, std::string* scratch,
193
201
  WALRecoveryMode wal_recovery_mode =
194
- WALRecoveryMode::kTolerateCorruptedTailRecords) override;
202
+ WALRecoveryMode::kTolerateCorruptedTailRecords,
203
+ uint64_t* record_checksum = nullptr) override;
195
204
  void UnmarkEOF() override;
196
205
 
197
206
  private:
@@ -385,9 +385,7 @@ TEST_F(RepairTest, RepairColumnFamilyOptions) {
385
385
  ASSERT_OK(db_->GetPropertiesOfAllTables(handles_[1], &fname_to_props));
386
386
  ASSERT_EQ(fname_to_props.size(), 2U);
387
387
  for (const auto& fname_and_props : fname_to_props) {
388
- std::string comparator_name (
389
- InternalKeyComparator(rev_opts.comparator).Name());
390
- comparator_name = comparator_name.substr(comparator_name.find(':') + 1);
388
+ std::string comparator_name(rev_opts.comparator->Name());
391
389
  ASSERT_EQ(comparator_name,
392
390
  fname_and_props.second->comparator_name);
393
391
  }
@@ -799,6 +799,12 @@ std::string VersionEdit::DebugString(bool hex_key) const {
799
799
  r.append("\n LastSeq: ");
800
800
  AppendNumberTo(&r, last_sequence_);
801
801
  }
802
+ for (const auto& level_and_compact_cursor : compact_cursors_) {
803
+ r.append("\n CompactCursor: ");
804
+ AppendNumberTo(&r, level_and_compact_cursor.first);
805
+ r.append(" ");
806
+ r.append(level_and_compact_cursor.second.DebugString(hex_key));
807
+ }
802
808
  for (const auto& deleted_file : deleted_files_) {
803
809
  r.append("\n DeleteFile: ");
804
810
  AppendNumberTo(&r, deleted_file.first);