-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(compaction): compact tier level at first when overlapping level too many #14482
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ad7b88f
compact tier level at first when overlapping level too many
Little-Wallace b72133f
Merge branch 'main' into wallace/fix-stall-selector
Little-Wallace de57eca
Merge branch 'main' into wallace/fix-stall-selector
Little-Wallace e89a8d9
check not partition level
Little-Wallace 825d4e7
fix format
Little-Wallace a82dba8
Merge branch 'main' into wallace/fix-stall-selector
Little-Wallace f0d9a6a
Merge branch 'main' into wallace/fix-stall-selector
Little-Wallace 962c70c
fix comment
Little-Wallace 2739c44
Merge branch 'main' into wallace/fix-stall-selector
Little-Wallace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,13 @@ | |
use std::sync::Arc; | ||
|
||
use risingwave_pb::hummock::hummock_version::Levels; | ||
use risingwave_pb::hummock::CompactionConfig; | ||
use risingwave_pb::hummock::{CompactionConfig, LevelType}; | ||
|
||
use super::{ | ||
CompactionInput, CompactionPicker, CompactionTaskValidator, LevelCompactionPicker, | ||
LocalPickerStatistic, TierCompactionPicker, | ||
}; | ||
use crate::hummock::compaction::picker::intra_compaction_picker::WholeLevelCompactionPicker; | ||
use crate::hummock::compaction::CompactionDeveloperConfig; | ||
use crate::hummock::level_handler::LevelHandler; | ||
|
||
|
@@ -50,20 +51,65 @@ impl EmergencyCompactionPicker { | |
stats: &mut LocalPickerStatistic, | ||
) -> Option<CompactionInput> { | ||
let unused_validator = Arc::new(CompactionTaskValidator::unused()); | ||
|
||
let mut base_level_compaction_picker = LevelCompactionPicker::new_with_validator( | ||
self.target_level, | ||
self.config.clone(), | ||
unused_validator.clone(), | ||
self.developer_config.clone(), | ||
); | ||
|
||
if let Some(ret) = | ||
base_level_compaction_picker.pick_compaction(levels, level_handlers, stats) | ||
let l0 = levels.l0.as_ref().unwrap(); | ||
let overlapping_count = l0 | ||
.sub_levels | ||
.iter() | ||
.filter(|level| level.level_type == LevelType::Overlapping as i32) | ||
.count(); | ||
let no_overlap_count = l0 | ||
.sub_levels | ||
.iter() | ||
.filter(|level| { | ||
level.level_type == LevelType::Nonoverlapping as i32 | ||
&& level.vnode_partition_count == 0 | ||
}) | ||
.count(); | ||
let partitioned_count = l0 | ||
.sub_levels | ||
.iter() | ||
.filter(|level| { | ||
level.level_type == LevelType::Nonoverlapping as i32 | ||
&& level.vnode_partition_count > 0 | ||
}) | ||
.count(); | ||
// We trigger `EmergencyCompactionPicker` only when some unexpected condition cause the number of l0 levels increase and the origin strategy | ||
// can not compact those data to lower level. But if most of these levels are overlapping level, it is dangerous to compact small data of non-overlapping sub level | ||
// to base level, it will cost a lot of compactor resource because of large write-amplification. | ||
if (self.config.split_weight_by_vnode == 0 && no_overlap_count > overlapping_count) | ||
|| (self.config.split_weight_by_vnode > 0 | ||
&& partitioned_count > no_overlap_count | ||
&& partitioned_count > overlapping_count) | ||
{ | ||
return Some(ret); | ||
let mut base_level_compaction_picker = LevelCompactionPicker::new_with_validator( | ||
self.target_level, | ||
self.config.clone(), | ||
unused_validator.clone(), | ||
self.developer_config.clone(), | ||
); | ||
|
||
if let Some(ret) = | ||
base_level_compaction_picker.pick_compaction(levels, level_handlers, stats) | ||
{ | ||
return Some(ret); | ||
} | ||
} | ||
if self.config.split_weight_by_vnode > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always think about whether it is right to unconditionally compact l0 to base. This will lead to base-level accumulation. Should we continue to follow the selection rules of the level selector? What's your opinion? |
||
&& no_overlap_count > partitioned_count | ||
&& no_overlap_count > overlapping_count | ||
{ | ||
let intral_level_compaction_picker = | ||
WholeLevelCompactionPicker::new(self.config.clone(), unused_validator.clone()); | ||
|
||
if let Some(ret) = intral_level_compaction_picker.pick_whole_level( | ||
levels.l0.as_ref().unwrap(), | ||
&level_handlers[0], | ||
self.config.split_weight_by_vnode, | ||
stats, | ||
) { | ||
return Some(ret); | ||
} | ||
} | ||
let mut tier_compaction_picker = | ||
TierCompactionPicker::new_with_validator(self.config.clone(), unused_validator); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good solution, please add some comments for the strategy.