Skip to content

[CASSSIDECAR-475] - Restore job fails with "Keyspace does not exist" fo…#365

Open
bianca-stanciu29 wants to merge 3 commits into
apache:trunkfrom
bianca-stanciu29:CASSSIDECAR-475
Open

[CASSSIDECAR-475] - Restore job fails with "Keyspace does not exist" fo…#365
bianca-stanciu29 wants to merge 3 commits into
apache:trunkfrom
bianca-stanciu29:CASSSIDECAR-475

Conversation

@bianca-stanciu29

Copy link
Copy Markdown

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.

}

if (metadata.getKeyspace(keyspace) == null)
if (metadata.getKeyspace(Metadata.quoteIfNecessary(keyspace)) == null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check for keyspace == null before this, otherwise quoteIfNecessary may access null string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyspace should not be null here ever

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same is applicable for other changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants