From 36290b00687f0a5cd1e003ecd22a8b7072bc8ff6 Mon Sep 17 00:00:00 2001 From: William Wen <44139337+wenym1@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:28:23 +0800 Subject: [PATCH] refactor(storage): remove unnecessary wrap L0 with Option in Levels (#17881) --- src/ctl/src/cmd_impl/hummock/list_version.rs | 8 +- .../src/cmd_impl/hummock/validate_version.rs | 10 +- .../rw_catalog/rw_hummock_version.rs | 8 +- .../picker/base_level_compaction_picker.rs | 34 +++---- .../picker/emergency_compaction_picker.rs | 4 +- .../picker/intra_compaction_picker.rs | 38 ++++---- .../picker/manual_compaction_picker.rs | 16 ++-- .../picker/min_overlap_compaction_picker.rs | 4 +- .../picker/space_reclaim_compaction_picker.rs | 8 +- .../picker/tier_compaction_picker.rs | 14 +-- .../tombstone_reclaim_compaction_picker.rs | 3 - .../picker/ttl_reclaim_compaction_picker.rs | 2 +- .../compaction/selector/level_selector.rs | 38 ++------ .../src/hummock/compaction/selector/mod.rs | 17 +--- src/meta/src/hummock/manager/compaction.rs | 2 +- src/meta/src/hummock/manager/tests.rs | 6 +- src/meta/src/hummock/manager/timer_task.rs | 2 - src/meta/src/hummock/manager/versioning.rs | 18 +--- src/meta/src/hummock/metrics_utils.rs | 48 +++++----- src/meta/src/hummock/test_utils.rs | 2 +- src/meta/src/manager/diagnose.rs | 4 +- .../compaction_group/hummock_version_ext.rs | 92 +++++++------------ src/storage/hummock_sdk/src/level.rs | 32 ++----- src/storage/hummock_sdk/src/time_travel.rs | 4 +- .../hummock_test/src/compactor_tests.rs | 2 - .../hummock/local_version/pinned_version.rs | 2 - .../src/delete_range_runner.rs | 2 +- 27 files changed, 151 insertions(+), 269 deletions(-) diff --git a/src/ctl/src/cmd_impl/hummock/list_version.rs b/src/ctl/src/cmd_impl/hummock/list_version.rs index 282f4edf4d607..0f88d881ddb69 100644 --- a/src/ctl/src/cmd_impl/hummock/list_version.rs +++ b/src/ctl/src/cmd_impl/hummock/list_version.rs @@ -30,8 +30,8 @@ pub async fn list_version( } else if verbose { version.levels.iter_mut().for_each(|(_cg_id, levels)| { // l0 - if levels.l0.is_some() { - let l0 = levels.l0.as_mut().unwrap(); + { + let l0 = &mut levels.l0; for sub_level in &mut l0.sub_levels { for t in &mut sub_level.table_infos { t.remove_key_range(); @@ -58,8 +58,8 @@ pub async fn list_version( println!("CompactionGroup {}", cg); // l0 - if levels.l0.is_some() { - for sub_level in levels.l0.as_ref().unwrap().sub_levels.iter().rev() { + { + for sub_level in levels.l0.sub_levels.iter().rev() { println!( "sub_level_id {} type {} sst_num {} size {}", sub_level.sub_level_id, diff --git a/src/ctl/src/cmd_impl/hummock/validate_version.rs b/src/ctl/src/cmd_impl/hummock/validate_version.rs index 7d0af4da9fee0..4d857ad8b91f1 100644 --- a/src/ctl/src/cmd_impl/hummock/validate_version.rs +++ b/src/ctl/src/cmd_impl/hummock/validate_version.rs @@ -100,15 +100,7 @@ async fn print_user_key_in_version( ) -> anyhow::Result<()> { println!("print key {:?} in version {}", target_key, version.id); for cg in version.levels.values() { - for level in cg - .l0 - .as_ref() - .unwrap() - .sub_levels - .iter() - .rev() - .chain(cg.levels.iter()) - { + for level in cg.l0.sub_levels.iter().rev().chain(cg.levels.iter()) { for sstable_info in &level.table_infos { let key_range = &sstable_info.key_range; let left_user_key = FullKey::decode(&key_range.left); diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_version.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_version.rs index bd54381c2bc9f..d4281434c962f 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_version.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_version.rs @@ -86,11 +86,7 @@ async fn read_hummock_sstables(reader: &SysCatalogReaderImpl) -> Result HummockVersion { // Because key range is too verbose for manual analysis, just don't expose it. for cg in version.levels.values_mut() { - for level in cg - .levels - .iter_mut() - .chain(cg.l0.as_mut().unwrap().sub_levels.iter_mut()) - { + for level in cg.levels.iter_mut().chain(cg.l0.sub_levels.iter_mut()) { for sst in &mut level.table_infos { sst.remove_key_range(); } @@ -115,7 +111,7 @@ fn version_to_compaction_group_rows(version: &HummockVersion) -> Vec Vec { let mut sstables = vec![]; for cg in version.levels.into_values() { - for level in cg.levels.into_iter().chain(cg.l0.unwrap().sub_levels) { + for level in cg.levels.into_iter().chain(cg.l0.sub_levels) { for sst in level.table_infos { let key_range = sst.key_range; sstables.push(RwHummockSstable { diff --git a/src/meta/src/hummock/compaction/picker/base_level_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/base_level_compaction_picker.rs index 8b2831d28e1d5..52ea3017d49a2 100644 --- a/src/meta/src/hummock/compaction/picker/base_level_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/base_level_compaction_picker.rs @@ -47,7 +47,7 @@ impl CompactionPicker for LevelCompactionPicker { level_handlers: &[LevelHandler], stats: &mut LocalPickerStatistic, ) -> Option { - let l0 = levels.l0.as_ref().unwrap(); + let l0 = &levels.l0; if l0.sub_levels.is_empty() { return None; } @@ -315,11 +315,11 @@ pub mod tests { ], ); let mut levels = Levels { - l0: Some(OverlappingLevel { + l0: OverlappingLevel { total_file_size: l0.total_file_size, uncompressed_file_size: l0.total_file_size, sub_levels: vec![l0], - }), + }, levels: vec![generate_level( 1, vec![ @@ -353,10 +353,10 @@ pub mod tests { assert_eq!(ret2.input_levels[1].table_infos[0].sst_id, 5); } - levels.l0.as_mut().unwrap().sub_levels[0] + levels.l0.sub_levels[0] .table_infos .retain(|table| table.sst_id != 4); - levels.l0.as_mut().unwrap().total_file_size -= ret.input_levels[0].table_infos[0].file_size; + levels.l0.total_file_size -= ret.input_levels[0].table_infos[0].file_size; levels_handler[0].remove_task(0); levels_handler[1].remove_task(0); @@ -415,11 +415,11 @@ pub mod tests { }]; let mut levels = Levels { levels, - l0: Some(OverlappingLevel { + l0: OverlappingLevel { sub_levels: vec![], total_file_size: 0, uncompressed_file_size: 0, - }), + }, ..Default::default() }; push_tables_level0_nonoverlapping(&mut levels, vec![generate_table(1, 1, 50, 140, 2)]); @@ -477,11 +477,11 @@ pub mod tests { }]; let mut levels = Levels { levels, - l0: Some(OverlappingLevel { + l0: OverlappingLevel { sub_levels: vec![], total_file_size: 0, uncompressed_file_size: 0, - }), + }, ..Default::default() }; push_tables_level0_nonoverlapping( @@ -543,7 +543,7 @@ pub mod tests { uncompressed_file_size: 900, ..Default::default() }], - l0: Some(generate_l0_nonoverlapping_sublevels(vec![])), + l0: generate_l0_nonoverlapping_sublevels(vec![]), ..Default::default() }; push_tables_level0_nonoverlapping( @@ -557,11 +557,7 @@ pub mod tests { let mut levels_handler = vec![LevelHandler::new(0), LevelHandler::new(1)]; let mut local_stats = LocalPickerStatistic::default(); - levels_handler[0].add_pending_task( - 1, - 4, - &levels.l0.as_ref().unwrap().sub_levels[0].table_infos, - ); + levels_handler[0].add_pending_task(1, 4, &levels.l0.sub_levels[0].table_infos); let ret = picker.pick_compaction(&levels, &levels_handler, &mut local_stats); // Skip this compaction because the write amplification is too large. assert!(ret.is_none()); @@ -583,7 +579,7 @@ pub mod tests { s.level_type = LevelType::Nonoverlapping; } let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(3, 1, 0, 100000, 1)])], ..Default::default() }; @@ -660,7 +656,7 @@ pub mod tests { ]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(3, 1, 0, 100000, 1)])], ..Default::default() }; @@ -668,7 +664,7 @@ pub mod tests { let mut local_stats = LocalPickerStatistic::default(); // Create a pending sub-level. - let pending_level = levels.l0.as_ref().unwrap().sub_levels[1].clone(); + let pending_level = levels.l0.sub_levels[1].clone(); assert_eq!(pending_level.sub_level_id, 1); let tier_task_input = CompactionInput { input_levels: vec![InputLevel { @@ -726,7 +722,7 @@ pub mod tests { ]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(3, 1, 1, 100, 1)])], ..Default::default() }; diff --git a/src/meta/src/hummock/compaction/picker/emergency_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/emergency_compaction_picker.rs index f0fc3f2376592..ab91589bdd46d 100644 --- a/src/meta/src/hummock/compaction/picker/emergency_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/emergency_compaction_picker.rs @@ -51,7 +51,7 @@ impl EmergencyCompactionPicker { stats: &mut LocalPickerStatistic, ) -> Option { let unused_validator = Arc::new(CompactionTaskValidator::unused()); - let l0 = levels.l0.as_ref().unwrap(); + let l0 = &levels.l0; let overlapping_count = l0 .sub_levels .iter() @@ -100,7 +100,7 @@ impl EmergencyCompactionPicker { WholeLevelCompactionPicker::new(self.config.clone(), unused_validator.clone()); if let Some(ret) = intral_level_compaction_picker.pick_whole_level( - levels.l0.as_ref().unwrap(), + &levels.l0, &level_handlers[0], self.config.split_weight_by_vnode, stats, diff --git a/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs index dcd41073f05bf..6f0bfced1cc03 100644 --- a/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/intra_compaction_picker.rs @@ -41,7 +41,7 @@ impl CompactionPicker for IntraCompactionPicker { level_handlers: &[LevelHandler], stats: &mut LocalPickerStatistic, ) -> Option { - let l0 = levels.l0.as_ref().unwrap(); + let l0 = &levels.l0; if l0.sub_levels.is_empty() { return None; } @@ -450,11 +450,11 @@ pub mod tests { }]; let mut levels = Levels { levels, - l0: Some(OverlappingLevel { + l0: OverlappingLevel { sub_levels: vec![], total_file_size: 0, uncompressed_file_size: 0, - }), + }, ..Default::default() }; push_tables_level0_nonoverlapping( @@ -495,10 +495,10 @@ pub mod tests { table_infos: vec![generate_table(3, 1, 200, 300, 2)], ..Default::default() }], - l0: Some(generate_l0_nonoverlapping_sublevels(vec![ + l0: generate_l0_nonoverlapping_sublevels(vec![ generate_table(1, 1, 100, 210, 2), generate_table(2, 1, 200, 250, 2), - ])), + ]), ..Default::default() }; let mut levels_handler = vec![LevelHandler::new(0), LevelHandler::new(1)]; @@ -534,7 +534,7 @@ pub mod tests { ], ]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(100, 1, 0, 1000, 1)])], ..Default::default() }; @@ -582,7 +582,7 @@ pub mod tests { ], ]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(100, 1, 0, 1000, 1)])], ..Default::default() }; @@ -653,7 +653,7 @@ pub mod tests { ], ]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(100, 1, 0, 1000, 1)])], ..Default::default() }; @@ -728,7 +728,7 @@ pub mod tests { generate_table(2, 1, 150, 250, 1), ]]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(100, 1, 0, 1000, 1)])], ..Default::default() }; @@ -748,7 +748,7 @@ pub mod tests { vec![generate_table(5, 1, 10, 90, 1)], ]); let mut levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(100, 1, 0, 1000, 1)])], ..Default::default() }; @@ -757,20 +757,20 @@ pub mod tests { .is_none()); // Cannot trivial move because latter sub-level is overlapping - levels.l0.as_mut().unwrap().sub_levels[0].level_type = LevelType::Nonoverlapping; - levels.l0.as_mut().unwrap().sub_levels[1].level_type = LevelType::Overlapping; + levels.l0.sub_levels[0].level_type = LevelType::Nonoverlapping; + levels.l0.sub_levels[1].level_type = LevelType::Overlapping; let ret = picker.pick_compaction(&levels, &levels_handler, &mut local_stats); assert!(ret.is_none()); // Cannot trivial move because former sub-level is overlapping - levels.l0.as_mut().unwrap().sub_levels[0].level_type = LevelType::Overlapping; - levels.l0.as_mut().unwrap().sub_levels[1].level_type = LevelType::Nonoverlapping; + levels.l0.sub_levels[0].level_type = LevelType::Overlapping; + levels.l0.sub_levels[1].level_type = LevelType::Nonoverlapping; let ret = picker.pick_compaction(&levels, &levels_handler, &mut local_stats); assert!(ret.is_none()); // trivial move - levels.l0.as_mut().unwrap().sub_levels[0].level_type = LevelType::Nonoverlapping; - levels.l0.as_mut().unwrap().sub_levels[1].level_type = LevelType::Nonoverlapping; + levels.l0.sub_levels[0].level_type = LevelType::Nonoverlapping; + levels.l0.sub_levels[1].level_type = LevelType::Nonoverlapping; let ret = picker .pick_compaction(&levels, &levels_handler, &mut local_stats) .unwrap(); @@ -845,7 +845,7 @@ pub mod tests { let mut local_stats = LocalPickerStatistic::default(); let levels = Levels { - l0: Some(l0), + l0, levels: vec![generate_level(1, vec![generate_table(100, 1, 0, 1000, 1)])], ..Default::default() }; @@ -860,11 +860,11 @@ pub mod tests { let input = ret.as_ref().unwrap(); assert_eq!(input.input_levels.len(), 2); assert_ne!( - levels.l0.as_ref().unwrap().sub_levels[0].table_infos.len(), + levels.l0.sub_levels[0].table_infos.len(), input.input_levels[0].table_infos.len() ); assert_ne!( - levels.l0.as_ref().unwrap().sub_levels[1].table_infos.len(), + levels.l0.sub_levels[1].table_infos.len(), input.input_levels[1].table_infos.len() ); } diff --git a/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs index 251a0a694b1ae..98f27254ab46c 100644 --- a/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs @@ -114,7 +114,7 @@ impl ManualCompactionPicker { for l in 1..self.target_level { assert!(levels.levels[l - 1].table_infos.is_empty()); } - let l0 = levels.l0.as_ref().unwrap(); + let l0 = &levels.l0; let mut input_levels = vec![]; let mut max_sub_level_idx = usize::MAX; let mut info = self.overlap_strategy.create_overlap_info(); @@ -222,7 +222,7 @@ impl CompactionPicker for ManualCompactionPicker { ) -> Option { if self.option.level == 0 { if !self.option.sst_ids.is_empty() { - return self.pick_l0_to_sub_level(levels.l0.as_ref().unwrap(), level_handlers); + return self.pick_l0_to_sub_level(&levels.l0, level_handlers); } else if self.target_level > 0 { return self.pick_l0_to_base_level(levels, level_handlers); } else { @@ -401,7 +401,7 @@ pub mod tests { ]; let mut levels = Levels { levels, - l0: Some(generate_l0_nonoverlapping_sublevels(vec![])), + l0: generate_l0_nonoverlapping_sublevels(vec![]), ..Default::default() }; let mut levels_handler = vec![ @@ -586,7 +586,7 @@ pub mod tests { } let levels = Levels { levels, - l0: Some(l0), + l0, ..Default::default() }; @@ -613,7 +613,7 @@ pub mod tests { }]; let levels = Levels { levels, - l0: Some(l0), + l0, ..Default::default() }; @@ -635,7 +635,7 @@ pub mod tests { }]; let levels = Levels { levels, - l0: Some(l0), + l0, ..Default::default() }; let levels_handler = vec![LevelHandler::new(0), LevelHandler::new(1)]; @@ -1174,7 +1174,7 @@ pub mod tests { assert_eq!(levels.len(), 4); let levels = Levels { levels, - l0: Some(l0), + l0, ..Default::default() }; let mut levels_handler = (0..5).map(LevelHandler::new).collect_vec(); @@ -1294,7 +1294,7 @@ pub mod tests { assert_eq!(levels.len(), 4); let levels = Levels { levels, - l0: Some(l0), + l0, ..Default::default() }; let mut levels_handler = (0..5).map(LevelHandler::new).collect_vec(); diff --git a/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs index c444f1f647eba..dfbe6950c5b49 100644 --- a/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs @@ -567,7 +567,7 @@ pub mod tests { ]; let levels = Levels { levels, - l0: Some(generate_l0_nonoverlapping_sublevels(vec![])), + l0: generate_l0_nonoverlapping_sublevels(vec![]), ..Default::default() }; let mut level_handlers = vec![ @@ -636,7 +636,7 @@ pub mod tests { ]; let levels = Levels { levels, - l0: Some(generate_l0_nonoverlapping_sublevels(vec![])), + l0: generate_l0_nonoverlapping_sublevels(vec![]), ..Default::default() }; let levels_handler = vec![ diff --git a/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs index 8d69e85bcc48c..7a4eb86831c33 100644 --- a/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs @@ -63,9 +63,9 @@ impl SpaceReclaimCompactionPicker { ) -> Option { assert!(!levels.levels.is_empty()); let mut select_input_ssts = vec![]; - if let Some(l0) = levels.l0.as_ref() - && state.last_level == 0 - { + + if state.last_level == 0 { + let l0 = &levels.l0; // only pick trivial reclaim sstables because this kind of task could be optimized and do not need send to compactor. for level in &l0.sub_levels { for sst in &level.table_infos { @@ -240,7 +240,7 @@ mod test { assert_eq!(levels.len(), 4); let levels = Levels { levels, - l0: Some(l0), + l0, ..Default::default() }; let mut member_table_ids = BTreeSet::new(); diff --git a/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs index 776a83019dc6d..9099550232e3f 100644 --- a/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/tier_compaction_picker.rs @@ -146,7 +146,7 @@ impl CompactionPicker for TierCompactionPicker { level_handlers: &[LevelHandler], stats: &mut LocalPickerStatistic, ) -> Option { - let l0 = levels.l0.as_ref().unwrap(); + let l0 = &levels.l0; if l0.sub_levels.is_empty() { return None; } @@ -195,7 +195,7 @@ pub mod tests { ], ]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![], ..Default::default() }; @@ -222,7 +222,7 @@ pub mod tests { ); let empty_level = Levels { - l0: Some(generate_l0_overlapping_sublevels(vec![])), + l0: generate_l0_overlapping_sublevels(vec![]), levels: vec![], ..Default::default() }; @@ -243,7 +243,7 @@ pub mod tests { ]); let levels = Levels { - l0: Some(l0), + l0, levels: vec![], ..Default::default() }; @@ -285,11 +285,11 @@ pub mod tests { ], ); let levels = Levels { - l0: Some(OverlappingLevel { + l0: OverlappingLevel { total_file_size: l1.total_file_size + l2.total_file_size, uncompressed_file_size: l1.total_file_size + l2.total_file_size, sub_levels: vec![l1, l2], - }), + }, levels: vec![], ..Default::default() }; @@ -319,7 +319,7 @@ pub mod tests { generate_table(10, 1, 1, 100, 1), ]]); let mut levels = Levels { - l0: Some(l0), + l0, levels: vec![], ..Default::default() }; diff --git a/src/meta/src/hummock/compaction/picker/tombstone_reclaim_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/tombstone_reclaim_compaction_picker.rs index 0b3aad7ef8b24..ab6bfd1ed8490 100644 --- a/src/meta/src/hummock/compaction/picker/tombstone_reclaim_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/tombstone_reclaim_compaction_picker.rs @@ -132,8 +132,6 @@ impl TombstoneReclaimCompactionPicker { #[cfg(test)] pub mod tests { - use risingwave_hummock_sdk::level::OverlappingLevel; - use super::*; use crate::hummock::compaction::compaction_config::CompactionConfigBuilder; use crate::hummock::compaction::create_overlap_strategy; @@ -142,7 +140,6 @@ pub mod tests { #[test] fn test_basic() { let mut levels = Levels { - l0: Some(OverlappingLevel::default()), levels: vec![ generate_level(1, vec![]), generate_level( diff --git a/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs index 51a1d56f34dcd..5d3f17e31b6bc 100644 --- a/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs @@ -355,7 +355,7 @@ mod test { assert_eq!(levels.len(), 4); let levels = Levels { levels, - l0: Some(l0), + l0, ..Default::default() }; let mut levels_handler = (0..5).map(LevelHandler::new).collect_vec(); diff --git a/src/meta/src/hummock/compaction/selector/level_selector.rs b/src/meta/src/hummock/compaction/selector/level_selector.rs index 918361bc4d44d..7076096fcfe16 100644 --- a/src/meta/src/hummock/compaction/selector/level_selector.rs +++ b/src/meta/src/hummock/compaction/selector/level_selector.rs @@ -207,8 +207,6 @@ impl DynamicLevelSelectorCore { let idle_file_count = levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .map(|level| level.table_infos.len()) @@ -223,8 +221,6 @@ impl DynamicLevelSelectorCore { // to calculate the score let overlapping_file_count = levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .filter(|level| level.level_type == LevelType::Overlapping) @@ -250,8 +246,6 @@ impl DynamicLevelSelectorCore { // calculation rule to avoid unbalanced compact task due to large size. let total_size = levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .filter(|level| { @@ -270,8 +264,6 @@ impl DynamicLevelSelectorCore { // level count limit let non_overlapping_level_count = levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .filter(|level| level.level_type == LevelType::Nonoverlapping) @@ -357,8 +349,6 @@ impl DynamicLevelSelectorCore { let mut compact_to_next_level_bytes = 0; let l0_size = levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .map(|sub_level| sub_level.total_file_size) @@ -523,7 +513,7 @@ pub mod tests { ]; let mut levels = Levels { levels, - l0: Some(generate_l0_nonoverlapping_sublevels(vec![])), + l0: generate_l0_nonoverlapping_sublevels(vec![]), ..Default::default() }; let ctx = selector.calculate_level_base_size(&levels); @@ -559,8 +549,8 @@ pub mod tests { assert_eq!(ctx.level_max_bytes[3], 600); assert_eq!(ctx.level_max_bytes[4], 3000); - levels.l0.as_mut().unwrap().sub_levels.clear(); - levels.l0.as_mut().unwrap().total_file_size = 0; + levels.l0.sub_levels.clear(); + levels.l0.total_file_size = 0; levels.levels[0].table_infos = generate_tables(26..32, 0..1000, 1, 100); levels.levels[0].total_file_size = levels.levels[0] .table_infos @@ -597,12 +587,7 @@ pub mod tests { ]; let mut levels = Levels { levels, - l0: Some(generate_l0_nonoverlapping_sublevels(generate_tables( - 15..25, - 0..600, - 3, - 10, - ))), + l0: generate_l0_nonoverlapping_sublevels(generate_tables(15..25, 0..600, 3, 10)), ..Default::default() }; @@ -637,8 +622,8 @@ pub mod tests { let group_config = CompactionGroup::new(1, config.clone()); let mut selector = DynamicLevelSelector::default(); - levels.l0.as_mut().unwrap().sub_levels.clear(); - levels.l0.as_mut().unwrap().total_file_size = 0; + levels.l0.sub_levels.clear(); + levels.l0.total_file_size = 0; push_tables_level0_nonoverlapping(&mut levels, generate_tables(15..25, 0..600, 3, 20)); let mut levels_handlers = (0..5).map(LevelHandler::new).collect_vec(); let compaction = selector @@ -663,7 +648,7 @@ pub mod tests { levels_handlers[0].remove_task(1); levels_handlers[2].remove_task(1); - levels.l0.as_mut().unwrap().sub_levels.clear(); + levels.l0.sub_levels.clear(); levels.levels[1].table_infos = generate_tables(20..30, 0..1000, 3, 10); let compaction = selector .pick_compaction( @@ -740,12 +725,7 @@ pub mod tests { ]; let levels = Levels { levels, - l0: Some(generate_l0_nonoverlapping_sublevels(generate_tables( - 15..25, - 0..600, - 3, - 100, - ))), + l0: generate_l0_nonoverlapping_sublevels(generate_tables(15..25, 0..600, 3, 100)), ..Default::default() }; @@ -755,7 +735,7 @@ pub mod tests { ); let ctx = dynamic_level_core.calculate_level_base_size(&levels); assert_eq!(1, ctx.base_level); - assert_eq!(1000, levels.l0.as_ref().unwrap().total_file_size); // l0 + assert_eq!(1000, levels.l0.total_file_size); // l0 assert_eq!(0, levels.levels.first().unwrap().total_file_size); // l1 assert_eq!(25000, levels.levels.get(1).unwrap().total_file_size); // l2 assert_eq!(15000, levels.levels.get(2).unwrap().total_file_size); // l3 diff --git a/src/meta/src/hummock/compaction/selector/mod.rs b/src/meta/src/hummock/compaction/selector/mod.rs index 86571bf1f65b8..9c813efa6c864 100644 --- a/src/meta/src/hummock/compaction/selector/mod.rs +++ b/src/meta/src/hummock/compaction/selector/mod.rs @@ -136,8 +136,8 @@ pub mod tests { use crate::hummock::test_utils::iterator_test_key_of_epoch; pub fn push_table_level0_overlapping(levels: &mut Levels, sst: SstableInfo) { - levels.l0.as_mut().unwrap().total_file_size += sst.file_size; - levels.l0.as_mut().unwrap().sub_levels.push(Level { + levels.l0.total_file_size += sst.file_size; + levels.l0.sub_levels.push(Level { level_idx: 0, level_type: LevelType::Overlapping, total_file_size: sst.file_size, @@ -150,14 +150,7 @@ pub mod tests { pub fn push_table_level0_nonoverlapping(levels: &mut Levels, sst: SstableInfo) { push_table_level0_overlapping(levels, sst); - levels - .l0 - .as_mut() - .unwrap() - .sub_levels - .last_mut() - .unwrap() - .level_type = LevelType::Nonoverlapping; + levels.l0.sub_levels.last_mut().unwrap().level_type = LevelType::Nonoverlapping; } pub fn push_tables_level0_nonoverlapping(levels: &mut Levels, table_infos: Vec) { @@ -167,8 +160,8 @@ pub mod tests { .map(|table| table.uncompressed_file_size) .sum(); let sub_level_id = table_infos[0].sst_id; - levels.l0.as_mut().unwrap().total_file_size += total_file_size; - levels.l0.as_mut().unwrap().sub_levels.push(Level { + levels.l0.total_file_size += total_file_size; + levels.l0.sub_levels.push(Level { level_idx: 0, level_type: LevelType::Nonoverlapping, total_file_size, diff --git a/src/meta/src/hummock/manager/compaction.rs b/src/meta/src/hummock/manager/compaction.rs index fbe0f1fe8a66a..b096298b7f401 100644 --- a/src/meta/src/hummock/manager/compaction.rs +++ b/src/meta/src/hummock/manager/compaction.rs @@ -1693,7 +1693,7 @@ pub fn check_cg_write_limit( compaction_config: &CompactionConfig, ) -> WriteLimitType { let threshold = compaction_config.level0_stop_write_threshold_sub_level_number as usize; - let l0_sub_level_number = levels.l0.as_ref().unwrap().sub_levels.len(); + let l0_sub_level_number = levels.l0.sub_levels.len(); if threshold < l0_sub_level_number { return WriteLimitType::WriteStop(l0_sub_level_number, threshold); } diff --git a/src/meta/src/hummock/manager/tests.rs b/src/meta/src/hummock/manager/tests.rs index 71f0d117acb06..a0780641a3f30 100644 --- a/src/meta/src/hummock/manager/tests.rs +++ b/src/meta/src/hummock/manager/tests.rs @@ -282,8 +282,6 @@ async fn test_hummock_table() { Ordering::Equal, levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .chain(levels.levels.iter()) @@ -1809,8 +1807,6 @@ async fn test_split_compaction_group_on_demand_bottom_levels() { assert!(current_version .get_compaction_group_levels(2) .l0 - .as_ref() - .unwrap() .sub_levels .is_empty()); assert_eq!( @@ -2226,7 +2222,7 @@ async fn test_partition_level() { } let current_version = hummock_manager.get_current_version().await; let group = current_version.get_compaction_group_levels(new_group_id); - for sub_level in &group.l0.as_ref().unwrap().sub_levels { + for sub_level in &group.l0.sub_levels { if sub_level.total_file_size > config.sub_level_max_compaction_bytes { assert!(sub_level.vnode_partition_count > 0); } diff --git a/src/meta/src/hummock/manager/timer_task.rs b/src/meta/src/hummock/manager/timer_task.rs index ba9e43edf8267..ec0f77ac88a8a 100644 --- a/src/meta/src/hummock/manager/timer_task.rs +++ b/src/meta/src/hummock/manager/timer_task.rs @@ -376,8 +376,6 @@ impl HummockManager { *id, group .l0 - .as_ref() - .unwrap() .sub_levels .iter() .map(|level| level.total_file_size) diff --git a/src/meta/src/hummock/manager/versioning.rs b/src/meta/src/hummock/manager/versioning.rs index 781c928ca4b05..1bea45720c1b2 100644 --- a/src/meta/src/hummock/manager/versioning.rs +++ b/src/meta/src/hummock/manager/versioning.rs @@ -406,7 +406,7 @@ mod tests { use std::sync::Arc; use risingwave_hummock_sdk::key_range::KeyRange; - use risingwave_hummock_sdk::level::{Level, Levels, OverlappingLevel}; + use risingwave_hummock_sdk::level::{Level, Levels}; use risingwave_hummock_sdk::sstable_info::SstableInfo; use risingwave_hummock_sdk::version::HummockVersion; use risingwave_hummock_sdk::{CompactionGroupId, HummockVersionId}; @@ -443,12 +443,7 @@ mod tests { #[test] fn test_calc_new_write_limits() { let add_level_to_l0 = |levels: &mut Levels| { - levels - .l0 - .as_mut() - .unwrap() - .sub_levels - .push(Level::default()); + levels.l0.sub_levels.push(Level::default()); }; let set_sub_level_number_threshold_for_group_1 = |target_groups: &mut HashMap, @@ -481,13 +476,7 @@ mod tests { .collect(); let mut version: HummockVersion = Default::default(); for group_id in 1..=3 { - version.levels.insert( - group_id, - Levels { - l0: Some(OverlappingLevel::default()), - ..Default::default() - }, - ); + version.levels.insert(group_id, Levels::default()); } let new_write_limits = calc_new_write_limits(target_groups.clone(), origin_snapshot.clone(), &version); @@ -574,7 +563,6 @@ mod tests { table_infos: vec![sst.clone()], ..Default::default() }], - l0: Some(Default::default()), ..Default::default() }, ); diff --git a/src/meta/src/hummock/metrics_utils.rs b/src/meta/src/hummock/metrics_utils.rs index 992d5b1146905..0b23a6970965c 100644 --- a/src/meta/src/hummock/metrics_utils.rs +++ b/src/meta/src/hummock/metrics_utils.rs @@ -224,42 +224,42 @@ pub fn trigger_sst_stat( let overlapping_sst_num = current_version .levels .get(&compaction_group_id) - .and_then(|level| { - level.l0.as_ref().map(|l0| { - l0.sub_levels - .iter() - .filter(|sub_level| sub_level.level_type == LevelType::Overlapping) - .count() - }) + .map(|level| { + level + .l0 + .sub_levels + .iter() + .filter(|sub_level| sub_level.level_type == LevelType::Overlapping) + .count() }) .unwrap_or(0); let non_overlap_sst_num = current_version .levels .get(&compaction_group_id) - .and_then(|level| { - level.l0.as_ref().map(|l0| { - l0.sub_levels - .iter() - .filter(|sub_level| sub_level.level_type == LevelType::Nonoverlapping) - .count() - }) + .map(|level| { + level + .l0 + .sub_levels + .iter() + .filter(|sub_level| sub_level.level_type == LevelType::Nonoverlapping) + .count() }) .unwrap_or(0); let partition_level_num = current_version .levels .get(&compaction_group_id) - .and_then(|level| { - level.l0.as_ref().map(|l0| { - l0.sub_levels - .iter() - .filter(|sub_level| { - sub_level.level_type == LevelType::Nonoverlapping - && sub_level.vnode_partition_count > 0 - }) - .count() - }) + .map(|level| { + level + .l0 + .sub_levels + .iter() + .filter(|sub_level| { + sub_level.level_type == LevelType::Nonoverlapping + && sub_level.vnode_partition_count > 0 + }) + .count() }) .unwrap_or(0); metrics diff --git a/src/meta/src/hummock/test_utils.rs b/src/meta/src/hummock/test_utils.rs index 84c19cfd4d936..9a6ab6d197998 100644 --- a/src/meta/src/hummock/test_utils.rs +++ b/src/meta/src/hummock/test_utils.rs @@ -296,7 +296,7 @@ pub fn get_sorted_committed_object_ids( levels .levels .iter() - .chain(levels.l0.as_ref().unwrap().sub_levels.iter()) + .chain(levels.l0.sub_levels.iter()) .flat_map(|levels| levels.table_infos.iter().map(|info| info.object_id)) .sorted() .collect_vec() diff --git a/src/meta/src/manager/diagnose.rs b/src/meta/src/manager/diagnose.rs index 90b9813fb9d26..cb5f005829e80 100644 --- a/src/meta/src/manager/diagnose.rs +++ b/src/meta/src/manager/diagnose.rs @@ -487,9 +487,7 @@ impl DiagnoseCommand { top_k_sstables(top_k, &mut top_tombstone_delete_sst, e); } }; - let Some(ref l0) = compaction_group.l0 else { - continue; - }; + let l0 = &compaction_group.l0; // FIXME: why chaining levels iter leads to segmentation fault? for level in &l0.sub_levels { visit_level(level); diff --git a/src/storage/hummock_sdk/src/compaction_group/hummock_version_ext.rs b/src/storage/hummock_sdk/src/compaction_group/hummock_version_ext.rs index b98e2d1abd786..3af0586e143ae 100644 --- a/src/storage/hummock_sdk/src/compaction_group/hummock_version_ext.rs +++ b/src/storage/hummock_sdk/src/compaction_group/hummock_version_ext.rs @@ -146,16 +146,9 @@ impl HummockVersion { } pub fn get_combined_levels(&self) -> impl Iterator + '_ { - self.levels.values().flat_map(|level| { - level - .l0 - .as_ref() - .unwrap() - .sub_levels - .iter() - .rev() - .chain(level.levels.iter()) - }) + self.levels + .values() + .flat_map(|level| level.l0.sub_levels.iter().rev().chain(level.levels.iter())) } pub fn get_object_ids(&self) -> HashSet { @@ -195,16 +188,7 @@ impl HummockVersion { None } }) - .flat_map(|level| { - level - .l0 - .as_ref() - .unwrap() - .sub_levels - .iter() - .rev() - .chain(level.levels.iter()) - }) + .flat_map(|level| level.l0.sub_levels.iter().rev().chain(level.levels.iter())) .flat_map(|level| level.table_infos.iter()) .chain(self.table_change_log.values().flat_map(|change_log| { // TODO: optimization: strip table change log @@ -223,7 +207,7 @@ impl HummockVersion { mut f: F, ) { if let Some(levels) = self.levels.get(&compaction_group_id) { - for sub_level in &levels.l0.as_ref().unwrap().sub_levels { + for sub_level in &levels.l0.sub_levels { if !f(sub_level) { return; } @@ -348,8 +332,8 @@ impl HummockVersion { .map_or(0, |parent_levels| { parent_levels .l0 + .sub_levels .iter() - .flat_map(|l0| &l0.sub_levels) .chain(parent_levels.levels.iter()) .flat_map(|level| &level.table_infos) .map(|sst_info| { @@ -382,9 +366,10 @@ impl HummockVersion { .levels .get_many_mut([&parent_group_id, &group_id]) .unwrap(); - if let Some(ref mut l0) = parent_levels.l0 { + let l0 = &mut parent_levels.l0; + { for sub_level in &mut l0.sub_levels { - let target_l0 = cur_levels.l0.as_mut().unwrap(); + let target_l0 = &mut cur_levels.l0; // When `insert_hint` is `Ok(idx)`, it means that the sub level `idx` in `target_l0` // will extend these SSTs. When `insert_hint` is `Err(idx)`, it // means that we will add a new sub level `idx` into `target_l0`. @@ -673,7 +658,7 @@ impl HummockVersion { ); if !insert_table_infos.is_empty() { insert_new_sub_level( - levels.l0.as_mut().unwrap(), + &mut levels.l0, insert_sub_level_id, PbLevelType::Overlapping, insert_table_infos, @@ -802,7 +787,7 @@ impl HummockVersion { let mut ret: BTreeMap<_, _> = BTreeMap::new(); for (compaction_group_id, group) in &self.levels { let mut levels = vec![]; - levels.extend(group.l0.as_ref().unwrap().sub_levels.iter()); + levels.extend(group.l0.sub_levels.iter()); levels.extend(group.levels.iter()); for level in levels { for table_info in &level.table_infos { @@ -860,7 +845,7 @@ impl Levels { } for level_idx in &delete_sst_levels { if *level_idx == 0 { - for level in &mut self.l0.as_mut().unwrap().sub_levels { + for level in &mut self.l0.sub_levels { level_delete_ssts(level, &delete_sst_ids_set); } } else { @@ -871,7 +856,7 @@ impl Levels { if !insert_table_infos.is_empty() { if insert_sst_level_id == 0 { - let l0 = self.l0.as_mut().unwrap(); + let l0 = &mut self.l0; let index = l0 .sub_levels .partition_point(|level| level.sub_level_id < insert_sub_level_id); @@ -912,22 +897,16 @@ impl Levels { } if delete_sst_levels.iter().any(|level_id| *level_id == 0) { self.l0 - .as_mut() - .unwrap() .sub_levels .retain(|level| !level.table_infos.is_empty()); - self.l0.as_mut().unwrap().total_file_size = self + self.l0.total_file_size = self .l0 - .as_mut() - .unwrap() .sub_levels .iter() .map(|level| level.total_file_size) .sum::(); - self.l0.as_mut().unwrap().uncompressed_file_size = self + self.l0.uncompressed_file_size = self .l0 - .as_mut() - .unwrap() .sub_levels .iter() .map(|level| level.uncompressed_file_size) @@ -942,7 +921,7 @@ impl Levels { ) -> bool { for level_idx in delete_sst_levels { if *level_idx == 0 { - for level in &self.l0.as_ref().unwrap().sub_levels { + for level in &self.l0.sub_levels { level.table_infos.iter().for_each(|table| { delete_sst_ids_set.remove(&table.sst_id); }); @@ -977,11 +956,11 @@ pub fn build_initial_compaction_group_levels( #[expect(deprecated)] // for backward-compatibility of previous hummock version delta Levels { levels, - l0: Some(OverlappingLevel { + l0: OverlappingLevel { sub_levels: vec![], total_file_size: 0, uncompressed_file_size: 0, - }), + }, group_id, parent_group_id: StaticCompactionGroupId::NewCompactionGroup as _, member_table_ids: vec![], @@ -1037,8 +1016,6 @@ pub fn get_compaction_group_ssts( let group_levels = version.get_compaction_group_levels(group_id); group_levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .rev() @@ -1298,22 +1275,19 @@ pub fn validate_version(version: &HummockVersion) -> Vec { } }; - if let Some(l0) = &levels.l0 { - let mut prev_sub_level_id = u64::MAX; - for sub_level in &l0.sub_levels { - // Ensure sub_level_id is sorted and unique - if sub_level.sub_level_id >= prev_sub_level_id { - res.push(format!( - "GROUP {} LEVEL 0: sub_level_id {} >= prev_sub_level {}", - group_id, sub_level.level_idx, prev_sub_level_id - )); - } - prev_sub_level_id = sub_level.sub_level_id; - - validate_level(*group_id, 0, sub_level, &mut res); + let l0 = &levels.l0; + let mut prev_sub_level_id = u64::MAX; + for sub_level in &l0.sub_levels { + // Ensure sub_level_id is sorted and unique + if sub_level.sub_level_id >= prev_sub_level_id { + res.push(format!( + "GROUP {} LEVEL 0: sub_level_id {} >= prev_sub_level {}", + group_id, sub_level.level_idx, prev_sub_level_id + )); } - } else { - res.push(format!("GROUP {}: level0 not exist", group_id)); + prev_sub_level_id = sub_level.sub_level_id; + + validate_level(*group_id, 0, sub_level, &mut res); } for idx in 1..=levels.levels.len() { @@ -1353,11 +1327,11 @@ mod tests { 0, Levels { levels: vec![], - l0: Some(OverlappingLevel { + l0: OverlappingLevel { sub_levels: vec![], total_file_size: 0, uncompressed_file_size: 0, - }), + }, ..Default::default() }, )]); @@ -1369,8 +1343,6 @@ mod tests { .get_mut(&0) .unwrap() .l0 - .as_mut() - .unwrap() .sub_levels .push(Level { table_infos: vec![SstableInfo { diff --git a/src/storage/hummock_sdk/src/level.rs b/src/storage/hummock_sdk/src/level.rs index d81e153ebd911..c7db09e69e76d 100644 --- a/src/storage/hummock_sdk/src/level.rs +++ b/src/storage/hummock_sdk/src/level.rs @@ -198,7 +198,7 @@ impl Level { #[derive(Debug, Clone, PartialEq, Default)] pub struct Levels { pub levels: Vec, - pub l0: Option, + pub l0: OverlappingLevel, pub group_id: u64, pub parent_group_id: u64, @@ -208,7 +208,7 @@ pub struct Levels { impl Levels { pub fn level0(&self) -> &OverlappingLevel { - self.l0.as_ref().unwrap() + &self.l0 } pub fn get_level(&self, level_idx: usize) -> &Level { @@ -254,9 +254,7 @@ impl Levels { + size_of::() + size_of::() + size_of::(); - if let Some(l0) = self.l0.as_ref() { - basic += l0.estimated_encode_len(); - } + basic += self.l0.estimated_encode_len(); basic } @@ -266,11 +264,7 @@ impl From<&PbLevels> for Levels { #[expect(deprecated)] fn from(pb_levels: &PbLevels) -> Self { Self { - l0: if pb_levels.l0.is_some() { - Some(OverlappingLevel::from(pb_levels.l0.as_ref().unwrap())) - } else { - None - }, + l0: OverlappingLevel::from(pb_levels.l0.as_ref().unwrap()), levels: pb_levels.levels.iter().map(Level::from).collect_vec(), group_id: pb_levels.group_id, parent_group_id: pb_levels.parent_group_id, @@ -283,11 +277,7 @@ impl From<&Levels> for PbLevels { #[expect(deprecated)] fn from(levels: &Levels) -> Self { Self { - l0: if levels.l0.is_some() { - Some(levels.l0.as_ref().unwrap().into()) - } else { - None - }, + l0: Some((&levels.l0).into()), levels: levels.levels.iter().map(PbLevel::from).collect_vec(), group_id: levels.group_id, parent_group_id: levels.parent_group_id, @@ -300,11 +290,7 @@ impl From for Levels { #[expect(deprecated)] fn from(pb_levels: PbLevels) -> Self { Self { - l0: if pb_levels.l0.is_some() { - Some(OverlappingLevel::from(pb_levels.l0.unwrap())) - } else { - None - }, + l0: OverlappingLevel::from(pb_levels.l0.as_ref().unwrap()), levels: pb_levels.levels.into_iter().map(Level::from).collect_vec(), group_id: pb_levels.group_id, parent_group_id: pb_levels.parent_group_id, @@ -317,11 +303,7 @@ impl From for PbLevels { fn from(levels: Levels) -> Self { #[expect(deprecated)] Self { - l0: if levels.l0.is_some() { - Some(levels.l0.unwrap().into()) - } else { - None - }, + l0: Some(levels.l0.into()), levels: levels.levels.into_iter().map(PbLevel::from).collect_vec(), group_id: levels.group_id, parent_group_id: levels.parent_group_id, diff --git a/src/storage/hummock_sdk/src/time_travel.rs b/src/storage/hummock_sdk/src/time_travel.rs index 7da9197e54dd2..a870d7d6d549a 100644 --- a/src/storage/hummock_sdk/src/time_travel.rs +++ b/src/storage/hummock_sdk/src/time_travel.rs @@ -101,8 +101,6 @@ pub fn refill_version( for level in version.levels.values_mut().flat_map(|level| { level .l0 - .as_mut() - .unwrap() .sub_levels .iter_mut() .rev() @@ -159,7 +157,7 @@ fn stripped_l0(origin: &OverlappingLevel) -> OverlappingLevel { fn stripped_levels(origin: &Levels) -> Levels { Levels { levels: origin.levels.iter().map(stripped_level).collect(), - l0: origin.l0.as_ref().map(stripped_l0), + l0: stripped_l0(&origin.l0), group_id: origin.group_id, parent_group_id: origin.parent_group_id, member_table_ids: Default::default(), diff --git a/src/storage/hummock_test/src/compactor_tests.rs b/src/storage/hummock_test/src/compactor_tests.rs index 4c5d8c9c65a19..38ef095969a1f 100644 --- a/src/storage/hummock_test/src/compactor_tests.rs +++ b/src/storage/hummock_test/src/compactor_tests.rs @@ -345,8 +345,6 @@ pub(crate) mod tests { .chain( group .l0 - .as_ref() - .unwrap() .sub_levels .iter() .flat_map(|level| level.table_infos.clone()), diff --git a/src/storage/src/hummock/local_version/pinned_version.rs b/src/storage/src/hummock/local_version/pinned_version.rs index 8819d0162a5e9..a3d7b5544ecfe 100644 --- a/src/storage/src/hummock/local_version/pinned_version.rs +++ b/src/storage/src/hummock/local_version/pinned_version.rs @@ -140,8 +140,6 @@ impl PinnedVersion { let levels = self.levels_by_compaction_groups_id(compaction_group_id); levels .l0 - .as_ref() - .unwrap() .sub_levels .iter() .rev() diff --git a/src/tests/compaction_test/src/delete_range_runner.rs b/src/tests/compaction_test/src/delete_range_runner.rs index 5d6c6ff7e70d1..2d272823d6058 100644 --- a/src/tests/compaction_test/src/delete_range_runner.rs +++ b/src/tests/compaction_test/src/delete_range_runner.rs @@ -288,7 +288,7 @@ async fn compaction_test( version.id, remote_version.id ); for (group, levels) in &version.levels { - let l0 = levels.l0.as_ref().unwrap(); + let l0 = &levels.l0; println!( "group-{}: l0 sz: {}, count: {}", group,