mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
feat: add cleanup jobs and previews across SDKs (#5107)
LanceDB SDK users connected to Enterprise had no explicit API to submit durable cleanup or preview its work; Python's existing cleanup helper remained a warning-only no-op. This PR adds the SDK support for [ENT-2687](https://linear.app/lancedb/issue/ENT-2687) through public SQL and Job APIs. It requires a compatible Enterprise release supporting `VACUUM`, JSON preview and result format version 1. Existing cleanup/optimize helpers retain their behavior; the new APIs reject Embedded and historical-version handles. This was accomplished with the following changes: - Add `cleanup_async()` / `cleanupAsync()` and `explain_cleanup()` / `explainCleanup()` in Python sync/async, TypeScript and Rust. - Preserve the handle's namespace/branch and resolve retention as invocation → table/branch TTL → deployment default. Omission inherits, zero is explicit, and malformed options fail rather than being discarded. - Require one nonempty durable SQL receipt, preserving diagnostics without REST fallback, query-ID substitution or automatic resubmission after ambiguous acceptance. - Add versioned `CleanupPlan` estimates and `CleanupResult` measurements. Preview creates no cleanup job or reservation; results preserve known zero, unknown retry/recovery totals and nonfatal failed deletes, excluding auxiliary sweeps. - Retain typed results on reopening and reuse shared status/progress/events/wait/cancel APIs. Timeout leaves work running; cancellation cannot undo deletion or prove storage I/O stopped. - Document Ownership/parent Usage and required coordination at every retention value: disable/drain automatic cleanup and prevent competing cleanup, tag creation/update, branch creation and restore across all clients until completion. The server does not enforce exclusion; concurrent restore can leave the current table unreadable. - Update Python's legacy no-op warning and the maintenance, Python, Rust and generated TypeScript references. | Interface | Submit with seven-day retention | | --- | --- | | SQL | `VACUUM events WITH (min_age_seconds = 604800);` | | CLI | `lancedb admin table cleanup --table events --min-age-seconds 604800 --wait` | | Python | `job = table.cleanup_async(min_age_seconds=604800)` (use `await` with AsyncTable) | | TypeScript | `const job = await table.cleanupAsync({ minAgeSeconds: 604800 });` | | Rust | `let job = table.cleanup_async(CleanupOptions::new().min_age_seconds(604800)).await?;` | ### Testing Added submission/preview, validation, typed-result and reopening tests, and updated the legacy no-op warning assertion. Focused Python cleanup/Job and compaction/prewarm regressions passed, alongside **34 TypeScript** and **46 Rust** tests. **31 end-to-end scenarios** passed against a real Enterprise server, covering CLI/SQL/REST/SDK submission, retention precedence, restart/reopening, timeouts, cancellation and branch/namespace isolation. Local native SDK validation used a separate `libsais-rs 0.2.0` lockfile because the registry could not resolve `0.2.4`; this PR retains main's dependency pins and lockfile.
This commit is contained in:
@@ -1001,6 +1001,33 @@ impl Table {
|
||||
Ok(self.inner_ref()?.current_branch())
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub async fn explain_cleanup(
|
||||
&self,
|
||||
min_age_seconds: Option<f64>,
|
||||
) -> napi::Result<serde_json::Value> {
|
||||
let plan = self
|
||||
.inner_ref()?
|
||||
.explain_cleanup(parse_cleanup_options(min_age_seconds)?)
|
||||
.await
|
||||
.default_error()?;
|
||||
serde_json::to_value(plan).map_err(|error| napi::Error::from_reason(error.to_string()))
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub async fn cleanup_async(
|
||||
&self,
|
||||
min_age_seconds: Option<f64>,
|
||||
) -> napi::Result<crate::job::Job> {
|
||||
let options = parse_cleanup_options(min_age_seconds)?;
|
||||
let job = self
|
||||
.inner_ref()?
|
||||
.cleanup_async(options)
|
||||
.await
|
||||
.default_error()?;
|
||||
Ok(crate::job::Job::new_typed(job))
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub async fn compact_async(
|
||||
&self,
|
||||
@@ -2557,3 +2584,19 @@ impl Branches {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_cleanup_options(
|
||||
min_age_seconds: Option<f64>,
|
||||
) -> napi::Result<lancedb::table::CleanupOptions> {
|
||||
let mut options = lancedb::table::CleanupOptions::new();
|
||||
if let Some(age) = min_age_seconds {
|
||||
if !age.is_finite() || age.fract() != 0.0 || !(0.0..=9_007_199_254_740_991.0).contains(&age)
|
||||
{
|
||||
return Err(napi::Error::from_reason(
|
||||
"minAgeSeconds must be a nonnegative safe integer",
|
||||
));
|
||||
}
|
||||
options.min_age_seconds = Some(age as u64);
|
||||
}
|
||||
Ok(options)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user