{"record":{"id":"8c787cdb77a574f2","repo":"apache/iceberg","slug":"error-trying-to-recover-the-latest-version-number","errorCode":null,"errorMessage":"Error trying to recover the latest version number for {}","messagePattern":"Error trying to recover the latest version number for (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java","lineNumber":347,"sourceCode":"        }\n\n        // List the metadata directory to find the version files, and try to recover the max\n        // available version\n        FileStatus[] files =\n            fs.listStatus(\n                metadataRoot(), name -> VERSION_PATTERN.matcher(name.getName()).matches());\n        int maxVersion = 0;\n\n        for (FileStatus file : files) {\n          int currentVersion = version(file.getPath().getName());\n          if (currentVersion > maxVersion && getMetadataFile(currentVersion) != null) {\n            maxVersion = currentVersion;\n          }\n        }\n\n        return maxVersion;\n      } catch (IOException io) {\n        LOG.warn(\"Error trying to recover the latest version number for {}\", versionHintFile, io);\n        return 0;\n      }\n    }\n  }\n\n  /**\n   * Renames the source file to destination, using the provided file system. If the rename failed,\n   * an attempt will be made to delete the source file.\n   *\n   * @param fs the filesystem used for the rename\n   * @param src the source file\n   * @param dst the destination file\n   */\n  private void renameToFinal(FileSystem fs, Path src, Path dst, int nextVersion) {\n    try {\n      if (!lockManager.acquire(dst.toString(), src.toString())) {\n        throw new CommitFailedException(\n            \"Failed to acquire lock on file: %s with owner: %s\", dst, src);","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java#L329-L365","documentation":"After failing to read version-hint.text, findVersion() falls back to listing the metadata directory to recover the max version. If that recovery listing itself throws IOException, this warning is logged and 0 is returned, meaning the table will be treated as having no version. This indicates the metadata directory could not be scanned at all.","triggerScenarios":"findVersion() called when version-hint.text read failed AND the recovery FileSystem.listStatus(metadataRoot()) (or per-file version parsing) throws IOException — e.g. metadata directory missing read permission or transient FS outage.","commonSituations":"HDFS/S3 permission misconfiguration on the metadata directory; transient cloud storage throttling or 5xx during listing; metadata root deleted while a table handle is still open.","solutions":["Fix read permissions on the table metadata directory","Verify the metadata directory exists and contains vN.metadata.json files","Retry after resolving transient storage/cloud storage errors","Check filesystem client logs for the underlying IOException root cause","Re-sync the table location from a healthy copy"],"exampleFix":"// before\nhdfs dfs -ls /warehouse/db/table/metadata  # -> Permission denied\n// after\nhdfs dfs -chmod -R o+r /warehouse/db/table/metadata","handlingStrategy":"retry","validationCode":"// before loading the table\nFileSystem fs = metadataRoot.getFileSystem(conf);\nif (!fs.exists(metadataRoot) || fs.listStatus(metadataRoot).length == 0) {\n  throw new IllegalStateException(\"metadata dir unreadable/empty\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  table = catalog.loadTable(name);\n} catch (RuntimeException e) {\n  // check HDFS/cloud storage health, fix permissions, retry once\n}","preventionTips":["Grant read access to the metadata directory for all readers","Check cloud storage health/throttling before large metadata listings","Ensure metadata directory is not deleted while table handles are open","Keep version-hint.text and vN.metadata.json files in sync during copies"],"tags":["hadoop","io","version-hint","recovery"],"backgroundTag":"file-read-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"}