[ 
https://issues.apache.org/jira/browse/CASSSIDECAR-475?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18089358#comment-18089358
 ] 

Bianca Stanciu commented on CASSSIDECAR-475:
--------------------------------------------

== Fix ==

Wrap the keyspace name with _*Metadata.quoteIfNecessary()*_ before passing it 
to the
Driver’s Metadata API. The method inspects the identifier: if it contains 
uppercase
letters, special characters, or is a reserved word, it wraps it in double 
quotes,
instructing the Driver to perform a case-sensitive lookup instead of 
normalizing to
lowercase.


{code:java}
  Metadata.quoteIfNecessary(“MyKeyspace”) → “\”MyKeyspace\“”
  Metadata.quoteIfNecessary(“mykeyspace”) → “mykeyspace”  (unchanged, already 
lowercase){code}
Changes applied to 4 call sites across 2 classes:

 
{code:java}
  CachedLocalTokenRanges.java:107
  - if (metadata.getKeyspace(keyspace) == null)
  + if (metadata.getKeyspace(Metadata.quoteIfNecessary(keyspace)) == null)
  CachedLocalTokenRanges.java:150
  - return metadata.getTokenRanges(keyspace, host)
  + return metadata.getTokenRanges(Metadata.quoteIfNecessary(keyspace), host)
  CassandraClientTokenRingProvider.java:88
  - if (keyspace == null || metadata.getKeyspace(keyspace) == null)
  + if (keyspace == null || 
metadata.getKeyspace(Metadata.quoteIfNecessary(keyspace)) == null)
  CassandraClientTokenRingProvider.java:254
  - Set<TokenRange> tokenRanges = metadata.getTokenRanges(ks.getName(), host)
  + Set<TokenRange> tokenRanges = 
metadata.getTokenRanges(Metadata.quoteIfNecessary(ks.getName()), host)


{code}
A patch is ready and a PR can be submitted for review upon ticket approval.

> Restore job fails with "Keyspace does not exist" for keyspaces created with 
> quoted mixed-case names
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CASSSIDECAR-475
>                 URL: https://issues.apache.org/jira/browse/CASSSIDECAR-475
>             Project: Sidecar for Apache Cassandra
>          Issue Type: Bug
>          Components: Client
>            Reporter: Bianca Stanciu
>            Priority: Major
>
> {{== Background ==}}
> {{}}
> 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.
> == Problem ==
> 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.
> == Root Cause ==
> The keyspace name flows through the restore pipeline as a raw unquoted string:
>  
> {code:java}
>   RestoreJob.java:94      → .keyspace(row.getString(“keyspace_name”))
>   RestoreSlice.java:219   → builder.keyspace(restoreJob.keyspaceName)
>   RestoreRangeTask.java:484 → 
> localTokenRangesProvider.localTokenRanges(range.keyspace())
>   CachedLocalTokenRanges.java:107 → metadata.getKeyspace(keyspace)  // no 
> quoting{code}
>  
> The Driver normalizes the raw string to lowercase, finds no match, returns 
> null.
> {code:java}
> Caused by: java.util.NoSuchElementException: Keyspace does not exist. 
> keyspace: MyKeyspace
>   at CachedLocalTokenRanges.localTokenRanges(CachedLocalTokenRanges.java:109)
>   at 
> LocalTokenRangesProvider.localTokenRanges(LocalTokenRangesProvider.java:39)
>   at RestoreRangeTask.removeOutOfRangeSSTables(RestoreRangeTask.java:484)
>   at RestoreRangeTask.validateFilesAction(RestoreRangeTask.java:450)
> ...{code}
> {{== Steps to Reproduce ==}}
> 1. Create a Cassandra keyspace using a quoted mixed-case identifier:
>      CREATE KEYSPACE “MyKeyspace” WITH replication = \{...};
>      CREATE TABLE “MyKeyspace”.“MyTable” (....);
> 2. Submit a Sidecar restore job targeting keyspace “MyKeyspace”.
> 3. Observe the restore range task failing during SSTable validation with:
>      “Keyspace does not exist. keyspace: MyKeyspace”
> A patch is ready and a PR can be submitted for review upon ticket approval.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to