Skip to content

feat(format): add cell preconditions to the transaction format - #9121

Open
lichuang wants to merge 1 commit into
lance-format:mainfrom
lichuang:issue-8976-proto
Open

lichuang wants to merge 1 commit into
lance-format:mainfrom
lichuang:issue-8976-proto

Conversation

@lichuang

@lichuang lichuang commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

feat(format): add cell preconditions to the transaction format

Part of #8976. Vote-only PR: proto change, format specification, and compile-required edits. The builder and commit-loop implementation is intentionally excluded and lands in the follow-up #9118, per the persisted-format change process.

Contract being accepted

A transaction may carry preconditions: declarations that specific cells must be unchanged relative to the transaction's read_version when the commit lands. A cell is a (field, physical row address) pair; each precondition declares a set of cells as the cartesian product of field ids and a per-fragment row selection.

Motivating case: read-compute-write workloads such as publishing a derived column y = f(x). The staged values are only valid if the cells of x they were computed from still hold the same contents. Conflict compatibility cannot guard this — a read-x-write-y transaction is compatible with a concurrent update of x, and rebasing over it silently publishes stale values.

Semantics fixed by this spec

The specification (docs/src/format/table/transaction.md, new "Preconditions" section) pins the points that must be decided language-agnostically, before any implementation fixes them by accident:

  1. Composition — preconditions is repeated and conjunctive: every entry must hold. A violation rejects the commit; it is never rebased over the changed cells.
  2. Absent / empty / invalid — absent or empty means no conditions. An entry with empty field_ids or empty rows declares no cells and is a no-op: consumers must safely ignore it rather than error on it (producers should not emit it). Consumers must reject negative field ids, duplicate fragment entries, or invalid Roaring bitmaps as corrupt transactions. A RowSelection whose coverage oneof is unset selects no rows (a no-op, equivalent to an empty bitmap); producers must set exactly one variant. (full = false is unrepresentable by construction — the full variant is a valueless google.protobuf.Empty message, so present always means selected.)
  3. "Unchanged" — defined conservatively, evaluated against the pinned read_version state, and checked at two levels. Field validity: every declared field must still exist with the same data type and nullability it had at the read version — a concurrent Project that drops the field while retaining its shared data file violates the precondition even when no manifest structure changed. Manifest structure: fragment removal, or any data file carrying a declared field being replaced / removed / with the declared field added or dropped from it, or any overlay affecting declared cells added / modified / removed / narrowed counts as a change. An overlay already present at the read version and unchanged does not. Files carrying no declared field may be added or removed (for example by a concurrent column addition) without violating the precondition. Masking exception: deletion-vector changes do not count as a change — a deleted row is masked, so any staged value on it is invisible to readers and does not need recomputation. Implementations may over-reject but must never under-reject.

The rows encoding is fully specified in the proto: one RowSelection per fragment (fragment_id + a coverage oneof of full — a valueless google.protobuf.Empty message, present means the entire fragment is selected — or a Roaring Bitmap portable-serialized bitmap of row offsets; if neither variant is set, the selection is empty and the entry is a no-op). Stable-row-id preconditions are explicitly reserved for a future revision.

Compatibility

  • Proto: additive field (repeated Precondition preconditions = 5 on Transaction; field 5 previously unused). Old readers ignore it; new readers see it absent for old writers. No field numbers reused or retyped.
  • The feature is inert until a producer emits it: no behavior change for any existing transaction.
  • transaction.proto is a stable persisted contract (transaction logs and inline manifest transactions), so this change requires the format-spec vote.

@github-actions github-actions Bot added A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). enhancement New feature or request labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

Format specification vote

This PR modifies the Lance format specification, so it requires 3 binding +1 votes from PMC members (excluding the proposer), at least one of them on the latest commit, and a minimum 72-hour voting period, weekends excluded, before it can merge. Vote by approving this PR (+1) or requesting changes (−1, a veto). See the voting process.

Approvals carry over across pushes, so a rebase or a typo fix does not send everyone back to re-vote. Whoever approves the latest commit is vouching that nothing substantive has changed since the earlier approvals; if something has, ask for fresh votes.

Status: ❌ Blocked — 1 of 3 required approvals

Approvals @wjones127 (1/3)
Latest commit approved by none — one PMC member must approve the latest commit
Vetoes none
Voting period elapsed — ended Tue 2026-09-15 05:43 UTC (Mon 22:43 PDT)

