Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5a4b74d
Cosmos Java: share PartitionKeyRangeCache across CosmosClients target…
xinlian12 Jun 18, 2026
f3fa638
Cosmos Java: use URI (not String) as registry key for case-insensitiv…
xinlian12 Jun 19, 2026
75f93d5
Cosmos Java: keep registry key as serviceEndpoint URI (not _rid) for …
xinlian12 Jun 19, 2026
05f6780
Cosmos Java: add PhantomReference-based leak safety net for unclosed …
xinlian12 Jun 19, 2026
cbd47a8
Cosmos Java: use azure-core ReferenceManager for leaked-client safety…
xinlian12 Jun 19, 2026
9b43616
remove kafka test output
xinlian12 Jun 19, 2026
892a7d7
Cosmos Java: trim comments to core logic; drop cross-SDK references
xinlian12 Jun 19, 2026
1a5e92d
Cosmos Java: address PR review feedback
xinlian12 Jun 19, 2026
9356fbc
Retrigger CI
xinlian12 Jun 19, 2026
3afed67
Retrigger CI
xinlian12 Jun 19, 2026
39913c6
Cosmos Java: clarify 2-arg RxPartitionKeyRangeCache ctor behavior
xinlian12 Jun 19, 2026
022836d
Retrigger CI
xinlian12 Jun 19, 2026
c3eaba8
Retrigger CI
xinlian12 Jun 19, 2026
d585e36
Retrigger CI
xinlian12 Jun 20, 2026
7285d1c
Remove 2-arg RxPartitionKeyRangeCache ctor; require explicit endpoint
xinlian12 Jun 22, 2026
d6494d8
Key shared PartitionKeyRangeCache registry by database account id
xinlian12 Jun 22, 2026
7a693fa
Add e2e tests for shared PartitionKeyRangeCache + refresh Configs com…
xinlian12 Jun 22, 2026
4fad3a9
Address PR review on e2e test: data provider, TestObject, public acce…
xinlian12 Jun 22, 2026
a806ee6
Fix two regressions caught by CI live tests
xinlian12 Jun 23, 2026
5ffb1c0
Revert registry key to service endpoint URI (drop fragile account-id …
xinlian12 Jun 23, 2026
9162bb2
Fix CI: remove unworkable e2e negative test; revert PKR_LOOK_UP diagn…
xinlian12 Jun 23, 2026
99dfd30
Cosmos: restore outer-site PKR_LOOK_UP diagnostics; fix FaultInjectio…
xinlian12 Jun 23, 2026
3559d7f
Cosmos: make CosmosContainerOpenConnectionsAndInitCachesTest robust t…
xinlian12 Jun 23, 2026
1db1321
Cosmos: drop racy exact refcount-delta assertions in SharedPartitionK…
xinlian12 Jun 23, 2026
abb1681
Cosmos: fix NPE in CosmosDiagnosticsContext.getRequestInfo() for stor…
xinlian12 Jun 24, 2026
0f35e7b
Merge remote-tracking branch 'upstream/main' into feature/shared-part…
xinlian12 Jun 24, 2026
c02a27f
[Cosmos] Revert PARTITION_KEY_RANGE_LOOK_UP diagnostics to network-only
xinlian12 Jun 26, 2026
41cac7d
fix few flaky tests
xinlian12 Jun 30, 2026
5992363
fix null ref exception
xinlian12 Jun 30, 2026
917fb7e
fix more flaky tests
xinlian12 Jun 30, 2026
c21a0e6
fix flaky tests
xinlian12 Jul 1, 2026
741087c
fix flaky tests
xinlian12 Jul 2, 2026
c93502a
merge from main and resolve conflicts
xinlian12 Jul 6, 2026
b8b8379
revert unnecessary changes
xinlian12 Jul 6, 2026
1b529da
[Cosmos] Address review: add PR link to CHANGELOG + shared-cache test…
xinlian12 Jul 6, 2026
0cc458a
[Cosmos] Fix live tests broken by shared PartitionKeyRangeCache
xinlian12 Jul 6, 2026
a5c33f4
revert unnecessary changes
xinlian12 Jul 7, 2026
4ca00fe
[Cosmos] Detach initial AsyncCacheNonBlocking load to avoid pinning t…
xinlian12 Jul 7, 2026
c0e4103
[Cosmos] Fix multi-master FaultInjection PK-range test broken by shar…
xinlian12 Jul 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void readThroughput(boolean useNameLink) throws Exception {
"SESSION",
Comment thread
tvaron3 marked this conversation as resolved.
2,
numberOfOperations,
0);
100);
try {
Main.main(new String[]{"-workloadConfig", configFile.getAbsolutePath()});
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ public void createItem_withCacheRefresh() throws InterruptedException {
assertThat(processedDoc.get()).isEqualTo(totalRequest);
RxDocumentClientImpl rxDocumentClient =
(RxDocumentClientImpl) this.bulkClient.getDocClientWrapper();
// The partition-key-range (routing map) cache is shared across clients on the same service
// endpoint, so it may hold multiple containers' entries. Assert on this container's own entry
// rather than an arbitrary key from the shared map.
String collectionRid = container.read().block().getProperties().getResourceId();
ConcurrentHashMap<String, ?> routingMap = getRoutingMap(rxDocumentClient);
String cacheKeyBeforePartition = routingMap.keys().nextElement();
assertThat(routingMap).containsKey(collectionRid);

// introduce a split and continue bulk operations after split. The partition key range cache has to be
// refreshed and bulk processing should complete without errors
Expand Down Expand Up @@ -157,10 +161,10 @@ public void createItem_withCacheRefresh() throws InterruptedException {
.as("Partition ranges should increase after split");
logger.info("After split num partitions = {}", partitionKeyRangesAfterSplit.size());

// After the split the routing map entry for this container is refreshed in place under the
// same collection rid, so the entry must still be present.
routingMap = getRoutingMap(rxDocumentClient);
String cacheKeyAfterPartition = routingMap.keys().nextElement();

assertThat(cacheKeyBeforePartition).isEqualTo(cacheKeyAfterPartition);
assertThat(routingMap).containsKey(collectionRid);

responseFlux = container.executeBulkOperations(cosmosItemOperationFlux2, cosmosBulkExecutionOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.azure.cosmos;

import com.azure.cosmos.implementation.DocumentCollection;
import com.azure.cosmos.implementation.HttpConstants;
import com.azure.cosmos.implementation.ImplementationBridgeHelpers;
import com.azure.cosmos.implementation.RetryAnalyzer;
import com.azure.cosmos.implementation.Utils;
Expand All @@ -26,7 +27,6 @@
import com.azure.cosmos.models.CosmosContainerResponse;
import com.azure.cosmos.models.CosmosItemResponse;
import com.azure.cosmos.models.FeedRange;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.PartitionKey;
import com.azure.cosmos.models.PartitionKeyDefinition;
import com.azure.cosmos.models.PartitionKeyDefinitionVersion;
Expand All @@ -52,6 +52,7 @@
import org.testng.annotations.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

import java.nio.charset.StandardCharsets;
import java.time.Duration;
Expand Down Expand Up @@ -1141,7 +1142,15 @@ List<String> insertDocumentsCore(

ArrayList<Mono<CosmosItemResponse<ObjectNode>>> result = new ArrayList<>();
for (int i = 0; i < docs.size(); i++) {
result.add(container.createItem(docs.get(i)));
result.add(
container.createItem(docs.get(i)).retryWhen(
Retry
.max(40)
.filter(throwable ->
throwable instanceof CosmosException
&& ((CosmosException) throwable).getStatusCode() == HttpConstants.StatusCodes.TOO_MANY_REQUESTS)
)
);
}

List<ObjectNode> insertedDocs = Flux.merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public void openConnectionsAndInitCachesForDirectMode(boolean useAsync) throws I

assertThat(provider.count()).isEqualTo(0);
assertThat(collectionInfoByNameMap.size()).isEqualTo(0);
assertThat(routingMap.size()).isEqualTo(0);
// The partition-key-range (routing map) cache is shared across clients targeting the same
// service endpoint, so its size reflects every container routed to in this JVM. Assert on this
// container's own entry (populated by openConnectionsAndInitCaches) instead of the total size.
assertThat(ReflectionUtils.isInitialized(asyncContainer).get()).isFalse();

// Calling it twice to make sure no side effect of second time no-op call
Expand All @@ -158,7 +160,8 @@ public void openConnectionsAndInitCachesForDirectMode(boolean useAsync) throws I
}

assertThat(collectionInfoByNameMap.size()).isEqualTo(1);
assertThat(routingMap.size()).isEqualTo(1);
String collectionRid = asyncContainer.read().block().getProperties().getResourceId();
assertThat(routingMap).containsKey(collectionRid);
assertThat(ReflectionUtils.isInitialized(asyncContainer).get()).isTrue();

GlobalAddressResolver globalAddressResolver = ReflectionUtils.getGlobalAddressResolver(rxDocumentClient);
Expand Down Expand Up @@ -229,11 +232,12 @@ public void openConnectionsAndInitCachesForGatewayMode(boolean useAsync) {

RxDocumentClientImpl rxDocumentClient = (RxDocumentClientImpl) asyncClient.getDocClientWrapper();

ConcurrentHashMap<String, ?> routingMap = getRoutingMap(rxDocumentClient);
ConcurrentHashMap<String, ?> collectionInfoByNameMap = getCollectionInfoByNameMap(rxDocumentClient);

assertThat(collectionInfoByNameMap.size()).isEqualTo(0);
assertThat(routingMap.size()).isEqualTo(0);
// The routing-map (partition-key-range) cache is shared per service endpoint; gateway-mode
// openConnectionsAndInitCaches does not populate it, but a sibling direct-mode test may have,
// so the shared routing map's size is not asserted here.
assertThat(ReflectionUtils.isInitialized(asyncContainer).get()).isFalse();

// Verifying no error when initializeContainer called on gateway mode
Expand All @@ -247,7 +251,6 @@ public void openConnectionsAndInitCachesForGatewayMode(boolean useAsync) {
}

assertThat(collectionInfoByNameMap.size()).isEqualTo(0);
assertThat(routingMap.size()).isEqualTo(0);
assertThat(ReflectionUtils.isInitialized(asyncContainer).get()).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,11 @@ private void validateDirectModeDiagnosticsOnSuccess(
assertThat(diagnostics).contains("gatewayStatisticsList");
assertThat(diagnostics).contains("addressResolutionStatistics");
assertThat(diagnostics).contains("\"metaDataName\":\"CONTAINER_LOOK_UP\"");
assertThat(diagnostics).contains("\"metaDataName\":\"PARTITION_KEY_RANGE_LOOK_UP\"");
// With the shared partition-key-range cache, a sibling client/test targeting the same service
// endpoint may have already populated this container's routing map. When that happens this client
// serves the partition-key-range lookup from the shared cache without issuing a /pkranges network
// request, so no PARTITION_KEY_RANGE_LOOK_UP metadata diagnostic is recorded for this operation.
// Its presence is therefore not asserted here.
assertThat(diagnostics).contains("\"metaDataName\":\"SERVER_ADDRESS_LOOKUP\"");
assertThat(diagnostics).contains("\"serializationType\":\"PARTITION_KEY_FETCH_SERIALIZATION\"");
assertThat(diagnostics).contains("\"userAgent\":\"" + userAgent + "\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void readItemWithVeryLargePartitionKey() throws Exception {
}
docDefinition.set("mypk", sb.toString());

CosmosItemResponse<InternalObjectNode> itemResponse = container.createItem(docDefinition);
container.createItem(docDefinition);

waitIfNeededForReplicasToCatchUp(getClientBuilder());

Expand All @@ -191,7 +191,9 @@ public void readItemWithVeryLargePartitionKey() throws Exception {
@Test(groups = { "fast" }, timeOut = TIMEOUT)
public void readItem() throws Exception {
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
CosmosItemResponse<InternalObjectNode> itemResponse = container.createItem(properties);
container.createItem(properties);

waitIfNeededForReplicasToCatchUp(getClientBuilder());

CosmosItemResponse<InternalObjectNode> readResponse1 = container.readItem(properties.getId(),
new PartitionKey(properties.get("mypk")),
Expand Down Expand Up @@ -291,6 +293,8 @@ public void readMany() throws Exception {
idSet.add(document.getId());
}

waitIfNeededForReplicasToCatchUp(getClientBuilder());

FeedResponse<InternalObjectNode> feedResponse = container.readMany(cosmosItemIdentities, InternalObjectNode.class);

assertThat(feedResponse).isNotNull();
Expand Down Expand Up @@ -565,6 +569,7 @@ public void readManyWithPojoAndSingleTuple() throws Exception {
CosmosItemIdentity cosmosItemIdentity = new CosmosItemIdentity(partitionKey, document.getId());
cosmosItemIdentities.add(cosmosItemIdentity);

waitIfNeededForReplicasToCatchUp(getClientBuilder());
FeedResponse<SampleType> feedResponse = container.readMany(cosmosItemIdentities, SampleType.class);

assertThat(feedResponse.getResults()).isNotNull();
Expand Down Expand Up @@ -1078,6 +1083,8 @@ public void readItemWithSoftTimeoutAndFallback() throws Exception {
ObjectNode fallBackProperties = getDocumentDefinition("justFallback", "justFallback");
container.createItem(properties);

waitIfNeededForReplicasToCatchUp(getClientBuilder());

String successfulResponse = wrapWithSoftTimeoutAndFallback(
container
.asyncContainer
Expand Down Expand Up @@ -1334,6 +1341,8 @@ public void queryItemsWithEventualConsistency() throws Exception{
ObjectNode properties = getDocumentDefinition(idAndPkValue, idAndPkValue);
CosmosItemResponse<ObjectNode> itemResponse = container.createItem(properties);

waitIfNeededForReplicasToCatchUp(this.getClientBuilder());

String query = String.format("SELECT * from c where c.id = '%s'", idAndPkValue);
CosmosQueryRequestOptions cosmosQueryRequestOptions =
new CosmosQueryRequestOptions()
Expand Down Expand Up @@ -1449,10 +1458,12 @@ public void queryItemsWithContinuationTokenAndPageSize() throws Exception{
public void readAllItemsOfLogicalPartition() throws Exception{
String pkValue = UUID.randomUUID().toString();
ObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString(), pkValue);
CosmosItemResponse<ObjectNode> itemResponse = container.createItem(properties);
container.createItem(properties);

CosmosQueryRequestOptions cosmosQueryRequestOptions = new CosmosQueryRequestOptions();

waitIfNeededForReplicasToCatchUp(getClientBuilder());

CosmosPagedIterable<ObjectNode> feedResponseIterator1 =
container.readAllItems(
new PartitionKey(pkValue),
Expand Down Expand Up @@ -1482,6 +1493,8 @@ public void readAllItemsOfLogicalPartitionWithContinuationTokenAndPageSize() thr
properties = getDocumentDefinition(UUID.randomUUID().toString(), pkValue);
container.createItem(properties);

waitIfNeededForReplicasToCatchUp(getClientBuilder());

CosmosQueryRequestOptions cosmosQueryRequestOptions = new CosmosQueryRequestOptions();
String continuationToken = null;
int pageSize = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ public void openConnectionsAndInitCachesWithContainer(ProactiveConnectionManagem

assertThat(provider.count()).isEqualTo(endpoints.size());
assertThat(collectionInfoByNameMap.size()).isEqualTo(cosmosContainerIdentities.size());
assertThat(routingMap.size()).isEqualTo(cosmosContainerIdentities.size());
// The partition-key-range (routing map) cache is shared across clients targeting the same
// service endpoint, so its size reflects every container routed to in this JVM. Assert on
// this container's own entry instead of the total size.
String collectionRid = cosmosAsyncContainer.read().block().getProperties().getResourceId();
assertThat(routingMap).containsKey(collectionRid);
} finally {
if (cosmosAsyncContainer != null) {
safeDeleteCollection(cosmosAsyncContainer);
Expand Down Expand Up @@ -408,7 +412,14 @@ public void openConnectionsAndInitCachesWithCosmosClient_And_PerContainerConnect

assertThat(provider.count()).isEqualTo(endpoints.size());
assertThat(collectionInfoByNameMap.size()).isEqualTo(cosmosContainerIdentities.size());
assertThat(routingMap.size()).isEqualTo(cosmosContainerIdentities.size());
// The partition-key-range (routing map) cache is shared across clients targeting the same
// service endpoint, so its size reflects every container routed to in this JVM. Assert that
// each proactively-initialized container's own entry is present instead of the total size.
for (CosmosAsyncContainer proactivelyInitializedContainer : asyncContainers) {
String collectionRid =
proactivelyInitializedContainer.read().block().getProperties().getResourceId();
assertThat(routingMap).containsKey(collectionRid);
}

int totalConnectionCountForAllEndpoints = 0;

Expand Down Expand Up @@ -560,7 +571,14 @@ public void openConnectionsAndInitCachesWithCosmosClient_And_PerContainerConnect

assertThat(provider.count()).isEqualTo(endpoints.size());
assertThat(collectionInfoByNameMap.size()).isEqualTo(cosmosContainerIdentities.size());
assertThat(routingMap.size()).isEqualTo(cosmosContainerIdentities.size());
// The partition-key-range (routing map) cache is shared across clients targeting the same
// service endpoint, so its size reflects every container routed to in this JVM. Assert that
// each proactively-initialized container's own entry is present instead of the total size.
for (CosmosAsyncContainer proactivelyInitializedContainer : asyncContainers) {
String collectionRid =
proactivelyInitializedContainer.read().block().getProperties().getResourceId();
assertThat(routingMap).containsKey(collectionRid);
}

int totalConnectionCountForAllEndpoints = 0;

Expand Down Expand Up @@ -737,7 +755,14 @@ public void openConnectionsAndInitCachesWithCosmosClient_And_PerContainerConnect

assertThat(provider.count()).isEqualTo(endpoints.size());
assertThat(collectionInfoByNameMap.size()).isEqualTo(cosmosContainerIdentities.size());
assertThat(routingMap.size()).isEqualTo(cosmosContainerIdentities.size());
// The partition-key-range (routing map) cache is shared across clients targeting the same
// service endpoint, so its size reflects every container routed to in this JVM. Assert that
// each proactively-initialized container's own entry is present instead of the total size.
for (CosmosAsyncContainer proactivelyInitializedContainer : asyncContainers) {
String collectionRid =
proactivelyInitializedContainer.read().block().getProperties().getResourceId();
assertThat(routingMap).containsKey(collectionRid);
}

int totalConnectionCountForAllEndpoints = 0;

Expand Down
Loading
Loading