Repository navigation
HIVE-30234: Iceberg: HiveCatalog rename can revert a concurrent commit's metadata_location - #6977
hemanthumashankar0511 wants to merge 2 commits into
Conversation
…t's metadata_location
|
|
||
| clients.run(client -> { | ||
| MetastoreUtil.alterTable(client, fromDatabase, fromName, table); | ||
| MetastoreUtil.alterTable(client, fromDatabase, fromName, table, |
There was a problem hiding this comment.
This follows #6930's rule that the lock and the CAS are alternatives. A rename holds no HMS lock when it alters: the SQL path's hook unlocks in commitAlterTable before Catalogs.renameTable, and the catalog API never locks. So the CAS is its only guard, whatever the lock mode.
Could you say so in a comment, so nobody later "aligns" it with the hook's lock-only branch? For example:
// The alter sends the whole table back. A rename holds no HMS lock, so the metadata_location CAS keeps it
// from reverting a commit that landed since the read.
|
|
||
| LOG.info("Renamed {} from {}, to {}", contentType.value(), from, to); | ||
|
|
||
| } catch (MetaException e) { |
There was a problem hiding this comment.
This is the 4th copy of the CAS message match (HiveTableOperations, HiveViewOperations and HiveTxnCoordinator.isCasFailure have the others), and the only one that uses startsWith.
Could you move HiveTxnCoordinator.isCasFailure into HiveOperationsBase as a static method and check it in the existing catch (TException e) arm?
} catch (TException e) {
if (HiveOperationsBase.isCasFailure(e)) {
throw new CommitFailedException(e, "Cannot rename %s to %s. It has been modified concurrently", from, to);
}
throw new RuntimeException("Failed to rename " + from + " to " + to, e);
That drops this arm and the MetaException import (line 36). It should also bring the method back within Sonar's S3776 limit (it reports 17 > 15 on this PR).
| * Returns the environment context that makes HMS apply an alter only if the table's current | ||
| * metadata location is still the given one. | ||
| */ | ||
| static Map<String, String> expectedMetadataLocationContext(String metadataLocation) { |
There was a problem hiding this comment.
Instead of a 2nd name for the same map: hmsEnvContext (line 96) has no override, and its only caller is persistTable in this interface.
Could you make it static in place and call HiveOperationsBase.hmsEnvContext(metadataLocation) from the rename?
That keeps the upstream name, and the diff against upstream shrinks to one keyword.
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| public class TestHiveCatalogRenameConcurrency { |
There was a problem hiding this comment.
Could this go into TestHiveCatalog instead of a new class?
Rename tests already live there, and its extension (line 110) can take the PRE_EVENT_LISTENERS config. The listener is a no-op until a test arms it, so nothing else changes, and we save one HMS startup.
|
Upstream Iceberg's HiveCatalog.renameTableOrView has the same race in both lock modes: it takes no lock and sends no env context, so a commit made under the HMS lock can still be reverted. Spark and Impala use that class, not Hive's copy. Could you file it against apache/iceberg and link it from the JIRA? |
| if (e.getMessage() != null && e.getMessage().startsWith( | ||
| "The table has been modified. The parameter value for key '" + | ||
| BaseMetastoreTableOperations.METADATA_LOCATION_PROP + "' is")) { | ||
| throw new CommitFailedException( |
There was a problem hiding this comment.
Through the HMS REST catalog this surfaces as the wrong error. HMSCatalogAdapter maps CommitFailedException to 409, and Iceberg's REST client turns a 409 on rename into AlreadyExistsException, so engines report "table already exists" and don't retry. A rename doesn't depend on the table contents, and the failed alter wrote nothing.
Could renameTableOrView re-read and retry a few times on a CAS failure, and throw only when the attempts run out?
There was a problem hiding this comment.
If you add the retry, the test changes too. With the listener committing once, the rename should now succeed, and the renamed table should keep the concurrent snapshot. To cover the give-up path, let the listener commit on every attempt and assert CommitFailedException after the last one.
|
Opened a new github issue at apache iceberg: apache/iceberg#19211 and linked it to the asf jira |
|
Thanks @deniskuzZ for the review. I've tried to address the comments in the latest commit. Could you please take another look when you have the bandwidth to do so. Thanks!! |



What changes were proposed in this pull request?
Send metadata_location CAS on HiveCatalog rename (same as no-lock commits) and fail with CommitFailedException on concurrent modify.
Why are the changes needed?
Rename could overwrite HMS params and silently drop a concurrent Iceberg snapshot.
Does this PR introduce any user-facing change?
Yes, concurrent rename now fails loudly instead of losing data
How was this patch tested?
Ran new unit test
mvn test -pl iceberg/iceberg-catalog -Dtest=TestHiveCatalogRenameConcurrencyTez on Yarn Integration test
Started the cluster in debug mode:
mvn test -Pitests,tez-yarn -pl itests/tez-yarn-it -Dtest=StartTezYarnCluster -Dmaven.surefire.debugAttached the IDE debugger to port 5005 and set a thread breakpoint in
HiveCatalog.renameTableOrViewafter getTable (before alterTable).Opened two Beeline sessions to HiveServer2 (session 1 and 2):
beeline -u 'jdbc:hive2://localhost:10000/default;auth=noSasl' -n hiveIn session 2, created the table and inserted the first row (no-lock mode for embedded Derby):
In session 1, started a rename and paused on the breakpoint:
ALTER TABLE ice_t RENAME TO ice_t2;In session 2, while 1 was paused, committed a concurrent write:
INSERT INTO ice_t VALUES (2);Resumed the debugger. With the fix, session 1’s rename failed (concurrent modification),
SELECT * FROM ice_tstill returned both rows, and a secondALTER TABLE ice_t RENAME TO ice_t2completed successfully with both rows visible onice_t2.