-
Notifications
You must be signed in to change notification settings - Fork 87
Vortex Session #5111
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
Vortex Session #5111
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
6a8e843
VortexSession
gatesn fda9329
VortexSession
gatesn f401263
VortexSession
gatesn 6286edd
VortexSession
gatesn 0feb761
merge
gatesn 00480c3
merge
gatesn 20b74bb
merge
gatesn 11b14f6
merge
gatesn ec3df62
merge
gatesn 1a151ba
merge
gatesn 711d309
merge
gatesn 6d7cd8a
merge
gatesn 9abd56a
merge
gatesn 0c279a0
Worker pool for current thread runtimes
gatesn 167411a
Worker pool for current thread runtimes
gatesn d21f335
merge
gatesn ed378ef
merge
gatesn ffbd9ab
merge
gatesn 3a7c7cd
merge
gatesn 1203432
merge
gatesn 1bb1aa3
merge
gatesn 9b5967d
merge
gatesn 25b09ee
merge
gatesn ec6c0f3
merge
gatesn c906faa
merge
gatesn bae2135
merge
gatesn 7b67217
merge
gatesn 9780d94
merge
gatesn 930ba8c
merge
gatesn 66ddb8b
merge
gatesn 97d9f25
merge
gatesn 90fcf41
merge
gatesn ab4ac88
merge
gatesn 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,24 @@ | ||
| [package] | ||
| name = "vortex-session" | ||
| authors.workspace = true | ||
| description = "Session object for Vortex" | ||
| edition = { workspace = true } | ||
| homepage = { workspace = true } | ||
| categories = { workspace = true } | ||
| include = { workspace = true } | ||
| keywords = { workspace = true } | ||
| license = { workspace = true } | ||
| readme = { workspace = true } | ||
| repository = { workspace = true } | ||
| rust-version = { workspace = true } | ||
| version = { workspace = true } | ||
|
|
||
| [package.metadata.docs.rs] | ||
| all-features = true | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
| [dependencies] | ||
| dashmap = { workspace = true } | ||
| vortex-error = { workspace = true } |
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,96 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| use dashmap::DashMap; | ||
| use std::any::{Any, TypeId}; | ||
| use std::fmt::Debug; | ||
| use std::hash::{BuildHasherDefault, Hasher}; | ||
| use std::ops::{Deref, DerefMut}; | ||
| use std::sync::Arc; | ||
| use vortex_error::VortexExpect; | ||
|
|
||
| /// A Vortex session encapsulates the set of extensible arrays, layouts, compute functions, dtypes, | ||
| /// etc. that are available for use in a given context. | ||
| /// | ||
| /// It is also the entry-point passed to dynamic libraries to initialize Vortex plugins. | ||
| #[derive(Clone, Debug)] | ||
| pub struct VortexSession(Arc<SessionVars>); | ||
|
|
||
| impl VortexSession { | ||
| /// Creates an empty Vortex session. | ||
| /// | ||
| /// Do not call this function otherwise you will end up with an empty session! | ||
| pub fn _empty() -> Self { | ||
| Self(Arc::new( | ||
| DashMap::with_hasher(BuildHasherDefault::default()), | ||
| )) | ||
| } | ||
|
|
||
| /// Returns the scope variable of type `V`, or inserts a default one if it does not exist. | ||
| pub fn get<V: SessionVar + Default>(&self) -> impl Deref<Target = V> { | ||
| self.0 | ||
| .entry(TypeId::of::<V>()) | ||
| .or_insert_with(|| Box::new(V::default())) | ||
| .downgrade() | ||
| .map(|v| { | ||
| v.as_any() | ||
| .downcast_ref::<V>() | ||
| .vortex_expect("Type mismatch - this is a bug") | ||
| }) | ||
| } | ||
|
|
||
| /// Returns the scope variable of type `V`, or inserts a default one if it does not exist. | ||
| /// | ||
| /// Note that the returned value internally holds a lock on the variable. | ||
| pub fn get_mut<V: SessionVar + Default>(&self) -> impl DerefMut<Target = V> { | ||
| self.0 | ||
| .entry(TypeId::of::<V>()) | ||
| .or_insert_with(|| Box::new(V::default())) | ||
| .map(|v| { | ||
| v.as_any_mut() | ||
| .downcast_mut::<V>() | ||
| .vortex_expect("Type mismatch - this is a bug") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /// A TypeMap based on `https://docs.rs/http/1.2.0/src/http/extensions.rs.html#41-266`. | ||
| type SessionVars = DashMap<TypeId, Box<dyn SessionVar>, BuildHasherDefault<IdHasher>>; | ||
gatesn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// With TypeIds as keys, there's no need to hash them. They are already hashes | ||
| /// themselves, coming from the compiler. The IdHasher just holds the u64 of | ||
| /// the TypeId, and then returns it, instead of doing any bit fiddling. | ||
| #[derive(Default)] | ||
| struct IdHasher(u64); | ||
|
|
||
| impl Hasher for IdHasher { | ||
| #[inline] | ||
| fn finish(&self) -> u64 { | ||
| self.0 | ||
| } | ||
|
|
||
| fn write(&mut self, _: &[u8]) { | ||
| unreachable!("TypeId calls write_u64"); | ||
| } | ||
|
|
||
| #[inline] | ||
| fn write_u64(&mut self, id: u64) { | ||
| self.0 = id; | ||
| } | ||
| } | ||
|
|
||
| /// This trait defines variables that can be stored against a Vortex session. | ||
| pub trait SessionVar: Any + Send + Debug { | ||
| fn as_any(&self) -> &dyn Any; | ||
| fn as_any_mut(&mut self) -> &mut dyn Any; | ||
| } | ||
|
|
||
| impl<T: Send + Debug + 'static> SessionVar for T { | ||
| fn as_any(&self) -> &dyn Any { | ||
| self | ||
| } | ||
|
|
||
| fn as_any_mut(&mut self) -> &mut dyn Any { | ||
| self | ||
| } | ||
| } | ||
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.
any reason to make pub?
if we really don't want people calling it we could slap a
#[doc(hidden)]on itUh oh!
There was an error while loading. Please reload this page.
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 haven't yet decided between: