Skip to content

Commit

Permalink
cover more case
Browse files Browse the repository at this point in the history
  • Loading branch information
wenym1 committed Oct 15, 2024
1 parent 385acc4 commit b132d9d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
24 changes: 16 additions & 8 deletions src/ctl/src/cmd_impl/hummock/validate_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,22 @@ pub async fn print_version_delta_in_archive(
}

fn match_delta(delta: &DeltaType, sst_id: HummockSstableObjectId) -> bool {
let DeltaType::IntraLevel(delta) = delta else {
return false;
};
delta
.inserted_table_infos
.iter()
.any(|sst| sst.sst_id == sst_id)
|| delta.removed_table_ids.iter().any(|sst| *sst == sst_id)
match delta {
DeltaType::GroupConstruct(_) | DeltaType::GroupDestroy(_) | DeltaType::GroupMerge(_) => {
false
}
DeltaType::IntraLevel(delta) => {
delta
.inserted_table_infos
.iter()
.any(|sst| sst.sst_id == sst_id)
|| delta.removed_table_ids.iter().any(|sst| *sst == sst_id)
}
DeltaType::NewL0SubLevel(delta) => delta
.inserted_table_infos
.iter()
.any(|sst| sst.sst_id == sst_id),
}
}

fn print_delta(delta: &DeltaType) {
Expand Down
51 changes: 32 additions & 19 deletions src/storage/hummock_sdk/src/compaction_group/hummock_version_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,36 +420,49 @@ impl HummockVersion {
let mut removed_ssts: BTreeMap<u32, BTreeSet<u64>> = BTreeMap::new();

// Build only if all deltas are intra level deltas.
if !group_deltas
.group_deltas
.iter()
.all(|delta| matches!(delta, GroupDelta::IntraLevel(_)))
{
if !group_deltas.group_deltas.iter().all(|delta| {
matches!(
delta,
GroupDelta::IntraLevel(_) | GroupDelta::NewL0SubLevel(_)
)
}) {
continue;
}

// TODO(MrCroxx): At most one insert delta is allowed here. It's okay for now with the
// current `hummock::manager::gen_version_delta` implementation. Better refactor the
// struct to reduce conventions.
for group_delta in &group_deltas.group_deltas {
if let GroupDelta::IntraLevel(intra_level) = group_delta {
if !intra_level.inserted_table_infos.is_empty() {
info.insert_sst_level = intra_level.level_idx;
info.insert_sst_infos
.extend(intra_level.inserted_table_infos.iter().cloned());
match group_delta {
GroupDeltaCommon::NewL0SubLevel(inserted_table_infos) => {
if !inserted_table_infos.is_empty() {
info.insert_sst_level = 0;
info.insert_sst_infos
.extend(inserted_table_infos.iter().cloned());
}
}
if !intra_level.removed_table_ids.is_empty() {
for id in &intra_level.removed_table_ids {
if intra_level.level_idx == 0 {
removed_l0_ssts.insert(*id);
} else {
removed_ssts
.entry(intra_level.level_idx)
.or_default()
.insert(*id);
GroupDeltaCommon::IntraLevel(intra_level) => {
if !intra_level.inserted_table_infos.is_empty() {
info.insert_sst_level = intra_level.level_idx;
info.insert_sst_infos
.extend(intra_level.inserted_table_infos.iter().cloned());
}
if !intra_level.removed_table_ids.is_empty() {
for id in &intra_level.removed_table_ids {
if intra_level.level_idx == 0 {
removed_l0_ssts.insert(*id);
} else {
removed_ssts
.entry(intra_level.level_idx)
.or_default()
.insert(*id);
}
}
}
}
GroupDeltaCommon::GroupConstruct(_)
| GroupDeltaCommon::GroupDestroy(_)
| GroupDeltaCommon::GroupMerge(_) => {}
}
}

Expand Down

0 comments on commit b132d9d

Please sign in to comment.