-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: reduce peak memory usage when round robin tiebreaker is disabled #23606
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
base: main
Are you sure you want to change the base?
Changes from all commits
9c0f156
4669a69
0fbffb4
bb788ac
95a0830
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,8 +142,9 @@ pub(crate) struct SortPreservingMergeStream<C: CursorValues> { | |||||||||||||
| /// Current reset count | ||||||||||||||
| current_reset_epoch: usize, | ||||||||||||||
|
|
||||||||||||||
| /// Stores the previous value of each partitions for tracking the poll counts on the same value. | ||||||||||||||
| prev_cursors: Vec<Option<Cursor<C>>>, | ||||||||||||||
| /// Stores the previous value of each partitions for tracking the poll counts on the same value | ||||||||||||||
| /// when round_robin_tie_breaker is enabled | ||||||||||||||
| prev_cursors: Option<Vec<Option<Cursor<C>>>>, | ||||||||||||||
|
|
||||||||||||||
| /// Optional number of rows to fetch | ||||||||||||||
| fetch: Option<usize>, | ||||||||||||||
|
|
@@ -174,7 +175,11 @@ impl<C: CursorValues> SortPreservingMergeStream<C> { | |||||||||||||
| done: false, | ||||||||||||||
| drain_in_progress_on_done: false, | ||||||||||||||
| cursors: (0..stream_count).map(|_| None).collect(), | ||||||||||||||
| prev_cursors: (0..stream_count).map(|_| None).collect(), | ||||||||||||||
| prev_cursors: if enable_round_robin_tie_breaker { | ||||||||||||||
| Some((0..stream_count).map(|_| None).collect()) | ||||||||||||||
| } else { | ||||||||||||||
| None | ||||||||||||||
| }, | ||||||||||||||
| round_robin_tie_breaker_mode: false, | ||||||||||||||
| num_of_polled_with_same_value: vec![0; stream_count], | ||||||||||||||
| current_reset_epoch: 0, | ||||||||||||||
|
|
@@ -361,7 +366,13 @@ impl<C: CursorValues> SortPreservingMergeStream<C> { | |||||||||||||
|
|
||||||||||||||
| if let Some(c) = cursor.as_mut() { | ||||||||||||||
| // Compare with the last row in the previous batch | ||||||||||||||
| let prev_cursor = &self.prev_cursors[partition_idx]; | ||||||||||||||
| let prev_cursor = self | ||||||||||||||
| .prev_cursors | ||||||||||||||
| .as_ref() | ||||||||||||||
| .map(|v| &v[partition_idx]) | ||||||||||||||
| .expect( | ||||||||||||||
| "prev_cursor should be set when round robin tie breaker is enabled", | ||||||||||||||
| ); | ||||||||||||||
| if c.is_eq_to_prev_one(prev_cursor.as_ref()) { | ||||||||||||||
| self.num_of_polled_with_same_value[partition_idx] += 1; | ||||||||||||||
| } else { | ||||||||||||||
|
|
@@ -385,7 +396,10 @@ impl<C: CursorValues> SortPreservingMergeStream<C> { | |||||||||||||
| let _ = cursor.advance(); | ||||||||||||||
| if cursor.is_finished() { | ||||||||||||||
| // Take the current cursor, leaving `None` in its place | ||||||||||||||
| self.prev_cursors[stream_idx] = self.cursors[stream_idx].take(); | ||||||||||||||
| let taken = self.cursors[stream_idx].take(); | ||||||||||||||
| if self.enable_round_robin_tie_breaker { | ||||||||||||||
| self.prev_cursors.as_mut().expect("prev_cursor should be set when round robin tie breaker is enabled")[stream_idx] = taken; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+400
to
+402
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. The expect() check seems a bit redundant, just match on the option directly
Suggested change
Contributor
Author
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. this would silently break if for some reason a None would end up in prev_cursors, I prefer to fail loudly |
||||||||||||||
| } | ||||||||||||||
| true | ||||||||||||||
| } else { | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.