Skip to content
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

fix(MemTable): make it cancel-safe and fix parallelism #5197

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions datafusion/core/src/datasource/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::error::{DataFusionError, Result};
use crate::execution::context::SessionState;
use crate::logical_expr::Expr;
use crate::physical_plan::common;
use crate::physical_plan::common::AbortOnDropSingle;
use crate::physical_plan::memory::MemoryExec;
use crate::physical_plan::ExecutionPlan;
use crate::physical_plan::{repartition::RepartitionExec, Partitioning};
Expand Down Expand Up @@ -76,20 +77,26 @@ impl MemTable {
.map(|part_i| {
let task = state.task_ctx();
let exec = exec.clone();
tokio::spawn(async move {
let task = tokio::spawn(async move {
let stream = exec.execute(part_i, task)?;
common::collect(stream).await
})
});

AbortOnDropSingle::new(task)
})
// this collect *is needed* so that the join below can
// switch between tasks
.collect::<Vec<_>>();

let mut data: Vec<Vec<RecordBatch>> =
Vec::with_capacity(exec.output_partitioning().partition_count());
for task in tasks {
let result = task.await.expect("MemTable::load could not join task")?;
data.push(result);

for result in futures::future::join_all(tasks).await {
data.push(result.map_err(|_| {
DataFusionError::Internal(
"MemTable::load could not join task".to_string(),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would help if we could preserve the original error here rather than turning it into an internal error

Perhaps using DataFusionError::Context

Suggested change
data.push(result.map_err(|_| {
DataFusionError::Internal(
"MemTable::load could not join task".to_string(),
)
data.push(result.map_err(|e| {
DataFusionError::Context(
"MemTable::load could not join task".to_string(), Box::new(e)
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context requires DataFusionError, so it's anyway should be wrapped to something 🤔

Could be data.push(result.map_err(|e| DataFusionError::External(Box::new(e)))??), WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would definitely be better than 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 🙂

})??)
}

let exec = MemoryExec::try_new(&data, schema.clone(), None)?;
Expand Down