CASSSIDECAR-475: Restore job fails with "Keyspace does not exist" for keyspaces created with quoted mixed-case names#365
Conversation
…r keyspaces created with quoted mixed-case names
| } | ||
|
|
||
| if (metadata.getKeyspace(keyspace) == null) | ||
| if (metadata.getKeyspace(Metadata.quoteIfNecessary(keyspace)) == null) |
There was a problem hiding this comment.
We need to check for keyspace == null before this, otherwise quoteIfNecessary may access null string
There was a problem hiding this comment.
keyspace should not be null here ever
There was a problem hiding this comment.
Fixed, moved to MetadataUtils.keyspace() which handles the null keyspace case internally before any lookup.
| checkAndReloadReloadCaches(); | ||
| Metadata metadata = instancesMetadata.instances().get(0).delegate().metadata(); | ||
| if (keyspace == null || metadata.getKeyspace(keyspace) == null) | ||
| if (keyspace == null || metadata.getKeyspace(Metadata.quoteIfNecessary(keyspace)) == null) |
There was a problem hiding this comment.
Using quoteIfNecessary may cause regression when a mixed letter keyspace name used without quotes, because quoteIfNecessary decides quotes only based on the chars existing in the keyspace string. Using MetadataUtils.keyspace would avoid this I believe.
| Keyspace created as | Cassandra internal name | Sidecar keyspace_name | Pre-PR getKeyspace | Post-PR getKeyspace(quoteIfNecessary) |
|---|---|---|---|---|
| "MyKeyspace" (quoted) | MyKeyspace | MyKeyspace | folds→mykeyspace → null (bug) | "MyKeyspace"→MyKeyspace → found (fixed) |
| MyKeyspace (unquoted) | mykeyspace | MyKeyspace | folds→mykeyspace → found | "MyKeyspace"→MyKeyspace → null (REGRESSION) |
| myks (lowercase) | myks | myks | found | found |
There was a problem hiding this comment.
Same is applicable for other changes in this PR
…yspace helper and add tests
yifan-c
left a comment
There was a problem hiding this comment.
The fix is good in general. But I do not think it covers all code paths.
For example, updating the integration test RestoreJobDiscovererPhaseSignalIntTest to use mixed case names and it fails.
QualifiedName USER_KEYSPACE_TABLE = new QualifiedName("Restore_phase_signal_ks", "T", true, true);
…enceHandler and add integration test coverage
Cassandra CQL allows keyspace names to be defined as quoted identifiers, which
preserves their exact casing (e.g. CREATE KEYSPACE “MyKeyspace”).
The DataStax Java Driver (com.datastax.driver.core.Metadata) stores such keyspaces with their case-preserved name internally. When querying the Driver’s Metadata API, the argument must also be quoted for the Driver to perform a case-sensitive lookup. Without quoting, the Driver treats the argument as a case-insensitive identifier, normalizes it to
lowercase, and fails to find the keyspace.
A restore job targeting a keyspace created with a quoted mixed-case name (e.g.
“MyKeyspace”) fails with “Keyspace does not exist” during SSTable range validation,
even though the keyspace is present in the cluster.