ramitg254 commented on code in PR #6981:
URL: https://github.com/apache/hive/pull/6981#discussion_r4784302479
##########
ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java:
##########
@@ -5277,7 +5295,46 @@ private static Path mvFile(HiveConf conf, FileSystem
sourceFs, Path sourcePath,
isRenameAllowed);
if (isRenameAllowed) {
- destFs.rename(sourcePath, destFilePath);
+ // Filesystems that take the per-query _copy_<tag> name do not use a
numeric _copy_N
+ // counter. Parsing that tag as a counter throws or rewrites the name,
so rename once.
+ if (FileUtils.isNonAtomicRenameFs(destFs)) {
+ destFs.rename(sourcePath, destFilePath);
+ } else {
+ // HDFS rename returns false (and leaves the source in place) when the
destination
+ // already exists. Concurrent inserts can all choose the same name.
Overwrite deletes
+ // that file and retries the same name; otherwise advance or introduce
_copy_N.
+ String name = taskId == -1 ?
FilenameUtils.getBaseName(sourcePath.getName()) : getPathName(taskId);
+ String currentDestFileName = destFilePath.getName();
+ Integer counterEndIdx = copyCounterEndIndex(name, currentDestFileName);
+ int counter;
+ final String prefix = name + Utilities.COPY_KEYWORD;
+ final String suffix;
+ if (counterEndIdx == null) {
+ counter = 0;
+ suffix = currentDestFileName.substring(name.length());
+ } else {
+ counter = counterEndIdx == -1 ? -1
+ :
Integer.parseInt(currentDestFileName.substring(prefix.length(), counterEndIdx +
1));
+ suffix = currentDestFileName.substring(counterEndIdx + 1);
+ }
+ while (!destFs.rename(sourcePath, destFilePath)) {
+ if (!destFs.exists(destFilePath) || counter < 0) {
+ throw moveFailure("Unable to rename %s to %s; rename returned
false", sourcePath, destFilePath);
+ }
+ if (isOverwrite) {
+ if (!destFs.delete(destFilePath, false)) {
+ throw moveFailure("Unable to delete %2$s to overwrite it with
%1$s", sourcePath, destFilePath);
+ }
+ continue;
+ }
Review Comment:
yes last-writer-wins was intended as same thing was `pickDestFilePath` was
doing earlier for overwrite scenarios so retry should also follow the same
pattern.
documented it in this commit : 5d875760d2081607e4ce642879cea23a1063bc92 and
also capped the max attemps to 100 in this commit:
4af3fad949151ac96c3bb55c8406cf1c8c0548bd
--
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]