Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions sdk/cosmosdb/cosmos/src/ClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,8 @@ export class ClientContext {
*/
public isPartitionLevelFailOverEnabled(): boolean {
return (
this.connectionPolicy.enablePartitionLevelFailover ||
this.connectionPolicy.enablePartitionLevelCircuitBreaker
this.globalEndpointManager.enablePartitionLevelFailover ||
this.globalEndpointManager.enablePartitionLevelCircuitBreaker
);
}
}
11 changes: 6 additions & 5 deletions sdk/cosmosdb/cosmos/src/CosmosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export class CosmosClient {
optionsOrConnectionString.connectionPolicy,
);

// If endpoint discovery is disabled, automatically disable partition level features
if (!optionsOrConnectionString.connectionPolicy.enableEndpointDiscovery) {
optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover = false;
optionsOrConnectionString.connectionPolicy.enablePartitionLevelCircuitBreaker = false;
}

optionsOrConnectionString.defaultHeaders = optionsOrConnectionString.defaultHeaders || {};
optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.CacheControl] = "no-cache";
optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.Version] =
Expand Down Expand Up @@ -161,11 +167,6 @@ export class CosmosClient {
optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover ||
optionsOrConnectionString.connectionPolicy.enablePartitionLevelCircuitBreaker
) {
if (!optionsOrConnectionString.connectionPolicy.enableEndpointDiscovery) {
throw new Error(
"enableEndpointDiscovery must be set to true to use partition level failover or circuit breaker.",
);
}
this.globalPartitionEndpointManager = new GlobalPartitionEndpointManager(
optionsOrConnectionString,
globalEndpointManager,
Expand Down
4 changes: 1 addition & 3 deletions sdk/cosmosdb/cosmos/src/common/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export function getUserAgent(
if (hostFramework) {
ua = ua + " " + hostFramework;
}
if (optionsOrConnectionString) {
ua = ua + addFeatureFlagsToUserAgent(optionsOrConnectionString);
}
if (optionsOrConnectionString && optionsOrConnectionString.userAgentSuffix) {
ua = ua + " " + optionsOrConnectionString.userAgentSuffix;
}
Expand All @@ -41,6 +38,7 @@ function userAgentDetails(): string {

/**
* @hidden
* TODO: This function was getting used to track PPAF. Now by default PPAF is enabled. We need to revisit this function.
*/
export function addFeatureFlagsToUserAgent(optionsOrConnectionString: CosmosClientOptions): string {
let featureFlag = 0;
Expand Down
15 changes: 11 additions & 4 deletions sdk/cosmosdb/cosmos/src/documents/ConnectionPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ export interface ConnectionPolicy {
/** Flag to enable/disable background refreshing of endpoints. Defaults to true.
* Endpoint discovery using `enableEndpointsDiscovery` will still work for failed requests. */
enableBackgroundEndpointRefreshing?: boolean;
/** Flag to enable/disable the Per Partition Level Failover (PPAF).
* Defaults to true. When enablePartitionLevelFailover set to true, enablePartitionLevelCircuitBreaker will also be set to true.
* */
/**
* Flag to enable/disable Per Partition Level Failover (PPAF). Defaults to true.
* Automatically failovers to other available partitions when a partition becomes unavailable.
* When enabled, enablePartitionLevelCircuitBreaker will also be set to true.
* Note: Requires enableEndpointDiscovery to be true. Has no effect when endpoint discovery is disabled.
*/
enablePartitionLevelFailover?: boolean;
/** Flag to enable/disable the Per Partition Level Circuit Breaker (PPCB). Defaults to true */

/**
* Flag to enable/disable Per Partition Level Circuit Breaker (PPCB). Defaults to true.
* Note: Requires enableEndpointDiscovery to be true. Has no effect when endpoint discovery is disabled.
*/
enablePartitionLevelCircuitBreaker?: boolean;
}

Expand Down
1 change: 0 additions & 1 deletion sdk/cosmosdb/cosmos/src/globalEndpointManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ export class GlobalEndpointManager {
if (databaseAccount) {
this.refreshStaleUnavailableLocations();
this.refreshEndpoints(databaseAccount);
this.refreshPPAFFeatureFlag(databaseAccount.enablePerPartitionFailover);
}
this.isRefreshing = false;
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmosdb/cosmos/src/request/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ async function httpRequest(
// set a shorter timeout to allow for quicker failover in case of partition unavailability.
// This is to ensure that read requests can quickly failover to another partition if the current one is unavailable.
if (
(requestContext.connectionPolicy.enablePartitionLevelFailover ||
requestContext.connectionPolicy.enablePartitionLevelCircuitBreaker) &&
(requestContext.globalEndpointManager.enablePartitionLevelFailover ||
requestContext.globalEndpointManager.enablePartitionLevelCircuitBreaker) &&
requestContext.partitionKeyRangeId &&
requestContext.resourceType === ResourceType.item &&
isReadRequest(requestContext.operationType)
Expand Down
1 change: 0 additions & 1 deletion sdk/cosmosdb/cosmos/src/retry/retryUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export async function execute({
requestContext.resourceType,
requestContext.operationType,
requestContext.connectionPolicy.enableEndpointDiscovery,
requestContext.connectionPolicy.enablePartitionLevelFailover,
requestContext.globalPartitionEndpointManager,
),
};
Expand Down
7 changes: 5 additions & 2 deletions sdk/cosmosdb/cosmos/src/retry/timeoutFailoverRetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class TimeoutFailoverRetryPolicy implements RetryPolicy {
private resourceType: ResourceType,
private operationType: OperationType,
private enableEndPointDiscovery: boolean,
private enablePartitionLevelFailover: boolean,
private globalPartitionEndpointManager?: GlobalPartitionEndpointManager,
) {}

Expand Down Expand Up @@ -96,7 +95,11 @@ export class TimeoutFailoverRetryPolicy implements RetryPolicy {
);
const readRequest = isReadRequest(this.operationType);

if (!canUseMultipleWriteLocations && !readRequest && !this.enablePartitionLevelFailover) {
if (
!canUseMultipleWriteLocations &&
!readRequest &&
!this.globalEndpointManager.enablePartitionLevelFailover
) {
// Write requests on single master cannot be retried if partition level failover is disabled.
// This means there are no other regions available to serve the writes.
return false;
Expand Down