-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(storage): maintain sub_level id order #18915
Changes from 5 commits
8d6c2af
9b04349
0620d94
c654974
b8bdf81
d5ecedd
24e46b8
151c84d
74d130e
d0ba96c
d8ead5a
09d5b6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; | |
use std::sync::Arc; | ||
|
||
use bytes::Bytes; | ||
use itertools::Either::{Left, Right}; | ||
use itertools::Itertools; | ||
use risingwave_common::catalog::TableId; | ||
use risingwave_common::hash::VnodeBitmapExt; | ||
|
@@ -434,10 +435,10 @@ impl HummockVersion { | |
continue; | ||
} | ||
match group_split::get_sub_level_insert_hint(&target_l0.sub_levels, sub_level) { | ||
Ok(idx) => { | ||
Left(idx) => { | ||
add_ssts_to_sub_level(target_l0, idx, insert_table_infos); | ||
} | ||
Err(idx) => { | ||
Right(idx) => { | ||
insert_new_sub_level( | ||
target_l0, | ||
sub_level.sub_level_id, | ||
|
@@ -660,15 +661,10 @@ impl HummockVersion { | |
|| group_destroy.is_some(), | ||
"no sst should be deleted when committing an epoch" | ||
); | ||
let mut next_l0_sub_level_id = levels | ||
.l0 | ||
.sub_levels | ||
.last() | ||
.map(|level| level.sub_level_id + 1) | ||
.unwrap_or(1); | ||
for group_delta in &group_deltas.group_deltas { | ||
if let GroupDelta::IntraLevel(IntraLevelDelta { | ||
level_idx, | ||
l0_sub_level_id, | ||
inserted_table_infos, | ||
.. | ||
}) = group_delta | ||
|
@@ -680,12 +676,11 @@ impl HummockVersion { | |
if !inserted_table_infos.is_empty() { | ||
insert_new_sub_level( | ||
&mut levels.l0, | ||
next_l0_sub_level_id, | ||
*l0_sub_level_id, | ||
PbLevelType::Overlapping, | ||
inserted_table_infos.clone(), | ||
None, | ||
); | ||
next_l0_sub_level_id += 1; | ||
} | ||
} | ||
} | ||
|
@@ -764,6 +759,14 @@ impl HummockVersion { | |
&version_delta.state_table_info_delta, | ||
&changed_table_info, | ||
); | ||
|
||
// The max_sub_level_id may have been increased, e.g. during commit_epoch or merge_group. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should max with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Thanks. |
||
// Recalculate it. | ||
self.max_sub_level_id = self | ||
.levels | ||
.values() | ||
.filter_map(|levels| levels.l0.sub_levels.iter().map(|s| s.sub_level_id).max()) | ||
.max(); | ||
} | ||
|
||
pub fn apply_change_log_delta<T: Clone>( | ||
|
@@ -883,7 +886,7 @@ impl HummockVersion { | |
) | ||
}); | ||
|
||
group_split::merge_levels(left_levels, right_levels); | ||
group_split::merge_levels(left_levels, right_levels, self.max_sub_level_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's better to maintain a per-compaction group max_sub_level_id instead of a global one, and then we don't need to pass the global one here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to either option. @Li0k There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer global uniqueness, for me at the moment this sub level id has no more semantics. So globally unique is more concise. |
||
} | ||
} | ||
|
||
|
@@ -952,10 +955,10 @@ impl HummockVersionCommon<SstableInfo> { | |
l0.uncompressed_file_size -= sst_info.uncompressed_file_size; | ||
}); | ||
match group_split::get_sub_level_insert_hint(&target_l0.sub_levels, sub_level) { | ||
Ok(idx) => { | ||
Left(idx) => { | ||
add_ssts_to_sub_level(target_l0, idx, insert_table_infos); | ||
} | ||
Err(idx) => { | ||
Right(idx) => { | ||
insert_new_sub_level( | ||
target_l0, | ||
sub_level.sub_level_id, | ||
|
@@ -2032,7 +2035,7 @@ mod tests { | |
let mut left_levels = Levels::default(); | ||
let right_levels = Levels::default(); | ||
|
||
group_split::merge_levels(&mut left_levels, right_levels); | ||
group_split::merge_levels(&mut left_levels, right_levels, None); | ||
} | ||
|
||
{ | ||
|
@@ -2046,7 +2049,7 @@ mod tests { | |
); | ||
let right_levels = right_levels.clone(); | ||
|
||
group_split::merge_levels(&mut left_levels, right_levels); | ||
group_split::merge_levels(&mut left_levels, right_levels, None); | ||
|
||
assert!(left_levels.l0.sub_levels.len() == 3); | ||
assert!(left_levels.l0.sub_levels[0].sub_level_id == 101); | ||
|
@@ -2071,7 +2074,7 @@ mod tests { | |
}, | ||
); | ||
|
||
group_split::merge_levels(&mut left_levels, right_levels); | ||
group_split::merge_levels(&mut left_levels, right_levels, None); | ||
|
||
assert!(left_levels.l0.sub_levels.len() == 3); | ||
assert!(left_levels.l0.sub_levels[0].sub_level_id == 101); | ||
|
@@ -2089,7 +2092,7 @@ mod tests { | |
let mut left_levels = left_levels.clone(); | ||
let right_levels = right_levels.clone(); | ||
|
||
group_split::merge_levels(&mut left_levels, right_levels); | ||
group_split::merge_levels(&mut left_levels, right_levels, None); | ||
|
||
assert!(left_levels.l0.sub_levels.len() == 6); | ||
assert!(left_levels.l0.sub_levels[0].sub_level_id == 101); | ||
|
@@ -2459,7 +2462,7 @@ mod tests { | |
..Default::default() | ||
}; | ||
|
||
merge_levels(cg1, right_levels); | ||
merge_levels(cg1, right_levels, None); | ||
} | ||
|
||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be backward compatible, should we init the
max_sub_level_id
on meta startup to be the actual max sub-level id and we use themax_sub_level_id
field only for the new sublevel's id?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been done in
src/storage/hummock_sdk/src/version.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Therefore, reaching line 169 indicates that the version is indeed a fresh new one.
Alternatively we can make the in-mem
HummockVersion:: max_sub_level_id
u64 directly instead of Option<64>, in order to avoid suchunwrap_or
whenever readingmax_sub_level_id
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok for now, the newly introduced fields keep the Option restrictions.
When line 169 is reached, the sub_level will no longer exist in the compaciton group, so it is correct to use
FIRST_SUB_LEVEL_ID
for initialisation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it's a bug. Thanks.