{"record":{"id":"28510fcd5eb152ad","repo":"apache/iceberg","slug":"failed-to-delete-file","errorCode":null,"errorMessage":"Failed to delete file: ","messagePattern":"Failed to delete file: ","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopTables.java","lineNumber":200,"sourceCode":"    if (ops.current() != null) {\n      if (purge) {\n        lastMetadata = ops.current();\n      }\n    } else {\n      return false;\n    }\n\n    try {\n      if (purge && lastMetadata != null) {\n        // Since the data files and the metadata files may store in different locations,\n        // so it has to call dropTableData to force delete the data file.\n        CatalogUtil.dropTableData(ops.io(), lastMetadata);\n      }\n      Path tablePath = new Path(location);\n      Util.getFs(tablePath, conf).delete(tablePath, true /* recursive */);\n      return true;\n    } catch (IOException e) {\n      throw new UncheckedIOException(\"Failed to delete file: \" + location, e);\n    }\n  }\n\n  @VisibleForTesting\n  TableOperations newTableOps(String location) {\n    if (location.contains(METADATA_JSON)) {\n      return new StaticTableOperations(location, new HadoopFileIO(conf));\n    } else {\n      return new HadoopTableOperations(\n          new Path(location), new HadoopFileIO(conf), conf, createOrGetLockManager(this));\n    }\n  }\n\n  private static synchronized LockManager createOrGetLockManager(HadoopTables table) {\n    if (lockManager == null) {\n      Map<String, String> properties = table.conf.getPropsWithPrefix(LOCK_PROPERTY_PREFIX);\n      lockManager = LockManagers.from(properties);\n    }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopTables.java#L182-L218","documentation":"dropTable() deletes the table directory after dropping data; if the filesystem delete raises IOException it is wrapped in UncheckedIOException with this message. The table metadata may have been logically dropped while physical cleanup failed, so this can leave partial state.","triggerScenarios":"Util.getFs(...).delete(tablePath, true) throwing due to HDFS unavailability, permission denied on the directory, or network failure during dropTable().","commonSituations":"HDFS NameNode down or in safe mode during a drop; insufficient permissions to delete the table directory; dropping tables in a loop when one FS becomes unreachable; Kerberos token expiry mid-operation.","solutions":["Check the wrapped IOException cause and fix FS availability/permissions, then retry dropTable","Manually delete leftover table directory (hdfs dfs -rm -r) once the FS is healthy","Verify the calling user has write/delete permission on the table path","Retry with valid credentials if Kerberos/Token expired"],"exampleFix":"// before: unchecked failure\ntables.dropTable(location);\n// after\ntry {\n  tables.dropTable(location);\n} catch (UncheckedIOException e) {\n  LOG.warn(\"cleanup failed, retry later\", e); // table dir may remain\n}","handlingStrategy":"try-catch","validationCode":"Path p = new Path(location);\nFileSystem fs = Util.getFs(p, conf);\nif (!fs.exists(p)) return true; // nothing to drop\nfs.access(p, FsAction.WRITE); // throws if no delete permission","typeGuard":null,"tryCatchPattern":"try { tables.dropTable(location); } catch (UncheckedIOException e) { LOG.error(\"FS delete failed: {}\", e.getCause().toString()); /* retry or manual cleanup */ }","preventionTips":["Confirm FS availability and permissions before dropping tables","Drop tables through the catalog so metadata and data cleanup are coordinated","Keep retries around dropTable for transient FS errors","Inspect e.getCause() to distinguish permissions vs availability"],"tags":["io","delete","hadoop"],"backgroundTag":"file-delete-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}