mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
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.
192 lines
9.7 KiB
Plaintext
192 lines
9.7 KiB
Plaintext
---
|
|
title: "Intelligent Auto-Maintenance"
|
|
sidebarTitle: "Intelligent Auto-Maintenance"
|
|
description: "How Enterprise continuously tracks table activity in the background and decides what maintenance -- compaction, cleanup, indexing, remap catch-up -- a table needs next."
|
|
icon: "brain"
|
|
keywords: ["agent", "planning", "scheduling", "maintenance", "planner", "table events", "coverage", "cleanup", "automated", "retention", "gc", "version_interval", "min_age_seconds"]
|
|
availability:
|
|
embedded: unavailable
|
|
enterprise: available
|
|
---
|
|
|
|
Keeping a table in good condition takes several different kinds of work --
|
|
compacting files, catching indexes up, cleaning old versions, folding a
|
|
RTE write tier into the base table -- each with its own trigger. In
|
|
LanceDB Enterprise, a fleet of agent processes decides when each of these
|
|
needs to run, continuously, per table, in the background across your
|
|
cluster -- nothing to schedule, trigger, or monitor by hand unless you want
|
|
to.
|
|
|
|
<div className="hidden dark:block">
|
|
|
|
```mermaid
|
|
%%{init: {"theme": "base", "themeVariables": {
|
|
"background": "#171513", "primaryColor": "#1e1b19", "primaryTextColor": "#f4ebe8",
|
|
"primaryBorderColor": "#4c443f", "lineColor": "#847770", "textColor": "#f4ebe8",
|
|
"edgeLabelBackground": "#171513", "fontFamily": "Inter, sans-serif", "fontSize": "18px"
|
|
}}}%%
|
|
flowchart LR
|
|
E["Table event notifications"] --> P
|
|
S["Periodic sweep<br/>every table, on a timer"] --> P
|
|
P["Planner<br/>evaluates one table"]
|
|
P --> W["Possible next step:<br/>WAL index catch-up"]
|
|
P --> I["Possible next step:<br/>Index operations"]
|
|
P --> C["Possible next step:<br/>Compaction"]
|
|
P --> CL["Possible next step:<br/>Cleanup"]
|
|
P --> R["Possible next step:<br/>Remap catch-up"]
|
|
classDef default fill:#1e1b19,stroke:#4c443f,stroke-width:1px,color:#f4ebe8
|
|
classDef accent fill:#2a1810,stroke:#e8582d,stroke-width:1.5px,color:#f4ebe8
|
|
class P accent
|
|
```
|
|
|
|
</div>
|
|
|
|
<div className="block dark:hidden">
|
|
|
|
```mermaid
|
|
%%{init: {"theme": "base", "themeVariables": {
|
|
"background": "#ffffff", "primaryColor": "#ffffff", "primaryTextColor": "#221d19",
|
|
"primaryBorderColor": "#ad9e95", "lineColor": "#6b625c", "textColor": "#221d19",
|
|
"edgeLabelBackground": "#ffffff", "fontFamily": "Inter, sans-serif", "fontSize": "18px"
|
|
}}}%%
|
|
flowchart LR
|
|
E["Table event notifications"] --> P
|
|
S["Periodic sweep<br/>every table, on a timer"] --> P
|
|
P["Planner<br/>evaluates one table"]
|
|
P --> W["Possible next step:<br/>WAL index catch-up"]
|
|
P --> I["Possible next step:<br/>Index operations"]
|
|
P --> C["Possible next step:<br/>Compaction"]
|
|
P --> CL["Possible next step:<br/>Cleanup"]
|
|
P --> R["Possible next step:<br/>Remap catch-up"]
|
|
classDef default fill:#ffffff,stroke:#ad9e95,stroke-width:1px,color:#221d19
|
|
classDef accent fill:#fff1ec,stroke:#e8582d,stroke-width:1.5px,color:#221d19
|
|
class P accent
|
|
```
|
|
|
|
</div>
|
|
|
|
## Tracking activity {#tracking}
|
|
|
|
An agent's long-running process watches two independent sources for a
|
|
table: **table events** (Job Registry notifications, so it learns about a
|
|
write, a schema change, or a new index almost immediately) and a
|
|
**periodic sweep** that revisits every table it owns on a timer -- 600
|
|
seconds by default -- so a table that stops producing events still gets
|
|
re-evaluated rather than going stale. A hot table producing a flood of
|
|
events does not get to monopolize evaluation: notifications and the
|
|
periodic sweep share a bounded per-tick budget, and reads for a given table
|
|
run at most once at a time.
|
|
|
|
Each evaluation reopens the table and reads its manifest, indexes and
|
|
in-flight jobs fresh, rather than deciding from a cached guess. Those are
|
|
separate reads rather than one atomic snapshot, so a concurrent write
|
|
between them is possible; the next evaluation -- triggered by that same
|
|
write's own event notification -- is what catches anything the current
|
|
one missed.
|
|
|
|
## Deciding what to run {#deciding}
|
|
|
|
A table is not reduced to one "next best action" -- each evaluation walks a
|
|
fixed, priority-ordered sequence of independent decisions, launching
|
|
whichever ones are due:
|
|
|
|
1. **WAL index catch-up.** Checked first and gated by nothing else, because
|
|
it is correctness-driven rather than discretionary: while an index lags
|
|
behind the compacted generation, the RTE write tier cannot trim its
|
|
log. See [RTE Compaction](/enterprise/realtime-engine-compaction).
|
|
2. **Index operations.** Reindexing a column, unless a compaction that
|
|
cannot defer its remap is about to run this same tick -- deferred-remap
|
|
compaction lets index work proceed alongside it instead of waiting. See
|
|
[Incremental Indexing](/indexing/incremental-indexing).
|
|
3. **Compaction.** Whether enough small fragments or deleted rows have
|
|
accumulated to merge. See [Compaction](/maintenance/compaction) and
|
|
[Distributed Compaction](/enterprise/distributed-compaction).
|
|
4. **Cleanup.** Independent of the other four -- it can always run in
|
|
parallel with them. [See below](#cleanup) for exactly when it's due.
|
|
5. **Deferred-remap catch-up.** The batched, amortized follow-up for index
|
|
entries a deferred compaction didn't remap synchronously. See
|
|
[Advanced Conflict Resolution](/enterprise/advanced-conflict-resolution).
|
|
|
|
More than one of these can fire for the same table in the same evaluation --
|
|
a compaction and a cleanup are unrelated and can both launch together -- but
|
|
some gate each other where running them at the same time would be unsafe,
|
|
like index operations waiting on a compaction that can't defer its remap.
|
|
|
|
Compaction's four tuning fields can be set per table. Automatic jobs use table
|
|
tuning before deployment/built-in defaults; explicit manual invocation values
|
|
take precedence over both. Automatic enablement still gates background jobs,
|
|
while manual compaction can run with it disabled. Resolved tuning is captured in
|
|
each job. See [table compaction defaults](/maintenance/compaction#table-compaction-defaults)
|
|
for the fields, precedence, source-budget planning failures, and compatible-version requirements.
|
|
|
|
### When cleanup is due {#cleanup}
|
|
|
|
[Cleanup](/maintenance/cleanup) prunes old table versions and the files only
|
|
they referenced. In LanceDB Embedded, that always happens because you asked
|
|
for it, through a call to `optimize()`. In LanceDB Enterprise, a
|
|
[manual `optimize()` call](/maintenance/compaction#enterprise-manual-compaction)
|
|
submits compaction only. This planner controls automatic cleanup, which is
|
|
disabled by default unless the deployment sets a minimum version age:
|
|
with no minimum age configured, nothing is ever old enough to clean up
|
|
automatically. A table can also disable automatic cleanup individually even
|
|
when the deployment allows it, overriding the deployment-wide setting for
|
|
just that table.
|
|
|
|
You can [submit manual cleanup](/maintenance/cleanup#enterprise-manual-cleanup)
|
|
even when automatic cleanup is disabled. Follow the coordination requirements
|
|
in that guide before submitting a manual run.
|
|
|
|
Once automatic cleanup is enabled, a table becomes due when any one of these
|
|
is true:
|
|
|
|
| Trigger | Condition |
|
|
| --- | --- |
|
|
| Enough new versions | The current version has advanced far enough past the version the last successful cleanup started from |
|
|
| Enough time has passed | The last successful cleanup finished long enough ago -- the default is 24 hours -- so an idle table whose versions simply age past the retention window still gets revisited |
|
|
| Version went backward | The current version is lower than the version the last successful cleanup recorded, which re-triggers a run immediately |
|
|
|
|
A table that has never had a successful cleanup run is held to its own
|
|
initial version threshold first, so a brand-new table is not claimed for
|
|
cleanup before it has accumulated enough versions to be worth the pass. A
|
|
failed attempt is retried, but not immediately -- a minimum delay (60
|
|
seconds by default) must pass after the failure before the table becomes
|
|
eligible again, even if one of the triggers above would otherwise fire.
|
|
|
|
## Confirming it's actually running {#observability}
|
|
|
|
Rather than asking you to trust that evaluation is happening, the agent
|
|
exposes coverage metrics scoped to *successful* evaluations specifically --
|
|
a failed or timed-out attempt does not count:
|
|
|
|
| Metric (`lance_agent_` prefix) | What it tells you |
|
|
| --- | --- |
|
|
| `coverage_never_evaluated` | Tables this agent owns that have never completed an evaluation |
|
|
| `coverage_oldest_success_age_seconds` | How long it's been since the longest-overdue table was last successfully evaluated |
|
|
| `coverage_cycle_target` / `coverage_cycle_pending` | How much work the current full sweep has left |
|
|
| `coverage_cycles_completed_total` | How many full sweeps have finished |
|
|
|
|
A cycle freezes its target set of tables up front; new tables join the
|
|
*next* cycle rather than resetting progress on the current one, and a table
|
|
that disappears or changes ownership is dropped from the target rather than
|
|
counted as covered.
|
|
|
|
## What to read next {#next}
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Cleanup" icon="broom" href="/maintenance/cleanup">
|
|
What a cleanup pass actually removes, and the retention window it respects.
|
|
</Card>
|
|
<Card title="Advanced Conflict Resolution" icon="shuffle" href="/enterprise/advanced-conflict-resolution">
|
|
Why compaction and index maintenance need the deferred-remap decision at all.
|
|
</Card>
|
|
<Card title="RTE Compaction" icon="compress" href="/enterprise/realtime-engine-compaction">
|
|
The WAL-tier compaction this page's Decision 1 depends on.
|
|
</Card>
|
|
<Card title="Incremental Indexing" icon="refresh" href="/indexing/incremental-indexing">
|
|
What an index operation actually does once scheduled.
|
|
</Card>
|
|
<Card title="OpenTelemetry" icon="chart-line" href="/deployment/opentelemetry">
|
|
Viewing the `lance_agent_*` coverage metrics above.
|
|
</Card>
|
|
</CardGroup>
|