Skip to content

Commit e66c2a7

Browse files
hx235SoujanyaPonnapalli
authored andcommitted
Reduce universal compaction input lock time by forwarding intended compaction and re-picking (facebook#13633)
Summary: **Context:** RocksDB currently selects files for long-running compaction outputs to the bottommost level, preventing these selected files files from being selected, but does not execute the compaction immediately like other compactions. Instead, this compaction is forwarded to another Env::Priority::bottom thread pool, where it waits (potentially for a long time) until its thread is ready to execute. This extended L0 lock time in universal compaction caused our users write stall and read performance regression. **Summary:** This PR is to eliminate L0 lock time during bottom priority compaction waiting to execute by the following - Create and forward an intended compaction only consists of last input file (or sorted run if non-L0) instead of all the input files. This eliminate the locking for non-bottommost level input files while waiting for bottom priority thread is up to run. - Re-pick compaction that outputs to max output level when bottom priority thread is up to run - Refactor universal compaction picking logic to make it cleaner and easier to force picking compaction with max output level when bottom priority thread is up to run - Guard feature behind a temporary option as requested Pull Request resolved: facebook#13633 Test Plan: - New unit test to cover the case that's not covered by existing tests - bottom priority thread re-picks compaction ends up picking nothing due to LSM shape changes - Adapted existing unit tests to verify various bottom priority compaction behavior with this new option - Stress test `python3 tools/db_crashtest.py --simple blackbox --compaction_style=1 --target_file_size_base=1000 --write_buffer_size=1000 --compact_range_one_in=10000 --compact_files_one_in=10000 ` Reviewed By: cbi42 Differential Revision: D76005505 Pulled By: hx235 fbshipit-source-id: 9688f22d4a84f619452820f12f15b765c17301fd
1 parent ebb761c commit e66c2a7

23 files changed

+834
-364
lines changed

db/column_family.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ ColumnFamilyOptions SanitizeCfOptions(const ImmutableDBOptions& db_options,
463463
result.memtable_avg_op_scan_flush_trigger = 0;
464464
}
465465
}
466-
467466
return result;
468467
}
469468

@@ -1218,10 +1217,12 @@ Compaction* ColumnFamilyData::PickCompaction(
12181217
const MutableCFOptions& mutable_options,
12191218
const MutableDBOptions& mutable_db_options,
12201219
const std::vector<SequenceNumber>& existing_snapshots,
1221-
const SnapshotChecker* snapshot_checker, LogBuffer* log_buffer) {
1220+
const SnapshotChecker* snapshot_checker, LogBuffer* log_buffer,
1221+
bool require_max_output_level) {
12221222
auto* result = compaction_picker_->PickCompaction(
12231223
GetName(), mutable_options, mutable_db_options, existing_snapshots,
1224-
snapshot_checker, current_->storage_info(), log_buffer);
1224+
snapshot_checker, current_->storage_info(), log_buffer,
1225+
require_max_output_level);
12251226
if (result != nullptr) {
12261227
result->FinalizeInputInfo(current_);
12271228
}

db/column_family.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ class ColumnFamilyData {
424424
const MutableCFOptions& mutable_options,
425425
const MutableDBOptions& mutable_db_options,
426426
const std::vector<SequenceNumber>& existing_snapshots,
427-
const SnapshotChecker* snapshot_checker, LogBuffer* log_buffer);
427+
const SnapshotChecker* snapshot_checker, LogBuffer* log_buffer,
428+
bool require_max_output_level = false);
428429

429430
// Check if the passed range overlap with any running compactions.
430431
// REQUIRES: DB mutex held

db/compaction/compaction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ class Compaction {
463463
const int start_level,
464464
const int output_level);
465465

466+
static bool OutputToNonZeroMaxOutputLevel(int output_level,
467+
int max_output_level) {
468+
return output_level > 0 && output_level == max_output_level;
469+
}
470+
466471
// If some data cannot be safely migrated "up" the LSM tree due to a change
467472
// in the preclude_last_level_data_seconds setting, this indicates a sequence
468473
// number for the newest data that must be kept in the last level.

