Skip to content

Commit 77e22f0

Browse files
authored
feature flag ExecDriver implementations (#2005)
1. Feature flag tokio/rayon based `ExecDriver` implementation 2. If tokio is available AND running within the context of a runtime, use it.
1 parent dd09060 commit 77e22f0

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

vortex-datafusion/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ vortex-buffer = { workspace = true }
4040
vortex-dtype = { workspace = true }
4141
vortex-error = { workspace = true, features = ["datafusion"] }
4242
vortex-expr = { workspace = true, features = ["datafusion"] }
43-
vortex-file = { workspace = true, features = ["object_store"] }
43+
vortex-file = { workspace = true, features = ["object_store", "tokio"] }
4444
vortex-io = { workspace = true, features = ["object_store", "tokio"] }
4545
vortex-scan = { workspace = true }
4646

vortex-file/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ futures-util = { workspace = true }
2727
itertools = { workspace = true }
2828
log = { workspace = true }
2929
pin-project-lite = { workspace = true }
30-
rayon = { workspace = true }
31-
tokio = { workspace = true, features = ["rt"] }
30+
rayon = { workspace = true, optional = true }
31+
tokio = { workspace = true, features = ["rt"], optional = true }
3232
tracing = { workspace = true, optional = true }
3333
vortex-array = { workspace = true }
3434
vortex-buffer = { workspace = true }

vortex-file/src/exec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pub mod inline;
2+
3+
#[cfg(feature = "tokio")]
24
pub mod tokio;
35

46
use futures_util::future::BoxFuture;

vortex-file/src/open/exec.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use std::sync::Arc;
22

3+
#[cfg(feature = "tokio")]
4+
use tokio::runtime::Handle;
5+
36
use crate::exec::inline::InlineDriver;
7+
#[cfg(feature = "tokio")]
48
use crate::exec::tokio::TokioDriver;
59
use crate::exec::ExecDriver;
610

@@ -11,20 +15,32 @@ pub enum ExecutionMode {
1115
/// [`vortex_array::stream::ArrayStream`]. In other words, uses the same runtime.
1216
Inline,
1317
/// Spawns the tasks onto a provided Rayon thread pool.
14-
// TODO(ngates): feature-flag this dependency.
18+
#[cfg(feature = "rayon")]
1519
RayonThreadPool(Arc<rayon::ThreadPool>),
1620
/// Spawns the tasks onto a provided Tokio runtime.
17-
// TODO(ngates): feature-flag this dependency.
18-
TokioRuntime(tokio::runtime::Handle),
21+
#[cfg(feature = "tokio")]
22+
TokioRuntime(Handle),
1923
}
2024

2125
impl ExecutionMode {
2226
pub fn into_driver(self) -> Arc<dyn ExecDriver> {
2327
match self {
24-
ExecutionMode::Inline => Arc::new(InlineDriver),
28+
ExecutionMode::Inline => {
29+
// Default to tokio-specific behavior if its enabled and there's a runtime running.
30+
#[cfg(feature = "tokio")]
31+
match Handle::try_current() {
32+
Ok(h) => Arc::new(TokioDriver(h)),
33+
Err(_) => Arc::new(InlineDriver),
34+
}
35+
36+
#[cfg(not(feature = "tokio"))]
37+
Arc::new(InlineDriver)
38+
}
39+
#[cfg(feature = "rayon")]
2540
ExecutionMode::RayonThreadPool(_) => {
2641
todo!()
2742
}
43+
#[cfg(feature = "tokio")]
2844
ExecutionMode::TokioRuntime(handle) => Arc::new(TokioDriver(handle)),
2945
}
3046
}

vortex-file/src/read/record_batch_reader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub trait AsyncRuntime {
2424
fn block_on<F: Future>(&self, fut: F) -> F::Output;
2525
}
2626

27+
#[cfg(feature = "tokio")]
2728
impl AsyncRuntime for tokio::runtime::Runtime {
2829
fn block_on<F: Future>(&self, fut: F) -> F::Output {
2930
self.block_on(fut)

vortex/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ vortex-zigzag = { workspace = true }
5050
vortex-roaring = { workspace = true }
5151

5252
[features]
53-
tokio = ["vortex-io/tokio"]
53+
tokio = ["vortex-io/tokio", "vortex-file/tokio"]
5454
object_store = ["vortex-file/object_store"]
5555
parquet = ["vortex-error/parquet"]
5656
python = ["vortex-error/python"]

0 commit comments

Comments
 (0)