apache/cassandra · error · RuntimeException

Encountered exception creating schema

Error message

Encountered exception creating schema

What it means

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).

Solutions

  1. Read the chained 'Caused by' exception for the actual CQL/driver failure
  2. Verify -schema options, e.g. -schema replication(strategy=NetworkTopologyStrategy,datacenter1=3) is valid for your topology
  3. Ensure the cluster is up and the stress user has CREATE permission
  4. If the schema already exists and differs, create it manually first and use -schema keyspace=<name> without creation

Example fix

// before
-schema replication(factor=3) on a NetworkTopologyStrategy cluster
// after
-schema replication(strategy=NetworkTopologyStrategy,dc1=3)
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check cluster reachability and permissions
session.execute("SELECT cluster_name FROM system.local");
session.execute("LIST PERMISSIONS").all().stream().filter(p -> p.getResource().toString().contains("<keyspace>") && p.getPermission().equals("CREATE"));

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: Typo'd replication strategy in -schema replication, keyspace quota or auth problems, cluster still starting up, driver connection dropped mid-DDL.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/4826a13e1cea5933. Report an issue: GitHub.

Appendix: source

Thrown at tools/stress/src/org/apache/cassandra/stress/settings/SettingsSchema.java:89

        try
        {
            //Keyspace
            client.execute(createKeyspaceStatementCQL3(), org.apache.cassandra.db.ConsistencyLevel.LOCAL_ONE);

            //Add standard1 and counter1
            client.execute(createStandard1StatementCQL3(settings), org.apache.cassandra.db.ConsistencyLevel.LOCAL_ONE);
            client.execute(createCounter1StatementCQL3(settings), org.apache.cassandra.db.ConsistencyLevel.LOCAL_ONE);

            System.out.println(String.format("Created keyspaces. Sleeping %ss for propagation.", settings.node.nodes.size()));
            Thread.sleep(settings.node.nodes.size() * 1000L); // seconds
        }
        catch (AlreadyExistsException e)
        {
            //Ok.
        }
        catch (Exception e)
        {
            throw new RuntimeException("Encountered exception creating schema", e);
        }
    }

    String createKeyspaceStatementCQL3()
    {
        StringBuilder b = new StringBuilder();

        //Create Keyspace
        b.append("CREATE KEYSPACE IF NOT EXISTS \"")
         .append(keyspace)
         .append("\" WITH replication = {'class': '")
         .append(replicationStrategy)
         .append("'");

        if (replicationStrategyOptions.isEmpty())
        {
            b.append(", 'replication_factor': '1'}");
        }

View on GitHub (pinned to 88fd0f6a0e)