-
Notifications
You must be signed in to change notification settings - Fork 594
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): refactor on merge imm code #14880
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2abc32f
refactor(storage): do not track imm ids in imm
wenym1 e8459b4
replace tuple with struct
wenym1 7851355
Merge branch 'main' into yiming/no-track-merge-input-imm-id
wenym1 314da85
fix ut
wenym1 e33d5f7
make dylint happy
wenym1 adeac47
Merge branch 'main' into yiming/no-track-merge-input-imm-id
wenym1 99a1ca1
rename version to value
wenym1 c644d94
add comment
wenym1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ pub type SpawnMergingTask = Arc< | |
LocalInstanceId, | ||
Vec<ImmutableMemtable>, | ||
Option<MemoryTracker>, | ||
) -> JoinHandle<HummockResult<ImmutableMemtable>> | ||
) -> JoinHandle<ImmutableMemtable> | ||
+ Send | ||
+ Sync | ||
+ 'static, | ||
|
@@ -119,6 +119,8 @@ struct UploadingTask { | |
} | ||
|
||
pub struct MergeImmTaskOutput { | ||
/// Input imm ids of the merging task. Larger imm ids at the front. | ||
pub imm_ids: Vec<ImmId>, | ||
pub table_id: TableId, | ||
pub instance_id: LocalInstanceId, | ||
pub merged_imm: ImmutableMemtable, | ||
|
@@ -129,7 +131,17 @@ struct MergingImmTask { | |
table_id: TableId, | ||
instance_id: LocalInstanceId, | ||
input_imms: Vec<ImmutableMemtable>, | ||
join_handle: JoinHandle<HummockResult<ImmutableMemtable>>, | ||
join_handle: JoinHandle<ImmutableMemtable>, | ||
} | ||
|
||
impl Debug for MergingImmTask { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("MergingImmTask") | ||
.field("table_id", &self.table_id) | ||
.field("instance_id", &self.instance_id) | ||
.field("input_imms", &self.input_imms) | ||
.finish() | ||
} | ||
} | ||
|
||
impl MergingImmTask { | ||
|
@@ -140,6 +152,7 @@ impl MergingImmTask { | |
memory_tracker: Option<MemoryTracker>, | ||
context: &UploaderContext, | ||
) -> Self { | ||
assert!(imms.iter().rev().map(|imm| imm.batch_id()).is_sorted()); | ||
let input_imms = imms.clone(); | ||
let join_handle = (context.spawn_merging_task)(table_id, instance_id, imms, memory_tracker); | ||
|
||
|
@@ -152,19 +165,22 @@ impl MergingImmTask { | |
} | ||
|
||
/// Poll the result of the merge task | ||
fn poll_result(&mut self, cx: &mut Context<'_>) -> Poll<HummockResult<ImmutableMemtable>> { | ||
fn poll_result(&mut self, cx: &mut Context<'_>) -> Poll<ImmutableMemtable> { | ||
Poll::Ready(match ready!(self.join_handle.poll_unpin(cx)) { | ||
Ok(task_result) => task_result, | ||
Err(err) => Err(HummockError::other(format!( | ||
"fail to join imm merge join handle: {}", | ||
err.as_report() | ||
))), | ||
Err(err) => { | ||
panic!( | ||
"failed to join merging task: {:?} {:?}", | ||
err.as_report(), | ||
self | ||
); | ||
} | ||
Comment on lines
+171
to
+177
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. Given that the only await point in merge imm is |
||
}) | ||
} | ||
} | ||
|
||
impl Future for MergingImmTask { | ||
type Output = HummockResult<ImmutableMemtable>; | ||
type Output = ImmutableMemtable; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
self.poll_result(cx) | ||
|
@@ -510,7 +526,6 @@ impl SealedData { | |
} | ||
|
||
fn add_merged_imm(&mut self, merged_imm: &ImmutableMemtable) { | ||
debug_assert!(merged_imm.is_merged_imm()); | ||
// add merged_imm to merged_imms | ||
self.merged_imms.push_front(merged_imm.clone()); | ||
} | ||
|
@@ -573,15 +588,16 @@ impl SealedData { | |
fn poll_success_merge_imm(&mut self, cx: &mut Context<'_>) -> Poll<Option<MergeImmTaskOutput>> { | ||
// only poll the oldest merge task if there is any | ||
if let Some(task) = self.merging_tasks.back_mut() { | ||
let merge_result = ready!(task.poll_unpin(cx)); | ||
let merged_imm = ready!(task.poll_unpin(cx)); | ||
|
||
// pop the finished task | ||
let task = self.merging_tasks.pop_back().expect("must exist"); | ||
|
||
Poll::Ready(Some(MergeImmTaskOutput { | ||
imm_ids: task.input_imms.iter().map(|imm| imm.batch_id()).collect(), | ||
table_id: task.table_id, | ||
instance_id: task.instance_id, | ||
merged_imm: merge_result.unwrap(), | ||
merged_imm, | ||
})) | ||
} else { | ||
Poll::Ready(None) | ||
|
@@ -1655,17 +1671,10 @@ mod tests { | |
_ = sleep => { | ||
println!("sleep timeout") | ||
} | ||
res = &mut task => { | ||
match res { | ||
Ok(imm) => { | ||
println!("merging task success"); | ||
assert_eq!(table_id, imm.table_id); | ||
assert_eq!(9, imm.kv_count()); | ||
} | ||
Err(err) => { | ||
println!("merging task failed: {:?}", err); | ||
} | ||
} | ||
imm = &mut task => { | ||
println!("merging task success"); | ||
assert_eq!(table_id, imm.table_id); | ||
assert_eq!(9, imm.kv_count()); | ||
} | ||
} | ||
task.join_handle.abort(); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
May add comments of the reason for coop scheduling above.