Updated automatically by the format-spec vote gate, which re-checks every 15 minutes — just voted? Re-check now (press Run workflow; leave the input blank to re-check every open format PR). A PMC member may apply the format-waived label to waive the vote for a trivial edit (typo, wording, formatting).

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 10, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 10, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lichuang

Copy link
Copy Markdown
Contributor Author

https://github.com/lance-format/lance/actions/runs/34446896028/job/102773541990?pr=9121 the failed case dataset::scanner::test::test_scan_limit_offset is not related with this pr.

Comment thread docs/src/format/table/transaction.md Outdated
relocates the declared rows counts as a change; transparent remapping through compaction is not
required.
- If the fragment's data files or deletion file differ from the read version, the declared cells
are changed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to consider deletion to be a change? If we declare some cells and unrelated cells in the fragment get deleted then ideally that would not be an issue. Even if the declared cells are deleted, ideally that shouldn't cause recomputation of non-deleted values. The deleted/needlessly-computed values will be masked by the deletion vector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — the deletion part of "unchanged" is over-conservative. Deleting unrelated rows doesn't touch declared cells, and deleting declared cells masks them (stale value invisible), so neither should reject the commit. A precondition guards visible values, not fragment fingerprints.
Proposal: drop deletion from the change set. Rewrite, overlay, and schema evolution of protected fields stay violations; row masking by the delete vector is excluded. I'll relax #9118's deletion_file != check to row-granular and cover both cases in tests.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also update the description of this PR to match the diff?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendanclement done, updated.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 13, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 13, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 13, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Sep 13, 2026
@wjones127
wjones127 self-requested a review September 16, 2026 16:28
Comment thread docs/src/format/table/transaction.md Outdated
- If the fragment no longer exists, the declared cells are changed. A concurrent rewrite that
relocates the declared rows counts as a change; transparent remapping through compaction is not
required.
- If the fragment's data files differ from the read version, the declared cells are changed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make file changes an allowed conservative check rather than a mandatory failure? Adding an unrelated column can change the file list without affecting protected cells. This would leave room for more precise checks later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — refined the contract in docs/src/format/table/transaction.md: a change is now keyed to data files carrying a declared field (replaced, removed, or with the declared field added/dropped). Files carrying no declared field may be added or removed (e.g. a concurrent column addition) without violating the precondition. Field-level checks can get more precise later within this rule; implementations may still over-reject at fragment granularity, but must never under-reject.

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against the feature but if there is a derived column that is being asynchronously filled, and there are also updates to the source values happening at the same time, will this be enough to solve the problem?

For example, this scenario is fixed:

  • Begin derived column calculation at read version 5
  • Update some values and create version 6
  • Attempt to commit derived column calculation

But what about this scenario?:

  • Begin derived column calculation at read version 5
  • Commit derived column calculation as version 6
  • Update some values to create version 7

The update itself wouldn't have any preconditions and so it would succeed. But the data is out of data. How do you plan to detect and resolve the out-of-syncness?

@lichuang

Copy link
Copy Markdown
Contributor Author

I'm not against the feature but if there is a derived column that is being asynchronously filled, and there are also updates to the source values happening at the same time, will this be enough to solve the problem?

For example, this scenario is fixed:

  • Begin derived column calculation at read version 5
  • Update some values and create version 6
  • Attempt to commit derived column calculation

But what about this scenario?:

  • Begin derived column calculation at read version 5
  • Commit derived column calculation as version 6
  • Update some values to create version 7

The update itself wouldn't have any preconditions and so it would succeed. But the data is out of data. How do you plan to detect and resolve the out-of-syncness?

This feature guards the read-compute-write window only: it rejects a commit whose declared cells changed between the read version and publication. Scenario B — a source update landing after the derived column was published — is a different problem: materialization staleness. Once y is written at v6, any later update of x requires y to be recomputed, and a precondition on the derived commit cannot enforce that.
The options for closing it are compute-on-read columns (no materialized y, so it can never go stale), dependency-invalidation metadata (y declares a read dependency on x; updates of x mark y stale), or caller-managed recomputation. All are out of scope here. I'll open a separate issue to track derived-column staleness so it doesn't get lost.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 17, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 17, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 17, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Sep 17, 2026

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the overall idea, though I have two blocking comments.

