Skip to content

Commit 8b09f5e

Browse files
feat(sst id): avoid SST ID gap when generating (risingwavelabs#8542)
1 parent 53c6a4c commit 8b09f5e

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

src/meta/src/hummock/manager/compaction_group_manager.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::collections::{BTreeMap, HashMap};
15+
use std::collections::{BTreeMap, HashMap, HashSet};
1616
use std::ops::DerefMut;
1717
use std::sync::Arc;
1818

1919
use function_name::named;
2020
use itertools::Itertools;
2121
use risingwave_hummock_sdk::compaction_group::hummock_version_ext::{
2222
build_version_delta_after_version, get_compaction_group_ids, get_compaction_group_ssts,
23-
get_member_table_ids, try_get_compaction_group_id_by_table_id, HummockLevelsExt,
24-
HummockVersionExt, HummockVersionUpdateExt,
23+
get_member_table_ids, try_get_compaction_group_id_by_table_id, HummockVersionExt,
24+
HummockVersionUpdateExt,
2525
};
2626
use risingwave_hummock_sdk::compaction_group::{StateTableId, StaticCompactionGroupId};
2727
use risingwave_hummock_sdk::CompactionGroupId;
@@ -485,7 +485,10 @@ impl<S: MetaStore> HummockManager<S> {
485485
.env
486486
.id_gen_manager()
487487
.generate_interval::<{ IdCategory::HummockSstableId }>(
488-
parent_group.count_ssts() as u64 * 2,
488+
versioning.current_version.count_new_ssts_in_group_split(
489+
parent_group_id,
490+
&HashSet::from_iter(table_ids.iter().cloned()),
491+
),
489492
)
490493
.await?;
491494
let group_deltas = &mut new_version_delta

src/meta/src/hummock/manager/versioning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct Versioning {
7979
/// - AND It either contains no SST to delete, or all these SSTs has been deleted. See
8080
/// `extend_objects_to_delete_from_deltas`.
8181
pub deltas_to_delete: Vec<HummockVersionId>,
82-
/// SST which is referenced more than once
82+
/// SST whose `object_id` != `sst_id`
8383
pub branched_ssts: BTreeMap<
8484
// SST object id
8585
HummockSstableObjectId,

src/storage/hummock_sdk/src/compaction_group/hummock_version_ext.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ pub trait HummockVersionExt {
107107
}
108108

109109
pub trait HummockVersionUpdateExt {
110+
fn count_new_ssts_in_group_split(
111+
&mut self,
112+
parent_group_id: CompactionGroupId,
113+
member_table_ids: &HashSet<StateTableId>,
114+
) -> u64;
110115
fn init_with_parent_group(
111116
&mut self,
112117
parent_group_id: CompactionGroupId,
@@ -200,6 +205,43 @@ pub type SstSplitInfo = (
200205
);
201206

202207
impl HummockVersionUpdateExt for HummockVersion {
208+
fn count_new_ssts_in_group_split(
209+
&mut self,
210+
parent_group_id: CompactionGroupId,
211+
member_table_ids: &HashSet<StateTableId>,
212+
) -> u64 {
213+
self.levels
214+
.get(&parent_group_id)
215+
.map_or(0, |parent_levels| {
216+
parent_levels
217+
.l0
218+
.iter()
219+
.flat_map(|l0| l0.get_sub_levels())
220+
.chain(parent_levels.get_levels().iter())
221+
.flat_map(|level| level.get_table_infos())
222+
.map(|sst_info| {
223+
// `flag` is a bitmap
224+
let mut flag = 0;
225+
// `sst_info.table_ids` will never be empty.
226+
for table_id in sst_info.get_table_ids() {
227+
flag |= if member_table_ids.contains(table_id) {
228+
2
229+
} else {
230+
1
231+
};
232+
if flag == 3 {
233+
break;
234+
}
235+
}
236+
// We need to replace the SST id of the divided part in parent group with a
237+
// new SST id when it's not a trivial adjust. View function
238+
// `init_with_parent_group` for details.
239+
flag - 1
240+
})
241+
.sum()
242+
})
243+
}
244+
203245
fn init_with_parent_group(
204246
&mut self,
205247
parent_group_id: CompactionGroupId,

0 commit comments

Comments
 (0)