{"record":{"id":"1cc2a1f55502a85c","repo":"prestodb/presto","slug":"iceberg-invalid-metadata-1cc2a1","errorCode":"ICEBERG_INVALID_METADATA","errorMessage":"Unable to read metadata file %s","messagePattern":"Unable to read metadata file (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"critical","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java","lineNumber":754,"sourceCode":"\n    @Override\n    public void registerTable(ConnectorSession clientSession, SchemaTableName schemaTableName, Path metadataLocation, boolean deleteDataOnDrop)\n    {\n        String tableLocation = metadataLocation.getName();\n        HdfsContext hdfsContext = new HdfsContext(\n                clientSession,\n                schemaTableName.getSchemaName(),\n                schemaTableName.getTableName(),\n                tableLocation,\n                true);\n\n        InputFile inputFile = new HdfsInputFile(metadataLocation, hdfsEnvironment, hdfsContext);\n        TableMetadata tableMetadata;\n        try {\n            tableMetadata = TableMetadataParser.read(new HdfsFileIO(manifestFileCache, hdfsEnvironment, hdfsContext), inputFile);\n        }\n        catch (Exception e) {\n            throw new PrestoException(ICEBERG_INVALID_METADATA, String.format(\"Unable to read metadata file %s\", metadataLocation), e);\n        }\n\n        Table.Builder builder = Table.builder()\n                .setDatabaseName(schemaTableName.getSchemaName())\n                .setTableName(schemaTableName.getTableName())\n                .setOwner(clientSession.getUser())\n                .setDataColumns(toHiveColumns(tableMetadata.schema().columns()))\n                .setTableType(PrestoTableType.EXTERNAL_TABLE)\n                .withStorage(storage -> storage.setLocation(tableMetadata.location()))\n                .withStorage(storage -> storage.setStorageFormat(STORAGE_FORMAT))\n                .setParameter(\"EXTERNAL\", \"TRUE\")\n                .setParameter(BaseMetastoreTableOperations.TABLE_TYPE_PROP, BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE.toUpperCase(ENGLISH))\n                .setParameter(BaseMetastoreTableOperations.METADATA_LOCATION_PROP, tableMetadata.metadataFileLocation())\n                .setParameter(HiveTableOperations.PRESTO_DELETE_DATA_ON_DROP, String.valueOf(deleteDataOnDrop));\n        Table table = builder.build();\n\n        PrestoPrincipal owner = new PrestoPrincipal(USER, table.getOwner());\n        PrincipalPrivileges privileges = new PrincipalPrivileges(","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java#L736-L772","documentation":"When loading an Iceberg table, the connector parses the metadata JSON file pointed to by the metastore's metadata_location. If TableMetadataParser.read fails for any reason (missing/corrupt file, unreadable JSON, filesystem access error), Presto wraps the failure in ICEBERG_INVALID_METADATA with 'Unable to read metadata file <location>'.","triggerScenarios":"Querying or opening a table whose metadata_location points to a deleted, truncated, corrupt, or inaccessible metadata JSON; HDFS/S3 permission errors reading the file; version skew between the writer's metadata format and the parser.","commonSituations":"Metadata files cleaned up by an aggressive expiration job while the metastore pointer is stale; manually moved/renamed files; object-store outages or credentials expiring mid-read; table written by a newer Iceberg version than Presto supports.","solutions":["Verify the metadata file exists and is readable at the metadata_location shown by the metastore table properties","Restore the file from backup or re-point metadata_location to a valid earlier metadata JSON (via the engine that wrote the table)","Fix filesystem access: check permissions and credentials for the Presto user on the metadata path","Upgrade Presto (or the writer) so Iceberg metadata format versions are compatible","Roll back or repair the table using an Iceberg repair tool with a valid snapshot"],"exampleFix":"// before\n-- metastore metadata_location -> /warehouse/t/metadata/00003-...metadata.json (deleted)\n// after\n-- re-point to an existing metadata file (via Spark/expert tooling):\n-- metadata_location = /warehouse/t/metadata/00001-...metadata.json","handlingStrategy":"try-catch","validationCode":"-- Verify the current metadata file exists and is readable:\n-- metastore property metadata_location -> check the path on the filesystem (hdfs dfs -ls / hdfs dfs -cat ...tail of file)","typeGuard":null,"tryCatchPattern":"try (ResultSet rs = stmt.executeQuery(\"SELECT * FROM iceberg.sales.events\")) {\n    ...\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Unable to read metadata file\")) {\n        // restore/re-point metadata JSON, check permissions, or repair the table\n    } else { throw e; }\n}","preventionTips":["Don't expire metadata files more aggressively than the metastore pointer lifecycle","Keep metadata_location in sync with retained metadata JSONs (use Iceberg's own expire/rollback tools)","Monitor object-store/HDFS availability and credentials for the warehouse paths","Keep Presto and writer Iceberg versions compatible for the metadata format version"],"tags":["iceberg","metadata-corruption","hdfs","unreadable-file"],"backgroundTag":"iceberg-invalid-metadata","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}