apache/cassandra · error · IllegalArgumentException

Keyspace " + keyspaceName + " does not exist

Error message

Keyspace " + keyspaceName + " does not exist

What it means

Keyspace.verifyKeyspaceIsValid validates a keyspace name before opening it: it rejects virtual keyspaces outright and throws IllegalArgumentException when the name is not present in the local schema. It is a fast-fail guard so callers like getValidKeyspace never attempt operations against a nonexistent or virtual keyspace.

Source

Thrown at src/java/org/apache/cassandra/db/Keyspace.java:233

    }

    public ColumnFamilyStore getIfExists(TableId id)
    {
        return columnFamilyStores.get(id);
    }

    public boolean hasColumnFamilyStore(TableId id)
    {
        return columnFamilyStores.containsKey(id);
    }

    public static void verifyKeyspaceIsValid(String keyspaceName)
    {
        if (null != VirtualKeyspaceRegistry.instance.getKeyspaceNullable(keyspaceName))
            throw new IllegalArgumentException("Cannot perform any operations against virtual keyspace " + keyspaceName);

        if (!Schema.instance.getKeyspaces().contains(keyspaceName))
            throw new IllegalArgumentException("Keyspace " + keyspaceName + " does not exist");
    }

    public static Keyspace getValidKeyspace(String keyspaceName)
    {
        verifyKeyspaceIsValid(keyspaceName);
        return Keyspace.open(keyspaceName);
    }

    /**
     * @return A list of open SSTableReaders
     */
    public List<SSTableReader> getAllSSTables(SSTableSet sstableSet)
    {
        List<SSTableReader> list = new ArrayList<>(columnFamilyStores.size());
        for (ColumnFamilyStore cfStore : columnFamilyStores.values())
            Iterables.addAll(list, cfStore.getSSTables(sstableSet));
        return list;
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Verify the exact keyspace name with `SELECT keyspace_name FROM system_schema.keyspaces;` and correct any typo in the caller/config.
  2. Run `nodetool describecluster` / check schema versions and run `nodetool resettm`-free remedies: wait for schema agreement or restart the out-of-sync node so the keyspace propagates.
  3. Create the keyspace if it is genuinely missing: `CREATE KEYSPACE ... WITH replication = {...}`.

Example fix

// before
Keyspace ks = Keyspace.getValidKeyspace("UserKeySpace");
// after
String ksName = schemaAwareConfig.getKeyspace(); // verified via system_schema.keyspaces
if (!Schema.instance.getKeyspaces().contains(ksName)) throw newConfigurationException(...);
Keyspace ks = Keyspace.getValidKeyspace(ksName);
Defensive patterns

Strategy: validation

Validate before calling

if (!Schema.instance.getKeyspaces().contains(ksName))
    throw new IllegalArgumentException("keyspace missing: " + ksName);
if (VirtualKeyspaceRegistry.instance.getKeyspaceNullable(ksName) != null)
    throw new IllegalArgumentException("virtual keyspace: " + ksName);

Try / catch

try { ks = Keyspace.getValidKeyspace(name); } catch (IllegalArgumentException e) { LOG.error("keyspace invalid: {}", name, e); return null; }

Prevention

When it happens

Trigger: Calling Keyspace.getValidKeyspace(name) or verifyKeyspaceIsValid(name) with a keyspace that was never created, was dropped, or has not yet propagated via schema agreement to this node; also when the name refers to a virtual keyspace (a different IllegalArgumentException is thrown).

Common situations: Typos in keyspace name in application config or cqlsh; running against a node that has not yet learned about a newly created keyspace (schema disagreement); tools like nodetool/repair invoked right after keyspace creation; case-sensitivity mistakes (quoted vs unquoted identifiers).

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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