{"record":{"id":"33da429fc20913cf","repo":"apache/hadoop","slug":"file-conflicts-during-rename","errorCode":null,"errorMessage":"File conflicts during rename, {}","messagePattern":"File conflicts during rename, (.+?)","errorType":"exception","errorClass":"FileConflictException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSPosixBucketUtils.java","lineNumber":282,"sourceCode":"  static void innerFsRenameFile(final OBSFileSystem owner,\n      final String srcKey,\n      final String dstKey) throws IOException {\n    LOG.debug(\"RenameFile path {} to {}\", srcKey, dstKey);\n\n    try {\n      final RenameRequest renameObjectRequest = new RenameRequest();\n      renameObjectRequest.setBucketName(owner.getBucket());\n      renameObjectRequest.setObjectKey(srcKey);\n      renameObjectRequest.setNewObjectKey(dstKey);\n      owner.getObsClient().renameFile(renameObjectRequest);\n      owner.getSchemeStatistics().incrementWriteOps(1);\n    } catch (ObsException e) {\n      if (e.getResponseCode() == OBSCommonUtils.NOT_FOUND_CODE) {\n        throw new FileNotFoundException(\n            \"No such file or directory: \" + srcKey);\n      }\n      if (e.getResponseCode() == OBSCommonUtils.CONFLICT_CODE) {\n        throw new FileConflictException(\n            \"File conflicts during rename, \" + e.getResponseStatus());\n      }\n      throw OBSCommonUtils.translateException(\n          \"renameFile(\" + srcKey + \", \" + dstKey + \")\", srcKey, e);\n    }\n  }\n\n  /**\n   * Used to rename a source object to a destination object which is not existed\n   * before rename.\n   *\n   * @param owner  OBS File System instance\n   * @param srcKey source object key\n   * @param dstKey destination object key\n   * @throws IOException io exception\n   */\n  static void fsRenameToNewObject(final OBSFileSystem owner,\n      final String srcKey,","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSPosixBucketUtils.java#L264-L300","documentation":"An ObsException with response code CONFLICT from the POSIX RenameRequest becomes FileConflictException('File conflicts during rename, <responseStatus>'). POSIX-protocol OBS buckets perform a server-side atomic rename that never overwrites: if the destination key already exists, the service rejects the rename.","triggerScenarios":"rename(src, dst) where dst already exists; two clients renaming different sources onto the same destination concurrently; a retried commit whose destination was already written by the first attempt.","commonSituations":"Commit-by-rename algorithms ported from filesystems with overwrite semantics; concurrent writers to one output path; exactly-once sink implementations that assume rename is idempotent.","solutions":["Check fs.exists(dst) first and delete the destination when overwrite is intended","Make commits idempotent: missing source plus existing destination means the commit already happened","Use unique per-attempt destination names and finalize with a rename of a not-yet-existing key"],"exampleFix":"// before\nfs.rename(src, dst);\n\n// after\nif (fs.exists(dst)) {\n  fs.delete(dst, false);\n}\nfs.rename(src, dst);","handlingStrategy":"try-catch","validationCode":"if (fs.exists(dst)) {\n  fs.delete(dst, false); // deliberate overwrite of an existing destination\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.rename(src, dst);\n} catch (FileConflictException e) {\n  if (fs.exists(dst)) {\n    // destination taken: delete it or pick a new name, then retry once\n  } else {\n    throw e;\n  }\n}","preventionTips":["Never rely on rename-overwrite semantics on POSIX object buckets","Make commit paths unique per attempt and finalize with a rename to an absent key","Serialize writers that target the same destination key"],"tags":["hadoop","obs","posix","rename","conflict"],"backgroundTag":"rename-conflict","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}