@azure/cosmos 4.4.1 → 4.5.0-alpha.20250718.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/ClientContext.d.ts +19 -10
- package/dist/browser/ClientContext.d.ts.map +1 -1
- package/dist/browser/ClientContext.js +30 -11
- package/dist/browser/ClientContext.js.map +1 -1
- package/dist/browser/CosmosClient.d.ts.map +1 -1
- package/dist/browser/CosmosClient.js +13 -2
- package/dist/browser/CosmosClient.js.map +1 -1
- package/dist/browser/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/browser/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/browser/PartitionKeyRangeFailoverInfo.js +130 -0
- package/dist/browser/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/browser/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/browser/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/browser/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/browser/client/ClientUtils.d.ts +3 -1
- package/dist/browser/client/ClientUtils.d.ts.map +1 -1
- package/dist/browser/client/ClientUtils.js +10 -0
- package/dist/browser/client/ClientUtils.js.map +1 -1
- package/dist/browser/client/Item/Item.d.ts.map +1 -1
- package/dist/browser/client/Item/Item.js +13 -0
- package/dist/browser/client/Item/Item.js.map +1 -1
- package/dist/browser/client/Item/Items.d.ts +1 -0
- package/dist/browser/client/Item/Items.d.ts.map +1 -1
- package/dist/browser/client/Item/Items.js +29 -3
- package/dist/browser/client/Item/Items.js.map +1 -1
- package/dist/browser/common/constants.d.ts +20 -0
- package/dist/browser/common/constants.d.ts.map +1 -1
- package/dist/browser/common/constants.js +23 -1
- package/dist/browser/common/constants.js.map +1 -1
- package/dist/browser/common/platform.d.ts +6 -1
- package/dist/browser/common/platform.d.ts.map +1 -1
- package/dist/browser/common/platform.js +23 -4
- package/dist/browser/common/platform.js.map +1 -1
- package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/browser/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/browser/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/browser/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/browser/documents/ConnectionPolicy.js +2 -0
- package/dist/browser/documents/ConnectionPolicy.js.map +1 -1
- package/dist/browser/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/browser/documents/DatabaseAccount.js +3 -0
- package/dist/browser/documents/DatabaseAccount.js.map +1 -1
- package/dist/browser/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/browser/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/browser/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/browser/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/browser/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/browser/extractPartitionKey.d.ts.map +1 -1
- package/dist/browser/extractPartitionKey.js +33 -20
- package/dist/browser/extractPartitionKey.js.map +1 -1
- package/dist/browser/globalEndpointManager.d.ts +6 -0
- package/dist/browser/globalEndpointManager.d.ts.map +1 -1
- package/dist/browser/globalEndpointManager.js +9 -4
- package/dist/browser/globalEndpointManager.js.map +1 -1
- package/dist/browser/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/browser/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/browser/globalPartitionEndpointManager.js +278 -0
- package/dist/browser/globalPartitionEndpointManager.js.map +1 -0
- package/dist/browser/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/browser/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/browser/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/browser/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/documentProducer.js +16 -21
- package/dist/browser/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/browser/queryIterator.d.ts.map +1 -1
- package/dist/browser/queryIterator.js +2 -3
- package/dist/browser/queryIterator.js.map +1 -1
- package/dist/browser/request/ErrorResponse.d.ts +1 -1
- package/dist/browser/request/ErrorResponse.d.ts.map +1 -1
- package/dist/browser/request/ErrorResponse.js.map +1 -1
- package/dist/browser/request/RequestContext.d.ts +5 -0
- package/dist/browser/request/RequestContext.d.ts.map +1 -1
- package/dist/browser/request/RequestContext.js.map +1 -1
- package/dist/browser/request/RequestHandler.d.ts.map +1 -1
- package/dist/browser/request/RequestHandler.js +14 -4
- package/dist/browser/request/RequestHandler.js.map +1 -1
- package/dist/browser/request/request.d.ts.map +1 -1
- package/dist/browser/request/request.js +3 -3
- package/dist/browser/request/request.js.map +1 -1
- package/dist/browser/retry/RetryPolicy.d.ts +2 -2
- package/dist/browser/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/RetryPolicy.js.map +1 -1
- package/dist/browser/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/defaultRetryPolicy.js +4 -8
- package/dist/browser/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/browser/retry/retryUtility.d.ts.map +1 -1
- package/dist/browser/retry/retryUtility.js +11 -5
- package/dist/browser/retry/retryUtility.js.map +1 -1
- package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/browser/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/browser/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/browser/routing/partitionKeyRangeCache.js +11 -0
- package/dist/browser/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/browser/utils/checkURL.js +6 -0
- package/dist/browser/utils/checkURL.js.map +1 -1
- package/dist/browser/utils/hashing/hash.d.ts +2 -0
- package/dist/browser/utils/hashing/hash.d.ts.map +1 -1
- package/dist/browser/utils/hashing/hash.js +19 -0
- package/dist/browser/utils/hashing/hash.js.map +1 -1
- package/dist/browser/utils/time.d.ts +8 -0
- package/dist/browser/utils/time.d.ts.map +1 -1
- package/dist/browser/utils/time.js +19 -0
- package/dist/browser/utils/time.js.map +1 -1
- package/dist/commonjs/ClientContext.d.ts +19 -10
- package/dist/commonjs/ClientContext.d.ts.map +1 -1
- package/dist/commonjs/ClientContext.js +30 -11
- package/dist/commonjs/ClientContext.js.map +1 -1
- package/dist/commonjs/CosmosClient.d.ts.map +1 -1
- package/dist/commonjs/CosmosClient.js +13 -2
- package/dist/commonjs/CosmosClient.js.map +1 -1
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.js +135 -0
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/commonjs/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/commonjs/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/commonjs/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/commonjs/client/ClientUtils.d.ts +3 -1
- package/dist/commonjs/client/ClientUtils.d.ts.map +1 -1
- package/dist/commonjs/client/ClientUtils.js +11 -0
- package/dist/commonjs/client/ClientUtils.js.map +1 -1
- package/dist/commonjs/client/Item/Item.d.ts.map +1 -1
- package/dist/commonjs/client/Item/Item.js +13 -0
- package/dist/commonjs/client/Item/Item.js.map +1 -1
- package/dist/commonjs/client/Item/Items.d.ts +1 -0
- package/dist/commonjs/client/Item/Items.d.ts.map +1 -1
- package/dist/commonjs/client/Item/Items.js +27 -1
- package/dist/commonjs/client/Item/Items.js.map +1 -1
- package/dist/commonjs/common/constants.d.ts +20 -0
- package/dist/commonjs/common/constants.d.ts.map +1 -1
- package/dist/commonjs/common/constants.js +24 -2
- package/dist/commonjs/common/constants.js.map +1 -1
- package/dist/commonjs/common/platform.d.ts +6 -1
- package/dist/commonjs/common/platform.d.ts.map +1 -1
- package/dist/commonjs/common/platform.js +23 -3
- package/dist/commonjs/common/platform.js.map +1 -1
- package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/commonjs/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/commonjs/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/commonjs/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/commonjs/documents/ConnectionPolicy.js +2 -0
- package/dist/commonjs/documents/ConnectionPolicy.js.map +1 -1
- package/dist/commonjs/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/commonjs/documents/DatabaseAccount.js +3 -0
- package/dist/commonjs/documents/DatabaseAccount.js.map +1 -1
- package/dist/commonjs/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/commonjs/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/commonjs/encryption/Cache/ProtectedDataEncryptionKeyCache.d.ts.map +1 -1
- package/dist/commonjs/encryption/Cache/ProtectedDataEncryptionKeyCache.js +2 -1
- package/dist/commonjs/encryption/Cache/ProtectedDataEncryptionKeyCache.js.map +1 -1
- package/dist/commonjs/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/commonjs/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/commonjs/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/commonjs/extractPartitionKey.d.ts.map +1 -1
- package/dist/commonjs/extractPartitionKey.js +33 -20
- package/dist/commonjs/extractPartitionKey.js.map +1 -1
- package/dist/commonjs/globalEndpointManager.d.ts +6 -0
- package/dist/commonjs/globalEndpointManager.d.ts.map +1 -1
- package/dist/commonjs/globalEndpointManager.js +10 -5
- package/dist/commonjs/globalEndpointManager.js.map +1 -1
- package/dist/commonjs/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/commonjs/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/commonjs/globalPartitionEndpointManager.js +282 -0
- package/dist/commonjs/globalPartitionEndpointManager.js.map +1 -0
- package/dist/commonjs/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/commonjs/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/commonjs/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/commonjs/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/documentProducer.js +15 -20
- package/dist/commonjs/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/commonjs/queryIterator.d.ts.map +1 -1
- package/dist/commonjs/queryIterator.js +2 -3
- package/dist/commonjs/queryIterator.js.map +1 -1
- package/dist/commonjs/request/ErrorResponse.d.ts +1 -1
- package/dist/commonjs/request/ErrorResponse.d.ts.map +1 -1
- package/dist/commonjs/request/ErrorResponse.js.map +1 -1
- package/dist/commonjs/request/RequestContext.d.ts +5 -0
- package/dist/commonjs/request/RequestContext.d.ts.map +1 -1
- package/dist/commonjs/request/RequestContext.js.map +1 -1
- package/dist/commonjs/request/RequestHandler.d.ts.map +1 -1
- package/dist/commonjs/request/RequestHandler.js +12 -2
- package/dist/commonjs/request/RequestHandler.js.map +1 -1
- package/dist/commonjs/request/defaultAgent.js +4 -4
- package/dist/commonjs/request/defaultAgent.js.map +1 -1
- package/dist/commonjs/request/request.d.ts.map +1 -1
- package/dist/commonjs/request/request.js +3 -3
- package/dist/commonjs/request/request.js.map +1 -1
- package/dist/commonjs/retry/RetryPolicy.d.ts +2 -2
- package/dist/commonjs/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/RetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/defaultRetryPolicy.js +3 -7
- package/dist/commonjs/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/retryUtility.d.ts.map +1 -1
- package/dist/commonjs/retry/retryUtility.js +11 -5
- package/dist/commonjs/retry/retryUtility.js.map +1 -1
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/commonjs/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/commonjs/routing/partitionKeyRangeCache.js +11 -0
- package/dist/commonjs/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/utils/checkURL.js +7 -0
- package/dist/commonjs/utils/checkURL.js.map +1 -1
- package/dist/commonjs/utils/hashing/hash.d.ts +2 -0
- package/dist/commonjs/utils/hashing/hash.d.ts.map +1 -1
- package/dist/commonjs/utils/hashing/hash.js +20 -0
- package/dist/commonjs/utils/hashing/hash.js.map +1 -1
- package/dist/commonjs/utils/time.d.ts +8 -0
- package/dist/commonjs/utils/time.d.ts.map +1 -1
- package/dist/commonjs/utils/time.js +20 -0
- package/dist/commonjs/utils/time.js.map +1 -1
- package/dist/esm/ClientContext.d.ts +19 -10
- package/dist/esm/ClientContext.d.ts.map +1 -1
- package/dist/esm/ClientContext.js +30 -11
- package/dist/esm/ClientContext.js.map +1 -1
- package/dist/esm/CosmosClient.d.ts.map +1 -1
- package/dist/esm/CosmosClient.js +13 -2
- package/dist/esm/CosmosClient.js.map +1 -1
- package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/esm/PartitionKeyRangeFailoverInfo.js +130 -0
- package/dist/esm/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/esm/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/esm/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/esm/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/esm/client/ClientUtils.d.ts +3 -1
- package/dist/esm/client/ClientUtils.d.ts.map +1 -1
- package/dist/esm/client/ClientUtils.js +10 -0
- package/dist/esm/client/ClientUtils.js.map +1 -1
- package/dist/esm/client/Item/Item.d.ts.map +1 -1
- package/dist/esm/client/Item/Item.js +13 -0
- package/dist/esm/client/Item/Item.js.map +1 -1
- package/dist/esm/client/Item/Items.d.ts +1 -0
- package/dist/esm/client/Item/Items.d.ts.map +1 -1
- package/dist/esm/client/Item/Items.js +29 -3
- package/dist/esm/client/Item/Items.js.map +1 -1
- package/dist/esm/common/constants.d.ts +20 -0
- package/dist/esm/common/constants.d.ts.map +1 -1
- package/dist/esm/common/constants.js +23 -1
- package/dist/esm/common/constants.js.map +1 -1
- package/dist/esm/common/platform.d.ts +6 -1
- package/dist/esm/common/platform.d.ts.map +1 -1
- package/dist/esm/common/platform.js +23 -4
- package/dist/esm/common/platform.js.map +1 -1
- package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/esm/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/esm/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/esm/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/esm/documents/ConnectionPolicy.js +2 -0
- package/dist/esm/documents/ConnectionPolicy.js.map +1 -1
- package/dist/esm/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/esm/documents/DatabaseAccount.js +3 -0
- package/dist/esm/documents/DatabaseAccount.js.map +1 -1
- package/dist/esm/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/esm/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/esm/encryption/Cache/ProtectedDataEncryptionKeyCache.d.ts.map +1 -1
- package/dist/esm/encryption/Cache/ProtectedDataEncryptionKeyCache.js +2 -1
- package/dist/esm/encryption/Cache/ProtectedDataEncryptionKeyCache.js.map +1 -1
- package/dist/esm/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/esm/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/esm/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/esm/extractPartitionKey.d.ts.map +1 -1
- package/dist/esm/extractPartitionKey.js +33 -20
- package/dist/esm/extractPartitionKey.js.map +1 -1
- package/dist/esm/globalEndpointManager.d.ts +6 -0
- package/dist/esm/globalEndpointManager.d.ts.map +1 -1
- package/dist/esm/globalEndpointManager.js +9 -4
- package/dist/esm/globalEndpointManager.js.map +1 -1
- package/dist/esm/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/esm/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/esm/globalPartitionEndpointManager.js +278 -0
- package/dist/esm/globalPartitionEndpointManager.js.map +1 -0
- package/dist/esm/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/esm/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/esm/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/esm/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/documentProducer.js +16 -21
- package/dist/esm/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/esm/queryIterator.d.ts.map +1 -1
- package/dist/esm/queryIterator.js +2 -3
- package/dist/esm/queryIterator.js.map +1 -1
- package/dist/esm/request/ErrorResponse.d.ts +1 -1
- package/dist/esm/request/ErrorResponse.d.ts.map +1 -1
- package/dist/esm/request/ErrorResponse.js.map +1 -1
- package/dist/esm/request/RequestContext.d.ts +5 -0
- package/dist/esm/request/RequestContext.d.ts.map +1 -1
- package/dist/esm/request/RequestContext.js.map +1 -1
- package/dist/esm/request/RequestHandler.d.ts.map +1 -1
- package/dist/esm/request/RequestHandler.js +14 -4
- package/dist/esm/request/RequestHandler.js.map +1 -1
- package/dist/esm/request/defaultAgent.js +2 -2
- package/dist/esm/request/defaultAgent.js.map +1 -1
- package/dist/esm/request/request.d.ts.map +1 -1
- package/dist/esm/request/request.js +3 -3
- package/dist/esm/request/request.js.map +1 -1
- package/dist/esm/retry/RetryPolicy.d.ts +2 -2
- package/dist/esm/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/RetryPolicy.js.map +1 -1
- package/dist/esm/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/defaultRetryPolicy.js +4 -8
- package/dist/esm/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/esm/retry/retryUtility.d.ts.map +1 -1
- package/dist/esm/retry/retryUtility.js +11 -5
- package/dist/esm/retry/retryUtility.js.map +1 -1
- package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/esm/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/esm/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/esm/routing/partitionKeyRangeCache.js +11 -0
- package/dist/esm/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/esm/utils/checkURL.js +6 -0
- package/dist/esm/utils/checkURL.js.map +1 -1
- package/dist/esm/utils/hashing/hash.d.ts +2 -0
- package/dist/esm/utils/hashing/hash.d.ts.map +1 -1
- package/dist/esm/utils/hashing/hash.js +19 -0
- package/dist/esm/utils/hashing/hash.js.map +1 -1
- package/dist/esm/utils/time.d.ts +8 -0
- package/dist/esm/utils/time.d.ts.map +1 -1
- package/dist/esm/utils/time.js +19 -0
- package/dist/esm/utils/time.js.map +1 -1
- package/dist/react-native/ClientContext.d.ts +19 -10
- package/dist/react-native/ClientContext.d.ts.map +1 -1
- package/dist/react-native/ClientContext.js +30 -11
- package/dist/react-native/ClientContext.js.map +1 -1
- package/dist/react-native/CosmosClient.d.ts.map +1 -1
- package/dist/react-native/CosmosClient.js +13 -2
- package/dist/react-native/CosmosClient.js.map +1 -1
- package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/react-native/PartitionKeyRangeFailoverInfo.js +130 -0
- package/dist/react-native/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/react-native/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/react-native/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/react-native/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/react-native/client/ClientUtils.d.ts +3 -1
- package/dist/react-native/client/ClientUtils.d.ts.map +1 -1
- package/dist/react-native/client/ClientUtils.js +10 -0
- package/dist/react-native/client/ClientUtils.js.map +1 -1
- package/dist/react-native/client/Item/Item.d.ts.map +1 -1
- package/dist/react-native/client/Item/Item.js +13 -0
- package/dist/react-native/client/Item/Item.js.map +1 -1
- package/dist/react-native/client/Item/Items.d.ts +1 -0
- package/dist/react-native/client/Item/Items.d.ts.map +1 -1
- package/dist/react-native/client/Item/Items.js +29 -3
- package/dist/react-native/client/Item/Items.js.map +1 -1
- package/dist/react-native/common/constants.d.ts +20 -0
- package/dist/react-native/common/constants.d.ts.map +1 -1
- package/dist/react-native/common/constants.js +23 -1
- package/dist/react-native/common/constants.js.map +1 -1
- package/dist/react-native/common/platform.d.ts +6 -1
- package/dist/react-native/common/platform.d.ts.map +1 -1
- package/dist/react-native/common/platform.js +23 -4
- package/dist/react-native/common/platform.js.map +1 -1
- package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/react-native/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/react-native/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/react-native/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/react-native/documents/ConnectionPolicy.js +2 -0
- package/dist/react-native/documents/ConnectionPolicy.js.map +1 -1
- package/dist/react-native/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/react-native/documents/DatabaseAccount.js +3 -0
- package/dist/react-native/documents/DatabaseAccount.js.map +1 -1
- package/dist/react-native/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/react-native/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/react-native/encryption/Cache/ProtectedDataEncryptionKeyCache.d.ts.map +1 -1
- package/dist/react-native/encryption/Cache/ProtectedDataEncryptionKeyCache.js +2 -1
- package/dist/react-native/encryption/Cache/ProtectedDataEncryptionKeyCache.js.map +1 -1
- package/dist/react-native/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/react-native/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/react-native/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/react-native/extractPartitionKey.d.ts.map +1 -1
- package/dist/react-native/extractPartitionKey.js +33 -20
- package/dist/react-native/extractPartitionKey.js.map +1 -1
- package/dist/react-native/globalEndpointManager.d.ts +6 -0
- package/dist/react-native/globalEndpointManager.d.ts.map +1 -1
- package/dist/react-native/globalEndpointManager.js +9 -4
- package/dist/react-native/globalEndpointManager.js.map +1 -1
- package/dist/react-native/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/react-native/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/react-native/globalPartitionEndpointManager.js +278 -0
- package/dist/react-native/globalPartitionEndpointManager.js.map +1 -0
- package/dist/react-native/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/react-native/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/react-native/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/react-native/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/documentProducer.js +16 -21
- package/dist/react-native/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/react-native/queryIterator.d.ts.map +1 -1
- package/dist/react-native/queryIterator.js +2 -3
- package/dist/react-native/queryIterator.js.map +1 -1
- package/dist/react-native/request/ErrorResponse.d.ts +1 -1
- package/dist/react-native/request/ErrorResponse.d.ts.map +1 -1
- package/dist/react-native/request/ErrorResponse.js.map +1 -1
- package/dist/react-native/request/RequestContext.d.ts +5 -0
- package/dist/react-native/request/RequestContext.d.ts.map +1 -1
- package/dist/react-native/request/RequestContext.js.map +1 -1
- package/dist/react-native/request/RequestHandler.d.ts.map +1 -1
- package/dist/react-native/request/RequestHandler.js +14 -4
- package/dist/react-native/request/RequestHandler.js.map +1 -1
- package/dist/react-native/request/defaultAgent.js +2 -2
- package/dist/react-native/request/defaultAgent.js.map +1 -1
- package/dist/react-native/request/request.d.ts.map +1 -1
- package/dist/react-native/request/request.js +3 -3
- package/dist/react-native/request/request.js.map +1 -1
- package/dist/react-native/retry/RetryPolicy.d.ts +2 -2
- package/dist/react-native/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/RetryPolicy.js.map +1 -1
- package/dist/react-native/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/defaultRetryPolicy.js +4 -8
- package/dist/react-native/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/react-native/retry/retryUtility.d.ts.map +1 -1
- package/dist/react-native/retry/retryUtility.js +11 -5
- package/dist/react-native/retry/retryUtility.js.map +1 -1
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/react-native/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/react-native/routing/partitionKeyRangeCache.js +11 -0
- package/dist/react-native/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/react-native/utils/checkURL.js +6 -0
- package/dist/react-native/utils/checkURL.js.map +1 -1
- package/dist/react-native/utils/hashing/hash.d.ts +2 -0
- package/dist/react-native/utils/hashing/hash.d.ts.map +1 -1
- package/dist/react-native/utils/hashing/hash.js +19 -0
- package/dist/react-native/utils/hashing/hash.js.map +1 -1
- package/dist/react-native/utils/time.d.ts +8 -0
- package/dist/react-native/utils/time.d.ts.map +1 -1
- package/dist/react-native/utils/time.js +19 -0
- package/dist/react-native/utils/time.js.map +1 -1
- package/package.json +11 -11
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { OperationType, ResourceType, isReadRequest } from "./common/index.js";
|
|
4
|
+
import { Constants, } from "./index.js";
|
|
5
|
+
import { PartitionKeyRangeFailoverInfo } from "./PartitionKeyRangeFailoverInfo.js";
|
|
6
|
+
import { normalizeEndpoint } from "./utils/checkURL.js";
|
|
7
|
+
import { startBackgroundTask } from "./utils/time.js";
|
|
8
|
+
import { assertNotUndefined } from "./utils/typeChecks.js";
|
|
9
|
+
/**
|
|
10
|
+
* @hidden
|
|
11
|
+
* This class is used to failover single partitions to different regions.
|
|
12
|
+
*/
|
|
13
|
+
export class GlobalPartitionEndpointManager {
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
constructor(options, globalEndpointManager) {
|
|
18
|
+
this.globalEndpointManager = globalEndpointManager;
|
|
19
|
+
this.partitionKeyRangeToLocationForWrite = new Map();
|
|
20
|
+
this.partitionKeyRangeToLocationForReadAndWrite = new Map();
|
|
21
|
+
this.enablePartitionLevelFailover = options.connectionPolicy.enablePartitionLevelFailover;
|
|
22
|
+
this.enablePartitionLevelCircuitBreaker =
|
|
23
|
+
options.connectionPolicy.enablePartitionLevelCircuitBreaker ||
|
|
24
|
+
options.connectionPolicy.enablePartitionLevelFailover;
|
|
25
|
+
this.preferredLocations = options.connectionPolicy.preferredLocations;
|
|
26
|
+
this.preferredLocationsCount = this.preferredLocations ? this.preferredLocations.length : 0;
|
|
27
|
+
if (this.enablePartitionLevelCircuitBreaker) {
|
|
28
|
+
this.initiateCircuitBreakerFailbackLoop();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Checks eligibility of the request for partition failover and
|
|
33
|
+
* tries to mark the endpoint unavailable for the partition key range. Future
|
|
34
|
+
* requests will be routed to the next location if available.
|
|
35
|
+
*/
|
|
36
|
+
async tryPartitionLevelFailover(requestContext, diagnosticNode) {
|
|
37
|
+
if (!(await this.isRequestEligibleForPartitionFailover(requestContext, true))) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const isRequestEligibleForPerPartitionAutomaticFailover = this.isRequestEligibleForPerPartitionAutomaticFailover(requestContext);
|
|
41
|
+
const isRequestEligibleForPartitionLevelCircuitBreaker = this.isRequestEligibleForPartitionLevelCircuitBreaker(requestContext);
|
|
42
|
+
if (isRequestEligibleForPerPartitionAutomaticFailover ||
|
|
43
|
+
(isRequestEligibleForPartitionLevelCircuitBreaker &&
|
|
44
|
+
(await this.incrementFailureCounterAndCheckFailover(requestContext, isRequestEligibleForPerPartitionAutomaticFailover, isRequestEligibleForPartitionLevelCircuitBreaker)))) {
|
|
45
|
+
return this.tryMarkEndpointUnavailableForPartitionKeyRange(requestContext, diagnosticNode, isRequestEligibleForPerPartitionAutomaticFailover, isRequestEligibleForPartitionLevelCircuitBreaker);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Updates the DocumentServiceRequest routing location to point
|
|
51
|
+
* new a location based if a partition level failover occurred.
|
|
52
|
+
*/
|
|
53
|
+
async tryAddPartitionLevelLocationOverride(requestContext, diagnosticNode) {
|
|
54
|
+
if (!(await this.isRequestEligibleForPartitionFailover(requestContext, false))) {
|
|
55
|
+
return requestContext;
|
|
56
|
+
}
|
|
57
|
+
const partitionKeyRangeId = requestContext.partitionKeyRangeId;
|
|
58
|
+
if (this.isRequestEligibleForPerPartitionAutomaticFailover(requestContext)) {
|
|
59
|
+
if (this.partitionKeyRangeToLocationForWrite.has(partitionKeyRangeId)) {
|
|
60
|
+
const partitionFailOver = this.partitionKeyRangeToLocationForWrite.get(partitionKeyRangeId);
|
|
61
|
+
requestContext.endpoint = partitionFailOver.getCurrentEndPoint();
|
|
62
|
+
diagnosticNode.recordEndpointResolution(requestContext.endpoint);
|
|
63
|
+
return requestContext;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (this.isRequestEligibleForPartitionLevelCircuitBreaker(requestContext)) {
|
|
67
|
+
if (this.partitionKeyRangeToLocationForReadAndWrite.has(partitionKeyRangeId)) {
|
|
68
|
+
const partitionFailOver = this.partitionKeyRangeToLocationForReadAndWrite.get(partitionKeyRangeId);
|
|
69
|
+
const canCircuitBreakerTriggerPartitionFailOver = await partitionFailOver.canCircuitBreakerTriggerPartitionFailOver(isReadRequest(requestContext.operationType));
|
|
70
|
+
if (canCircuitBreakerTriggerPartitionFailOver) {
|
|
71
|
+
requestContext.endpoint = partitionFailOver.getCurrentEndPoint();
|
|
72
|
+
diagnosticNode.recordEndpointResolution(requestContext.endpoint);
|
|
73
|
+
return requestContext;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return requestContext;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* This method clears the background refresher for circuit breaker failback
|
|
81
|
+
* and stops the periodic checks for unhealthy endpoints.
|
|
82
|
+
*/
|
|
83
|
+
dispose() {
|
|
84
|
+
if (this.circuitBreakerFailbackBackgroundRefresher) {
|
|
85
|
+
clearTimeout(this.circuitBreakerFailbackBackgroundRefresher);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async tryMarkEndpointUnavailableForPartitionKeyRange(requestContext, diagnosticNode, isRequestEligibleForPerPartitionAutomaticFailover, isRequestEligibleForPartitionLevelCircuitBreaker) {
|
|
89
|
+
const partitionKeyRangeId = requestContext.partitionKeyRangeId;
|
|
90
|
+
const failedEndPoint = requestContext.endpoint;
|
|
91
|
+
const readLocations = await this.globalEndpointManager.getReadLocations();
|
|
92
|
+
const readEndPoints = [];
|
|
93
|
+
if (isRequestEligibleForPerPartitionAutomaticFailover) {
|
|
94
|
+
// For any single master write accounts, the next locations to fail over will be the read regions configured at the account level.
|
|
95
|
+
for (const location of readLocations) {
|
|
96
|
+
readEndPoints.push(location.databaseAccountEndpoint);
|
|
97
|
+
}
|
|
98
|
+
return this.tryAddOrUpdatePartitionFailoverInfoAndMoveToNextLocation(partitionKeyRangeId, failedEndPoint, readEndPoints, this.partitionKeyRangeToLocationForWrite, diagnosticNode);
|
|
99
|
+
}
|
|
100
|
+
else if (isRequestEligibleForPartitionLevelCircuitBreaker) {
|
|
101
|
+
// For the read requests or multi-master write requests, the next locations to fail over will be the preferred locations
|
|
102
|
+
// configured at the account level plus any other read locations that are not already in the preferred locations.
|
|
103
|
+
if (this.preferredLocations && this.preferredLocations.length > 0) {
|
|
104
|
+
for (const preferredLocation of this.preferredLocations) {
|
|
105
|
+
const location = readLocations.find((loc) => normalizeEndpoint(loc.name) === normalizeEndpoint(preferredLocation));
|
|
106
|
+
if (location) {
|
|
107
|
+
readEndPoints.push(location.databaseAccountEndpoint);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Add the rest of the locations not already added
|
|
111
|
+
for (const location of readLocations) {
|
|
112
|
+
if (!readEndPoints.includes(location.databaseAccountEndpoint)) {
|
|
113
|
+
readEndPoints.push(location.databaseAccountEndpoint);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
for (const location of readLocations) {
|
|
119
|
+
readEndPoints.push(location.databaseAccountEndpoint);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return this.tryAddOrUpdatePartitionFailoverInfoAndMoveToNextLocation(partitionKeyRangeId, failedEndPoint, readEndPoints, this.partitionKeyRangeToLocationForReadAndWrite, diagnosticNode);
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Increments the failure counter for the specified partition and checks if the partition can fail over.
|
|
128
|
+
* This method is used to determine if a partition should be failed over based on the number of request failures.
|
|
129
|
+
*/
|
|
130
|
+
async incrementFailureCounterAndCheckFailover(requestContext, isRequestEligibleForPerPartitionAutomaticFailover, isRequestEligibleForPartitionLevelCircuitBreaker) {
|
|
131
|
+
const partitionKeyRangeId = requestContext.partitionKeyRangeId;
|
|
132
|
+
const failedEndPoint = requestContext.endpoint;
|
|
133
|
+
let partitionKeyRangeFailoverInfo;
|
|
134
|
+
if (isRequestEligibleForPerPartitionAutomaticFailover) {
|
|
135
|
+
if (!this.partitionKeyRangeToLocationForWrite.has(partitionKeyRangeId)) {
|
|
136
|
+
// If the partition key range is not already in the map, add it
|
|
137
|
+
const failoverInfo = new PartitionKeyRangeFailoverInfo(failedEndPoint);
|
|
138
|
+
this.partitionKeyRangeToLocationForWrite.set(partitionKeyRangeId, failoverInfo);
|
|
139
|
+
}
|
|
140
|
+
partitionKeyRangeFailoverInfo =
|
|
141
|
+
this.partitionKeyRangeToLocationForWrite.get(partitionKeyRangeId);
|
|
142
|
+
}
|
|
143
|
+
else if (isRequestEligibleForPartitionLevelCircuitBreaker) {
|
|
144
|
+
if (!this.partitionKeyRangeToLocationForReadAndWrite.has(partitionKeyRangeId)) {
|
|
145
|
+
// If the partition key range is not already in the map, add it
|
|
146
|
+
const failoverInfo = new PartitionKeyRangeFailoverInfo(failedEndPoint);
|
|
147
|
+
this.partitionKeyRangeToLocationForReadAndWrite.set(partitionKeyRangeId, failoverInfo);
|
|
148
|
+
}
|
|
149
|
+
partitionKeyRangeFailoverInfo =
|
|
150
|
+
this.partitionKeyRangeToLocationForReadAndWrite.get(partitionKeyRangeId);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
assertNotUndefined(partitionKeyRangeFailoverInfo, "partitionKeyRangeFailoverInfo should be set if failover flags are true.");
|
|
156
|
+
const currentTimeInMilliseconds = Date.now();
|
|
157
|
+
await partitionKeyRangeFailoverInfo.incrementRequestFailureCounts(isReadRequest(requestContext.operationType), currentTimeInMilliseconds);
|
|
158
|
+
return partitionKeyRangeFailoverInfo.canCircuitBreakerTriggerPartitionFailOver(isReadRequest(requestContext.operationType));
|
|
159
|
+
}
|
|
160
|
+
/** Validates if the given request is eligible for partition failover. */
|
|
161
|
+
async isRequestEligibleForPartitionFailover(requestContext, shouldValidateFailedLocation) {
|
|
162
|
+
if (!requestContext ||
|
|
163
|
+
!requestContext.operationType ||
|
|
164
|
+
!requestContext.resourceType ||
|
|
165
|
+
!requestContext.partitionKeyRangeId) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const canUsePartitionLevelFailoverLocations = await this.canUsePartitionLevelFailoverLocations(requestContext.operationType, requestContext.resourceType);
|
|
169
|
+
if (!canUsePartitionLevelFailoverLocations) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
if (shouldValidateFailedLocation && !requestContext.endpoint) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
/** Determines if partition level failover locations can be used for the given request. */
|
|
178
|
+
async canUsePartitionLevelFailoverLocations(operationType, resourceType) {
|
|
179
|
+
const readEndPoints = await this.globalEndpointManager.getReadEndpoints();
|
|
180
|
+
if (readEndPoints.length <= 1) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (resourceType === ResourceType.item ||
|
|
184
|
+
(resourceType === ResourceType.sproc && operationType === OperationType.Execute)) {
|
|
185
|
+
// Right now, for single-master only reads are supported for circuit breaker, and writes are supported for automatic.
|
|
186
|
+
// failover. For multi master, both reads and writes are supported. Hence return true for both the cases.
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Determines if a request is eligible for per-partition automatic failover.
|
|
193
|
+
* A request is eligible if it is a write request, partition level failover is enabled,
|
|
194
|
+
* and the global endpoint manager cannot use multiple write locations for the request.
|
|
195
|
+
*/
|
|
196
|
+
isRequestEligibleForPerPartitionAutomaticFailover(requestContext) {
|
|
197
|
+
return (this.enablePartitionLevelFailover &&
|
|
198
|
+
!isReadRequest(requestContext.operationType) &&
|
|
199
|
+
!this.globalEndpointManager.canUseMultipleWriteLocations(requestContext.resourceType, requestContext.operationType));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Determines if a request is eligible for partition-level circuit breaker.
|
|
203
|
+
* This method checks if partition-level circuit breaker is enabled, and if the request is a read-only request or
|
|
204
|
+
* the global endpoint manager can use multiple write locations for the request.
|
|
205
|
+
*/
|
|
206
|
+
isRequestEligibleForPartitionLevelCircuitBreaker(requestContext) {
|
|
207
|
+
if (!this.enablePartitionLevelCircuitBreaker) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
if (isReadRequest(requestContext.operationType)) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return this.globalEndpointManager.canUseMultipleWriteLocations(requestContext.resourceType, requestContext.operationType);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Attempts to add or update the partition failover information and move to the next available location.
|
|
217
|
+
* This method checks if the current location for the partition key range has failed and updates the failover
|
|
218
|
+
* information to route the request to the next available location. If all locations have been tried, it removes
|
|
219
|
+
* the failover information for the partition key range. Return True if the failover information was successfully
|
|
220
|
+
* updated and the request was routed to a new location, otherwise false.
|
|
221
|
+
*/
|
|
222
|
+
async tryAddOrUpdatePartitionFailoverInfoAndMoveToNextLocation(partitionKeyRangeId, failedEndPoint, nextEndPoints, partitionKeyRangeToLocation, diagnosticNode) {
|
|
223
|
+
if (!partitionKeyRangeToLocation.has(partitionKeyRangeId)) {
|
|
224
|
+
// If the partition key range is not already in the map, add it
|
|
225
|
+
const failoverInfo = new PartitionKeyRangeFailoverInfo(failedEndPoint);
|
|
226
|
+
partitionKeyRangeToLocation.set(partitionKeyRangeId, failoverInfo);
|
|
227
|
+
}
|
|
228
|
+
const partitionFailOver = partitionKeyRangeToLocation.get(partitionKeyRangeId);
|
|
229
|
+
// Will return true if it was able to update to a new region
|
|
230
|
+
if (await partitionFailOver.tryMoveNextLocation(nextEndPoints, failedEndPoint, diagnosticNode, partitionKeyRangeId)) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
// All the locations have been tried. Remove the override information
|
|
234
|
+
partitionKeyRangeToLocation.delete(partitionKeyRangeId);
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Initiates a background loop that periodically checks for unhealthy endpoints
|
|
239
|
+
* and attempts to open connections to them. If a connection is successfully
|
|
240
|
+
* established, it initiates a failback to the original location for the partition key range.
|
|
241
|
+
* This is useful for scenarios where a partition key range has been marked as unavailable
|
|
242
|
+
* due to a circuit breaker, and we want to periodically check if the original location
|
|
243
|
+
* has become healthy again.
|
|
244
|
+
* The loop runs at a defined interval specified by Constants.StalePartitionUnavailabilityRefreshIntervalInMs.
|
|
245
|
+
*/
|
|
246
|
+
initiateCircuitBreakerFailbackLoop() {
|
|
247
|
+
this.circuitBreakerFailbackBackgroundRefresher = startBackgroundTask(async () => {
|
|
248
|
+
try {
|
|
249
|
+
await this.openConnectionToUnhealthyEndpointsWithFailback();
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
console.error("Failed to open connection to unhealthy endpoints: ", err);
|
|
253
|
+
}
|
|
254
|
+
}, Constants.StalePartitionUnavailabilityRefreshIntervalInMs);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Attempts to open connections to unhealthy endpoints and initiates failback if the connections are successful.
|
|
258
|
+
* This method checks the partition key ranges that have failed locations and tries to re-establish connections
|
|
259
|
+
* to those locations. If a connection is successfully re-established, it initiates a failback to the original
|
|
260
|
+
* location for the partition key range.
|
|
261
|
+
*/
|
|
262
|
+
async openConnectionToUnhealthyEndpointsWithFailback() {
|
|
263
|
+
for (const pkRange of this.partitionKeyRangeToLocationForReadAndWrite.keys()) {
|
|
264
|
+
const partitionFailover = this.partitionKeyRangeToLocationForReadAndWrite.get(pkRange);
|
|
265
|
+
if (!partitionFailover)
|
|
266
|
+
continue;
|
|
267
|
+
const { firstRequestFailureTime } = await partitionFailover.snapshotPartitionFailoverTimestamps();
|
|
268
|
+
const now = new Date();
|
|
269
|
+
if (now.getTime() - firstRequestFailureTime >
|
|
270
|
+
Constants.AllowedPartitionUnavailabilityDurationInMs) {
|
|
271
|
+
// Un-deterministically marking the original failed endpoint for the PkRange back to healthy.
|
|
272
|
+
// Initiate Failback to the original failed location.
|
|
273
|
+
this.partitionKeyRangeToLocationForReadAndWrite.delete(pkRange);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=globalPartitionEndpointManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globalPartitionEndpointManager.js","sourceRoot":"","sources":["../../src/globalPartitionEndpointManager.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EACL,SAAS,GAKV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;GAGG;AACH,MAAM,OAAO,8BAA8B;IAYzC;;OAEG;IACH,YACE,OAA4B,EACpB,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;QAEpD,IAAI,CAAC,mCAAmC,GAAG,IAAI,GAAG,EAAyC,CAAC;QAC5F,IAAI,CAAC,0CA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AAE,CAAC;YAEvB,IACE,GAAG,CAAC,OAAO,EAAE,GAAG,uBAAuB;gBACvC,SAAS,CAAC,0CAA0C,EACpD,CAAC;gBACD,6FAA6F;gBAC7F,qDAAqD;gBACrD,IAAI,CAAC,0CAA0C,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { OperationType, ResourceType, isReadRequest } from \"./common/index.js\";\nimport {\n Constants,\n DiagnosticNodeInternal,\n type CosmosClientOptions,\n type GlobalEndpointManager,\n type RequestContext,\n} from \"./index.js\";\nimport { PartitionKeyRangeFailoverInfo } from \"./PartitionKeyRangeFailoverInfo.js\";\nimport { normalizeEndpoint } from \"./utils/checkURL.js\";\nimport { startBackgroundTask } from \"./utils/time.js\";\nimport { assertNotUndefined } from \"./utils/typeChecks.js\";\n\n/**\n * @hidden\n * This class is used to failover single partitions to different regions.\n */\nexport class GlobalPartitionEndpointManager {\n private readonly partitionKeyRangeToLocationForWrite: Map<string, PartitionKeyRangeFailoverInfo>;\n private readonly partitionKeyRangeToLocationForReadAndWrite: Map<\n string,\n PartitionKeyRangeFailoverInfo\n >;\n private enablePartitionLevelFailover: boolean;\n private enablePartitionLevelCircuitBreaker: boolean;\n private preferredLocations: string[];\n public preferredLocationsCount: number;\n private circuitBreakerFailbackBackgroundRefresher: NodeJS.Timeout;\n\n /**\n * @internal\n */\n constructor(\n options: CosmosClientOptions,\n private globalEndpointManager: GlobalEndpointManager,\n ) {\n this.partitionKeyRangeToLocationForWrite = new Map<string, PartitionKeyRangeFailoverInfo>();\n this.partitionKeyRangeToLocationForReadAndWrite = new Map<\n string,\n PartitionKeyRangeFailoverInfo\n >();\n\n this.enablePartitionLevelFailover = options.connectionPolicy.enablePartitionLevelFailover;\n this.enablePartitionLevelCircuitBreaker =\n options.connectionPolicy.enablePartitionLevelCircuitBreaker ||\n options.connectionPolicy.enablePartitionLevelFailover;\n\n this.preferredLocations = options.connectionPolicy.preferredLocations;\n this.preferredLocationsCount = this.preferredLocations ? this.preferredLocations.length : 0;\n if (this.enablePartitionLevelCircuitBreaker) {\n this.initiateCircuitBreakerFailbackLoop();\n }\n }\n\n /**\n * Checks eligibility of the request for partition failover and\n * tries to mark the endpoint unavailable for the partition key range. Future\n * requests will be routed to the next location if available.\n */\n public async tryPartitionLevelFailover(\n requestContext: RequestContext,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<boolean> {\n if (!(await this.isRequestEligibleForPartitionFailover(requestContext, true))) {\n return false;\n }\n\n const isRequestEligibleForPerPartitionAutomaticFailover =\n this.isRequestEligibleForPerPartitionAutomaticFailover(requestContext);\n const isRequestEligibleForPartitionLevelCircuitBreaker =\n this.isRequestEligibleForPartitionLevelCircuitBreaker(requestContext);\n\n if (\n isRequestEligibleForPerPartitionAutomaticFailover ||\n (isRequestEligibleForPartitionLevelCircuitBreaker &&\n (await this.incrementFailureCounterAndCheckFailover(\n requestContext,\n isRequestEligibleForPerPartitionAutomaticFailover,\n isRequestEligibleForPartitionLevelCircuitBreaker,\n )))\n ) {\n return this.tryMarkEndpointUnavailableForPartitionKeyRange(\n requestContext,\n diagnosticNode,\n isRequestEligibleForPerPartitionAutomaticFailover,\n isRequestEligibleForPartitionLevelCircuitBreaker,\n );\n }\n return false;\n }\n\n /**\n * Updates the DocumentServiceRequest routing location to point\n * new a location based if a partition level failover occurred.\n */\n public async tryAddPartitionLevelLocationOverride(\n requestContext: RequestContext,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<RequestContext> {\n if (!(await this.isRequestEligibleForPartitionFailover(requestContext, false))) {\n return requestContext;\n }\n\n const partitionKeyRangeId = requestContext.partitionKeyRangeId;\n\n if (this.isRequestEligibleForPerPartitionAutomaticFailover(requestContext)) {\n if (this.partitionKeyRangeToLocationForWrite.has(partitionKeyRangeId)) {\n const partitionFailOver = this.partitionKeyRangeToLocationForWrite.get(partitionKeyRangeId);\n requestContext.endpoint = partitionFailOver.getCurrentEndPoint();\n diagnosticNode.recordEndpointResolution(requestContext.endpoint);\n return requestContext;\n }\n } else if (this.isRequestEligibleForPartitionLevelCircuitBreaker(requestContext)) {\n if (this.partitionKeyRangeToLocationForReadAndWrite.has(partitionKeyRangeId)) {\n const partitionFailOver =\n this.partitionKeyRangeToLocationForReadAndWrite.get(partitionKeyRangeId);\n\n const canCircuitBreakerTriggerPartitionFailOver =\n await partitionFailOver.canCircuitBreakerTriggerPartitionFailOver(\n isReadRequest(requestContext.operationType),\n );\n if (canCircuitBreakerTriggerPartitionFailOver) {\n requestContext.endpoint = partitionFailOver.getCurrentEndPoint();\n diagnosticNode.recordEndpointResolution(requestContext.endpoint);\n return requestContext;\n }\n }\n }\n return requestContext;\n }\n\n /**\n * This method clears the background refresher for circuit breaker failback\n * and stops the periodic checks for unhealthy endpoints.\n */\n public dispose(): void {\n if (this.circuitBreakerFailbackBackgroundRefresher) {\n clearTimeout(this.circuitBreakerFailbackBackgroundRefresher);\n }\n }\n\n private async tryMarkEndpointUnavailableForPartitionKeyRange(\n requestContext: RequestContext,\n diagnosticNode: DiagnosticNodeInternal,\n isRequestEligibleForPerPartitionAutomaticFailover: boolean,\n isRequestEligibleForPartitionLevelCircuitBreaker: boolean,\n ): Promise<boolean> {\n const partitionKeyRangeId = requestContext.partitionKeyRangeId;\n const failedEndPoint = requestContext.endpoint;\n\n const readLocations = await this.globalEndpointManager.getReadLocations();\n const readEndPoints: string[] = [];\n\n if (isRequestEligibleForPerPartitionAutomaticFailover) {\n // For any single master write accounts, the next locations to fail over will be the read regions configured at the account level.\n for (const location of readLocations) {\n readEndPoints.push(location.databaseAccountEndpoint);\n }\n return this.tryAddOrUpdatePartitionFailoverInfoAndMoveToNextLocation(\n partitionKeyRangeId,\n failedEndPoint,\n readEndPoints,\n this.partitionKeyRangeToLocationForWrite,\n diagnosticNode,\n );\n } else if (isRequestEligibleForPartitionLevelCircuitBreaker) {\n // For the read requests or multi-master write requests, the next locations to fail over will be the preferred locations\n // configured at the account level plus any other read locations that are not already in the preferred locations.\n if (this.preferredLocations && this.preferredLocations.length > 0) {\n for (const preferredLocation of this.preferredLocations) {\n const location = readLocations.find(\n (loc) => normalizeEndpoint(loc.name) === normalizeEndpoint(preferredLocation),\n );\n if (location) {\n readEndPoints.push(location.databaseAccountEndpoint);\n }\n }\n\n // Add the rest of the locations not already added\n for (const location of readLocations) {\n if (!readEndPoints.includes(location.databaseAccountEndpoint)) {\n readEndPoints.push(location.databaseAccountEndpoint);\n }\n }\n } else {\n for (const location of readLocations) {\n readEndPoints.push(location.databaseAccountEndpoint);\n }\n }\n return this.tryAddOrUpdatePartitionFailoverInfoAndMoveToNextLocation(\n partitionKeyRangeId,\n failedEndPoint,\n readEndPoints,\n this.partitionKeyRangeToLocationForReadAndWrite,\n diagnosticNode,\n );\n }\n return false;\n }\n\n /**\n * Increments the failure counter for the specified partition and checks if the partition can fail over.\n * This method is used to determine if a partition should be failed over based on the number of request failures.\n */\n private async incrementFailureCounterAndCheckFailover(\n requestContext: RequestContext,\n isRequestEligibleForPerPartitionAutomaticFailover: boolean,\n isRequestEligibleForPartitionLevelCircuitBreaker: boolean,\n ): Promise<boolean> {\n const partitionKeyRangeId = requestContext.partitionKeyRangeId;\n const failedEndPoint = requestContext.endpoint;\n let partitionKeyRangeFailoverInfo: PartitionKeyRangeFailoverInfo;\n\n if (isRequestEligibleForPerPartitionAutomaticFailover) {\n if (!this.partitionKeyRangeToLocationForWrite.has(partitionKeyRangeId)) {\n // If the partition key range is not already in the map, add it\n const failoverInfo = new PartitionKeyRangeFailoverInfo(failedEndPoint);\n this.partitionKeyRangeToLocationForWrite.set(partitionKeyRangeId, failoverInfo);\n }\n partitionKeyRangeFailoverInfo =\n this.partitionKeyRangeToLocationForWrite.get(partitionKeyRangeId);\n } else if (isRequestEligibleForPartitionLevelCircuitBreaker) {\n if (!this.partitionKeyRangeToLocationForReadAndWrite.has(partitionKeyRangeId)) {\n // If the partition key range is not already in the map, add it\n const failoverInfo = new PartitionKeyRangeFailoverInfo(failedEndPoint);\n this.partitionKeyRangeToLocationForReadAndWrite.set(partitionKeyRangeId, failoverInfo);\n }\n partitionKeyRangeFailoverInfo =\n this.partitionKeyRangeToLocationForReadAndWrite.get(partitionKeyRangeId);\n } else {\n return false;\n }\n\n assertNotUndefined(\n partitionKeyRangeFailoverInfo,\n \"partitionKeyRangeFailoverInfo should be set if failover flags are true.\",\n );\n\n const currentTimeInMilliseconds = Date.now();\n await partitionKeyRangeFailoverInfo.incrementRequestFailureCounts(\n isReadRequest(requestContext.operationType),\n currentTimeInMilliseconds,\n );\n\n return partitionKeyRangeFailoverInfo.canCircuitBreakerTriggerPartitionFailOver(\n isReadRequest(requestContext.operationType),\n );\n }\n\n /** Validates if the given request is eligible for partition failover. */\n private async isRequestEligibleForPartitionFailover(\n requestContext: RequestContext,\n shouldValidateFailedLocation: boolean,\n ): Promise<boolean> {\n if (\n !requestContext ||\n !requestContext.operationType ||\n !requestContext.resourceType ||\n !requestContext.partitionKeyRangeId\n ) {\n return false;\n }\n\n const canUsePartitionLevelFailoverLocations = await this.canUsePartitionLevelFailoverLocations(\n requestContext.operationType,\n requestContext.resourceType,\n );\n if (!canUsePartitionLevelFailoverLocations) {\n return false;\n }\n\n if (shouldValidateFailedLocation && !requestContext.endpoint) {\n return false;\n }\n return true;\n }\n\n /** Determines if partition level failover locations can be used for the given request. */\n private async canUsePartitionLevelFailoverLocations(\n operationType?: OperationType,\n resourceType?: ResourceType,\n ): Promise<boolean> {\n const readEndPoints = await this.globalEndpointManager.getReadEndpoints();\n if (readEndPoints.length <= 1) {\n return false;\n }\n if (\n resourceType === ResourceType.item ||\n (resourceType === ResourceType.sproc && operationType === OperationType.Execute)\n ) {\n // Right now, for single-master only reads are supported for circuit breaker, and writes are supported for automatic.\n // failover. For multi master, both reads and writes are supported. Hence return true for both the cases.\n return true;\n }\n return false;\n }\n\n /**\n * Determines if a request is eligible for per-partition automatic failover.\n * A request is eligible if it is a write request, partition level failover is enabled,\n * and the global endpoint manager cannot use multiple write locations for the request.\n */\n private isRequestEligibleForPerPartitionAutomaticFailover(\n requestContext: RequestContext,\n ): boolean {\n return (\n this.enablePartitionLevelFailover &&\n !isReadRequest(requestContext.operationType) &&\n !this.globalEndpointManager.canUseMultipleWriteLocations(\n requestContext.resourceType,\n requestContext.operationType,\n )\n );\n }\n\n /**\n * Determines if a request is eligible for partition-level circuit breaker.\n * This method checks if partition-level circuit breaker is enabled, and if the request is a read-only request or\n * the global endpoint manager can use multiple write locations for the request.\n */\n private isRequestEligibleForPartitionLevelCircuitBreaker(\n requestContext: RequestContext,\n ): boolean {\n if (!this.enablePartitionLevelCircuitBreaker) {\n return false;\n }\n if (isReadRequest(requestContext.operationType)) {\n return true;\n }\n return this.globalEndpointManager.canUseMultipleWriteLocations(\n requestContext.resourceType,\n requestContext.operationType,\n );\n }\n\n /**\n * Attempts to add or update the partition failover information and move to the next available location.\n * This method checks if the current location for the partition key range has failed and updates the failover\n * information to route the request to the next available location. If all locations have been tried, it removes\n * the failover information for the partition key range. Return True if the failover information was successfully\n * updated and the request was routed to a new location, otherwise false.\n */\n private async tryAddOrUpdatePartitionFailoverInfoAndMoveToNextLocation(\n partitionKeyRangeId: string,\n failedEndPoint: string,\n nextEndPoints: readonly string[],\n partitionKeyRangeToLocation: Map<string, PartitionKeyRangeFailoverInfo>,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<boolean> {\n if (!partitionKeyRangeToLocation.has(partitionKeyRangeId)) {\n // If the partition key range is not already in the map, add it\n const failoverInfo = new PartitionKeyRangeFailoverInfo(failedEndPoint);\n partitionKeyRangeToLocation.set(partitionKeyRangeId, failoverInfo);\n }\n const partitionFailOver = partitionKeyRangeToLocation.get(partitionKeyRangeId);\n\n // Will return true if it was able to update to a new region\n if (\n await partitionFailOver.tryMoveNextLocation(\n nextEndPoints,\n failedEndPoint,\n diagnosticNode,\n partitionKeyRangeId,\n )\n ) {\n return true;\n }\n // All the locations have been tried. Remove the override information\n partitionKeyRangeToLocation.delete(partitionKeyRangeId);\n return false;\n }\n\n /**\n * Initiates a background loop that periodically checks for unhealthy endpoints\n * and attempts to open connections to them. If a connection is successfully\n * established, it initiates a failback to the original location for the partition key range.\n * This is useful for scenarios where a partition key range has been marked as unavailable\n * due to a circuit breaker, and we want to periodically check if the original location\n * has become healthy again.\n * The loop runs at a defined interval specified by Constants.StalePartitionUnavailabilityRefreshIntervalInMs.\n */\n private initiateCircuitBreakerFailbackLoop(): void {\n this.circuitBreakerFailbackBackgroundRefresher = startBackgroundTask(async () => {\n try {\n await this.openConnectionToUnhealthyEndpointsWithFailback();\n } catch (err) {\n console.error(\"Failed to open connection to unhealthy endpoints: \", err);\n }\n }, Constants.StalePartitionUnavailabilityRefreshIntervalInMs);\n }\n\n /**\n * Attempts to open connections to unhealthy endpoints and initiates failback if the connections are successful.\n * This method checks the partition key ranges that have failed locations and tries to re-establish connections\n * to those locations. If a connection is successfully re-established, it initiates a failback to the original\n * location for the partition key range.\n */\n private async openConnectionToUnhealthyEndpointsWithFailback(): Promise<void> {\n for (const pkRange of this.partitionKeyRangeToLocationForReadAndWrite.keys()) {\n const partitionFailover = this.partitionKeyRangeToLocationForReadAndWrite.get(pkRange);\n if (!partitionFailover) continue;\n\n const { firstRequestFailureTime } =\n await partitionFailover.snapshotPartitionFailoverTimestamps();\n const now = new Date();\n\n if (\n now.getTime() - firstRequestFailureTime >\n Constants.AllowedPartitionUnavailabilityDurationInMs\n ) {\n // Un-deterministically marking the original failed endpoint for the PkRange back to healthy.\n // Initiate Failback to the original failed location.\n this.partitionKeyRangeToLocationForReadAndWrite.delete(pkRange);\n }\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/queryExecutionContext/Aggregators/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAIpE,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,GAE1B,iBAAiB,GACjB,eAAe,GACf,aAAa,GACb,aAAa,GACb,aAAa,GACb,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/queryExecutionContext/Aggregators/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAIpE,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,GAE1B,iBAAiB,GACjB,eAAe,GACf,aAAa,GACb,aAAa,GACb,aAAa,GACb,qBAAqB,CAoBxB;AAED,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/queryExecutionContext/Aggregators/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAU,gBAAgB,CAC9B,aAA4B;IAQ5B,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,SAAS;YACZ,OAAO,IAAI,iBAAiB,EAAE,CAAC;QACjC,KAAK,OAAO;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/queryExecutionContext/Aggregators/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAU,gBAAgB,CAC9B,aAA4B;IAQ5B,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,SAAS;YACZ,OAAO,IAAI,iBAAiB,EAAE,CAAC;QACjC,KAAK,OAAO,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,IAAI,eAAe,EAAE,CAAC;QAC/B,KAAK,KAAK;YACR,OAAO,IAAI,aAAa,EAAE,CAAC;QAC7B,KAAK,KAAK;YACR,OAAO,IAAI,aAAa,EAAE,CAAC;QAC7B,KAAK,KAAK;YACR,OAAO,IAAI,aAAa,EAAE,CAAC;QAC7B,KAAK,UAAU;YACb,OAAO,IAAI,kBAAkB,EAAE,CAAC;QAClC,KAAK,SAAS;YACZ,OAAO,IAAI,iBAAiB,EAAE,CAAC;QACjC;YACE,OAAO,IAAI,qBAAqB,EAAE,CAAC;IACvC,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { AverageAggregator } from \"./AverageAggregator.js\";\nimport { CountAggregator } from \"./CountAggregator.js\";\nimport { MaxAggregator } from \"./MaxAggregator.js\";\nimport { MinAggregator } from \"./MinAggregator.js\";\nimport { SumAggregator } from \"./SumAggregator.js\";\nimport { StaticValueAggregator } from \"./StaticValueAggregator.js\";\nimport type { AggregateType } from \"../../request/ErrorResponse.js\";\nimport { MakeListAggregator } from \"./MakeListAggregator.js\";\nimport { MakeSetAggregator } from \"./MakeSetAggregator.js\";\n\nexport function createAggregator(\n aggregateType: AggregateType,\n):\n | AverageAggregator\n | CountAggregator\n | MaxAggregator\n | MinAggregator\n | SumAggregator\n | StaticValueAggregator {\n switch (aggregateType) {\n case \"Average\":\n return new AverageAggregator();\n case \"Count\":\n case \"CountIf\":\n return new CountAggregator();\n case \"Max\":\n return new MaxAggregator();\n case \"Min\":\n return new MinAggregator();\n case \"Sum\":\n return new SumAggregator();\n case \"MakeList\":\n return new MakeListAggregator();\n case \"MakeSet\":\n return new MakeSetAggregator();\n default:\n return new StaticValueAggregator();\n }\n}\n\nexport { AverageAggregator, CountAggregator, MaxAggregator, MinAggregator, SumAggregator };\nexport { Aggregator } from \"./Aggregator.js\";\n"]}
|
|
@@ -5,6 +5,7 @@ import type { FeedOptions } from "../request/index.js";
|
|
|
5
5
|
import type { Response } from "../request/index.js";
|
|
6
6
|
import type { FetchFunctionCallback } from "./defaultQueryExecutionContext.js";
|
|
7
7
|
import { FetchResult } from "./FetchResult.js";
|
|
8
|
+
import type { CosmosHeaders } from "./headerUtils.js";
|
|
8
9
|
import type { SqlQuerySpec } from "./index.js";
|
|
9
10
|
/** @hidden */
|
|
10
11
|
export declare class DocumentProducer {
|
|
@@ -18,7 +19,6 @@ export declare class DocumentProducer {
|
|
|
18
19
|
previousContinuationToken: string;
|
|
19
20
|
continuationToken: string;
|
|
20
21
|
generation: number;
|
|
21
|
-
private respHeaders;
|
|
22
22
|
private internalExecutionContext;
|
|
23
23
|
startEpk: string;
|
|
24
24
|
endEpk: string;
|
|
@@ -36,13 +36,12 @@ export declare class DocumentProducer {
|
|
|
36
36
|
fetchFunction: FetchFunctionCallback;
|
|
37
37
|
hasMoreResults(): boolean;
|
|
38
38
|
gotSplit(): boolean;
|
|
39
|
-
private _getAndResetActiveResponseHeaders;
|
|
40
39
|
private _updateStates;
|
|
41
40
|
private static _needPartitionKeyRangeCacheRefresh;
|
|
42
41
|
/**
|
|
43
42
|
* Fetches and bufferes the next page of results in internal buffer
|
|
44
43
|
*/
|
|
45
|
-
bufferMore(diagnosticNode: DiagnosticNodeInternal): Promise<
|
|
44
|
+
bufferMore(diagnosticNode: DiagnosticNodeInternal): Promise<CosmosHeaders>;
|
|
46
45
|
getTargetParitionKeyRange(): PartitionKeyRange;
|
|
47
46
|
/**
|
|
48
47
|
* Peak the next item in the buffer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentProducer.d.ts","sourceRoot":"","sources":["../../../src/queryExecutionContext/documentProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAY,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAmB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"documentProducer.d.ts","sourceRoot":"","sources":["../../../src/queryExecutionContext/documentProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAY,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAmB,MAAM,kBAAkB,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,cAAc;AACd,qBAAa,gBAAgB;IAwBzB,OAAO,CAAC,aAAa;IAvBvB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,KAAK,CAAwB;IAC9B,uBAAuB,EAAE,iBAAiB,CAAC;IAC3C,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAQ;IACZ,yBAAyB,EAAE,MAAM,CAAC;IAClC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAK;IAC9B,OAAO,CAAC,wBAAwB,CAA+B;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,EAAE,OAAO,CAAC;IAExC;;;;;;;OAOG;gBAEO,aAAa,EAAE,aAAa,EACpC,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,YAAY,EACnB,uBAAuB,EAAE,iBAAiB,EAC1C,OAAO,EAAE,WAAW,EACpB,oBAAoB,EAAE,MAAM,EAC5B,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EACf,uBAAuB,GAAE,OAAe;IAuBnC,iBAAiB,IAAI,GAAG,EAAE;IAmB1B,aAAa,EAAE,qBAAqB,CAwBzC;IAEK,cAAc,IAAI,OAAO;IAIzB,QAAQ,IAAI,OAAO;IAY1B,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,MAAM,CAAC,kCAAkC;IASjD;;OAEG;IACU,UAAU,CAAC,cAAc,EAAE,sBAAsB,GAAG,OAAO,CAAC,aAAa,CAAC;IAkDhF,yBAAyB,IAAI,iBAAiB;IAGrD;;OAEG;IACI,YAAY,IAAI,GAAG;IAqB1B;;OAEG;IACU,aAAa,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAoBpD;;OAEG;IACU,kBAAkB,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IA6B3D;;OAEG;IACH,OAAO,CAAC,OAAO;CAiChB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Constants, getIdFromLink, getPathFromLink, ResourceType, StatusCodes, SubStatusCodes, } from "../common/index.js";
|
|
2
2
|
import { DefaultQueryExecutionContext } from "./defaultQueryExecutionContext.js";
|
|
3
3
|
import { FetchResult, FetchResultType } from "./FetchResult.js";
|
|
4
|
-
import { getInitialHeader
|
|
4
|
+
import { getInitialHeader } from "./headerUtils.js";
|
|
5
5
|
/** @hidden */
|
|
6
6
|
export class DocumentProducer {
|
|
7
7
|
/**
|
|
@@ -44,7 +44,6 @@ export class DocumentProducer {
|
|
|
44
44
|
this.err = undefined;
|
|
45
45
|
this.previousContinuationToken = undefined;
|
|
46
46
|
this.continuationToken = undefined;
|
|
47
|
-
this.respHeaders = getInitialHeader();
|
|
48
47
|
this.internalExecutionContext = new DefaultQueryExecutionContext(options, this.fetchFunction, correlatedActivityId);
|
|
49
48
|
this.startEpk = startEpk;
|
|
50
49
|
this.endEpk = endEpk;
|
|
@@ -82,11 +81,6 @@ export class DocumentProducer {
|
|
|
82
81
|
}
|
|
83
82
|
return false;
|
|
84
83
|
}
|
|
85
|
-
_getAndResetActiveResponseHeaders() {
|
|
86
|
-
const ret = this.respHeaders;
|
|
87
|
-
this.respHeaders = getInitialHeader();
|
|
88
|
-
return ret;
|
|
89
|
-
}
|
|
90
84
|
_updateStates(err, allFetched) {
|
|
91
85
|
if (err) {
|
|
92
86
|
this.err = err;
|
|
@@ -136,7 +130,7 @@ export class DocumentProducer {
|
|
|
136
130
|
headerResponse[Constants.HttpHeaders.QueryMetrics][this.targetPartitionKeyRange.id] =
|
|
137
131
|
queryMetrics;
|
|
138
132
|
}
|
|
139
|
-
|
|
133
|
+
return headerResponse;
|
|
140
134
|
}
|
|
141
135
|
catch (err) {
|
|
142
136
|
if (DocumentProducer._needPartitionKeyRangeCacheRefresh(err)) {
|
|
@@ -144,7 +138,7 @@ export class DocumentProducer {
|
|
|
144
138
|
// Buffer the error so the execution context can still get the feedResponses in the itemBuffer
|
|
145
139
|
const bufferedError = new FetchResult(undefined, err);
|
|
146
140
|
this.fetchResults.push(bufferedError);
|
|
147
|
-
|
|
141
|
+
return err.headers;
|
|
148
142
|
}
|
|
149
143
|
else {
|
|
150
144
|
this._updateStates(err, err.resources === undefined);
|
|
@@ -184,7 +178,7 @@ export class DocumentProducer {
|
|
|
184
178
|
throw this.err;
|
|
185
179
|
}
|
|
186
180
|
if (this.allFetched) {
|
|
187
|
-
return { result: undefined, headers:
|
|
181
|
+
return { result: undefined, headers: getInitialHeader() };
|
|
188
182
|
}
|
|
189
183
|
try {
|
|
190
184
|
const { result, headers } = this.current();
|
|
@@ -208,23 +202,24 @@ export class DocumentProducer {
|
|
|
208
202
|
throw this.err;
|
|
209
203
|
}
|
|
210
204
|
if (this.allFetched) {
|
|
211
|
-
return { result: undefined, headers:
|
|
205
|
+
return { result: undefined, headers: getInitialHeader() };
|
|
212
206
|
}
|
|
213
207
|
const resources = [];
|
|
214
|
-
const resHeaders = getInitialHeader();
|
|
215
208
|
try {
|
|
216
209
|
while (this.fetchResults.length > 0) {
|
|
217
|
-
const { result
|
|
210
|
+
const { result } = this.current();
|
|
218
211
|
this._updateStates(undefined, result === undefined);
|
|
219
|
-
mergeHeaders(resHeaders, headers);
|
|
220
212
|
if (result === undefined) {
|
|
221
|
-
return {
|
|
213
|
+
return {
|
|
214
|
+
result: resources.length > 0 ? resources : undefined,
|
|
215
|
+
headers: getInitialHeader(),
|
|
216
|
+
};
|
|
222
217
|
}
|
|
223
218
|
else {
|
|
224
219
|
resources.push(result);
|
|
225
220
|
}
|
|
226
221
|
}
|
|
227
|
-
return { result: resources, headers:
|
|
222
|
+
return { result: resources, headers: getInitialHeader() };
|
|
228
223
|
}
|
|
229
224
|
catch (err) {
|
|
230
225
|
this._updateStates(err, err.item === undefined);
|
|
@@ -243,15 +238,15 @@ export class DocumentProducer {
|
|
|
243
238
|
case FetchResultType.Done:
|
|
244
239
|
return {
|
|
245
240
|
result: undefined,
|
|
246
|
-
headers:
|
|
241
|
+
headers: getInitialHeader(),
|
|
247
242
|
};
|
|
248
243
|
case FetchResultType.Exception:
|
|
249
|
-
fetchResult.error.headers =
|
|
244
|
+
fetchResult.error.headers = getInitialHeader();
|
|
250
245
|
throw fetchResult.error;
|
|
251
246
|
case FetchResultType.Result:
|
|
252
247
|
return {
|
|
253
248
|
result: fetchResult.feedResponse,
|
|
254
|
-
headers:
|
|
249
|
+
headers: getInitialHeader(),
|
|
255
250
|
};
|
|
256
251
|
}
|
|
257
252
|
}
|
|
@@ -259,11 +254,11 @@ export class DocumentProducer {
|
|
|
259
254
|
if (this.allFetched) {
|
|
260
255
|
return {
|
|
261
256
|
result: undefined,
|
|
262
|
-
headers:
|
|
257
|
+
headers: getInitialHeader(),
|
|
263
258
|
};
|
|
264
259
|
}
|
|
265
260
|
// If the internal buffer is empty, return empty result
|
|
266
|
-
return { result: [], headers:
|
|
261
|
+
return { result: [], headers: getInitialHeader() };
|
|
267
262
|
}
|
|
268
263
|
}
|
|
269
264
|
//# sourceMappingURL=documentProducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentProducer.js","sourceRoot":"","sources":["../../../src/queryExecutionContext/documentProducer.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,cAAc,GACf,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIlE,cAAc;AACd,MAAM,OAAO,gBAAgB;IAgB3B;;;;;;;OAOG;IACH,YACU,aAA4B,EACpC,cAAsB,EACtB,KAAmB,EACnB,uBAA0C,EAC1C,OAAoB,EACpB,oBAA4B,EAC5B,QAAiB,EACjB,MAAe,EACf,0BAAmC,KAAK;QARhC,kBAAa,GAAb,aAAa,CAAe;QAhB/B,eAAU,GAAW,CAAC,CAAC;QAmEvB,kBAAa,GAA0B,KAAK,EACjD,cAAsC,EACtC,OAA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C,iCAAiC,EAAE,CAAC;oBACrE,MAAM,WAAW,CAAC,KAAK,CAAC;gBAC1B,KAAK,eAAe,CAAC,MAAM;oBACzB,OAAO;wBACL,MAAM,EAAE,WAAW,CAAC,YAAY;wBAChC,OAAO,EAAE,IAAI,CAAC,iCAAiC,EAAE;qBAClD,CAAC;YACN,CAAC;QACH,CAAC;QAED,qEAAqE;QACrE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,IAAI,CAAC,iCAAiC,EAAE;aAClD,CAAC;QACJ,CAAC;QAED,uDAAuD;QACvD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,iCAAiC,EAAE,EAAE,CAAC;IAC3E,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { PartitionKeyRange, Resource } from \"../client/index.js\";\nimport type { ClientContext } from \"../ClientContext.js\";\nimport {\n Constants,\n getIdFromLink,\n getPathFromLink,\n ResourceType,\n StatusCodes,\n SubStatusCodes,\n} from \"../common/index.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { FeedOptions } from \"../request/index.js\";\nimport type { Response } from \"../request/index.js\";\nimport { DefaultQueryExecutionContext } from \"./defaultQueryExecutionContext.js\";\nimport type { FetchFunctionCallback } from \"./defaultQueryExecutionContext.js\";\nimport { FetchResult, FetchResultType } from \"./FetchResult.js\";\nimport { getInitialHeader, mergeHeaders } from \"./headerUtils.js\";\nimport type { CosmosHeaders } from \"./headerUtils.js\";\nimport type { SqlQuerySpec } from \"./index.js\";\n\n/** @hidden */\nexport class DocumentProducer {\n private collectionLink: string;\n private query: string | SqlQuerySpec;\n public targetPartitionKeyRange: PartitionKeyRange;\n public fetchResults: FetchResult[];\n public allFetched: boolean;\n private err: Error;\n public previousContinuationToken: string;\n public continuationToken: string;\n public generation: number = 0;\n private respHeaders: CosmosHeaders;\n private internalExecutionContext: DefaultQueryExecutionContext;\n public startEpk: string;\n public endEpk: string;\n public populateEpkRangeHeaders: boolean;\n\n /**\n * Provides the Target Partition Range Query Execution Context.\n * @param clientContext - The service endpoint to use to create the client.\n * @param collectionLink - Represents collection link\n * @param query - A SQL query.\n * @param targetPartitionKeyRange - Query Target Partition key Range\n * @hidden\n */\n constructor(\n private clientContext: ClientContext,\n collectionLink: string,\n query: SqlQuerySpec,\n targetPartitionKeyRange: PartitionKeyRange,\n options: FeedOptions,\n correlatedActivityId: string,\n startEpk?: string,\n endEpk?: string,\n populateEpkRangeHeaders: boolean = false,\n ) {\n // TODO: any options\n this.collectionLink = collectionLink;\n this.query = query;\n this.targetPartitionKeyRange = targetPartitionKeyRange;\n this.fetchResults = [];\n\n this.allFetched = false;\n this.err = undefined;\n\n this.previousContinuationToken = undefined;\n this.continuationToken = undefined;\n this.respHeaders = getInitialHeader();\n\n this.internalExecutionContext = new DefaultQueryExecutionContext(\n options,\n this.fetchFunction,\n correlatedActivityId,\n );\n this.startEpk = startEpk;\n this.endEpk = endEpk;\n this.populateEpkRangeHeaders = populateEpkRangeHeaders;\n }\n public peekBufferedItems(): any[] {\n const bufferedResults = [];\n for (let i = 0, done = false; i < this.fetchResults.length && !done; i++) {\n const fetchResult = this.fetchResults[i];\n switch (fetchResult.fetchResultType) {\n case FetchResultType.Done:\n done = true;\n break;\n case FetchResultType.Exception:\n done = true;\n break;\n case FetchResultType.Result:\n bufferedResults.push(fetchResult.feedResponse);\n break;\n }\n }\n return bufferedResults;\n }\n\n public fetchFunction: FetchFunctionCallback = async (\n diagnosticNode: DiagnosticNodeInternal,\n options: FeedOptions,\n correlatedActivityId: string,\n ): Promise<Response<Resource>> => {\n const path = getPathFromLink(this.collectionLink, ResourceType.item);\n diagnosticNode.addData({ partitionKeyRangeId: this.targetPartitionKeyRange.id });\n const id = getIdFromLink(this.collectionLink);\n const startEpk = this.populateEpkRangeHeaders ? this.startEpk : undefined;\n const endEpk = this.populateEpkRangeHeaders ? this.endEpk : undefined;\n\n return this.clientContext.queryFeed({\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n resultFn: (result: any) => result.Documents,\n query: this.query,\n options,\n diagnosticNode,\n partitionKeyRangeId: this.targetPartitionKeyRange[\"id\"],\n correlatedActivityId: correlatedActivityId,\n startEpk: startEpk,\n endEpk: endEpk,\n });\n };\n\n public hasMoreResults(): boolean {\n return this.internalExecutionContext.hasMoreResults() || this.fetchResults.length !== 0;\n }\n\n public gotSplit(): boolean {\n if (this.fetchResults.length !== 0) {\n const fetchResult = this.fetchResults[0];\n if (fetchResult.fetchResultType === FetchResultType.Exception) {\n if (DocumentProducer._needPartitionKeyRangeCacheRefresh(fetchResult.error)) {\n return true;\n }\n }\n }\n return false;\n }\n\n private _getAndResetActiveResponseHeaders(): CosmosHeaders {\n const ret = this.respHeaders;\n this.respHeaders = getInitialHeader();\n return ret;\n }\n\n private _updateStates(err: any, allFetched: boolean): void {\n if (err) {\n this.err = err;\n return;\n }\n if (allFetched) {\n this.allFetched = true;\n }\n if (this.internalExecutionContext.continuationToken === this.continuationToken) {\n // nothing changed\n return;\n }\n this.previousContinuationToken = this.continuationToken;\n this.continuationToken = this.internalExecutionContext.continuationToken;\n }\n\n private static _needPartitionKeyRangeCacheRefresh(error: any): boolean {\n // TODO: error\n return (\n error.code === StatusCodes.Gone &&\n \"substatus\" in error &&\n error[\"substatus\"] === SubStatusCodes.PartitionKeyRangeGone\n );\n }\n\n /**\n * Fetches and bufferes the next page of results in internal buffer\n */\n public async bufferMore(diagnosticNode: DiagnosticNodeInternal): Promise<void> {\n if (this.err) {\n throw this.err;\n }\n\n try {\n const { result: resources, headers: headerResponse } =\n await this.internalExecutionContext.fetchMore(diagnosticNode);\n ++this.generation;\n this._updateStates(undefined, resources === undefined);\n if (resources !== undefined) {\n // add fetched header to the 1st element in the buffer\n let addHeaderToFetchResult = true;\n resources.forEach((element: any) => {\n this.fetchResults.push(\n new FetchResult(\n element,\n undefined,\n addHeaderToFetchResult ? headerResponse : getInitialHeader(),\n ),\n );\n addHeaderToFetchResult = false;\n });\n }\n\n // need to modify the header response so that the query metrics are per partition\n if (headerResponse != null && Constants.HttpHeaders.QueryMetrics in headerResponse) {\n // \"0\" is the default partition before one is actually assigned.\n const queryMetrics = headerResponse[Constants.HttpHeaders.QueryMetrics][\"0\"];\n\n // Wraping query metrics in a object where the keys are the partition key range.\n headerResponse[Constants.HttpHeaders.QueryMetrics] = {};\n headerResponse[Constants.HttpHeaders.QueryMetrics][this.targetPartitionKeyRange.id] =\n queryMetrics;\n }\n mergeHeaders(this.respHeaders, headerResponse);\n } catch (err: any) {\n if (DocumentProducer._needPartitionKeyRangeCacheRefresh(err)) {\n // Split just happend\n // Buffer the error so the execution context can still get the feedResponses in the itemBuffer\n const bufferedError = new FetchResult(undefined, err);\n this.fetchResults.push(bufferedError);\n mergeHeaders(this.respHeaders, err.headers);\n } else {\n this._updateStates(err, err.resources === undefined);\n throw err;\n }\n }\n }\n\n public getTargetParitionKeyRange(): PartitionKeyRange {\n return this.targetPartitionKeyRange;\n }\n /**\n * Peak the next item in the buffer\n */\n public peakNextItem(): any {\n if (this.err) {\n throw this.err;\n }\n if (this.allFetched || this.fetchResults.length === 0) {\n return undefined;\n }\n const fetchResult = this.fetchResults[0];\n\n switch (fetchResult.fetchResultType) {\n case FetchResultType.Done:\n return undefined;\n\n case FetchResultType.Exception: // do not throw this error\n return undefined;\n\n case FetchResultType.Result:\n return fetchResult.feedResponse;\n }\n }\n\n /**\n * Returns the first item in the buffered results if any, or [] otherwise.\n */\n public async fetchNextItem(): Promise<Response<any>> {\n if (this.err) {\n this._updateStates(this.err, undefined);\n throw this.err;\n }\n if (this.allFetched) {\n return { result: undefined, headers: this._getAndResetActiveResponseHeaders() };\n }\n try {\n const { result, headers } = this.current();\n this._updateStates(undefined, result === undefined);\n if (result === undefined || result.length === 0) {\n return { result: undefined, headers };\n }\n return { result, headers }; //\n } catch (err: any) {\n this._updateStates(err, err.item === undefined);\n throw err;\n }\n }\n /**\n * Fetches all the buffered results\n */\n public async fetchBufferedItems(): Promise<Response<any[]>> {\n if (this.err) {\n this._updateStates(this.err, undefined);\n throw this.err;\n }\n if (this.allFetched) {\n return { result: undefined, headers: this._getAndResetActiveResponseHeaders() };\n }\n const resources: any[] = [];\n const resHeaders: CosmosHeaders = getInitialHeader();\n try {\n while (this.fetchResults.length > 0) {\n const { result, headers } = this.current();\n this._updateStates(undefined, result === undefined);\n mergeHeaders(resHeaders, headers);\n if (result === undefined) {\n return { result: resources.length > 0 ? resources : undefined, headers: resHeaders };\n } else {\n resources.push(result);\n }\n }\n return { result: resources, headers: resHeaders };\n } catch (err: any) {\n this._updateStates(err, err.item === undefined);\n throw err;\n }\n }\n\n /**\n * Retrieve the current element on the DocumentProducer.\n */\n private current(): Response<any> {\n // If something is buffered just give that\n if (this.fetchResults.length > 0) {\n const fetchResult = this.fetchResults.shift();\n // Need to unwrap fetch results\n switch (fetchResult.fetchResultType) {\n case FetchResultType.Done:\n return {\n result: undefined,\n headers: this._getAndResetActiveResponseHeaders(),\n };\n case FetchResultType.Exception:\n fetchResult.error.headers = this._getAndResetActiveResponseHeaders();\n throw fetchResult.error;\n case FetchResultType.Result:\n return {\n result: fetchResult.feedResponse,\n headers: this._getAndResetActiveResponseHeaders(),\n };\n }\n }\n\n // If there isn't anymore items left to fetch then let the user know.\n if (this.allFetched) {\n return {\n result: undefined,\n headers: this._getAndResetActiveResponseHeaders(),\n };\n }\n\n // If the internal buffer is empty, return empty result\n return { result: [], headers: this._getAndResetActiveResponseHeaders() };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentProducer.js","sourceRoot":"","sources":["../../../src/queryExecutionContext/documentProducer.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,cAAc,GACf,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,4BAA4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AAS;oBAC5B,WAAW,CAAC,KAAK,CAAC,OAAO,GAAG,gBAAgB,EAAE,CAAC;oBAC/C,MAAM,WAAW,CAAC,KAAK,CAAC;gBAC1B,KAAK,eAAe,CAAC,MAAM;oBACzB,OAAO;wBACL,MAAM,EAAE,WAAW,CAAC,YAAY;wBAChC,OAAO,EAAE,gBAAgB,EAAE;qBAC5B,CAAC;YACN,CAAC;QACH,CAAC;QAED,qEAAqE;QACrE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,gBAAgB,EAAE;aAC5B,CAAC;QACJ,CAAC;QAED,uDAAuD;QACvD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,CAAC;IACrD,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { PartitionKeyRange, Resource } from \"../client/index.js\";\nimport type { ClientContext } from \"../ClientContext.js\";\nimport {\n Constants,\n getIdFromLink,\n getPathFromLink,\n ResourceType,\n StatusCodes,\n SubStatusCodes,\n} from \"../common/index.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { FeedOptions } from \"../request/index.js\";\nimport type { Response } from \"../request/index.js\";\nimport { DefaultQueryExecutionContext } from \"./defaultQueryExecutionContext.js\";\nimport type { FetchFunctionCallback } from \"./defaultQueryExecutionContext.js\";\nimport { FetchResult, FetchResultType } from \"./FetchResult.js\";\nimport { getInitialHeader } from \"./headerUtils.js\";\nimport type { CosmosHeaders } from \"./headerUtils.js\";\nimport type { SqlQuerySpec } from \"./index.js\";\n\n/** @hidden */\nexport class DocumentProducer {\n private collectionLink: string;\n private query: string | SqlQuerySpec;\n public targetPartitionKeyRange: PartitionKeyRange;\n public fetchResults: FetchResult[];\n public allFetched: boolean;\n private err: Error;\n public previousContinuationToken: string;\n public continuationToken: string;\n public generation: number = 0;\n private internalExecutionContext: DefaultQueryExecutionContext;\n public startEpk: string;\n public endEpk: string;\n public populateEpkRangeHeaders: boolean;\n\n /**\n * Provides the Target Partition Range Query Execution Context.\n * @param clientContext - The service endpoint to use to create the client.\n * @param collectionLink - Represents collection link\n * @param query - A SQL query.\n * @param targetPartitionKeyRange - Query Target Partition key Range\n * @hidden\n */\n constructor(\n private clientContext: ClientContext,\n collectionLink: string,\n query: SqlQuerySpec,\n targetPartitionKeyRange: PartitionKeyRange,\n options: FeedOptions,\n correlatedActivityId: string,\n startEpk?: string,\n endEpk?: string,\n populateEpkRangeHeaders: boolean = false,\n ) {\n // TODO: any options\n this.collectionLink = collectionLink;\n this.query = query;\n this.targetPartitionKeyRange = targetPartitionKeyRange;\n this.fetchResults = [];\n\n this.allFetched = false;\n this.err = undefined;\n\n this.previousContinuationToken = undefined;\n this.continuationToken = undefined;\n\n this.internalExecutionContext = new DefaultQueryExecutionContext(\n options,\n this.fetchFunction,\n correlatedActivityId,\n );\n this.startEpk = startEpk;\n this.endEpk = endEpk;\n this.populateEpkRangeHeaders = populateEpkRangeHeaders;\n }\n public peekBufferedItems(): any[] {\n const bufferedResults = [];\n for (let i = 0, done = false; i < this.fetchResults.length && !done; i++) {\n const fetchResult = this.fetchResults[i];\n switch (fetchResult.fetchResultType) {\n case FetchResultType.Done:\n done = true;\n break;\n case FetchResultType.Exception:\n done = true;\n break;\n case FetchResultType.Result:\n bufferedResults.push(fetchResult.feedResponse);\n break;\n }\n }\n return bufferedResults;\n }\n\n public fetchFunction: FetchFunctionCallback = async (\n diagnosticNode: DiagnosticNodeInternal,\n options: FeedOptions,\n correlatedActivityId: string,\n ): Promise<Response<Resource>> => {\n const path = getPathFromLink(this.collectionLink, ResourceType.item);\n diagnosticNode.addData({ partitionKeyRangeId: this.targetPartitionKeyRange.id });\n const id = getIdFromLink(this.collectionLink);\n const startEpk = this.populateEpkRangeHeaders ? this.startEpk : undefined;\n const endEpk = this.populateEpkRangeHeaders ? this.endEpk : undefined;\n\n return this.clientContext.queryFeed({\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n resultFn: (result: any) => result.Documents,\n query: this.query,\n options,\n diagnosticNode,\n partitionKeyRangeId: this.targetPartitionKeyRange[\"id\"],\n correlatedActivityId: correlatedActivityId,\n startEpk: startEpk,\n endEpk: endEpk,\n });\n };\n\n public hasMoreResults(): boolean {\n return this.internalExecutionContext.hasMoreResults() || this.fetchResults.length !== 0;\n }\n\n public gotSplit(): boolean {\n if (this.fetchResults.length !== 0) {\n const fetchResult = this.fetchResults[0];\n if (fetchResult.fetchResultType === FetchResultType.Exception) {\n if (DocumentProducer._needPartitionKeyRangeCacheRefresh(fetchResult.error)) {\n return true;\n }\n }\n }\n return false;\n }\n\n private _updateStates(err: any, allFetched: boolean): void {\n if (err) {\n this.err = err;\n return;\n }\n if (allFetched) {\n this.allFetched = true;\n }\n if (this.internalExecutionContext.continuationToken === this.continuationToken) {\n // nothing changed\n return;\n }\n this.previousContinuationToken = this.continuationToken;\n this.continuationToken = this.internalExecutionContext.continuationToken;\n }\n\n private static _needPartitionKeyRangeCacheRefresh(error: any): boolean {\n // TODO: error\n return (\n error.code === StatusCodes.Gone &&\n \"substatus\" in error &&\n error[\"substatus\"] === SubStatusCodes.PartitionKeyRangeGone\n );\n }\n\n /**\n * Fetches and bufferes the next page of results in internal buffer\n */\n public async bufferMore(diagnosticNode: DiagnosticNodeInternal): Promise<CosmosHeaders> {\n if (this.err) {\n throw this.err;\n }\n\n try {\n const { result: resources, headers: headerResponse } =\n await this.internalExecutionContext.fetchMore(diagnosticNode);\n ++this.generation;\n this._updateStates(undefined, resources === undefined);\n if (resources !== undefined) {\n // add fetched header to the 1st element in the buffer\n let addHeaderToFetchResult = true;\n resources.forEach((element: any) => {\n this.fetchResults.push(\n new FetchResult(\n element,\n undefined,\n addHeaderToFetchResult ? headerResponse : getInitialHeader(),\n ),\n );\n addHeaderToFetchResult = false;\n });\n }\n\n // need to modify the header response so that the query metrics are per partition\n if (headerResponse != null && Constants.HttpHeaders.QueryMetrics in headerResponse) {\n // \"0\" is the default partition before one is actually assigned.\n const queryMetrics = headerResponse[Constants.HttpHeaders.QueryMetrics][\"0\"];\n\n // Wraping query metrics in a object where the keys are the partition key range.\n headerResponse[Constants.HttpHeaders.QueryMetrics] = {};\n headerResponse[Constants.HttpHeaders.QueryMetrics][this.targetPartitionKeyRange.id] =\n queryMetrics;\n }\n return headerResponse;\n } catch (err: any) {\n if (DocumentProducer._needPartitionKeyRangeCacheRefresh(err)) {\n // Split just happend\n // Buffer the error so the execution context can still get the feedResponses in the itemBuffer\n const bufferedError = new FetchResult(undefined, err);\n this.fetchResults.push(bufferedError);\n return err.headers;\n } else {\n this._updateStates(err, err.resources === undefined);\n throw err;\n }\n }\n }\n\n public getTargetParitionKeyRange(): PartitionKeyRange {\n return this.targetPartitionKeyRange;\n }\n /**\n * Peak the next item in the buffer\n */\n public peakNextItem(): any {\n if (this.err) {\n throw this.err;\n }\n if (this.allFetched || this.fetchResults.length === 0) {\n return undefined;\n }\n const fetchResult = this.fetchResults[0];\n\n switch (fetchResult.fetchResultType) {\n case FetchResultType.Done:\n return undefined;\n\n case FetchResultType.Exception: // do not throw this error\n return undefined;\n\n case FetchResultType.Result:\n return fetchResult.feedResponse;\n }\n }\n\n /**\n * Returns the first item in the buffered results if any, or [] otherwise.\n */\n public async fetchNextItem(): Promise<Response<any>> {\n if (this.err) {\n this._updateStates(this.err, undefined);\n throw this.err;\n }\n if (this.allFetched) {\n return { result: undefined, headers: getInitialHeader() };\n }\n try {\n const { result, headers } = this.current();\n this._updateStates(undefined, result === undefined);\n if (result === undefined || result.length === 0) {\n return { result: undefined, headers };\n }\n return { result, headers }; //\n } catch (err: any) {\n this._updateStates(err, err.item === undefined);\n throw err;\n }\n }\n /**\n * Fetches all the buffered results\n */\n public async fetchBufferedItems(): Promise<Response<any[]>> {\n if (this.err) {\n this._updateStates(this.err, undefined);\n throw this.err;\n }\n if (this.allFetched) {\n return { result: undefined, headers: getInitialHeader() };\n }\n const resources: any[] = [];\n try {\n while (this.fetchResults.length > 0) {\n const { result } = this.current();\n this._updateStates(undefined, result === undefined);\n if (result === undefined) {\n return {\n result: resources.length > 0 ? resources : undefined,\n headers: getInitialHeader(),\n };\n } else {\n resources.push(result);\n }\n }\n return { result: resources, headers: getInitialHeader() };\n } catch (err: any) {\n this._updateStates(err, err.item === undefined);\n throw err;\n }\n }\n\n /**\n * Retrieve the current element on the DocumentProducer.\n */\n private current(): Response<any> {\n // If something is buffered just give that\n if (this.fetchResults.length > 0) {\n const fetchResult = this.fetchResults.shift();\n // Need to unwrap fetch results\n switch (fetchResult.fetchResultType) {\n case FetchResultType.Done:\n return {\n result: undefined,\n headers: getInitialHeader(),\n };\n case FetchResultType.Exception:\n fetchResult.error.headers = getInitialHeader();\n throw fetchResult.error;\n case FetchResultType.Result:\n return {\n result: fetchResult.feedResponse,\n headers: getInitialHeader(),\n };\n }\n }\n\n // If there isn't anymore items left to fetch then let the user know.\n if (this.allFetched) {\n return {\n result: undefined,\n headers: getInitialHeader(),\n };\n }\n\n // If the internal buffer is empty, return empty result\n return { result: [], headers: getInitialHeader() };\n }\n}\n"]}
|