{"record":{"id":"4826a13e1cea5933","repo":"apache/cassandra","slug":"encountered-exception-creating-schema","errorCode":null,"errorMessage":"Encountered exception creating schema","messagePattern":"Encountered exception creating schema","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/stress/settings/SettingsSchema.java","lineNumber":89,"sourceCode":"        try\n        {\n            //Keyspace\n            client.execute(createKeyspaceStatementCQL3(), org.apache.cassandra.db.ConsistencyLevel.LOCAL_ONE);\n\n            //Add standard1 and counter1\n            client.execute(createStandard1StatementCQL3(settings), org.apache.cassandra.db.ConsistencyLevel.LOCAL_ONE);\n            client.execute(createCounter1StatementCQL3(settings), org.apache.cassandra.db.ConsistencyLevel.LOCAL_ONE);\n\n            System.out.println(String.format(\"Created keyspaces. Sleeping %ss for propagation.\", settings.node.nodes.size()));\n            Thread.sleep(settings.node.nodes.size() * 1000L); // seconds\n        }\n        catch (AlreadyExistsException e)\n        {\n            //Ok.\n        }\n        catch (Exception e)\n        {\n            throw new RuntimeException(\"Encountered exception creating schema\", e);\n        }\n    }\n\n    String createKeyspaceStatementCQL3()\n    {\n        StringBuilder b = new StringBuilder();\n\n        //Create Keyspace\n        b.append(\"CREATE KEYSPACE IF NOT EXISTS \\\"\")\n         .append(keyspace)\n         .append(\"\\\" WITH replication = {'class': '\")\n         .append(replicationStrategy)\n         .append(\"'\");\n\n        if (replicationStrategyOptions.isEmpty())\n        {\n            b.append(\", 'replication_factor': '1'}\");\n        }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/stress/settings/SettingsSchema.java#L71-L107","documentation":"createKeySpaces issues CREATE KEYSPACE/TABLE statements through the CQL driver and wraps any unexpected failure in RuntimeException 'Encountered exception creating schema' with the original exception as cause. AlreadyExistsException is deliberately swallowed (schema already present).","triggerScenarios":"Running cassandra-stress with -schema options where the CREATE KEYSPACE or CREATE TABLE fails: replication strategy errors, insufficient permissions, syntax problems from -schema options like replication factor, or the node being unavailable/uninitialized.","commonSituations":"Typo'd replication strategy in -schema replication, keyspace quota or auth problems, cluster still starting up, driver connection dropped mid-DDL.","solutions":["Read the chained 'Caused by' exception for the actual CQL/driver failure","Verify -schema options, e.g. -schema replication(strategy=NetworkTopologyStrategy,datacenter1=3) is valid for your topology","Ensure the cluster is up and the stress user has CREATE permission","If the schema already exists and differs, create it manually first and use -schema keyspace=<name> without creation"],"exampleFix":"// before\n-schema replication(factor=3) on a NetworkTopologyStrategy cluster\n// after\n-schema replication(strategy=NetworkTopologyStrategy,dc1=3)","handlingStrategy":"try-catch","validationCode":"// pre-check cluster reachability and permissions\nsession.execute(\"SELECT cluster_name FROM system.local\");\nsession.execute(\"LIST PERMISSIONS\").all().stream().filter(p -> p.getResource().toString().contains(\"<keyspace>\") && p.getPermission().equals(\"CREATE\"));","typeGuard":null,"tryCatchPattern":"try { stress.run(); } catch (RuntimeException e) { if (e.getMessage().equals(\"Encountered exception creating schema\")) { Throwable cause = e.getCause(); log(\"schema creation failed: \" + cause); fixSchemaOrRetry(); } else throw e; }","preventionTips":["Validate -schema replication options against your actual topology/datacenter names","Ensure the stress user has CREATE permission","Create the schema manually with cqlsh and let stress reuse it if you need exact DDL","Confirm nodes are up before launching stress"],"tags":["schema","cql","database"],"backgroundTag":"database-query-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}