fix(jdbc): share embedded H2 runtimes with isolated logical sessions
Closes #10923
This commit is contained in:
1 parent
9e52ac60c4
commit
b57b3873d9
8 files changed
+1534
-56
No files matched your search
@@ -10,6 +10,7 @@ mod assets;
|
||||
mod filesystem;
|
||||
mod host;
|
||||
mod installer;
|
||||
mod jdbc_sessions;
|
||||
mod lifecycle;
|
||||
mod manifest;
|
||||
mod marketplace;
|
||||
@@ -157,6 +158,7 @@ pub struct PluginRegistry {
|
||||
root_dir: PathBuf,
|
||||
app_version: String,
|
||||
lifecycle: PluginLifecycle,
|
||||
jdbc_runtimes: jdbc_sessions::JdbcRuntimeCache,
|
||||
}
|
||||
|
||||
impl PluginRegistry {
|
||||
@@ -165,7 +167,12 @@ impl PluginRegistry {
|
||||
}
|
||||
|
||||
pub fn new_with_app_version(root_dir: PathBuf, app_version: impl Into<String>) -> Self {
|
||||
Self { root_dir, app_version: app_version.into(), lifecycle: PluginLifecycle::default() }
|
||||
Self {
|
||||
root_dir,
|
||||
app_version: app_version.into(),
|
||||
lifecycle: PluginLifecycle::default(),
|
||||
jdbc_runtimes: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lifecycle(&self) -> PluginLifecycle {
|
||||
@@ -381,7 +388,8 @@ fn ensure_plugin_compatible(plugin: &InstalledPlugin) -> Result<(), String> {
|
||||
pub struct PluginDriverSession {
|
||||
sidecar: Arc<PluginSidecarSession>,
|
||||
driver_id: String,
|
||||
_activity: lifecycle::PluginUsageGuard,
|
||||
_activity: Option<lifecycle::PluginUsageGuard>,
|
||||
logical: Option<Arc<jdbc_sessions::JdbcLogicalSession>>,
|
||||
}
|
||||
|
||||
impl PluginDriverSession {
|
||||
@@ -393,7 +401,7 @@ impl PluginDriverSession {
|
||||
activity: lifecycle::PluginUsageGuard,
|
||||
) -> Result<Self, String> {
|
||||
let sidecar = PluginSidecarSession::start(plugin, app_version, env).await?;
|
||||
Ok(Self { sidecar, driver_id, _activity: activity })
|
||||
Ok(Self { sidecar, driver_id, _activity: Some(activity), logical: None })
|
||||
}
|
||||
|
||||
pub async fn invoke<T>(&self, method: &str, params: serde_json::Value) -> Result<T, String>
|
||||
@@ -412,13 +420,24 @@ impl PluginDriverSession {
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
if let Some(logical) = &self.logical {
|
||||
return logical.invoke(method, params, timeout_duration).await;
|
||||
}
|
||||
self.sidecar.invoke_with_timeout(method, params, Some(&self.driver_id), timeout_duration).await
|
||||
}
|
||||
|
||||
pub async fn shutdown(&self) {
|
||||
if let Some(logical) = &self.logical {
|
||||
logical.close().await;
|
||||
return;
|
||||
}
|
||||
self.sidecar.shutdown().await;
|
||||
}
|
||||
|
||||
pub fn is_available(&self) -> bool {
|
||||
self.logical.as_ref().is_none_or(|logical| logical.is_available())
|
||||
}
|
||||
|
||||
pub async fn pid(&self) -> Option<u32> {
|
||||
self.sidecar.pid().await
|
||||
}
|
||||
@@ -446,6 +465,14 @@ impl PluginDriverSession {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PluginDriverSession {
|
||||
fn drop(&mut self) {
|
||||
if let Some(logical) = &self.logical {
|
||||
logical.close_in_background();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
Reference in new issue
Block a user