hemanthumashankar0511 opened a new issue, #19211: URL: https://github.com/apache/iceberg/issues/19211
### Apache Iceberg version 1.12.0 (latest release) ### Query engine Hive ### Please describe the bug 🐞 Related: Apache Hive [HIVE-30234](https://issues.apache.org/jira/browse/HIVE-30234), fixed in https://github.com/apache/hive/pull/6977 `HiveCatalog.renameTableOrView` loads the table from HMS, changes its database and table name, and writes it back with `alter_table`: https://github.com/apache/iceberg/blob/909cbb99bfb95891553947784691f36842e8fa7e/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L417-L428 The problem is that `alter_table` replaces the entire table, parameters included, and the rename does nothing to protect that write. It doesn't take the HMS lock, and it doesn't send the `metadata_location` check (`expected_parameter_key` / `expected_parameter_value`) that commits use. So if a commit lands between the rename's `getTable` and its `alter_table`, the rename writes back the old `metadata_location` it read earlier. The table ends up pointing at the previous metadata file, the new snapshot disappears, and its files are left orphaned. Both the commit and the rename report success, so nobody notices. This affects both lock modes: - **Lock mode** (`engine.hive.lock-enabled=true`, the default): the commit holds the HMS lock, but the rename never asks for it. Nothing blocks the rename, and it overwrites the commit's `metadata_location`. - **No-lock mode:** commits are protected by the `metadata_location` compare-and-swap, but the rename doesn't send one. **Steps to reproduce** 1. Create a table `db.t` with `HiveCatalog` and append a file. This gives snapshot S1, with `metadata_location` M1. 2. Call `catalog.renameTable(db.t, db.t2)`. While the rename is between its `getTable` and its `alter_table`, commit another append to `db.t` (snapshot S2, `metadata_location` M2). 3. The rename succeeds, but `db.t2` points at M1, and S2 is gone. **Suggested fix** Have the rename send the same `metadata_location` compare-and-swap that the no-lock commit path already uses. It should be sent in both lock modes, since the rename never holds the lock. If the table has no `metadata_location`, no check is sent. HMS already supports this in `HiveAlterHandler`. Inside its transaction it re-reads the table under the old name and rejects the alter if `metadata_location` has changed. The client can then turn that rejection into a `CommitFailedException`, so the caller knows to retry the rename. ### Willingness to contribute - [ ] I can contribute a fix for this bug independently - [x] I would be willing to contribute a fix for this bug with guidance from the Iceberg community - [ ] I cannot contribute a fix for this bug at this time -- 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]
