{"record":{"id":"d294e00c4fc6ff50","repo":"apache/hadoop","slug":"unable-to-delete-file","errorCode":null,"errorMessage":"Unable to delete ${file}","messagePattern":"Unable to delete (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/HistoryServerFileSystemStateStoreService.java","lineNumber":295,"sourceCode":"    byte[] data = new byte[(int)numBytes];\n    FSDataInputStream in = fs.open(file);\n    try {\n      in.readFully(data);\n    } finally {\n      IOUtils.cleanupWithLogger(LOG, in);\n    }\n    return data;\n  }\n\n  private void deleteFile(Path file) throws IOException {\n    boolean deleted;\n    try {\n      deleted = fs.delete(file, false);\n    } catch (FileNotFoundException e) {\n      deleted = true;\n    }\n    if (!deleted) {\n      throw new IOException(\"Unable to delete \" + file);\n    }\n  }\n\n  private byte[] buildTokenData(MRDelegationTokenIdentifier tokenId,\n      Long renewDate) throws IOException {\n    ByteArrayOutputStream memStream = new ByteArrayOutputStream();\n    DataOutputStream dataStream = new DataOutputStream(memStream);\n    try {\n      tokenId.write(dataStream);\n      dataStream.writeLong(renewDate);\n      dataStream.close();\n      dataStream = null;\n    } finally {\n      IOUtils.cleanupWithLogger(LOG, dataStream);\n    }\n    return memStream.toByteArray();\n  }\n","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/HistoryServerFileSystemStateStoreService.java#L277-L313","documentation":"deleteFile removes a token or key file; a FileNotFoundException is treated as success (idempotent delete), but fs.delete returning false throws IOException 'Unable to delete'. This happens when the filesystem declines the delete without throwing: permission denial, snapshot/quota constraints, or the file being recreated concurrently by another writer.","triggerScenarios":"JHS user lacks delete permission on the file or its parent; HDFS snapshot or quota semantics blocking removal; a concurrent second writer recreating the file; trash configuration interfering.","commonSituations":"Permission hardening after initial deployment; a second JHS sharing the store; store directory on a restricted mount.","solutions":["Check and fix delete permissions on the whole store tree for the mapred history user.","Identify and stop any second writer to the same store location.","Verify no HDFS snapshot, quota, or trash policy holds the file, then retry after remediation.","Restart JHS once the filesystem permits the operation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  store.removeToken(tokenId);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Unable to delete\")) {\n    // delete refused without exception: check permissions/snapshots, then retry\n  }\n}","preventionTips":["Grant the JHS user delete rights on the whole store tree.","Avoid snapshot or trash policies that block deletion in the store path.","Prevent concurrent writers recreating files during removal."],"tags":["mapreduce","job-history-server","state-store","filesystem","delete"],"backgroundTag":"delete-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}