{"record":{"id":"953e46817a462d52","repo":"apache/iceberg","slug":"failed-to-delete","errorCode":null,"errorMessage":"Failed to delete: {}","messagePattern":"Failed to delete: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/apache/iceberg/actions/BaseRewriteDataFilesAction.java","lineNumber":318,"sourceCode":"    return tasksGroupedByPartition.asMap();\n  }\n\n  private void replaceDataFiles(\n      Iterable<DataFile> deletedDataFiles,\n      Iterable<DataFile> addedDataFiles,\n      long startingSnapshotId) {\n    try {\n      doReplace(deletedDataFiles, addedDataFiles, startingSnapshotId);\n    } catch (CommitStateUnknownException e) {\n      LOG.warn(\"Commit state unknown, cannot clean up files that may have been committed\", e);\n      throw e;\n    } catch (Exception e) {\n      if (e instanceof CleanableFailure) {\n        LOG.warn(\"Failed to commit rewrite, cleaning up rewritten files\", e);\n        Tasks.foreach(Iterables.transform(addedDataFiles, ContentFile::location))\n            .noRetry()\n            .suppressFailureWhenFinished()\n            .onFailure((location, exc) -> LOG.warn(\"Failed to delete: {}\", location, exc))\n            .run(fileIO::deleteFile);\n      }\n\n      throw e;\n    }\n  }\n\n  @VisibleForTesting\n  void doReplace(\n      Iterable<DataFile> deletedDataFiles,\n      Iterable<DataFile> addedDataFiles,\n      long startingSnapshotId) {\n    RewriteFiles rewriteFiles = table.newRewrite().validateFromSnapshot(startingSnapshotId);\n\n    for (DataFile dataFile : deletedDataFiles) {\n      rewriteFiles.deleteFile(dataFile);\n    }\n","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/actions/BaseRewriteDataFilesAction.java#L300-L336","documentation":"This is a WARN logged by BaseRewriteDataFilesAction when cleanup of files added by a failed rewrite commit cannot be deleted. After a rewrite commit fails with a CleanableFailure, the action attempts to delete the newly written data files; the onFailure handler logs each per-file deletion error. It does not abort the original exception, which is rethrown after cleanup.","triggerScenarios":"execute() of RewriteDataFilesAction starts, writes new data files, the commit throws a CleanableFailure, and then fileIO.deleteFile(location) fails for one or more of the added files (e.g. object-store eventual consistency, permissions, or the file was already removed).","commonSituations":"S3/GCS permission or throttling during cleanup; a concurrent process already deleted the files; FileIO configured without delete capability; transient network errors during bulk delete.","solutions":["Inspect the chained exception in the WARN for the actual delete failure cause (permissions, throttling, 404).","Check the FileIO/credential configuration used for the table has delete permissions on the table's data location.","Re-run the rewrite action; leftover files can also be removed by expireSnapshots/orphan-file cleanup since they were never committed.","If 404-style errors, verify no concurrent cleanup job is racing the rewrite."],"exampleFix":"// before\nFileIO io = table.io();\n// after\n// ensure credentials allow delete, or configure a FileIO with correct permissions\nHadoopFileIO io = new HadoopFileIO(hadoopConf); // with fs perms granting delete on data dir","handlingStrategy":"fallback","validationCode":"// before rewrite\nimport org.apache.iceberg.ManifestFiles;\n// confirm FileIO can delete in data dir (dry-run a harmless op / check perms)\n// e.g. verify credentials:\n// fileIO io configured with permissions for s3://bucket/table/data","typeGuard":null,"tryCatchPattern":"try {\n  action.execute();\n} catch (Exception e) {\n  // cleanup failures are logged and suppressed; inspect logs for 'Failed to delete'\n  throw e;\n}","preventionTips":["Grant delete permissions to the FileIO credentials on the table data location.","Avoid running multiple concurrent cleanup/rewrite jobs on the same table.","Run orphan-file expiration periodically to clean leftovers."],"tags":["cleanup","file-deletion","rewrite","object-store"],"backgroundTag":"file-write-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}