Skip to content
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
5 changes: 5 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Added

- Add execution-scoped client query deadlines to the Rust and C APIs.
- Add an opt-in `release-with-debuginfo` Cargo profile and cross-platform
symbol smoke checks for statically linked native consumers.
- Create SQL Exec API sessions in FAST mode and exchange the maximum observed session version.
Expand All @@ -22,6 +23,10 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Changed

- Client query deadlines now allow an already-running statement-status request
Comment thread
cathleeny marked this conversation as resolved.
Resolved
up to five seconds to return a terminal result; no new poll starts after the
configured deadline.

### Updated

### Fixed
Expand Down
13 changes: 10 additions & 3 deletions docs/spec-v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,18 @@ impl Statement {
/// Read-only access (for logging or assertion).
pub fn spec_ref(&self) -> &StatementSpec;

/// Wait-for-result execution. Auto-cancels + closes any prior handle.
/// Spec is unchanged after the call; can be re-executed.
/// Wait-for-result execution with the existing 600s polling ceiling.
pub async fn execute(&mut self) -> Result<ExecutedStatement>;

/// Execute with a client deadline through terminal-state mapping.
/// Zero and Duration::MAX select unlimited execution; result materialisation
/// is excluded. An in-flight status request gets a fixed five-second grace
/// period, but no new status request starts after the deadline.
pub async fn execute_with_timeout(
&mut self,
timeout: std::time::Duration,
) -> Result<ExecutedStatement>;

/// Submit-and-return. Auto-cancels + closes any prior handle.
pub async fn submit(&mut self) -> Result<ExecutedAsyncStatement>;
}
Expand Down Expand Up @@ -950,4 +958,3 @@ string (`[error_code STATEMENT_NOT_FOUND]`) since
`adbc_core::error::Error` has no string-shaped slot for it. Lossy
bridge — wrappers that consume `kernel_error::Error` directly
(PyO3, napi-rs, the C ABI) get the structured field.

28 changes: 26 additions & 2 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
#include <stddef.h>
#include <stdint.h>

/* Largest finite value accepted by kernel_statement_execute_with_timeout_ms. */
#define DATABRICKS_KERNEL_MAX_CLIENT_QUERY_TIMEOUT_MS UINT64_C(9223372036854)

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -705,12 +708,33 @@ KernelStatusCode kernel_statement_set_query_tags(kernel_statement_t* stmt,
const char* query_tags);

/*
* Wait-for-result execution. On success, `*out` holds an executed handle
* released with `kernel_executed_statement_close`.
* Wait-for-result execution with the existing 600-second polling ceiling and
* no caller-supplied deadline. On success, release `*out` with
* `kernel_executed_statement_close`.
*/
KernelStatusCode kernel_statement_execute(kernel_statement_t* stmt,
kernel_executed_statement_t** out);

/*
* Wait-for-result execution with a client-side deadline in milliseconds.
* Zero selects unlimited execution; values above
* DATABRICKS_KERNEL_MAX_CLIENT_QUERY_TIMEOUT_MS return InvalidArgument. A finite
* deadline starts on entry and covers execution through terminal-state mapping,
* and excludes result materialisation and fetching. A status request already in
* flight at the deadline may finish within a fixed five-second grace period; no
* new status request starts after the deadline. The deadline is never sent to
* the server.
*
* Timeout returns KernelStatusCode_Timeout with SQLSTATE HYT00 and leaves
* `*out` NULL. Cleanup is best effort and asynchronous; `stmt` remains reusable.
*
* This function has the same handle invalidation and panic contract as
* kernel_statement_execute.
*/
KernelStatusCode kernel_statement_execute_with_timeout_ms(
kernel_statement_t* stmt, uint64_t timeout_ms,
kernel_executed_statement_t** out);

