Skip to content

Commit c7e8ae9

Browse files
authored
Back VortexSession with ArcSwap for mutable but less errorprone session management (#8631)
I think immutable session is nice but hard to integrate it with for a lot of systems
1 parent 3e7098c commit c7e8ae9

38 files changed

Lines changed: 657 additions & 426 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/developer-guide/internals/session.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ or other shared resources.
1212

1313
The session is built on two primitives from the `vortex-session` crate:
1414

15-
- **`VortexSession`** -- a cloneable, thread-safe map from Rust `TypeId` to a boxed value. Any
16-
type that is `Send + Sync + Debug + 'static` can be stored as a session variable.
15+
- **`VortexSession`** -- a cloneable, thread-safe map from Rust `TypeId` to a shared
16+
(`Arc`-wrapped) value. Any type that is `Clone + Send + Sync + Debug + 'static` can be stored
17+
as a session variable.
1718
- **`Registry<T>`** -- a concurrent map from string IDs to values of type `T`, used by each
1819
component to look up registered plugins at runtime.
1920

20-
Because `VortexSession` is backed by an `Arc<DashMap>`, cloning is cheap and all clones share
21-
the same state. This makes it safe to hand the session to multiple threads, tasks, or I/O
22-
operations without coordination.
21+
Because `VortexSession` is backed by an `ArcSwap`, cloning is cheap and all clones share the
22+
same state, with lock-free reads and copy-on-write writes. This makes it safe to hand the
23+
session to multiple threads, tasks, or I/O operations without coordination.
2324

2425
## Component Registries
2526

@@ -95,14 +96,13 @@ all built-in components and encodings:
9596
let session = VortexSession::default();
9697
```
9798

98-
For tests or specialized use-cases, sessions can be assembled from individual components using
99-
the `.with::<T>()` builder:
99+
For tests or specialized use-cases, sessions can be assembled from individual components by
100+
starting from an empty session and chaining the `.with::<T>()` helpers:
100101

101102
```rust
102-
let session = VortexSession::builder()
103+
let session = VortexSession::empty()
103104
.with::<ArraySession>()
104105
.with::<LayoutSession>()
105106
.with::<ScalarFnSession>()
106-
.with::<RuntimeSession>()
107-
.build();
107+
.with::<RuntimeSession>();
108108
```

encodings/fastlanes/src/rle/kernel.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ use crate::RLE;
2020
use crate::rle::RLEArrayExt;
2121

2222
pub(crate) fn initialize(session: &VortexSession) {
23-
session
24-
.kernels()
25-
.register_execute_parent_kernel(Slice.id(), RLE, SliceExecuteAdaptor(RLE));
23+
let kernels = session.kernels();
24+
kernels.register_execute_parent_kernel(Slice.id(), RLE, SliceExecuteAdaptor(RLE));
2625
}
2726

2827
impl SliceKernel for RLE {

encodings/zigzag/src/kernel.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use vortex_session::VortexSession;
1010
use crate::ZigZag;
1111

1212
pub(crate) fn initialize(session: &VortexSession) {
13-
session
14-
.kernels()
15-
.register_execute_parent_kernel(Dict.id(), ZigZag, TakeExecuteAdaptor(ZigZag));
13+
let kernels = session.kernels();
14+
kernels.register_execute_parent_kernel(Dict.id(), ZigZag, TakeExecuteAdaptor(ZigZag));
1615
}

fuzz/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod native_runtime {
5656
if vortex_cuda::cuda_available() {
5757
use vortex_cuda::CudaSessionExt;
5858
session = session.with::<vortex_cuda::CudaSession>();
59-
vortex_cuda::initialize_cuda(session.cuda_session());
59+
vortex_cuda::initialize_cuda(&session.cuda_session());
6060
}
6161
session
6262
});

vortex-array/src/aggregate_fn/accumulator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ impl<V: AggregateFnVTable> DynAccumulator for Accumulator<V> {
264264
mod tests {
265265
use vortex_buffer::buffer;
266266
use vortex_error::VortexResult;
267+
use vortex_session::SessionExt;
267268
use vortex_session::VortexSession;
268269

269270
use crate::ArrayRef;

vortex-array/src/aggregate_fn/proto.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,9 @@ mod tests {
195195

196196
#[test]
197197
fn unknown_aggregate_fn_id_allow_unknown() {
198-
let session = VortexSession::builder()
198+
let session = VortexSession::empty()
199199
.with::<AggregateFnSession>()
200-
.allow_unknown()
201-
.build();
200+
.allow_unknown();
202201

203202
let proto = pb::AggregateFn {
204203
id: "vortex.test.foreign_aggregate".to_string(),

vortex-array/src/aggregate_fn/session.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::any::Any;
55
use std::sync::Arc;
66

77
use vortex_session::SessionExt;
8+
use vortex_session::SessionGuard;
89
use vortex_session::SessionVar;
910

1011
use crate::aggregate_fn::AggregateFnId;
@@ -221,7 +222,7 @@ impl AggregateFnSession {
221222
/// Extension trait for accessing aggregate function session data.
222223
pub trait AggregateFnSessionExt: SessionExt {
223224
/// Returns the aggregate function session data.
224-
fn aggregate_fns(&self) -> &AggregateFnSession {
225+
fn aggregate_fns(&self) -> SessionGuard<'_, AggregateFnSession> {
225226
self.get::<AggregateFnSession>()
226227
}
227228
}

vortex-array/src/arrays/filter/kernel.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ use crate::optimizer::kernels::ArrayKernelsExt;
2828
use crate::optimizer::rules::ArrayParentReduceRule;
2929

3030
pub(crate) fn initialize(session: &VortexSession) {
31-
session
32-
.kernels()
33-
.register_execute_parent_kernel(Dict.id(), Filter, TakeExecuteAdaptor(Filter));
31+
let kernels = session.kernels();
32+
kernels.register_execute_parent_kernel(Dict.id(), Filter, TakeExecuteAdaptor(Filter));
3433
}
3534

3635
pub trait FilterReduce: VTable {

vortex-array/src/arrays/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ pub use varbinview::VarBinViewArray;
119119
pub mod variant;
120120
pub use variant::Variant;
121121
pub use variant::VariantArray;
122+
use vortex_session::VortexSession;
122123

123-
pub(crate) fn initialize(session: &vortex_session::VortexSession) {
124+
pub(crate) fn initialize(session: &VortexSession) {
124125
bool::initialize(session);
125126
chunked::initialize(session);
126127
decimal::initialize(session);

0 commit comments

Comments
 (0)