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

bug(deadlock): change to async rwlock #48

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ arrow-ipc = { version = "51" }

serde_json = { version = "1" }

parking_lot = { version = "0.12", features = ["send_guard"]}

prost = { version = "0.12" }
prost-types = { version = "0.12" }

Expand Down
5 changes: 3 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ arrow-ipc = { workspace = true }

serde_json = { workspace = true }

parking_lot = { workspace = true }

prost = { workspace = true }
prost-types = { workspace = true }

Expand All @@ -46,6 +44,9 @@ datafusion = { workspace = true, optional = true }
polars = { workspace = true, optional = true }
polars-arrow = { workspace = true, optional = true }

[dev-dependencies]
futures = "0.3"

[build-dependencies]
tonic-build = "0.11.0"

Expand Down
21 changes: 6 additions & 15 deletions core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use arrow::error::ArrowError;
use arrow::record_batch::RecordBatch;
use arrow_ipc::reader::StreamReader;

use parking_lot::RwLock;

use tonic::codegen::{Body, Bytes, StdError};
use tonic::metadata::{
Ascii, AsciiMetadataValue, KeyAndValueRef, MetadataKey, MetadataMap, MetadataValue,
};
use tonic::service::Interceptor;
use tonic::Status;

use tokio::sync::RwLock;

use url::Url;

use uuid::Uuid;
Expand Down Expand Up @@ -410,15 +410,13 @@ where
}
}

#[allow(clippy::await_holding_lock)]
async fn execute_and_fetch(
&mut self,
req: spark::ExecutePlanRequest,
) -> Result<(), SparkError> {
let mut client = self.stub.write();
let mut client = self.stub.write().await;

let mut resp = client.execute_plan(req).await?.into_inner();

drop(client);

// clear out any prior responses
Expand All @@ -436,7 +434,6 @@ where
Ok(())
}

#[allow(clippy::await_holding_lock)]
pub async fn analyze(
&mut self,
analyze: spark::analyze_plan_request::Analyze,
Expand All @@ -445,19 +442,16 @@ where

req.analyze = Some(analyze);

let mut client = self.stub.write();

// clear out any prior responses
self.analyzer = AnalyzeHandler::new();

let mut client = self.stub.write().await;
let resp = client.analyze_plan(req).await?.into_inner();

drop(client);

self.handle_analyze(resp)
}

#[allow(clippy::await_holding_lock)]
pub async fn interrupt_request(
&mut self,
interrupt_type: spark::interrupt_request::InterruptType,
Expand Down Expand Up @@ -494,10 +488,9 @@ where
}
};

let mut client = self.stub.write();
let mut client = self.stub.write().await;

let resp = client.interrupt(req).await?.into_inner();
drop(client);

Ok(resp)
}
Expand Down Expand Up @@ -538,7 +531,6 @@ where
self.tags = vec![];
}

#[allow(clippy::await_holding_lock)]
pub async fn config_request(
&mut self,
operation: spark::config_request::Operation,
Expand All @@ -550,10 +542,9 @@ where
operation: Some(operation),
};

let mut client = self.stub.write();
let mut client = self.stub.write().await;

let resp = client.config(operation).await?.into_inner();
drop(client);

Ok(resp)
}
Expand Down
18 changes: 18 additions & 0 deletions core/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,4 +2202,22 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn test_df_explain_concurrent() -> Result<(), SparkError> {
let spark = setup().await;
let spark_clone = spark.clone();

let data = mock_data();

let df = spark.createDataFrame(&data)?;
let df_clone = spark_clone.createDataFrame(&data)?;

let (res, res_clone) = futures::join!(df.explain(None), df_clone.explain(None));
let (val, val_clone) = (res?, res_clone?);

assert!(val.contains("== Physical Plan =="));
assert!(val_clone.contains("== Physical Plan =="));
Ok(())
}
}
2 changes: 1 addition & 1 deletion core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use spark::spark_connect_service_client::SparkConnectServiceClient;

use arrow::record_batch::RecordBatch;

use parking_lot::RwLock;
use tokio::sync::RwLock;

#[cfg(not(feature = "wasm"))]
use tonic::transport::{Channel, Endpoint};
Expand Down
Loading