Comment thread docs/src/format/table/transaction.md Outdated
Comment on lines +578 to +579
- **Degenerate entries.** An entry with an empty `field_ids` or an empty `rows` list declares no
cells; producers must not emit them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(blocking): does this need to be invalid? Or could it just be considered a no-op? If I say there's no fields or rows that are part of the precondition, it's just an empty one, and can be ignored, right? I ask because it would probably be more robust if we can safely ignore rather than have to error if we get something that's empty.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: empty entries (empty field_ids or empty rows) are now no-ops — consumers must safely ignore them rather than error, so reads stay robust against degenerate entries. Producers should not emit them.

Comment thread protos/transaction.proto Outdated
Comment on lines +472 to +473
/* The entire fragment is selected. Must be true when set. */
bool full = 2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(blocking): this currently means that full=false is can be written but is invalid. Could we make invalid states unrepresentable? For example, we could say if the bitmap is empty, then that implies full.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: full is now a valueless google.protobuf.Empty message — present means the entire fragment is selected, so full = false is unrepresentable and consumers need no defensive rejection. I went with the valueless-message form rather than "empty bitmap implies full" so that an empty selection stays expressible through the bitmap variant.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

This revision addresses the empty-precondition concern and the full-selection concern: empty field or row lists are explicitly no-ops, and google.protobuf.Empty makes a full selection valueless while preserving a distinct empty bitmap selection. The protobuf, specification, and voting summary agree.

The field-aware change rules, schema-validity checks, and deletion-masking exception remain intact. The additive format stays inert for current writers, with enforcement following separately in #9118. Preconditions guard the read-compute-publish window; keeping derived values fresh after later source updates remains a separate concern.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026
wjones127 added a commit that referenced this pull request Oct 26, 2026
Without read assertions, footprint conflicts give snapshot isolation, so
UPDATE a=b and UPDATE b=a from one snapshot both commit. A writer whose
values depend on a read declares it with AssertCellsUnchanged, whose
RowSelection mirrors the legacy cell preconditions proposed in #9121.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks better, thanks. Please rebase and I'll get more PMC members to vote.

Comment thread protos/transaction.proto

/* Which rows of the fragment are selected. The selection is
* exhaustive: a variant that selects no rows is representable as an
* empty bitmap, and there is no way to encode `full = false`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Nice, this makes full = false unrepresentable. A proto3 oneof can still be unset, though. Please say in the comment and in the spec's "Invalid encodings" list that a RowSelection with neither full nor bitmap set is rejected as corrupt, or that it selects nothing. Either way the behavior is then defined for every consumer.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 29, 2026
Defines the Transaction.Precondition message: a declared set of cells
(fields × physical row addresses) that must be unchanged relative to the
transaction's read_version for the commit to land. Rows are encoded as
per-fragment RowSelection entries (whole-fragment flag or portable
Roaring bitmap of offsets). The spec pins the composition semantics
(conjunctive), absent/empty behavior, invalid encoding handling, and the
conservative meaning of "unchanged" — declared fields must still exist
with unchanged data type and nullability, and over-rejection is
permitted while under-rejection is forbidden.

This is the format-vote half of lance-format#8976; it carries only the proto change,
the docs/src/format specification, and compile-required edits. The
builder and commit-loop implementation lands in a follow-up PR (lance-format#9118).
geruh pushed a commit to geruh/lance that referenced this pull request Nov 4, 2026
Without read assertions, footprint conflicts give snapshot isolation, so
UPDATE a=b and UPDATE b=a from one snapshot both commit. A writer whose
values depend on a read declares it with AssertCellsUnchanged, whose
RowSelection mirrors the legacy cell preconditions proposed in lance-format#9121.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lichuang

Copy link
Copy Markdown
Contributor Author

@Xuanwo @westonpace can you review this pr again please, i have fixed the problems.

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying that adding an unrelated column can leave protected cells unchanged. That addresses my earlier concern.

Since #8646 landed, the opt-in V2 AssertCellsUnchanged action already supports read-dependent commits with conservative fragment-level conflict checks. The concurrent column-swap and cleaned-history tests passed on the implementation now on main. Which caller needs the condition on a legacy operation, or needs disjoint writes in the same fragment to both commit? That would help establish whether to refine action 21 or introduce a second representation.

There is a concrete compatibility blocker across the two current heads. I encoded the same whole-fragment selection for fragment 3 using the two protobuf schemas. Neither #9121 nor #9118 could decode the other’s selection. An older descriptor could parse the enclosing Append while ignoring field 5. Please specify which committer must enforce a staged transaction’s conditions before publication. Reading an already committed transaction and handing a pending one to an older committer have different consequences.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-format On-disk format: protos and format spec docs enhancement New feature or request format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants