Azure-Samples / azure-cosmos-cassandra-extensions-java-sample-v4

Java code sample for using Cosmos DB extensions for Cassandra API (Java v4 Driver).
MIT License
1 stars 3 forks source link

read-datacenter configuration not working as expected #8

Closed faizmsft closed 9 months ago

faizmsft commented 1 year ago

As per the documentation in the reference.conf, the "read-datacenter" configuration if added would typically allow reads from the local region but that not happening in the older and recent version of the cassandra extension library

Application configuration

Library

 <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-cosmos-cassandra-driver-4-extensions</artifactId>
            <version>1.1.2</version>
  </dependency>

Extension related configuration in the code

System.setProperty("datastax-java-driver.basic.load-balancing-policy.class",
                "com.azure.cosmos.cassandra.CosmosLoadBalancingPolicy");
System.setProperty("datastax-java-driver.basic.load-balancing-policy.global-endpoint","cassandraks.cassandra.cosmos.azure.com:10350");
System.setProperty("datastax-java-driver.basic.load-balancing-policy.write-datacenter","South India");
System.setProperty("datastax-java-driver.basic.load-balancing-policy.read-datacenter","West US");

Cosmos Cassandra account is configured with 4 regions

image

Code Execution

Based on the above configuration, we are expecting the reads to happen from the "West US" region for the following cassandra operation

image

What we noticed in the server side diagnostics was that the Execute operation happened in the "South India" region, following snap for reference.

image

When we perform the Query operation then also the same thing is observed, following snaps for reference

image

Check the region, it is "South India" instead of "West US"

image

Preferred region configuration

If we perform the test now with the preferred region configuration, the first region is treated as the local or preferred region and the code get executed in that specific region.

As per the following configuration, the "West US" is the read-datacenter location and "Southeast Asia" is the first region in the preferred locations configuration.

image

When we execute the Query operation, it gets executed in "Southeast Asia" region instead of "West US" region

image

Need help/clarity

  1. Why the read-datacenter property which means read from local region is not working as expected
  2. The preferred region configuration based on my understanding talking to few folks and the blog would be applicable during failover scenarios, so why is the first region treated as the local read region
iriaosara commented 9 months ago

https://learn.microsoft.com/en-us/azure/cosmos-db/cassandra/driver-extensions