Skip to content

Comments

feat(rust)!: define cancellation in a sensible way#3905

Open
lidavidm wants to merge 1 commit intoapache:mainfrom
lidavidm:gh-3454
Open

feat(rust)!: define cancellation in a sensible way#3905
lidavidm wants to merge 1 commit intoapache:mainfrom
lidavidm:gh-3454

Conversation

@lidavidm
Copy link
Member

Closes #3454.

@lidavidm lidavidm marked this pull request as ready for review January 22, 2026 08:31
@lidavidm lidavidm requested a review from wjones127 as a code owner January 22, 2026 08:31
@github-actions github-actions bot added this to the ADBC Libraries 23 milestone Jan 22, 2026
@lidavidm lidavidm changed the title feat(rust/core)!: define cancellation in a sensible way feat(rust)!: define cancellation in a sensible way Jan 26, 2026
@lidavidm
Copy link
Member Author

CC @felipecrv @abonander @eitsupi

@lidavidm
Copy link
Member Author

Any concerns here?

@felipecrv
Copy link
Contributor

I started looking at the code and got confused. Are you going to cancel any statement currently running in the connection or do I get one handle per Statement?

@lidavidm
Copy link
Member Author

One per statement (the handle has a weak reference to the specific statement)

Copy link

@abonander abonander left a comment

Choose a reason for hiding this comment

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

This seems all right, the inheritance can be implemented using tokio_util::sync::CancellationToken::child_token().

Just a few questions about the detailed semantics.

Comment on lines +52 to +53
/// Cancel the in-progress operation on a connection.
fn try_cancel(&self) -> Result<()>;

Choose a reason for hiding this comment

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

Are the try_ prefix and the default to NoOpCancellationHandle meant to imply that this is on a best-effort basis only? Can that be more clearly documented?

Choose a reason for hiding this comment

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

It's only sort-of implied by

/// methods of ArrowArrayStream). (It is not guaranteed to, for
/// instance, the result set may be buffered in memory already.)

///
/// This is a separated handle because otherwise it would be impossible to
/// call a `cancel` method on a connection or statement itself.
pub trait CancelHandle: Send {

Choose a reason for hiding this comment

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

/// This must always be thread-safe (other operations are not). It is
/// not necessarily signal-safe.

"thread-safe" implies that this handle should be Sync as well since there isn't really a distinction between "can be moved between threads" and "can be called concurrently from multiple threads" in C.


impl CancelHandle for NoOpCancellationHandle {
fn try_cancel(&self) -> Result<()> {
Ok(())

Choose a reason for hiding this comment

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

Should the default be to return ADBC_STATUS_UNKNOWN to indicate that the operation cannot be cancelled per

/// \return ADBC_STATUS_UNKNOWN if the query could not be cancelled.

Comment on lines +99 to +101
fn get_cancel_handle(&self) -> Box<dyn CancelHandle> {
Box::new(NoOpCancellationHandle {})
}
Copy link

@abonander abonander Feb 24, 2026

Choose a reason for hiding this comment

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

Are you going to introduce AdbcDatabaseCancel() to the C API? Otherwise I don't see why this needs to exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rust: cancel is effectively useless since everything is &mut self

3 participants