Skip to content

HIVE-30265: Table rename retried by RetryingHMSHandler leaves partitions at the old location - #6967

Open
cxzl25 wants to merge 3 commits into
apache:masterfrom
cxzl25:HIVE-30265
Open

cxzl25 wants to merge 3 commits into
apache:masterfrom
cxzl25:HIVE-30265

Conversation

@cxzl25

@cxzl25 cxzl25 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

HiveAlterHandler.alterTable rewrites the location of the new table object passed in by the caller when it handles a rename that has to move data. This PR keeps the original value and restores it in the finally block when the transaction did not commit.

  • HiveAlterHandler: record the caller's location at the two places that rewrite it (managed table rename and translated-to-external table rename), and restore it before rollbackTransaction() on failure. The restore comes first because the rollback itself may throw.
  • TestAlterTableRenameWithHMSHandlerRetry: new test that fails the first alterPartitions call with a JDODataStoreException and checks the state after the retry.

Why are the changes needed?

RetryingHMSHandler retries a failed call with the same argument objects. The rename flow is selected by comparing the old and the new table location:

boolean renamedManagedTable = rename && ...
    && (oldt.getSd().getLocation().compareTo(newt.getSd().getLocation()) == 0
        || StringUtils.isEmpty(newt.getSd().getLocation()))
    && (!MetaStoreUtils.isExternalTable(oldt));

After a first attempt that failed past newt.getSd().setLocation(destPath.toString()), the retry sees a location that differs from the old one and treats the call as a rename with a caller-specified location. It commits the new table name and table location, does not move the data and does not update partition locations, and returns success.

The table keeps working because the partitions still point at the old directory. The damage comes later: once another table uses the old name, both tables share partition directories, and dropping the renamed managed table deletes the other table's data.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Add UT

@cxzl25

cxzl25 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@zhangbutao @dengzhhu653 Please help review, thanks in advance!

boolean dataWasMoved = false;
boolean isPartitionedTable = false;
// Location of the new table as passed in by the caller, kept so it can be put back on failure.
String originalNewLocation = null;

@dengzhhu653 dengzhhu653 Nov 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! can you try creating a new table by newt.deepCopy() at the beginning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! can you try creating a new table by newt.deepCopy() at the beginning?

Yes, I used deepcopy to implement it at first, and then changed it to the plan of saving location.

@dengzhhu653 dengzhhu653 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, pending green run!

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants