diff --git a/sdk/cosmosdb/cosmos/src/ClientContext.ts b/sdk/cosmosdb/cosmos/src/ClientContext.ts index 5601ddc3059f..3ba0043f39d3 100644 --- a/sdk/cosmosdb/cosmos/src/ClientContext.ts +++ b/sdk/cosmosdb/cosmos/src/ClientContext.ts @@ -1073,8 +1073,8 @@ export class ClientContext { */ public isPartitionLevelFailOverEnabled(): boolean { return ( - this.connectionPolicy.enablePartitionLevelFailover || - this.connectionPolicy.enablePartitionLevelCircuitBreaker + this.globalEndpointManager.enablePartitionLevelFailover || + this.globalEndpointManager.enablePartitionLevelCircuitBreaker ); } } diff --git a/sdk/cosmosdb/cosmos/src/CosmosClient.ts b/sdk/cosmosdb/cosmos/src/CosmosClient.ts index 67100b76f793..303d7007e2e0 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClient.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClient.ts @@ -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] = @@ -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, diff --git a/sdk/cosmosdb/cosmos/src/common/platform.ts b/sdk/cosmosdb/cosmos/src/common/platform.ts index 0c657246769e..7c64b469f66f 100644 --- a/sdk/cosmosdb/cosmos/src/common/platform.ts +++ b/sdk/cosmosdb/cosmos/src/common/platform.ts @@ -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; } @@ -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; diff --git a/sdk/cosmosdb/cosmos/src/documents/ConnectionPolicy.ts b/sdk/cosmosdb/cosmos/src/documents/ConnectionPolicy.ts index b8becc6f2761..ce02158801d5 100644 --- a/sdk/cosmosdb/cosmos/src/documents/ConnectionPolicy.ts +++ b/sdk/cosmosdb/cosmos/src/documents/ConnectionPolicy.ts @@ -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; } diff --git a/sdk/cosmosdb/cosmos/src/globalEndpointManager.ts b/sdk/cosmosdb/cosmos/src/globalEndpointManager.ts index dc21cb3fbf88..5c6083ddfb47 100644 --- a/sdk/cosmosdb/cosmos/src/globalEndpointManager.ts +++ b/sdk/cosmosdb/cosmos/src/globalEndpointManager.ts @@ -304,7 +304,6 @@ export class GlobalEndpointManager { if (databaseAccount) { this.refreshStaleUnavailableLocations(); this.refreshEndpoints(databaseAccount); - this.refreshPPAFFeatureFlag(databaseAccount.enablePerPartitionFailover); } this.isRefreshing = false; } diff --git a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts index 54113a55b57d..115fbeca221e 100644 --- a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts +++ b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts @@ -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) diff --git a/sdk/cosmosdb/cosmos/src/retry/retryUtility.ts b/sdk/cosmosdb/cosmos/src/retry/retryUtility.ts index c11134e03f48..2af8b8737d44 100644 --- a/sdk/cosmosdb/cosmos/src/retry/retryUtility.ts +++ b/sdk/cosmosdb/cosmos/src/retry/retryUtility.ts @@ -82,7 +82,6 @@ export async function execute({ requestContext.resourceType, requestContext.operationType, requestContext.connectionPolicy.enableEndpointDiscovery, - requestContext.connectionPolicy.enablePartitionLevelFailover, requestContext.globalPartitionEndpointManager, ), }; diff --git a/sdk/cosmosdb/cosmos/src/retry/timeoutFailoverRetryPolicy.ts b/sdk/cosmosdb/cosmos/src/retry/timeoutFailoverRetryPolicy.ts index ee2b69039cb5..5cc3926e7157 100644 --- a/sdk/cosmosdb/cosmos/src/retry/timeoutFailoverRetryPolicy.ts +++ b/sdk/cosmosdb/cosmos/src/retry/timeoutFailoverRetryPolicy.ts @@ -35,7 +35,6 @@ export class TimeoutFailoverRetryPolicy implements RetryPolicy { private resourceType: ResourceType, private operationType: OperationType, private enableEndPointDiscovery: boolean, - private enablePartitionLevelFailover: boolean, private globalPartitionEndpointManager?: GlobalPartitionEndpointManager, ) {} @@ -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;