Skip to content

fix(table): publish DV lookup overwrite state before competing compaction - #1525

Open
QuakeWang wants to merge 7 commits into
apache:mainfrom
QuakeWang:dv-lookup-overwrite-publication
Open

QuakeWang wants to merge 7 commits into
apache:mainfrom
QuakeWang:dv-lookup-overwrite-publication

Conversation

@QuakeWang

Copy link
Copy Markdown
Member

Purpose

A primary-key deletion-vector table with lookup changelogs could publish an overwrite with its replacement rows still in L0. A batch reader could already see those rows, while a lookup stream starting at the same snapshot skipped them. A competing compaction could then emit an unchanged row as an INSERT or report an update as an INSERT.

Reported in the review of #1454. Reproduced independently on main.

Brief change log

With automatic compaction enabled, publish replacement rows at a positive level in the overwrite snapshot. Promote eligible disjoint files in place and merge overlapping runs before publication. Later lookup compaction uses the published rows as its before state.

Tests

Verified batch and stream bootstrap, complete changelogs from automatic and manual compaction, idempotent retry, and atomic publication of indexed data.

API and Format

No public API or storage format changes.

Documentation

Updated docs/src/compaction.md with overwrite visibility and staging-file cleanup behavior.

…tion

Signed-off-by: QuakeWang <wangfuzheng0814@foxmail.com>
…-publication

Signed-off-by: QuakeWang <wangfuzheng0814@foxmail.com>

@JingsongLi JingsongLi 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.

The overwrite snapshot gives lookup streams a consistent starting state. On 3f35837e integrated with d557fb13, all 141 selected integration tests passed across overwrite recovery, primary-key compaction, stream scanning, and sequence parity. A separate retry test reproduced the storage cleanup issue below.

&mut resolved,
latest_snapshot,
commit_identifier,
partition_overwrite,

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.

[P2] Reclaim replacement files after a definite snapshot conflict

This overwrite can now write a fresh data run and PK indexes inside each publication attempt. If another writer wins the snapshot CAS, commit returns Ok(false) and the cleanup only handles COMPACT DV containers. I forced a competing append between snapshot preparation and publication for an overwrite with two overlapping L0 files. The retry succeeded, and the Parquet file generated for the rejected attempt remained in the bucket. A contended overwrite can leave a full replacement run and its indexes per retry until orphan cleanup. Track these attempt-owned outputs and remove them on a definite conflict. Keep the staged inputs for the retry and preserve outputs when publication returns an ambiguous error.

Keep staged inputs for retries and preserve generated files when REST publication is ambiguous. Resolve the lookup producer from the effective schema so stale writers publish an overwrite that streams can bootstrap from.

Signed-off-by: QuakeWang <wangfuzheng0814@foxmail.com>

@JingsongLi JingsongLi 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.

Publishing the replacement state with the overwrite snapshot fixes a real lookup-stream consistency issue. On 660c9f15 merged with cd2b15af, 132 overwrite, compaction, sequence, REST, and retry tests passed. An additional OSS conditional-write replay test reproduced the missing-file failure below.

Comment thread crates/paimon/src/table/table_commit.rs Resolved

@JingsongLi JingsongLi 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.

Publishing the replacement state with the overwrite snapshot fixes a real lookup-stream bootstrap mismatch. On this head integrated with ebcff9f1, 319 overwrite, compaction, REST, streaming, and sequence integration tests and both focused retry tests passed. An additional rollback/replay probe reproduced data loss in a retained branch.

Comment thread crates/paimon/src/table/table_commit.rs Outdated
}
// A replay of our own successful conditional PUT also reports a conflict.
// Reclaim payloads only if another attempt published this snapshot ID.
if !created_payloads.is_empty() && self.another_attempt_published(&snapshot).await {

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.

[P1] Preserve published overwrite files when a main snapshot ID is reused. I let an overlapping overwrite publish snapshot 2 and created a branch from its tag. The branch read [1, 2, 3]. I then modeled rollback by removing main’s snapshot 2 and resetting its latest hint to 1, committed a different UUID at snapshot 2, and returned false from the original publisher as a conditional PUT replay would. This comparison deletes the original attempt’s Parquet and index files because a different UUID now occupies snapshot 2 on main. The retained branch then fails with NotFound reading its Parquet file. Reclaim files when publication was definitively rejected, and leave ambiguous attempts for cleanup that checks references from branches and tags.

Reclaim generated files before submission and retain them when a publication conflict may be a replay. A rollback can reuse the snapshot ID while a branch still references the first publication.

Use the current schema and explicit writer options to decide whether to promote lookup overwrite files. Add regression coverage for retained files, publication retries, and stale write-only settings.

@JingsongLi JingsongLi 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 reviewed 437ced1d integrated with 8105e1eb. The retained-branch rollback/replay, OSS replay, and unpublished-file cleanup regressions passed. All 340 selected integration tests passed. The core unit suite reproduced the Linux CI failure in row_id_update_retry_reloads_base_after_overwrite, with 5,164 other core tests passing. Linux CI failure

Comment thread crates/paimon/src/table/table_commit.rs Outdated
None
// A replay can collide after a rollback reused this ID. A branch or
// tag can still reference the first publication even if main moved.
Ok(false) => Some(crate::Error::UnexpectedError {

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.

[P1] Preserve typed row-ID conflicts after a definite publication rejection. When a manifest-only overwrite reassigns the target row IDs while a Data Evolution update is committing, the update loses the snapshot CAS. The next iteration detects RowIdExistenceConflict as expected. Classifying every Ok(false) as uncertain here causes try_commit to wrap that error in UnexpectedError, so DataFusion's is_row_id_conflict stops the automatic replan for UPDATE, DELETE, and MERGE INTO. The existing row_id_update_retry_reloads_base_after_overwrite test reproduces the change locally and on Linux CI. Keep the conservative retention for potentially replayed submissions, and carry a distinct result when the publisher can prove rejection so the existing typed retry path remains available.

Let the built-in filesystem and memory publishers report that a failed conditional write never published the snapshot. This preserves the typed conflict DataFusion uses to replan after a concurrent overwrite.

Keep submitted files when the publisher can replay a successful write. Exercise both outcomes with the same manifest replacement and check the DataFusion retry classifier.

@JingsongLi JingsongLi 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 tested d33af759 merged onto d4411cf8. The 5,549 core, compaction, and REST tests and 17 DataFusion MERGE/retry tests passed. The local-filesystem row-ID retry is fixed. The test below isolates a remaining REST regression.

}
// A replay can collide after a rollback reused this ID while a branch still
// references the first publication. Retain its files and prevent DML replanning.
Ok(false) => Some(crate::Error::UnexpectedError {

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.

[P1] Preserve row-ID replanning after a definite REST commit rejection. Through RESTCatalog, I staged an update for row ID 0 and paused its snapshot 2 POST. A concurrent overwrite published snapshot 2 with fresh row IDs. When resumed, the test server rejected the stale POST before attempting publication and returned success:false. The same test on main returns RowIdExistenceConflict. On this head the error is wrapped in UnexpectedError because the REST publisher marks every false response as uncertain. DataFusion then stops automatic replanning of the affected UPDATE, DELETE, or MERGE. The filesystem-backed REST server also returns success:false after a definite atomic publication loss. Please carry an explicit definite rejection from publishers that can prove it and retain the uncertain path for possible replays.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants