-
Notifications
You must be signed in to change notification settings - Fork 14
Introduce DistributedExt trait that extends the capabilities of DataFusion's session building tools
#106
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
Merged
Merged
Introduce DistributedExt trait that extends the capabilities of DataFusion's session building tools
#106
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5dc4584
Introduce DistributedExt
gabotechs e55c8ef
Include user codecs in DistributedExt
gabotechs 248f7fb
Add with_ variants to DistributedExt
gabotechs a0dc5e5
Include ChannelManager in the DistributedExt trait
gabotechs a4fa271
Run cargo fmt
gabotechs e94da39
Rename methods
gabotechs e902e1f
Improve distributed_ext.rs doc comments
gabotechs 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 was deleted.
Oops, something went wrong.
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,52 @@ | ||
| use async_trait::async_trait; | ||
| use datafusion::error::DataFusionError; | ||
| use datafusion::prelude::SessionConfig; | ||
| use std::sync::Arc; | ||
| use tonic::body::BoxBody; | ||
| use url::Url; | ||
|
|
||
| pub(crate) fn set_distributed_channel_resolver( | ||
| cfg: &mut SessionConfig, | ||
| channel_resolver: impl ChannelResolver + Send + Sync + 'static, | ||
| ) { | ||
| cfg.set_extension(Arc::new(ChannelResolverExtension(Arc::new( | ||
| channel_resolver, | ||
| )))); | ||
| } | ||
|
|
||
| pub(crate) fn get_distributed_channel_resolver( | ||
| cfg: &SessionConfig, | ||
| ) -> Option<Arc<dyn ChannelResolver + Send + Sync>> { | ||
| cfg.get_extension::<ChannelResolverExtension>() | ||
| .map(|cm| cm.0.clone()) | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| struct ChannelResolverExtension(Arc<dyn ChannelResolver + Send + Sync>); | ||
|
|
||
| pub type BoxCloneSyncChannel = tower::util::BoxCloneSyncService< | ||
| http::Request<BoxBody>, | ||
| http::Response<BoxBody>, | ||
| tonic::transport::Error, | ||
| >; | ||
|
|
||
| /// Abstracts networking details so that users can implement their own network resolution | ||
| /// mechanism. | ||
| #[async_trait] | ||
| pub trait ChannelResolver { | ||
| /// Gets all available worker URLs. Used during stage assignment. | ||
| fn get_urls(&self) -> Result<Vec<Url>, DataFusionError>; | ||
| /// For a given URL, get a channel for communicating to it. | ||
| async fn get_channel_for_url(&self, url: &Url) -> Result<BoxCloneSyncChannel, DataFusionError>; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl ChannelResolver for Arc<dyn ChannelResolver + Send + Sync> { | ||
| fn get_urls(&self) -> Result<Vec<Url>, DataFusionError> { | ||
| self.as_ref().get_urls() | ||
| } | ||
|
|
||
| async fn get_channel_for_url(&self, url: &Url) -> Result<BoxCloneSyncChannel, DataFusionError> { | ||
| self.as_ref().get_channel_for_url(url).await | ||
| } | ||
| } | ||
File renamed without changes.
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 |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| mod composed_extension_codec; | ||
| #[allow(unused)] | ||
| pub mod ttl_map; | ||
| pub mod util; | ||
|
|
||
| pub(crate) use composed_extension_codec::ComposedPhysicalExtensionCodec; |
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.
I like this interface and I know you are refactoring it so it is not new but because I am here, I am trying to think out loud whether these are possible if we want to consider them in the future. I am talking about these in the context of providing API for scheduling, workload balancing and fairness for queries.
IIUC, these URLs are set per session, right? This means all queries of the same session will get the same set of workers. However, the number of workers each stage of a query uses depends on the needs of each stage itself and the stage will be able to control that which is very nice.
So a few thinkings:
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.
Not really, only the head stage in a plan has control over which URLs get assigned to all tasks in the plan, so the worker URLs are just decided once per query (at the beginning of it)
User's right now need to implement this trait for providing the URLs:
As they are free to return any
Vec<Url>they want, they can choose to either always return the same, randomize it, etc..Although at some point we probably want to extend the API to let people more control over the worker assignation itself.
If the user implements something that does not shuffle the vector before returning it, then yes, probably only the first subset of workers will be used.
A first initial approach could be to just document this behavior so that users can inform their implementation, but extending the API somehow to allow finer grained control over worker assignation could also be a good approach.