From a42826ee24aa75b42dda9f189464b3074712f530 Mon Sep 17 00:00:00 2001 From: David Li Date: Thu, 22 Jan 2026 16:56:27 +0900 Subject: [PATCH 1/4] feat(rust/core)!: define cancellation in a sensible way Closes #3454. --- rust/core/src/sync.rs | 45 ++++++++-- rust/driver/dummy/src/lib.rs | 32 +++---- .../dummy/tests/driver_exporter_dummy.rs | 22 +++-- rust/driver_manager/src/lib.rs | 84 +++++++++++++------ .../tests/driver_manager_sqlite.rs | 10 ++- rust/ffi/src/driver_exporter.rs | 52 +++++++++--- 6 files changed, 174 insertions(+), 71 deletions(-) diff --git a/rust/core/src/sync.rs b/rust/core/src/sync.rs index e14c6b2245..2656070504 100644 --- a/rust/core/src/sync.rs +++ b/rust/core/src/sync.rs @@ -21,7 +21,7 @@ use arrow_array::{RecordBatch, RecordBatchReader}; use arrow_schema::Schema; use crate::PartitionedResult; -use crate::error::Result; +use crate::error::{Error, Result, Status}; use crate::options::{self, OptionConnection, OptionDatabase, OptionStatement, OptionValue}; /// Ability to configure an object by setting/getting options. @@ -44,6 +44,28 @@ pub trait Optionable { fn get_option_double(&self, key: Self::Option) -> Result; } +/// A handle to cancel an in-progress operation. +/// +/// This is a separated handle because otherwise it would be impossible to +/// safely call a `cancel` method on a database/connection/statement itself +/// due to the borrow checker. +pub trait CancelHandle: Send + Sync { + /// Attempt to cancel the in-progress operation (best-effort). + fn try_cancel(&self) -> Result<()>; +} + +/// A cancellation handle that does nothing (because cancellation is unsupported). +pub struct NoOpCancellationHandle; + +impl CancelHandle for NoOpCancellationHandle { + fn try_cancel(&self) -> Result<()> { + Err(Error::with_message_and_status( + "cancellation not implemented", + Status::Unknown, + )) + } +} + /// A handle to an ADBC driver. pub trait Driver { type DatabaseType: Database; @@ -76,6 +98,11 @@ pub trait Database: Optionable