cxzl25 opened a new pull request, #6967:
URL: https://github.com/apache/hive/pull/6967

   ### 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:
   
   ```java
   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


-- 
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]

Reply via email to