db/compaction/compaction_picker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CompactionPicker {
6565
const MutableDBOptions& mutable_db_options,
6666
const std::vector<SequenceNumber>& existing_snapshots,
6767
const SnapshotChecker* snapshot_checker, VersionStorageInfo* vstorage,
68-
LogBuffer* log_buffer) = 0;
68+
LogBuffer* log_buffer, bool require_max_output_level) = 0;
6969

7070
// The returned Compaction might not include the whole requested range.
7171
// In that case, compaction_end will be set to the next key that needs
@@ -272,7 +272,8 @@ class NullCompactionPicker : public CompactionPicker {
272272
const MutableDBOptions& /*mutable_db_options*/,
273273
const std::vector<SequenceNumber>& /*existing_snapshots*/,
274274
const SnapshotChecker* /*snapshot_checker*/,
275-
VersionStorageInfo* /*vstorage*/, LogBuffer* /* log_buffer */) override {
275+
VersionStorageInfo* /*vstorage*/, LogBuffer* /* log_buffer */,
276+
bool /*require_max_output_level*/ = false) override {
276277
return nullptr;
277278
}
278279

db/compaction/compaction_picker_fifo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Compaction* FIFOCompactionPicker::PickCompaction(
428428
const MutableDBOptions& mutable_db_options,
429429
const std::vector<SequenceNumber>& /* existing_snapshots */,
430430
const SnapshotChecker* /* snapshot_checker */, VersionStorageInfo* vstorage,
431-
LogBuffer* log_buffer) {
431+
LogBuffer* log_buffer, bool /* require_max_output_level*/) {
432432
Compaction* c = nullptr;
433433
if (mutable_cf_options.ttl > 0) {
434434
c = PickTTLCompaction(cf_name, mutable_cf_options, mutable_db_options,

db/compaction/compaction_picker_fifo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class FIFOCompactionPicker : public CompactionPicker {
2323
const MutableDBOptions& mutable_db_options,
2424
const std::vector<SequenceNumber>& /* existing_snapshots */,
2525
const SnapshotChecker* /* snapshot_checker */,
26-
VersionStorageInfo* version, LogBuffer* log_buffer) override;
26+
VersionStorageInfo* version, LogBuffer* log_buffer,
27+
bool /* require_max_output_level*/ = false) override;
2728

2829
Compaction* CompactRange(const std::string& cf_name,
2930
const MutableCFOptions& mutable_cf_options,

db/compaction/compaction_picker_level.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ Compaction* LevelCompactionPicker::PickCompaction(
978978
const MutableDBOptions& mutable_db_options,
979979
const std::vector<SequenceNumber>& /*existing_snapshots */,
980980
const SnapshotChecker* /*snapshot_checker*/, VersionStorageInfo* vstorage,
981-
LogBuffer* log_buffer) {
981+
LogBuffer* log_buffer, bool /* require_max_output_level*/) {
982982
LevelCompactionBuilder builder(cf_name, vstorage, this, log_buffer,
983983
mutable_cf_options, ioptions_,
984984
mutable_db_options);

db/compaction/compaction_picker_level.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class LevelCompactionPicker : public CompactionPicker {
2525
const MutableDBOptions& mutable_db_options,
2626
const std::vector<SequenceNumber>& /* existing_snapshots */,
2727
const SnapshotChecker* /* snapshot_checker */,
28-
VersionStorageInfo* vstorage, LogBuffer* log_buffer) override;
28+
VersionStorageInfo* vstorage, LogBuffer* log_buffer,
29+
bool /*require_max_output_level*/ = false) override;
2930

3031
bool NeedsCompaction(const VersionStorageInfo* vstorage) const override;
3132
};

0 commit comments

Comments
 (0)