nisan1101 opened a new issue, #2586: URL: https://github.com/apache/iceberg-go/issues/2586
### Apache Iceberg version v0.7.0 and main (development), checked at `8d13e317c79f36f38f52a16b2f81f1d966f1fc27`. ### Please describe the bug 🐞 `UpdateSchema.BuildUpdates()` emits these updates when adding a new schema: ```go NewAddSchemaUpdate(newSchema), NewSetCurrentSchemaUpdate(newSchema.ID), ``` The second update uses a client-predicted schema ID. If another writer registers a different schema between our metadata read and commit, the catalog can assign our schema a different ID, causing `set-current-schema` to select the other writer's schema. [Relevant source](https://github.com/apache/iceberg-go/blob/8d13e317c79f36f38f52a16b2f81f1d966f1fc27/table/update_schema.go#L1098-L1105). #### Reproduction scenario 1. A table has current schema ID `0`, containing fields `a`, `b`, and `c`. 2. Writer A reads that metadata and uses `UpdateSchema.BuildUpdates()` to drop `b`. Its updates add schema `{a, c}` and select predicted schema ID `1`. 3. Before A commits, writer B registers schema `{a, b}` with ID `1`, **without making it current**. 4. A commits its previously built updates. 5. The catalog assigns A's schema ID `2`, but A's `set-current-schema` still selects ID `1`. The commit selects B's schema `{a, b}` instead of A's intended schema `{a, c}`. `AssertCurrentSchemaID(0)` still passes because B did not change the current schema. Even an additional `AssertLastAssignedFieldID` requirement does not catch this case because B added no field IDs. #### Expected behavior / proposed fix After adding a new schema, emit: ```go NewAddSchemaUpdate(newSchema), NewSetCurrentSchemaUpdate(-1), ``` The [REST Catalog specification](https://github.com/apache/iceberg/blob/d1a422988cbde266f10c9e174ddf7c36a08de51a/open-api/rest-catalog-open-api.yaml#L3383-L3395) defines `schema-id` as: > Schema ID to set as current, or -1 to set last added schema Using `-1` selects the schema added by this request using its actual assigned ID. The branch that selects an already-existing schema should continue using that schema's explicit ID, and the existing `AssertCurrentSchemaID` requirement should remain. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
