{"record":{"id":"3901bd2bc9446806","repo":"apache/cassandra","slug":"unknown-keyspace-s-this-can-occur-if-the-keyspac-3901bd","errorCode":null,"errorMessage":"Unknown keyspace %s. This can occur if the keyspace is being dropped.","messagePattern":"Unknown keyspace (.+?)\\. This can occur if the keyspace is being dropped\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/index/sai/virtual/SegmentsSystemView.java","lineNumber":107,"sourceCode":"        SimpleDataSet dataset = new SimpleDataSet(metadata());\n\n        forEachIndex(index -> {\n            for (SSTableIndex sstableIndex : index.view())\n            {\n                sstableIndex.populateSegmentView(dataset);\n            }\n        });\n\n        return dataset;\n    }\n\n    private void forEachIndex(Consumer<StorageAttachedIndex> process)\n    {\n        for (KeyspaceMetadata ks : Schema.instance.getUserKeyspaces())\n        {\n            Keyspace keyspace = Schema.instance.getKeyspaceInstance(ks.name);\n            if (keyspace == null)\n                throw new IllegalStateException(\"Unknown keyspace \" + ks + \". This can occur if the keyspace is being dropped.\");\n\n            for (ColumnFamilyStore cfs : keyspace.getColumnFamilyStores())\n            {\n                StorageAttachedIndexGroup group = StorageAttachedIndexGroup.getIndexGroup(cfs);\n\n                if (group != null)\n                    group.getIndexes().stream().map(index -> (StorageAttachedIndex) index).forEach(process);\n            }\n        }\n    }\n}\n","sourceCodeStart":89,"sourceCodeEnd":119,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/sai/virtual/SegmentsSystemView.java#L89-L119","documentation":"SegmentsSystemView.forEachIndex (used by data()) walks user keyspaces and live instances to enumerate SAI segments. If a keyspace exists in metadata but its live instance is missing — normally because it is being dropped concurrently — it throws IllegalStateException(\"Unknown keyspace %s. This can occur if the keyspace is being dropped.\").","triggerScenarios":"SELECT from the segments virtual table during concurrent DROP KEYSPACE; metadata iteration yields the keyspace but the live instance lookup returns null inside forEachIndex.","commonSituations":"Dashboard/monitoring polling of system_views.segments during schema changes; parallel test frameworks dropping keyspaces while others inspect segment views.","solutions":["Retry the virtual-table read after the drop completes","Pause schema mutations while polling virtual tables","Upgrade to a build that skips keyspaces with no live instance"],"exampleFix":"null","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    rs = session.execute(querySegmentsView);\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Unknown keyspace\")) {\n        // retry after backoff; keyspace likely being dropped\n    } else throw e;\n}","preventionTips":["Pause segment monitoring during keyspace drops","Use retry-with-backoff for virtual-table scans","Coordinate schema changes across tools sharing the cluster"],"tags":["sai","virtual-table","race-condition","schema"],"backgroundTag":"resource-not-found","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"}