abstractdog commented on code in PR #6642: URL: https://github.com/apache/hive/pull/6642#discussion_r3665829200
########## ql/src/java/org/apache/hadoop/hive/ql/metadata/UnstableRenameFileSystem.java: ########## @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.ql.metadata; + +import java.util.EnumSet; +import java.util.Locale; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.hadoop.fs.FileSystem; + +/** + * File systems whose {@link FileSystem#rename(org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path)} + * implementation is not atomic-if-absent and can silently overwrite an existing destination when + * two concurrent writers race between an {@code exists()} probe and the subsequent rename call. + * <p> + * Object stores (S3, GCS, etc.) fall in this category: the S3A rename is a copy+delete on the + * client, with the "does the destination exist?" check performed on the client before the copy; + * two writers whose probes both fire before either PUT commits will both proceed and one will + * silently overwrite the other. + * <p> + * Callers use this enum to decide whether to apply defensive strategies such as suffixing the + * destination filename with a per-query tag so concurrent writers pick distinct keys — see + * {@code Hive#mvFile}. It is intentionally an in-code enum rather than a configuration knob: + * the set of unsafe filesystems is a property of the filesystem implementation, not something an + * operator should override. + */ +public enum UnstableRenameFileSystem { Review Comment: ack, and this is over-engineered too, fixed in https://github.com/apache/hive/pull/6642/changes/aab3c3b6b0d75bfa8ead3f10306460ff0dc93e33 ########## ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java: ########## @@ -5170,6 +5170,96 @@ private static String getPathName(int taskId) { return Utilities.replaceTaskId("000000", taskId) + "_0"; } + /** + * Compute a compact per-query uniqueness tag (8 lowercase hex chars) used by the non-ACID + * rename branch of {@link #mvFile} to make each concurrent writer's destination key unique + * on filesystems whose {@code rename} is not atomic-if-absent. The tag becomes the copy + * suffix ({@code basename_copy_<tag>}) in place of the numeric {@code _copy_N} counter. + * Reads {@code hive.query.id} from the passed {@link HiveConf}; returns the empty string + * when the id is missing. The 8 hex chars come from {@code queryId.hashCode()}; that is + * short enough to keep S3 listings readable and collision-free for realistic per-partition + * concurrency (birthday-collides only at ~65k concurrent writers to the same partition). + * <p> + * The shape matches {@link ParsedOutputFileName}'s copy-index group so downstream filename + * parsing (taskId, attemptId, copyIndex) keeps working. + */ + static String computeUniquenessTag(HiveConf conf) { + String qid = HiveConf.getVar(conf, ConfVars.HIVE_QUERY_ID); + if (qid == null || qid.isEmpty()) { + return ""; + } + return String.format("%08x", qid.hashCode()); Review Comment: fixed https://github.com/apache/hive/pull/6642/changes/aab3c3b6b0d75bfa8ead3f10306460ff0dc93e33 -- 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]
