Skip to content

Commit dda6ce0

Browse files
committed
Change default coop strategy to 'tokio_fallback'
1 parent cc5742b commit dda6ce0

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ uninlined_format_args = "warn"
218218

219219
[workspace.lints.rust]
220220
unexpected_cfgs = { level = "warn", check-cfg = [
221-
'cfg(datafusion_coop, values("tokio", "tokio_fallback"))',
221+
'cfg(datafusion_coop, values("tokio", "tokio_fallback", "per_stream"))',
222222
"cfg(tarpaulin)",
223223
"cfg(tarpaulin_include)",
224224
] }

datafusion/physical-plan/src/coop.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@
3535
//! - New source operators that do not make use of Tokio resources
3636
//! - Exchange like operators that do not use Tokio's `Channel` implementation to pass data between
3737
//! tasks
38-
//!
38+
//!
3939
//! # Available utilities
40-
//!
40+
//!
4141
//! This module provides two function that can be used to add cooperative scheduling to existing
4242
//! `Stream` implementations.
43-
//!
43+
//!
4444
//! [`cooperative`] is a generic function that takes ownership of the wrapped [`RecordBatchStream`].
4545
//! This function has the benefit of not requiring an additional heap allocation and can avoid
4646
//! dynamic dispatch.
47-
//!
47+
//!
4848
//! [`make_cooperative`] is a non-generic function that wraps a [`SendableRecordBatchStream`]. This
4949
//! can be used to wrap dynamically typed, heap allocated [`RecordBatchStream`]s.
5050
51-
#[cfg(datafusion_coop = "tokio_fallback")]
51+
#[cfg(any(
52+
datafusion_coop = "tokio_fallback",
53+
not(any(datafusion_coop = "tokio", datafusion_coop = "per_stream"))
54+
))]
5255
use futures::Future;
5356
use std::any::Any;
5457
use std::pin::Pin;
@@ -72,18 +75,18 @@ use futures::{Stream, StreamExt};
7275
/// A stream that passes record batches through unchanged while cooperating with the Tokio runtime.
7376
/// It consumes cooperative scheduling budget for each returned [`RecordBatch`],
7477
/// allowing other tasks to execute when the budget is exhausted.
75-
///
76-
/// See the [module level documentation](crate::coop) for an in-depth discussion.
78+
///
79+
/// See the [module level documentation](crate::coop) for an in-depth discussion.
7780
pub struct CooperativeStream<T>
7881
where
7982
T: RecordBatchStream + Unpin,
8083
{
8184
inner: T,
82-
#[cfg(not(any(datafusion_coop = "tokio", datafusion_coop = "tokio_fallback")))]
85+
#[cfg(datafusion_coop = "per_stream")]
8386
budget: u8,
8487
}
8588

86-
#[cfg(not(any(datafusion_coop = "tokio", datafusion_coop = "tokio_fallback")))]
89+
#[cfg(datafusion_coop = "per_stream")]
8790
// Magic value that matches Tokio's task budget value
8891
const YIELD_FREQUENCY: u8 = 128;
8992

@@ -97,10 +100,7 @@ where
97100
pub fn new(inner: T) -> Self {
98101
Self {
99102
inner,
100-
#[cfg(not(any(
101-
datafusion_coop = "tokio",
102-
datafusion_coop = "tokio_fallback"
103-
)))]
103+
#[cfg(datafusion_coop = "per_stream")]
104104
budget: YIELD_FREQUENCY,
105105
}
106106
}
@@ -128,10 +128,13 @@ where
128128
value
129129
}
130130

131-
#[cfg(datafusion_coop = "tokio_fallback")]
131+
#[cfg(any(
132+
datafusion_coop = "tokio_fallback",
133+
not(any(datafusion_coop = "tokio", datafusion_coop = "per_stream"))
134+
))]
132135
{
133-
// This is a temporary placeholder implementation
134-
// that may have slightly worse performance compared to `poll_proceed`
136+
// This is a temporary placeholder implementation that may have slightly
137+
// worse performance compared to `poll_proceed`
135138
if !tokio::task::coop::has_budget_remaining() {
136139
cx.waker().wake_by_ref();
137140
return Poll::Pending;
@@ -151,7 +154,7 @@ where
151154
value
152155
}
153156

154-
#[cfg(not(any(datafusion_coop = "tokio", datafusion_coop = "tokio_fallback")))]
157+
#[cfg(datafusion_coop = "per_stream")]
155158
{
156159
if self.budget == 0 {
157160
self.budget = YIELD_FREQUENCY;

0 commit comments

Comments
 (0)