-
Notifications
You must be signed in to change notification settings - Fork 66
feat: plan distributed dynamic filters #634
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
Open
jayshrivastava
wants to merge
6
commits into
main
from
js/2-forward-dynamic-filter-updates-to-coordinator
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa8db4f
feat: plan distributed dynamic filters
jayshrivastava 9866970
delete registers_dynamic_filters_by_expression_id test
jayshrivastava a1e2ed4
better comments around dynamic filter "sever" functions
jayshrivastava bd4cb92
migrate dynamic filter discovery tests to integration tests
jayshrivastava 41032c9
only do dynamic filtering display and plan severing when enabled
jayshrivastava 2b1213f
move dynamic filter anchors to remote stages
jayshrivastava 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| use crate::TaskKey; | ||
| use crate::dynamic_filtering::{ | ||
| discover_dynamic_filter_consumers, discover_dynamic_filter_producers, | ||
| }; | ||
| use datafusion::common::{HashMap, HashSet, Result}; | ||
| use datafusion::physical_plan::ExecutionPlan; | ||
| use std::sync::{Arc, Mutex}; | ||
|
|
||
| #[derive(Default)] | ||
| pub(super) struct PlannedDynamicFilter { | ||
| // Producer and consumer tasks for a dynamic filter. | ||
| // | ||
| // Note that it is not guaranteed that every task within a stage produces / consumes dynamic filters. For | ||
| // example, a distributed union may prevent a dynamic filter from appearing in all tasks. So, we | ||
| // store task keys rather than stage ids. | ||
| pub(super) producer_tasks: HashSet<TaskKey>, | ||
| pub(super) consumer_tasks: HashSet<TaskKey>, | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub(super) struct DynamicFilterRegistryState { | ||
| pub(super) filters: HashMap<u64, PlannedDynamicFilter>, | ||
| } | ||
|
|
||
| /// Query-scoped hub for distributed dynamic filtering. | ||
| /// | ||
| /// It stores the locations of dynamic filters and their runtime state. Informs the coordinator | ||
| /// - where dynamic filter updates are coming from | ||
| /// - how/if dynamic filter updates should be merged | ||
| /// - where dynamic filter updates should be forwarded | ||
| #[derive(Default)] | ||
| pub(crate) struct DynamicFilterRegistry { | ||
| pub(super) state: Mutex<DynamicFilterRegistryState>, | ||
| } | ||
|
|
||
| impl DynamicFilterRegistry { | ||
| pub(crate) fn new() -> Self { | ||
| Self::default() | ||
| } | ||
|
|
||
| /// Adds any dynamic filter producers and consumers found in `plan` to the registry. | ||
| pub(crate) fn register_task( | ||
| &self, | ||
| plan: &Arc<dyn ExecutionPlan>, | ||
| task_key: TaskKey, | ||
| ) -> Result<()> { | ||
| let producers = discover_dynamic_filter_producers(plan)?; | ||
| // We can safely ignore anchors because they are not evaluated by network boundaries. This | ||
| // means they do not need updates forwarded to them. | ||
| let consumers = discover_dynamic_filter_consumers(plan)?.consumers; | ||
|
|
||
| let mut state = self.state.lock().expect("dynamic filter registry poisoned"); | ||
| for producer in producers { | ||
| state | ||
| .filters | ||
| .entry(producer.id) | ||
| .or_default() | ||
| .producer_tasks | ||
| .insert(task_key); | ||
| } | ||
| for consumer in consumers { | ||
| state | ||
| .filters | ||
| .entry(consumer.id) | ||
| .or_default() | ||
| .consumer_tasks | ||
| .insert(task_key); | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
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.
In future PRs, we add more mutex protected state in this struct.