Skip to content

Commit

Permalink
fix(storage): fix unexpected task picked by sublevel picker (#16454)
Browse files Browse the repository at this point in the history
  • Loading branch information
Li0k authored Apr 29, 2024
1 parent fbc3a6c commit 4cfcbcd
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::cell::RefCell;
use std::sync::Arc;

use itertools::Itertools;
Expand All @@ -28,6 +29,10 @@ use crate::hummock::compaction::picker::TrivialMovePicker;
use crate::hummock::compaction::{create_overlap_strategy, CompactionDeveloperConfig};
use crate::hummock::level_handler::LevelHandler;

std::thread_local! {
static LOG_COUNTER: RefCell<usize> = RefCell::new(0);
}

pub struct LevelCompactionPicker {
target_level: usize,
config: Arc<CompactionConfig>,
Expand Down Expand Up @@ -253,13 +258,21 @@ impl LevelCompactionPicker {
stats,
) {
if l0.total_file_size > target_level.total_file_size * 8 {
tracing::warn!("skip task with level count: {}, file count: {}, select size: {}, target size: {}, target level size: {}",
result.input_levels.len(),
result.total_file_count,
result.select_input_size,
result.target_input_size,
target_level.total_file_size,
);
let log_counter = LOG_COUNTER.with_borrow_mut(|counter| {
*counter += 1;
*counter
});

// reduce log
if log_counter % 100 == 0 {
tracing::warn!("skip task with level count: {}, file count: {}, select size: {}, target size: {}, target level size: {}",
result.input_levels.len(),
result.total_file_count,
result.select_input_size,
result.target_input_size,
target_level.total_file_size,
);
}
}
continue;
}
Expand Down
27 changes: 17 additions & 10 deletions src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl CompactionPicker for IntraCompactionPicker {

impl IntraCompactionPicker {
#[cfg(test)]
pub fn new(
pub fn for_test(
config: Arc<CompactionConfig>,
developer_config: Arc<CompactionDeveloperConfig>,
) -> IntraCompactionPicker {
Expand All @@ -87,6 +87,7 @@ impl IntraCompactionPicker {
compaction_task_validator: Arc<CompactionTaskValidator>,
developer_config: Arc<CompactionDeveloperConfig>,
) -> IntraCompactionPicker {
assert!(config.level0_sub_level_compact_level_count > 1);
IntraCompactionPicker {
config,
compaction_task_validator,
Expand Down Expand Up @@ -414,7 +415,7 @@ pub mod tests {
.level0_sub_level_compact_level_count(1)
.build(),
);
IntraCompactionPicker::new(config, Arc::new(CompactionDeveloperConfig::default()))
IntraCompactionPicker::for_test(config, Arc::new(CompactionDeveloperConfig::default()))
}

#[test]
Expand Down Expand Up @@ -528,8 +529,10 @@ pub mod tests {
.level0_overlapping_sub_level_compact_level_count(4)
.build(),
);
let mut picker =
IntraCompactionPicker::new(config, Arc::new(CompactionDeveloperConfig::default()));
let mut picker = IntraCompactionPicker::for_test(
config,
Arc::new(CompactionDeveloperConfig::default()),
);
let mut local_stats = LocalPickerStatistic::default();
let ret = picker
.pick_compaction(&levels, &levels_handler, &mut local_stats)
Expand Down Expand Up @@ -574,8 +577,10 @@ pub mod tests {
.level0_sub_level_compact_level_count(1)
.build(),
);
let mut picker =
IntraCompactionPicker::new(config, Arc::new(CompactionDeveloperConfig::default()));
let mut picker = IntraCompactionPicker::for_test(
config,
Arc::new(CompactionDeveloperConfig::default()),
);
let mut local_stats = LocalPickerStatistic::default();
let ret = picker
.pick_compaction(&levels, &levels_handler, &mut local_stats)
Expand Down Expand Up @@ -644,8 +649,10 @@ pub mod tests {
.level0_sub_level_compact_level_count(1)
.build(),
);
let mut picker =
IntraCompactionPicker::new(config, Arc::new(CompactionDeveloperConfig::default()));
let mut picker = IntraCompactionPicker::for_test(
config,
Arc::new(CompactionDeveloperConfig::default()),
);
let mut local_stats = LocalPickerStatistic::default();
let ret = picker
.pick_compaction(&levels, &levels_handler, &mut local_stats)
Expand Down Expand Up @@ -698,7 +705,7 @@ pub mod tests {
.build(),
);
let mut picker =
IntraCompactionPicker::new(config, Arc::new(CompactionDeveloperConfig::default()));
IntraCompactionPicker::for_test(config, Arc::new(CompactionDeveloperConfig::default()));

// Cannot trivial move because there is only 1 sub-level.
let l0 = generate_l0_overlapping_sublevels(vec![vec![
Expand Down Expand Up @@ -792,7 +799,7 @@ pub mod tests {
CompactionConfigBuilder::new()
.level0_max_compact_file_number(20)
.sub_level_max_compaction_bytes(1)
.level0_sub_level_compact_level_count(1)
.level0_sub_level_compact_level_count(2)
.build(),
);
let mut table_infos = vec![];
Expand Down
Loading

0 comments on commit 4cfcbcd

Please sign in to comment.