Repository navigation
fix(table): assert last-assigned-field-id on UpdateSchema - #2622
laskoviymishka merged 4 commits into
Conversation
UpdateSchema only required the current schema ID. With commit retries enabled by default (apache#2462), a stale writer could replay an AddSchema whose new column reused a field ID that another writer had assigned and then dropped. The peer's drop returns the table to the original schema ID, so the schema assertion still holds after refresh, and the stale column silently reads the dropped column's data. When UpdateSchema adds a new schema, it now also sends AssertLastAssignedFieldID with the transaction base's last-column-id, as Java's UpdateRequirements does for AddSchema. The requirement type, its REST encoding and local validation in every catalog already exist, and the retry path already checks non-rebased requirements against the refreshed metadata, so a conflicting writer now fails with ErrCommitFailed instead of committing a reused ID. Using the base value lets chained schema updates in one transaction dedupe to one requirement. If the stored last-column-id is stale (lower than a field ID in schema history), catalogs compare against the stored counter while the transaction compares against the builder's raised one. The assertion is skipped for that case so schema updates on such tables keep working. The first commit writes the raised counter, so later updates are protected. Fixes apache#2609. Signed-off-by: laskoviymishka <laskoviymishka@gmail.com>
3f6eeba to
8b2ab49
Compare
Signed-off-by: laskoviymishka <laskoviymishka@gmail.com>
Signed-off-by: laskoviymishka <laskoviymishka@gmail.com>
badalprasadsingh
left a comment
There was a problem hiding this comment.
approved @laskoviymishka :)
zeroshade
left a comment
There was a problem hiding this comment.
LGTM. Asserting the base last-column-id when adding a schema closes the add-then-drop case from #2609 and matches Java's UpdateRequirements. With the requirement disabled, the SQL two-writer test commits instead of failing with ErrCommitFailed, and both BuildUpdates subtests fail. Taking the counter from the transaction's starting table, and the chained-update dedup, both look right.
| // on the counter and every commit would fail. | ||
| base := u.txn.tbl.Metadata() | ||
| if base.LastColumnID() == columnIDFloor(base.LastColumnID(), base.Schemas()) { | ||
| requirements = append(requirements, AssertLastAssignedFieldID(base.LastColumnID())) |
There was a problem hiding this comment.
Could this get an entry under "Unreleased compatibility notes" in website/src/releases.md? Users will see the change: a stale UpdateSchema that adds a column now fails with table.ErrCommitFailed when another writer has assigned field IDs since its base (for example by adding and then dropping a column), where it used to commit silently. Something like:
Schema updates assert the last assigned field ID. When
UpdateSchemaadds a schema, the commit now also requires the table'slast-column-idto match the transaction's base, as Iceberg Java does. A stale writer whose base predates another writer's column additions now fails withtable.ErrCommitFailedinstead of reusing field IDs. Reload the table and reapply the schema change.
nssalian
left a comment
There was a problem hiding this comment.
I checked the skip for tables whose stored last-column-id is lower than a field ID in the schema history. If I force the new assertion on for every schema add (removing the columnIDFloor comparison), the existing TestUpdateSchemaAssignsIDAboveHistoricalSchemas fails. So that skip is already covered by a test.
The dynamodb_integration_test.go reformat in this PR is the same change that landed on main in #2621, and #2620 carries it too. git merge-tree shows this PR merging cleanly with main and with #2620, so the order doesn't matter.
+1 on the release note @zeroshade asked for.
|
|
||
| current, err := cat.LoadTable(ctx, tblID) | ||
| s.Require().NoError(err) | ||
| s.Equal(peer.MetadataLocation(), current.MetadataLocation(), "nothing may be committed") |
There was a problem hiding this comment.
nit: if this check is s.Require().Equal, the loop below that scans every column for "42" can be removed. Once the current metadata location is the peer's, the table schema is just foo (the peer dropped y), so that loop can never find "42" and can't fail on its own.
Also tighten the stale schema update test: require the metadata location to be unchanged and drop the scan for "42", which could never fail after that check. Signed-off-by: laskoviymishka <laskoviymishka@gmail.com>
UpdateSchema only asserted the current schema ID, so with retries on by default since #2462 a stale writer could replay an AddSchema that reuses a field ID another writer assigned and then dropped. The drop returns the table to its old schema ID, so the assertion still passes after refresh and the new column reads the dropped column's data.
When UpdateSchema adds a schema it now also sends AssertLastAssignedFieldID with the base last-column-id, as Java's UpdateRequirements does. The requirement, its REST encoding, the catalog-side validation and the retry path's check were already on main, so the change is a few lines in BuildUpdates.
The SQL catalog test is Badal's two-writer repro: A stages adding x, B adds y, writes 42 to it and drops it, and A's commit now fails with ErrCommitFailed instead of committing a column that reads 42.
One case is left open. If stored metadata has a last-column-id lower than a field ID in the schema history, the assertion is skipped so those tables stay writable. The first commit writes the corrected counter, so later updates are protected. Re-running the ops against the refreshed base and reassigning IDs, instead of failing, could be a follow-up.
Fixes #2609.
AI-assisted, reviewed by a human.