Files
lancedb/docs/web/enterprise/advanced-conflict-resolution.mdx
T
Bruno Ramirez 16af729792 feat(sdk)!: add typed SQL job handles for compaction and data prewarm (#5056)
Remote data prewarm used REST even though SQL supported filters and
concurrency, and both maintenance APIs returned after acceptance without
exposing a consistent typed completion handle. Compaction's legacy
statistics therefore could not describe the work committed by its
durable job. This PR adds job-returning compaction and data-prewarm
methods across Rust, Python sync/async and TypeScript, and moves
data-prewarm submission to SQL. Legacy methods retain
return-after-acceptance behavior; data prewarm now requires a compatible
SQL PREWARM server and Flight SQL connectivity. This consolidates #5037,
#5055 and #4906.

This was accomplished with the following changes:

- Added `compact_async()` / `compactAsync()` and `prewarm_data_async()`
/ `prewarmDataAsync()`, retaining the command receipt's durable job ID.
- Added `PrewarmDataOptions` for columns, a metadata-pruning filter and
concurrency; both operations inherit database, namespace and branch from
the table handle.
- Added filter/concurrency arguments to legacy Python `prewarm_data()`
and a TypeScript `prewarmData(options)` overload, preserving the
columns-array form and discarding the handle after acceptance.
- Added typed `CompactionResult` and `PrewarmDataResult` decoding,
including reopened jobs; missing result payloads fail explicitly and
omitted measurements remain unknown.
- Reused the shared Job lifecycle for status, refresh, progress
callbacks, cancellation and events; Python maintenance progress bars
display rewritten rows or completed executors.
- Added TypeScript `wait({ timeoutMs, onProgress })` and Rust
`wait_with_options(JobWaitOptions)`, complementing Python's existing
timeout argument without cancelling the durable job.
- Validated single unambiguous receipts, preserved compaction option
presence/default inheritance, and returned actionable unsupported-server
errors without dropping options or falling back to REST.
- Updated native bindings, API references and maintenance documentation
with job methods, result semantics, tuning and compatibility
requirements.

### Usage and behaviour

**New** = added here; **Enhanced** = existing support extended;
**Existing** = already on main. This table describes remote SDK
behavior; server-side SQL/CLI capabilities are prerequisites, not
additions made by this SDK PR.

| Surface | Capability | Compact | Data prewarm | Assessment |
| --- | --- | --- | --- | --- |
| Rust / Python sync+async / TypeScript | Submission transport |
Existing SQL OPTIMIZE | **New:** REST → SQL PREWARM | Both now submit
through SQL |
| All SDKs | Durable job-returning API | **New:** `compact_async` /
`compactAsync` | **New:** `prewarm_data_async` / `prewarmDataAsync` |
Same lifecycle model |
| All SDKs | Options and target scope | **New handle:** four existing
compaction overrides, with omitted fields inherited | **New options:**
columns/filter/concurrency | Namespace and branch preserved for both |
| Python / TypeScript | Legacy convenience calls | Existing optimize
acceptance behavior preserved | **Enhanced:** legacy methods accept
filter/concurrency and use SQL | Return after acceptance; no completion
wait |
| All SDKs | Typed successful result | **New:** committed rows,
file/fragment changes, partial commit and `more_work` | **New:** pinned
version, fragments and executor outcomes | Different measurements are
intentional |
| All SDKs | Status / refresh / progress | Existing Job APIs reused by
**new** maintenance handle | Existing Job APIs reused by **new**
maintenance handle | HTTP monitoring remains |
| Python / TypeScript | Progress presentation | **Enhanced:** rewrite
rows/groups | **Enhanced:** executor progress | Shared callbacks; Python
bars use operation counters |
| All SDKs | Bounded wait | Python existing; **new** TS/Rust timeout
controls | Same shared timeout support | Timeout stops this wait; job
continues |
| All SDKs | Reopen and await typed outcome | **New:** compaction result
decoding on reopened handle | **New:** prewarm result decoding on
reopened handle | Rust selects the typed result explicitly |
| All SDKs | Cancel / events | Existing shared APIs available on **new**
handle | Same | HTTP underneath; permissions unchanged |
| All SDKs | Typed preview helper | Unavailable | Unavailable | General
SQL where exposed; no helper added |
| Authorization | Submission | Existing table Ownership plus parent
Usage | SQL path uses Select plus parent Usage | Intentional difference
|
| All SDKs | Local / historical handles | New durable API rejects them |
New durable API rejects them | Remote current-branch jobs only |

```python
from datetime import timedelta

# Legacy convenience call: returns None after acceptance.
table.prewarm_data(["payload"], filter="id >= 1000", concurrency=4)

warm = table.prewarm_data_async(["payload"], filter="id >= 1000", concurrency=4)
warmed = warm.wait(timeout=timedelta(minutes=10), progress=print)
print(warmed.table_version, warmed.executors_completed)

compact = table.compact_async(compaction_options={"max_source_rows": 1000000})
committed = compact.wait(timeout=timedelta(minutes=10), progress=print)
print(committed.rows_succeeded, committed.fragments_removed, committed.more_work)

reopened_result = db.open_job(compact.id).wait()
```

```typescript
await table.prewarmData({ columns: ["payload"], filter: "id >= 1000", concurrency: 4 });
const job = await table.prewarmDataAsync({
  columns: ["payload"], filter: "id >= 1000", concurrency: 4,
});
const result = await job.wait({ timeoutMs: 600_000, onProgress: console.log });
```

```rust
use std::time::Duration;
use lancedb::job::JobWaitOptions;

let job = table.compact_async(Default::default()).await?;
let result = job.wait_with_options(
    JobWaitOptions::new().timeout(Duration::from_secs(600)),
).await?;
```

Python async tables await both submission and Job methods. Rust's legacy
`prewarm_data(columns)` keeps its columns-only signature; use
`PrewarmDataOptions` on the new job-returning method for
filtering/concurrency.

Wait deadlines cover pending status requests and polling delays.
Existing `wait()`, TypeScript `wait(callback)` and Rust
`wait_with_progress(callback)` remain supported.
Status/progress/refresh/cancel/events still use generic HTTP job APIs;
those endpoints and their read/event/cancel permissions must remain
available. Cancelling or timing out does not roll back committed work.

Compaction results describe committed rewrites and include deletion
files in file counts. Prewarm results describe work against a pinned
snapshot, with partial executors included in completed executors;
nonempty byte/range measurements remain unknown. Missing results require
compatible server/worker support rather than placeholder zero
statistics. Filtering uses conservative metadata pruning, not an exact
row-filter scan.

### Testing

Six checked-in live Python sync/async cases pass against matching
server/worker builds for compaction, job-returning prewarm and legacy
filtered submission. Ten additional live Node scenarios pass for
legacy/default/options forms, filters/concurrency, empty plans,
validation, persisted specifications and readback.

Targeted regressions pass: Python remote maintenance (80), shared jobs
(82), local prewarm rejection (4); Node remote (107) and prewarm API
cases (28), plus the previously exercised Rust remote regressions. Tests
cover receipt parsing, typed results, reopening, unknown measurements,
timeouts, and legacy calls returning None/undefined without polling.

Dependency pins are unchanged. Azure account-hint acknowledgment was
verified locally with filesystem storage; real Azure-backed storage
still needs deployment-specific validation.
2026-11-17 10:57:56 -08:00

202 lines
10 KiB
Plaintext

---
title: "Advanced Conflict Resolution"
sidebarTitle: "Advanced Conflict Resolution"
description: "How compaction and indexing stay safe to run concurrently, using Lance's fragment reuse index."
icon: shuffle
keywords: ["fragment reuse index", "FRI", "compaction", "indexing", "remap", "conflict resolution"]
availability:
embedded: unavailable
enterprise: available
---
[Compaction](/maintenance/compaction) rewrites fragments into fewer, larger
files, which changes the physical row address -- file and offset -- of every
row it moves. An index built against the old layout stores exactly those
addresses, so a naive compaction would leave any index covering the rewritten
fragments pointing at rows that have moved or no longer exist there.
LanceDB Embedded avoids this by default by never letting the two run
independently: `optimize()` compacts and remaps affected indexes in the
same call, before returning. Compaction's `defer_index_remap` option opts
out of that -- the call returns once compaction itself commits, leaving
the remap for later -- which is what lets a custom remapper or a
stable-row-ID table skip the synchronous step. LanceDB Enterprise schedules
automatic compaction and indexing independently, so an eligible table can compact
while an index build is still catching up from earlier compaction. Deferred
remapping keeps indexes correct without making every automatic compaction wait
for a synchronous remap. Explicit
[manual compaction](/maintenance/compaction#enterprise-manual-compaction) uses one
worker with atomic execution and inline index remapping instead.
## The fragment reuse index {#fri}
The **fragment reuse index** (FRI) is a Lance format-level mechanism, not an
Enterprise add-on: a system index that records every fragment rewrite as a
**transition** -- the source fragments' digests, the destination fragments'
digests, and a row-address mapping between them (`Transition` and `Mapping`
in `lance-table`'s `system_index::frag_reuse::ledger`). An index that covers
a rewritten fragment does not need to be rebuilt before the rewrite commits;
it can instead translate the row addresses it already stores forward through
the chain of recorded transitions at read time.
Only a compaction run with `defer_index_remap` ever touches the FRI; a
synchronous-remap rewrite -- the Embedded default -- never tags a table or
appends anything. Every `defer_index_remap` commit is classified before
it is admitted; that classifier is Lance's own commit protocol
(`lance-table`'s `frag_reuse::gate::classify`), the same one every write
funnels through -- not a lock or a sequencing rule Enterprise imposes from
outside. A table starts **untagged**: its deferred rewrites are admitted
as ordinary business with nothing appended, unless the rewrite has
stable row IDs to translate or touches a fragment an index covers -- either
one makes that commit record a legacy, untagged ("v0") FRI entry, which
does **not** tag the table. Tagging is a separate, one-way transition (a
sticky manifest flag that a later trim never clears) that publishes the
FRI's first real transition; this page does not cover what triggers it.
Once a table is tagged, its commits are classified against which indexes
cover the rewritten fragments the way the rest of this page describes, and
every entry it records from then on is a tagged transition, never v0
again. A table with stable row IDs is permanently confined to the
untagged, v0 form -- Lance refuses to tag it at all -- so its deferred
compactions keep recording v0 entries indefinitely, for every rewrite that
moves row addresses, not only ones that touch an indexed fragment: the
address translation itself depends on that record, independent of
indexing.
Once a table is tagged, Lance refuses a compaction that does not set
`defer_index_remap`, including a plain Embedded `optimize()` call: an
Enterprise-tagged table has to keep deferring the remap, or be compacted
by a writer that can remap the tagged history eagerly.
<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 TD
Commit["Compaction commit<br/>(defer_index_remap only)"] --> Tagged{"Table already<br/>tagged with an FRI?"}
Tagged -->|no| First{"Stable row IDs, or does<br/>any index cover the<br/>rewritten fragments?"}
First -->|no| Admit["Admitted as<br/>ordinary business --<br/>nothing appended"]
First -->|yes| V0["Records a legacy v0 entry --<br/>table stays untagged"]
Tagged -->|yes| Classify{"Does any index<br/>cover the rewritten<br/>fragments?"}
Classify -->|no| Admit
Classify -->|yes| Append["Must append a tagged<br/>transition before the<br/>commit is admitted"]
V0 --> FRI[("Fragment reuse index")]
Append --> FRI
classDef default fill:#1e1b19,stroke:#4c443f,stroke-width:1px,color:#f4ebe8
classDef accent fill:#2a1810,stroke:#e8582d,stroke-width:1.5px,color:#f4ebe8
class FRI 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 TD
Commit["Compaction commit<br/>(defer_index_remap only)"] --> Tagged{"Table already<br/>tagged with an FRI?"}
Tagged -->|no| First{"Stable row IDs, or does<br/>any index cover the<br/>rewritten fragments?"}
First -->|no| Admit["Admitted as<br/>ordinary business --<br/>nothing appended"]
First -->|yes| V0["Records a legacy v0 entry --<br/>table stays untagged"]
Tagged -->|yes| Classify{"Does any index<br/>cover the rewritten<br/>fragments?"}
Classify -->|no| Admit
Classify -->|yes| Append["Must append a tagged<br/>transition before the<br/>commit is admitted"]
V0 --> FRI[("Fragment reuse index")]
Append --> FRI
classDef default fill:#ffffff,stroke:#ad9e95,stroke-width:1px,color:#221d19
classDef accent fill:#fff1ec,stroke:#e8582d,stroke-width:1.5px,color:#221d19
class FRI accent
```
</div>
## Enterprise defers and batches the catch-up {#catch-up}
Translating addresses through a long chain of transitions at every read adds
up, so Enterprise does not let the FRI grow without bound. Its job planner
tracks how many transitions have accumulated for a table and schedules a
dedicated **remap catch-up** job -- which applies the accumulated transitions
to the indexes that need them, physically, in one pass -- once either:
- the FRI reaches **5 pending transitions** (`remap_fri_version_threshold`,
tunable), or
- the oldest pending transition is **1 day old**
(`remap_fri_max_age_secs`, tunable), whichever comes first.
The version count only climbs while a table keeps compacting, so the age
threshold exists to clear a lingering FRI -- and the per-read remap cost that
comes with it -- on a table that stops compacting before reaching the count
threshold, without scheduling a catch-up job on every table that is still
actively compacting. This is what lets compaction and index maintenance run
as separate background jobs (see
[Index maintenance jobs](/indexing/incremental-indexing#index))
rather than one blocking on the other: a handful of compactions can land
before their indexes are physically remapped, and the catch-up job amortizes
that remap across all of them in one job instead of one per compaction.
<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 TD
C1["Compaction job"] -->|appends transition| FRI["Fragment reuse index<br/>(ledger of transitions)"]
C2["Compaction job"] -->|appends transition| FRI
C3["Compaction job"] -->|appends transition| FRI
FRI -->|5 transitions or<br/>1 day old| R["Remap catch-up job"]
R -->|applies accumulated<br/>transitions| IDX["Affected indexes,<br/>physically remapped"]
classDef default fill:#1e1b19,stroke:#4c443f,stroke-width:1px,color:#f4ebe8
classDef accent fill:#2a1810,stroke:#e8582d,stroke-width:1.5px,color:#f4ebe8
class FRI,R 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 TD
C1["Compaction job"] -->|appends transition| FRI["Fragment reuse index<br/>(ledger of transitions)"]
C2["Compaction job"] -->|appends transition| FRI
C3["Compaction job"] -->|appends transition| FRI
FRI -->|5 transitions or<br/>1 day old| R["Remap catch-up job"]
R -->|applies accumulated<br/>transitions| IDX["Affected indexes,<br/>physically remapped"]
classDef default fill:#ffffff,stroke:#ad9e95,stroke-width:1px,color:#221d19
classDef accent fill:#fff1ec,stroke:#e8582d,stroke-width:1.5px,color:#221d19
class FRI,R accent
```
</div>
## What to read next {#next}
<CardGroup cols={2}>
<Card title="Compaction and cleanup" icon="broom" href="/maintenance/compaction">
What compaction merges, and how the embedded library runs it in one call.
</Card>
<Card title="Incremental Indexing" icon="arrows-rotate" href="/indexing/incremental-indexing#index">
The `index_remap` job type, and keeping an index current as the table changes.
</Card>
<Card title="Distributed Compaction" icon="layer-group" href="/enterprise/distributed-compaction">
How compaction itself scales across the jobs fleet.
</Card>
<Card title="Distributed Indexing" icon="diagram-project" href="/enterprise/distributed-indexing">
How an index build scales across the jobs fleet.
</Card>
</CardGroup>