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
3 changes: 3 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ changes go in their respective binding's NEXT_CHANGELOG.
### Changed

- Route function metadata through the Thrift-native metadata path when supported by the server.
- Authenticated SEA requests now use `Accept-Encoding: identity` by default to
avoid gzipping inline LZ4-compressed Arrow results. Response compression can
be re-enabled through `HttpConfig` or the C ABI.

### Updated

Expand Down
5 changes: 5 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ KernelStatusCode kernel_session_config_set_session_conf(KernelSessionConfig* con
KernelStatusCode kernel_session_config_set_custom_header(KernelSessionConfig* config,
const char* name, const char* value);

/* Configure whether authenticated SEA responses may use HTTP compression.
* Disabled by default. */
KernelStatusCode kernel_session_config_set_sea_response_compression_enabled(
KernelSessionConfig* config, bool enabled);

/* Configure the total timeout for one HTTP request, from connection start
* through response-body completion. A separate 30s connection timeout also
* applies, so connection establishment is bounded by the shorter limit.
Expand Down
3 changes: 3 additions & 0 deletions napi/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ layout, or npm publishing. Pure-kernel changes go in the root

### Added

- Added `ConnectionOptions.seaResponseCompressionEnabled` to opt back into
HTTP compression for bandwidth-constrained SEA connections.

### Changed

### Updated
Expand Down
4 changes: 4 additions & 0 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ export interface ConnectionOptions {
* `User-Agent` entry here.
*/
customHeaders?: Array<HeaderEntry>
/**
* Whether SEA API responses may use HTTP compression. Defaults to false.
*/
seaResponseCompressionEnabled?: boolean
/**
* Retry/backoff tuning — all optional. An unset field keeps the kernel's
* built-in policy (1s/60s exponential backoff, 6 total attempts, 900s
Expand Down
16 changes: 16 additions & 0 deletions napi/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ pub struct ConnectionOptions {
/// `User-Agent` entry here.
pub custom_headers: Option<Vec<HeaderEntry>>,

/// Whether SEA API responses may use HTTP compression. Defaults to false.
pub sea_response_compression_enabled: Option<bool>,

/// Retry/backoff tuning — all optional. An unset field keeps the kernel's
/// built-in policy (1s/60s exponential backoff, 6 total attempts, 900s
/// budget). Mirrors the pyo3 binding's `retry_*` kwargs so the Node.js
Expand Down Expand Up @@ -610,6 +613,8 @@ fn build_tls_config(options: &ConnectionOptions) -> TlsConfig {
/// strings.
fn build_http_config(options: &mut ConnectionOptions) -> HttpConfig {
let mut http = HttpConfig::default();
http.sea_response_compression_enabled =
options.sea_response_compression_enabled.unwrap_or(false);
http.pool_max_idle_per_host = options
.max_connections
.map(|max| max as usize)
Expand Down Expand Up @@ -922,6 +927,7 @@ mod tests {
client_cert_pem: None,
client_key_pem: None,
custom_headers: None,
sea_response_compression_enabled: None,
retry_min_wait_secs: None,
retry_max_wait_secs: None,
retry_max_attempts: None,
Expand Down Expand Up @@ -1525,6 +1531,16 @@ mod tests {
assert_eq!(http.custom_headers[1].1, "Connector/2.0");
}

#[test]
fn sea_response_compression_option_maps_to_http_config() {
let mut defaults = base();
assert!(!build_http_config(&mut defaults).sea_response_compression_enabled);

let mut enabled = base();
enabled.sea_response_compression_enabled = Some(true);
assert!(build_http_config(&mut enabled).sea_response_compression_enabled);
}

#[test]
fn http_retry_knobs_map_onto_http_config() {
let mut o = base();
Expand Down
3 changes: 3 additions & 0 deletions pyo3/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ changes go in the root `NEXT_CHANGELOG.md`.

### Added

- Added `Session(..., sea_response_compression_enabled=...)` to opt back into
HTTP compression for bandwidth-constrained SEA connections.

### Changed

### Updated
Expand Down
37 changes: 27 additions & 10 deletions pyo3/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ fn build_telemetry_config(

#[allow(clippy::too_many_arguments)]
fn build_http_config(
sea_response_compression_enabled: bool,
request_timeout_secs: Option<f64>,
max_connections: Option<usize>,
retry_min_wait_secs: Option<u64>,
Expand Down Expand Up @@ -179,7 +180,8 @@ fn build_http_config(
));
}
let has_http_headers = http_headers.as_ref().is_some_and(|h| !h.is_empty());
if request_timeout.is_none()
if !sea_response_compression_enabled
&& request_timeout.is_none()
&& max_connections.is_none()
&& retry_min_wait_secs.is_none()
&& retry_max_wait_secs.is_none()
Expand All @@ -191,6 +193,7 @@ fn build_http_config(
}

let mut http = databricks_sql_kernel::HttpConfig::default();
http.sea_response_compression_enabled = sea_response_compression_enabled;
if let Some(timeout) = request_timeout {
http.request_timeout = timeout;
}
Expand Down Expand Up @@ -354,6 +357,7 @@ impl Session {
tls_skip_hostname_verify=false,
tls_client_cert=None,
tls_client_key=None,
sea_response_compression_enabled=false,
request_timeout_secs=None,
max_connections=None,
retry_min_wait_secs=None,
Expand Down Expand Up @@ -419,6 +423,7 @@ impl Session {
tls_skip_hostname_verify: bool,
tls_client_cert: Option<Vec<u8>>,
tls_client_key: Option<Vec<u8>>,
sea_response_compression_enabled: bool,
request_timeout_secs: Option<f64>,
max_connections: Option<usize>,
retry_min_wait_secs: Option<u64>,
Expand Down Expand Up @@ -536,6 +541,7 @@ impl Session {
// composed `User-Agent`). The kernel applies them before its own
// `Authorization` / `x-databricks-org-id`, which always win.
let http_config = build_http_config(
sea_response_compression_enabled,
request_timeout_secs,
max_connections,
retry_min_wait_secs,
Expand Down Expand Up @@ -816,14 +822,14 @@ mod send_sync_tests {
#[test]
fn request_timeout_kwarg_maps_to_http_config() {
let default = databricks_sql_kernel::HttpConfig::default();
assert!(build_http_config(None, None, None, None, None, None, None)
assert!(build_http_config(false, None, None, None, None, None, None, None)
.unwrap()
.is_none());
assert!(build_http_config(Some(0.0), None, None, None, None, None, None)
assert!(build_http_config(false, Some(0.0), None, None, None, None, None, None)
.unwrap()
.is_none());

let http = build_http_config(Some(0.5), None, None, None, None, None, None)
let http = build_http_config(false, Some(0.5), None, None, None, None, None, None)
.unwrap()
.expect("positive request timeout should build an HTTP config");
assert_eq!(http.request_timeout, std::time::Duration::from_millis(500));
Expand All @@ -832,28 +838,39 @@ mod send_sync_tests {

let one_ns = std::time::Duration::from_nanos(1).as_secs_f64();
assert!(
build_http_config(Some(one_ns / 1_000.0), None, None, None, None, None, None)
build_http_config(false, Some(one_ns / 1_000.0), None, None, None, None, None, None)
.is_err()
);
let http = build_http_config(Some(one_ns), None, None, None, None, None, None)
let http = build_http_config(false, Some(one_ns), None, None, None, None, None, None)
.unwrap()
.expect("one-nanosecond request timeout should be accepted");
assert_eq!(http.request_timeout, std::time::Duration::from_nanos(1));

assert!(build_http_config(Some(-1.0), None, None, None, None, None, None).is_err());
assert!(build_http_config(Some(f64::NAN), None, None, None, None, None, None).is_err());
assert!(build_http_config(false, Some(-1.0), None, None, None, None, None, None).is_err());
assert!(build_http_config(false, Some(f64::NAN), None, None, None, None, None, None).is_err());
}

#[test]
fn max_connections_kwarg_maps_to_http_config() {
let default = databricks_sql_kernel::HttpConfig::default();
let http = build_http_config(None, Some(17), None, None, None, None, None)
let http = build_http_config(false, None, Some(17), None, None, None, None, None)
.unwrap()
.expect("max connections should build an HTTP config");
assert_eq!(http.pool_max_idle_per_host, 17);
assert_eq!(http.request_timeout, default.request_timeout);

assert!(build_http_config(None, Some(0), None, None, None, None, None).is_err());
assert!(build_http_config(false, None, Some(0), None, None, None, None, None).is_err());
}

#[test]
fn sea_response_compression_kwarg_maps_to_http_config() {
assert!(build_http_config(false, None, None, None, None, None, None, None)
.unwrap()
.is_none());
let http = build_http_config(true, None, None, None, None, None, None, None)
.unwrap()
.expect("enabling SEA response compression should build an HTTP config");
assert!(http.sea_response_compression_enabled);
}

#[test]
Expand Down
55 changes: 53 additions & 2 deletions src/c_abi/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ pub struct KernelSessionConfig {
/// Extra HTTP headers sent on every request (accumulated by
/// `..._set_custom_header`, one `(name, value)` pair per call).
custom_headers: Vec<(String, String)>,
/// Whether authenticated SEA responses may use HTTP compression.
sea_response_compression_enabled: bool,
/// Total request timeout (populated by `..._set_request_timeout`). `None`
/// keeps [`HttpConfig::default`]'s 120-second timeout.
request_timeout: Option<Duration>,
Expand Down Expand Up @@ -265,6 +267,7 @@ pub unsafe extern "C" fn kernel_session_config_new(
proxy: None,
tls: TlsSpec::default(),
custom_headers: Vec::new(),
sea_response_compression_enabled: false,
request_timeout: None,
max_connections: None,
retry: None,
Expand Down Expand Up @@ -587,6 +590,22 @@ pub unsafe extern "C" fn kernel_session_config_set_custom_header(
})
}

/// Configure whether authenticated SEA responses may use HTTP compression.
/// The default is `false`.
///
/// # Safety
/// `config` must be a live config handle.
#[no_mangle]
pub unsafe extern "C" fn kernel_session_config_set_sea_response_compression_enabled(
config: *mut KernelSessionConfig,
enabled: bool,
) -> KernelStatusCode {
set_on_config(config, |c| {
c.sea_response_compression_enabled = enabled;
Ok(())
})
}

/// Configure the total timeout for one HTTP request, from connection start
/// through response-body completion. A separate 30-second connection timeout
/// also applies, so connection establishment is bounded by the shorter limit.
Expand Down Expand Up @@ -1417,12 +1436,14 @@ fn parse_scopes(s: &str) -> Option<Vec<String>> {
/// kept unit-testable without a live session.
fn merge_http_config(
custom_headers: Vec<(String, String)>,
sea_response_compression_enabled: bool,
request_timeout: Option<Duration>,
max_connections: Option<usize>,
retry: Option<RetrySpec>,
) -> HttpConfig {
let mut http = HttpConfig {
custom_headers,
sea_response_compression_enabled,
..HttpConfig::default()
};
if let Some(t) = request_timeout {
Expand Down Expand Up @@ -1554,6 +1575,7 @@ fn build_session(config: KernelSessionConfig) -> Result<Session, KernelStatusCod
proxy,
tls,
custom_headers,
sea_response_compression_enabled,
request_timeout,
max_connections,
retry,
Expand Down Expand Up @@ -1616,12 +1638,14 @@ fn build_session(config: KernelSessionConfig) -> Result<Session, KernelStatusCod
// Skip `.http()` when no HTTP override was set, so the kernel's
// full `HttpConfig::default()` applies untouched.
if !custom_headers.is_empty()
|| sea_response_compression_enabled
|| request_timeout.is_some()
|| max_connections.is_some()
|| retry.is_some()
{
builder = builder.http(merge_http_config(
custom_headers,
sea_response_compression_enabled,
request_timeout,
max_connections,
retry,
Expand Down Expand Up @@ -2531,6 +2555,23 @@ mod tests {
}
}

#[test]
fn set_sea_response_compression_records_value() {
unsafe {
let mut config = std::ptr::null_mut();
assert_eq!(
kernel_session_config_new(&mut config),
KernelStatusCode::Success
);
assert_eq!(
kernel_session_config_set_sea_response_compression_enabled(config, true),
KernelStatusCode::Success
);
assert!(config.as_ref().unwrap().sea_response_compression_enabled);
kernel_session_config_free(config);
}
}

/// The retry setter rejects a zero min_wait with `InvalidArgument` (a zero
/// floor is genuinely invalid), but a `max_wait < min_wait` pair is a tuning
/// typo that is CORRECTED (max raised to min) with a warning rather than
Expand Down Expand Up @@ -3086,6 +3127,7 @@ mod tests {
fn merge_http_config_maps_every_retry_field() {
let http = merge_http_config(
Vec::new(),
false,
None,
None,
Some(RetrySpec {
Expand All @@ -3109,6 +3151,7 @@ mod tests {
let default_budget = HttpConfig::default().overall_timeout;
let http = merge_http_config(
Vec::new(),
false,
None,
None,
Some(RetrySpec {
Expand All @@ -3134,6 +3177,7 @@ mod tests {
// Retry-only: knobs applied, headers empty.
let retry_only = merge_http_config(
Vec::new(),
false,
None,
None,
Some(RetrySpec {
Expand All @@ -3151,6 +3195,7 @@ mod tests {
let default = HttpConfig::default();
let headers_only = merge_http_config(
vec![("X-Test".to_string(), "1".to_string())],
false,
None,
None,
None,
Expand All @@ -3168,7 +3213,13 @@ mod tests {
#[test]
fn merge_http_config_maps_request_timeout_and_preserves_other_defaults() {
let default = HttpConfig::default();
let http = merge_http_config(Vec::new(), Some(Duration::from_millis(4_500)), None, None);
let http = merge_http_config(
Vec::new(),
false,
Some(Duration::from_millis(4_500)),
None,
None,
);
assert_eq!(http.request_timeout, Duration::from_millis(4_500));
assert_eq!(http.retry_min_wait, default.retry_min_wait);
assert_eq!(http.overall_timeout, default.overall_timeout);
Expand All @@ -3177,7 +3228,7 @@ mod tests {
#[test]
fn merge_http_config_maps_max_connections_and_preserves_other_defaults() {
let default = HttpConfig::default();
let http = merge_http_config(Vec::new(), None, Some(23), None);
let http = merge_http_config(Vec::new(), false, None, Some(23), None);
assert_eq!(http.pool_max_idle_per_host, 23);
assert_eq!(http.request_timeout, default.request_timeout);
assert_eq!(http.retry_max_retries, default.retry_max_retries);
Expand Down
Loading
Loading