{"record":{"id":"1f9cc1fc40173848","repo":"prestodb/presto","slug":"metadata-for-view-s-already-exists","errorCode":null,"errorMessage":"Metadata for view %s already exists","messagePattern":"Metadata for view (.+?) already exists","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"presto-accumulo/src/main/java/com/facebook/presto/accumulo/metadata/ZooKeeperMetadataManager.java","lineNumber":225,"sourceCode":"    }\n\n    public void deleteTableMetadata(SchemaTableName tableName)\n    {\n        try {\n            curator.delete().deletingChildrenIfNeeded().forPath(getTablePath(tableName));\n        }\n        catch (Exception e) {\n            throw new PrestoException(ZOOKEEPER_ERROR, \"ZK error when deleting table metadata\", e);\n        }\n    }\n\n    public void createViewMetadata(AccumuloView view)\n    {\n        SchemaTableName tableName = view.getSchemaTableName();\n        String viewPath = getTablePath(tableName);\n        try {\n            if (curator.checkExists().forPath(viewPath) != null) {\n                throw new IOException(format(\"Metadata for view %s already exists\", tableName));\n            }\n        }\n        catch (Exception e) {\n            throw new PrestoException(ZOOKEEPER_ERROR, \"ZK error when checking if view already exists\", e);\n        }\n\n        try {\n            curator.create().creatingParentsIfNeeded().forPath(viewPath, toJsonBytes(view));\n        }\n        catch (Exception e) {\n            throw new PrestoException(ZOOKEEPER_ERROR, \"Error creating view znode in ZooKeeper\", e);\n        }\n    }\n\n    public void deleteViewMetadata(SchemaTableName tableName)\n    {\n        try {\n            curator.delete().deletingChildrenIfNeeded().forPath(getTablePath(tableName));","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-accumulo/src/main/java/com/facebook/presto/accumulo/metadata/ZooKeeperMetadataManager.java#L207-L243","documentation":"This is the wrapped IOException raised when createViewMetadata detects that a view's metadata znode already exists at viewPath (checkExists != null). The IOException 'Metadata for view %s already exists' is caught by the surrounding handler and rethrown as PrestoException ZOOKEEPER_ERROR ('ZK error when checking if view already exists') with the IOException as cause. It signals CREATE VIEW collision, not a ZK failure.","triggerScenarios":"Calling createViewMetadata(view) for a SchemaTableName whose znode already exists in ZooKeeper — i.e. a view (or leftover metadata) with the same schema.table was already created. The checkExists succeeds and returns non-null, triggering the IOException.","commonSituations":"CREATE VIEW on an existing view name without OR REPLACE; leftover znodes from a failed prior create or incomplete cleanup; two coordinators concurrently creating the same view; case-insensitive schema collision.","solutions":["Drop the existing view (or its znode) before recreating, or use CREATE OR REPLACE VIEW if supported.","Inspect ZooKeeper at the connector metadata root and delete stale view znodes from failed operations.","Check for concurrent creators (multiple coordinators) and serialize DDL.","Verify table vs view naming collision — the connector uses one path per schema.table.","Review the PrestoException's cause: if it contains this IOException, no ZK repair is needed — it's a naming conflict."],"exampleFix":"// before\nCREATE VIEW myview AS SELECT ...;\n// after\nDROP VIEW IF EXISTS myview;\nCREATE VIEW myview AS SELECT ...;","handlingStrategy":"validation","validationCode":"// Before CREATE VIEW, check for an existing view\nboolean exists = metadata.getView(new SchemaTableName(schema, table)) != null;\nif (exists) { drop or replace first }","typeGuard":"null","tryCatchPattern":"try {\n    metadata.createViewMetadata(view);\n} catch (PrestoException e) {\n    if (e.getCause() instanceof IOException && e.getCause().getMessage().contains(\"already exists\")) {\n        throw new PrestoException(ALREADY_EXISTS, \"View already exists: \" + viewName, e);\n    }\n    throw e;\n}","preventionTips":["Use CREATE OR REPLACE VIEW or DROP VIEW IF EXISTS before re-creating","Clean up stale znodes after failed DDL operations","Avoid concurrent CREATE VIEW for the same schema.table name","Check the PrestoException cause — 'already exists' is a naming conflict, not a ZK outage","Document view-name collisions between views and tables in the connector"],"tags":["zookeeper","presto","accumulo","duplicate-view","name-conflict"],"backgroundTag":"znode-already-exists","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"}