Skip to content

Commit 7ee385c

Browse files
committed
Fix PKRangeGone retry scope for address resolution
Scopes `PartitionKeyRangeGoneException` retries to address-resolution stale routing-map cases, marks both address resolver paths, and updates retry-policy tests for marked vs unmarked behavior.
1 parent 012dede commit 7ee385c

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/directconnectivity/GoneAndRetryWithRetryPolicyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void shouldRetryWithAddressResolutionPartitionKeyRangeGoneException() {
337337
ResourceType.Document);
338338
GoneAndRetryWithRetryPolicy goneAndRetryWithRetryPolicy = new GoneAndRetryWithRetryPolicy(request, 30);
339339
Mono<ShouldRetryResult> singleShouldRetry = goneAndRetryWithRetryPolicy
340-
.shouldRetry(new PartitionKeyRangeGoneException().setShouldRetryWithRoutingMapRefresh());
340+
.shouldRetry(new PartitionKeyRangeGoneException().markRetryWithRoutingMapRefresh());
341341
ShouldRetryResult shouldRetryResult = singleShouldRetry.block();
342342
assertThat(shouldRetryResult.shouldRetry).isTrue();
343343
assertThat(request.forcePartitionKeyRangeRefresh).isTrue();
@@ -369,12 +369,12 @@ public void shouldWrapAddressResolutionPartitionKeyRangeGoneExceptionWithService
369369
GoneAndRetryWithRetryPolicy goneAndRetryWithRetryPolicy = new GoneAndRetryWithRetryPolicy(request, 0);
370370

371371
ShouldRetryResult shouldRetryResult = goneAndRetryWithRetryPolicy
372-
.shouldRetry(new PartitionKeyRangeGoneException().setShouldRetryWithRoutingMapRefresh())
372+
.shouldRetry(new PartitionKeyRangeGoneException().markRetryWithRoutingMapRefresh())
373373
.block();
374374
assertThat(shouldRetryResult.shouldRetry).isTrue();
375375

376376
shouldRetryResult = goneAndRetryWithRetryPolicy
377-
.shouldRetry(new PartitionKeyRangeGoneException().setShouldRetryWithRoutingMapRefresh())
377+
.shouldRetry(new PartitionKeyRangeGoneException().markRetryWithRoutingMapRefresh())
378378
.block();
379379

380380
assertThat(shouldRetryResult.shouldRetry).isFalse();

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/PartitionKeyRangeGoneException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public boolean shouldRetryWithRoutingMapRefresh() {
9292
return this.shouldRetryWithRoutingMapRefresh;
9393
}
9494

95-
public PartitionKeyRangeGoneException setShouldRetryWithRoutingMapRefresh() {
95+
public PartitionKeyRangeGoneException markRetryWithRoutingMapRefresh() {
9696
this.shouldRetryWithRoutingMapRefresh = true;
9797
return this;
9898
}

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/AddressResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ private ResolutionResult handleRangeAddressResolutionFailure(
584584
request.getPartitionKeyRangeIdentity().getPartitionKeyRangeId(),
585585
request.getPartitionKeyRangeIdentity().getCollectionRid());
586586
throw BridgeInternal.setResourceAddress(
587-
new PartitionKeyRangeGoneException(errorMessage).setShouldRetryWithRoutingMapRefresh(),
587+
new PartitionKeyRangeGoneException(errorMessage).markRetryWithRoutingMapRefresh(),
588588
request.requestContext.resourcePhysicalAddress);
589589
}
590590
logger.debug("handleRangeAddressResolutionFailure returns null");

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/GatewayAddressCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ private Mono<AddressInformation[]> getAddressesForRangeId(
733733
collectionRid);
734734

735735
PartitionKeyRangeGoneException e = new PartitionKeyRangeGoneException(errorMessage)
736-
.setShouldRetryWithRoutingMapRefresh();
736+
.markRetryWithRoutingMapRefresh();
737737
BridgeInternal.setResourceAddress(e, collectionRid);
738738

739739
return Mono.error(e);

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/GoneAndRetryWithRetryPolicy.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ private Pair<Mono<ShouldRetryResult>, Boolean> handlePartitionIsMigratingExcepti
317317
}
318318

319319
private Pair<Mono<ShouldRetryResult>, Boolean> handlePartitionKeyIsSplittingException(PartitionKeyRangeIsSplittingException exception) {
320-
this.request.requestContext.resolvedPartitionKeyRange = null;
321-
this.request.requestContext.quorumSelectedLSN = -1;
322-
this.request.requestContext.quorumSelectedStoreResponse = null;
320+
resetRequestContextForPartitionKeyRangeRefresh();
323321
logger.debug("Received partition key range splitting exception, will retry, {}", exception.toString());
324322
this.request.forcePartitionKeyRangeRefresh = true;
325323
return Pair.of(null, false);
@@ -329,13 +327,17 @@ private Pair<Mono<ShouldRetryResult>, Boolean> handlePartitionKeyRangeGoneExcept
329327
// PartitionKeyRangeGoneException is generally treated as non-retriable, but when it is thrown while resolving
330328
// addresses in direct mode it typically indicates stale routing/partition state; clear the cached target and
331329
// force a routing-map (partition key range) refresh to allow the request to be re-routed.
332-
this.request.requestContext.resolvedPartitionKeyRange = null;
333-
this.request.requestContext.quorumSelectedLSN = -1;
334-
this.request.requestContext.quorumSelectedStoreResponse = null;
330+
resetRequestContextForPartitionKeyRangeRefresh();
335331
logger.debug("Received partition key range gone exception, will retry, {}", exception.toString());
336332
this.request.forcePartitionKeyRangeRefresh = true;
337333
return Pair.of(null, false);
338334
}
335+
336+
private void resetRequestContextForPartitionKeyRangeRefresh() {
337+
this.request.requestContext.resolvedPartitionKeyRange = null;
338+
this.request.requestContext.quorumSelectedLSN = -1;
339+
this.request.requestContext.quorumSelectedStoreResponse = null;
340+
}
339341
}
340342

341343
}

0 commit comments

Comments
 (0)