From cb7199a95da8aefa4906557d4a91829407386656 Mon Sep 17 00:00:00 2001 From: Li0k Date: Mon, 17 Jun 2024 16:37:11 +0800 Subject: [PATCH] refactor(storage): unify split sst --- src/meta/src/hummock/manager/commit_epoch.rs | 7 +++---- .../src/compaction_group/hummock_version_ext.rs | 16 +++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/meta/src/hummock/manager/commit_epoch.rs b/src/meta/src/hummock/manager/commit_epoch.rs index a39390f03aad4..23e7167c7a0a7 100644 --- a/src/meta/src/hummock/manager/commit_epoch.rs +++ b/src/meta/src/hummock/manager/commit_epoch.rs @@ -16,6 +16,7 @@ use std::collections::{BTreeMap, HashMap}; use itertools::Itertools; use risingwave_common::catalog::TableId; +use risingwave_hummock_sdk::compaction_group::hummock_version_ext::split_sst; use risingwave_hummock_sdk::compaction_group::StaticCompactionGroupId; use risingwave_hummock_sdk::table_stats::{ add_prost_table_stats_map, purge_prost_table_stats, PbTableStatsMap, @@ -358,14 +359,12 @@ impl HummockManager { let mut new_sst_id = next_sstable_object_id(&self.env, new_sst_id_number).await?; let mut commit_sstables = Vec::with_capacity(sst_to_cg_vec.len() + new_sst_id_number); - for (sst, group_table_ids) in sst_to_cg_vec { + for (mut sst, group_table_ids) in sst_to_cg_vec { for (group_id, _match_ids) in group_table_ids { - let mut branch_sst = sst.sst_info.clone(); - branch_sst.sst_id = new_sst_id; + let branch_sst = split_sst(&mut sst.sst_info, &mut new_sst_id); commit_sstables.push(ExtendedSstableInfo::with_compaction_group( group_id, branch_sst, )); - new_sst_id += 1; } new_sst_id += 1; 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 36aa064a672d4..e6989ec245fb6 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 @@ -947,11 +947,8 @@ fn split_sst_info_for_level( .cloned() .collect_vec(); if !removed_table_ids.is_empty() { - let mut branch_table_info = sst_info.clone(); - branch_table_info.sst_id = *new_sst_id; - sst_info.sst_id = *new_sst_id + 1; - *new_sst_id += 1; - insert_table_infos.push(branch_table_info); + let branch_sst = split_sst(sst_info, new_sst_id); + insert_table_infos.push(branch_sst); } } insert_table_infos @@ -1293,6 +1290,15 @@ pub fn validate_version(version: &HummockVersion) -> Vec { res } +pub fn split_sst(sst_info: &mut SstableInfo, new_sst_id: &mut u64) -> SstableInfo { + let mut branch_table_info = sst_info.clone(); + branch_table_info.sst_id = *new_sst_id; + sst_info.sst_id = *new_sst_id + 1; + *new_sst_id += 1; + + branch_table_info +} + #[cfg(test)] mod tests { use std::collections::HashMap;