/*
* Submit-and-return (async). DEFERRED in v0: this always returns
* `KernelStatusCode_InvalidArgument` (with an explanatory last error) and
Expand Down
55 changes: 54 additions & 1 deletion src/c_abi/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
use super::error::{store_and_code, store_invalid_arg};
use super::result::{into_raw_executed_stream, kernel_result_stream_t};
use super::{block_on_ffi, catch_ffi, KernelStatusCode};
use crate::client::ExecutionTimeout;
use crate::kernel_error::Error;
use crate::statement::executed::ExecutedStatement;
use crate::statement::mutable::Statement;
use crate::statement::spec::TypedValue;
use crate::statement::validity::ValidityFlag;
use std::ffi::{c_char, CStr, CString};

pub use crate::statement::timeout::MAX_CLIENT_QUERY_TIMEOUT_MS;

/// Upper bound on a positional parameter ordinal accepted over the C ABI.
///
/// `StatementSpec::param` grows `positional_params` with
Expand Down Expand Up @@ -450,6 +453,56 @@ pub unsafe extern "C" fn kernel_statement_execute(
return store_invalid_arg("kernel_statement_execute: out must not be null");
}

execute_with_timeout_mode(stmt, ExecutionTimeout::Default, out)
}

/// Wait-for-result execution with a client deadline in milliseconds.
///
/// Zero selects unlimited execution. A finite deadline starts at native entry,
/// ends after terminal mapping, and excludes result materialisation. A status request
/// already in flight at the deadline may finish within a fixed five-second grace
/// period. Timeout returns [`KernelStatusCode::Timeout`] with `HYT00` and leaves
/// `*out` null.
///
/// # Safety
/// `stmt` must be a live statement handle; `out` must be writable.
#[no_mangle]
pub unsafe extern "C" fn kernel_statement_execute_with_timeout_ms(
stmt: *mut kernel_statement_t,
timeout_ms: u64,
out: *mut *mut kernel_executed_statement_t,
) -> KernelStatusCode {
// Include validation and runtime queueing in the deadline.
let entered_at = std::time::Instant::now();
crate::c_abi::error::clear_error();
if out.is_null() {
return store_invalid_arg("kernel_statement_execute_with_timeout_ms: out must not be null");
}
std::ptr::write(out, std::ptr::null_mut());
let Some(stmt) = statement_mut(stmt) else {
return store_invalid_arg(
"kernel_statement_execute_with_timeout_ms: stmt must not be null",
);
};
let timeout = match crate::statement::timeout::deadline_from_timeout_at(
std::time::Duration::from_millis(timeout_ms),
entered_at,
) {
Ok(deadline) => ExecutionTimeout::from_explicit_deadline(deadline),
Err(error) => return store_and_code(error),
};

execute_with_timeout_mode(stmt, timeout, out)
}

/// Run synchronous execution after entry-point validation.
///
/// The timeout entry point clears `out`; the existing entry point does not.
unsafe fn execute_with_timeout_mode(
stmt: &mut Statement,
timeout: ExecutionTimeout,
out: *mut *mut kernel_executed_statement_t,
) -> KernelStatusCode {
// `Statement::execute` borrows `&mut self`; we need that borrow to
// live across the `block_on`. Raw-pointer the statement so the
// closure can re-borrow it inside the runtime without entangling
Expand All @@ -458,7 +511,7 @@ pub unsafe extern "C" fn kernel_statement_execute(
let stmt_ptr: *mut Statement = stmt;
let executed = block_on_ffi(move || {
let stmt: &mut Statement = unsafe { &mut *stmt_ptr };
Box::pin(async move { stmt.execute().await })
Box::pin(async move { stmt.execute_with_timeout_mode(timeout).await })
});
match executed {
Ok(exec) => {
Expand Down
3 changes: 2 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ pub use retry::{
pub(crate) use sea::SeaRestTransport;
pub(crate) use transport::{
ChunkLinkFetchResult, DirectOutcome, ExecuteResponse, ExecuteResult, ExecuteResultData,
InlineChunkFetchResult, SessionAttribution, SessionInfo, Transport, TransportConfig,
ExecutionTimeout, InlineChunkFetchResult, SessionAttribution, SessionInfo, Transport,
TransportConfig,
};
Loading
Loading