From 32f53bd3d52d2079ceddda895285d4003ecd2547 Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Fri, 12 May 2023 19:58:26 -0700 Subject: [PATCH] Updated release versions to 4.45 for azure-cosmos and azure-cosmos-encryption (#34925) * Updated releaese versions to 4.45 for azure-cosmos and azure-cosmos-encryption * Code review comments * Code / API review comments * Making PriorityLevel a string enum * Renamed end to end timeout APIs * Reverted hot and control plane path timeout changes * Fixed compilation error * renamed latency policy --------- Co-authored-by: Fabian Meiswinkel --- eng/jacoco-test-coverage/pom.xml | 4 +- eng/versioning/version_client.txt | 4 +- sdk/cosmos/azure-cosmos-benchmark/pom.xml | 4 +- .../azure-cosmos-dotnet-benchmark/pom.xml | 2 +- .../azure-cosmos-encryption/CHANGELOG.md | 9 +- sdk/cosmos/azure-cosmos-encryption/README.md | 2 +- sdk/cosmos/azure-cosmos-encryption/pom.xml | 4 +- sdk/cosmos/azure-cosmos-spark_3_2-12/pom.xml | 2 +- sdk/cosmos/azure-cosmos-test/pom.xml | 2 +- sdk/cosmos/azure-cosmos-tests/pom.xml | 2 +- .../azure/cosmos/CosmosDiagnosticsTest.java | 2 +- .../EndToEndTimeOutValidationTests.java | 16 +-- .../EndToEndTimeOutWithSpeculationTest.java | 6 +- .../implementation/HttpTimeoutPolicyTest.java | 106 --------------- .../RxDocumentClientImplTest.java | 6 +- ...ThroughputControlGroupPropertiesTests.java | 14 +- ...tControlGroupConfigConfigurationTests.java | 4 +- .../ThroughputControlTests.java | 2 +- .../LocalThroughputControllerTests.java | 8 +- sdk/cosmos/azure-cosmos/CHANGELOG.md | 4 +- sdk/cosmos/azure-cosmos/README.md | 2 +- .../docs/TimeoutAndRetriesConfig.md | 10 +- sdk/cosmos/azure-cosmos/pom.xml | 2 +- .../java/com/azure/cosmos/BridgeInternal.java | 10 -- .../com/azure/cosmos/CosmosAsyncClient.java | 2 +- .../com/azure/cosmos/CosmosClientBuilder.java | 18 +-- ...EndToEndOperationLatencyPolicyConfig.java} | 4 +- ...dOperationLatencyPolicyConfigBuilder.java} | 16 +-- .../implementation/AsyncDocumentClient.java | 11 +- .../DocumentServiceRequestContext.java | 14 +- .../ImplementationBridgeHelpers.java | 46 ++++++- .../OperationCancelledException.java | 4 +- .../cosmos/implementation/RequestOptions.java | 8 +- .../implementation/RxDocumentClientImpl.java | 39 +++--- .../RxDocumentServiceRequest.java | 5 +- .../implementation/RxGatewayStoreModel.java | 18 ++- .../WebExceptionRetryPolicy.java | 67 ++++------ .../ReplicatedResourceClient.java | 7 +- .../rntbd/RntbdConstants.java | 12 -- .../rntbd/RntbdRequestHeaders.java | 21 ++- .../SpeculativeProcessor.java | 8 +- .../ThresholdBasedSpeculation.java | 8 +- .../HttpTimeoutPolicyControlPlaneHotPath.java | 6 +- .../HttpTimeoutPolicyControlPlaneRead.java | 8 +- .../DocumentQueryExecutionContextBase.java | 18 +-- .../ThroughputControlGroupInternal.java | 2 +- .../models/CosmosItemRequestOptions.java | 16 +-- .../models/CosmosQueryRequestOptions.java | 24 ++-- .../cosmos/models/ModelBridgeInternal.java | 1 + .../azure/cosmos/models/PriorityLevel.java | 122 ++++++++++++++++-- 50 files changed, 357 insertions(+), 375 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/HttpTimeoutPolicyTest.java rename sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/{CosmosE2EOperationRetryPolicyConfig.java => CosmosEndToEndOperationLatencyPolicyConfig.java} (92%) rename sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/{CosmosE2EOperationRetryPolicyConfigBuilder.java => CosmosEndToEndOperationLatencyPolicyConfigBuilder.java} (60%) diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index 4caec7a2f4239..1cd289ece30a1 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -183,12 +183,12 @@ com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 com.azure azure-cosmos-encryption - 2.1.0-beta.1 + 2.1.0 com.azure diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index fbd6704b38752..3e30d2b04a7c5 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -92,14 +92,14 @@ com.azure:azure-core-test;1.17.0;1.18.0-beta.1 com.azure:azure-core-tracing-opentelemetry;1.0.0-beta.35;1.0.0-beta.36 com.azure:azure-core-tracing-opentelemetry-samples;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-core-version-tests;1.0.0-beta.1;1.0.0-beta.1 -com.azure:azure-cosmos;4.44.0;4.45.0-beta.1 +com.azure:azure-cosmos;4.44.0;4.45.0 com.azure:azure-cosmos-benchmark;4.0.1-beta.1;4.0.1-beta.1 com.azure:azure-cosmos-dotnet-benchmark;4.0.1-beta.1;4.0.1-beta.1 com.azure.cosmos.spark:azure-cosmos-spark_3_2-12;1.0.0-beta.1;1.0.0-beta.1 com.azure.cosmos.spark:azure-cosmos-spark_3-1_2-12;4.18.1;4.19.0-beta.1 com.azure.cosmos.spark:azure-cosmos-spark_3-2_2-12;4.18.1;4.19.0-beta.1 com.azure.cosmos.spark:azure-cosmos-spark_3-3_2-12;4.18.1;4.19.0-beta.1 -com.azure:azure-cosmos-encryption;2.0.0;2.1.0-beta.1 +com.azure:azure-cosmos-encryption;2.0.0;2.1.0 com.azure:azure-cosmos-test;1.0.0-beta.3;1.0.0-beta.4 com.azure:azure-cosmos-tests;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-data-appconfiguration;1.4.4;1.5.0-beta.1 diff --git a/sdk/cosmos/azure-cosmos-benchmark/pom.xml b/sdk/cosmos/azure-cosmos-benchmark/pom.xml index 95f6b85645aa4..2c829eddee393 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/pom.xml +++ b/sdk/cosmos/azure-cosmos-benchmark/pom.xml @@ -51,13 +51,13 @@ Licensed under the MIT License. com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 com.azure azure-cosmos-encryption - 2.1.0-beta.1 + 2.1.0 diff --git a/sdk/cosmos/azure-cosmos-dotnet-benchmark/pom.xml b/sdk/cosmos/azure-cosmos-dotnet-benchmark/pom.xml index 17d2e159687fc..1af460195f11f 100644 --- a/sdk/cosmos/azure-cosmos-dotnet-benchmark/pom.xml +++ b/sdk/cosmos/azure-cosmos-dotnet-benchmark/pom.xml @@ -50,7 +50,7 @@ Licensed under the MIT License. com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 diff --git a/sdk/cosmos/azure-cosmos-encryption/CHANGELOG.md b/sdk/cosmos/azure-cosmos-encryption/CHANGELOG.md index e461114bd9d16..bbeb43f35be87 100644 --- a/sdk/cosmos/azure-cosmos-encryption/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos-encryption/CHANGELOG.md @@ -1,14 +1,11 @@ ## Release History -### 2.1.0-beta.1 (Unreleased) - -#### Features Added - -#### Breaking Changes - +### 2.1.0 (2023-05-12) #### Bugs Fixed +* Fixed an issue where empty array causes `NoSuchElementException` in `EncryptionProcessor` - See [PR 34847](https://github.com/Azure/azure-sdk-for-java/pull/34847) #### Other Changes +* Updated `azure-cosmos` to version `4.45.0`. ### 2.0.0 (2023-04-25) diff --git a/sdk/cosmos/azure-cosmos-encryption/README.md b/sdk/cosmos/azure-cosmos-encryption/README.md index e4024856b3ff5..09db95038708e 100644 --- a/sdk/cosmos/azure-cosmos-encryption/README.md +++ b/sdk/cosmos/azure-cosmos-encryption/README.md @@ -12,7 +12,7 @@ The Azure Cosmos Encryption Plugin is used for encrypting data with a user-provi com.azure azure-cosmos-encryption - 2.0.0 + 2.1.0 ``` [//]: # ({x-version-update-end}) diff --git a/sdk/cosmos/azure-cosmos-encryption/pom.xml b/sdk/cosmos/azure-cosmos-encryption/pom.xml index 07f78979578ed..2db90c480049b 100644 --- a/sdk/cosmos/azure-cosmos-encryption/pom.xml +++ b/sdk/cosmos/azure-cosmos-encryption/pom.xml @@ -13,7 +13,7 @@ Licensed under the MIT License. com.azure azure-cosmos-encryption - 2.1.0-beta.1 + 2.1.0 Encryption Plugin for Azure Cosmos DB SDK This Package contains Encryption Plugin for Microsoft Azure Cosmos SDK jar @@ -57,7 +57,7 @@ Licensed under the MIT License. com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 diff --git a/sdk/cosmos/azure-cosmos-spark_3_2-12/pom.xml b/sdk/cosmos/azure-cosmos-spark_3_2-12/pom.xml index 019a8e55459da..86eb25d52088c 100644 --- a/sdk/cosmos/azure-cosmos-spark_3_2-12/pom.xml +++ b/sdk/cosmos/azure-cosmos-spark_3_2-12/pom.xml @@ -63,7 +63,7 @@ com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 org.scala-lang.modules diff --git a/sdk/cosmos/azure-cosmos-test/pom.xml b/sdk/cosmos/azure-cosmos-test/pom.xml index 323a48cfada81..8454c69bb7ec1 100644 --- a/sdk/cosmos/azure-cosmos-test/pom.xml +++ b/sdk/cosmos/azure-cosmos-test/pom.xml @@ -54,7 +54,7 @@ Licensed under the MIT License. com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 diff --git a/sdk/cosmos/azure-cosmos-tests/pom.xml b/sdk/cosmos/azure-cosmos-tests/pom.xml index 9658d1b24858e..3f2709a971fd6 100644 --- a/sdk/cosmos/azure-cosmos-tests/pom.xml +++ b/sdk/cosmos/azure-cosmos-tests/pom.xml @@ -99,7 +99,7 @@ Licensed under the MIT License. com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 com.azure diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java index 485a26c28ada0..317a97c592e84 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java @@ -613,7 +613,7 @@ public void directDiagnosticsOnCancelledOperation() throws Exception { .key(TestConfigurations.MASTER_KEY) .endpoint(TestConfigurations.HOST) .endToEndOperationLatencyPolicyConfig( - new CosmosE2EOperationRetryPolicyConfigBuilder(Duration.ofSeconds(1)).build() + new CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration.ofSeconds(1)).build() ).buildAsyncClient(); CosmosAsyncContainer container = diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutValidationTests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutValidationTests.java index 9da2613040dbe..f7673c8056c20 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutValidationTests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutValidationTests.java @@ -44,13 +44,13 @@ public class EndToEndTimeOutValidationTests extends TestSuiteBase { private CosmosAsyncContainer createdContainer; private final Random random; private final List createdDocuments = new ArrayList<>(); - private final CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig; + private final CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig; @Factory(dataProvider = "clientBuildersWithDirectTcpSession") public EndToEndTimeOutValidationTests(CosmosClientBuilder clientBuilder) { super(clientBuilder); random = new Random(); - endToEndOperationLatencyPolicyConfig = new CosmosE2EOperationRetryPolicyConfigBuilder(Duration.ofSeconds(1)) + endToEndOperationLatencyPolicyConfig = new CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration.ofSeconds(1)) .build(); } @@ -149,12 +149,12 @@ public void queryItemWithEndToEndTimeoutPolicyInOptionsShouldTimeout() { if (getClientBuilder().buildConnectionPolicy().getConnectionMode() != ConnectionMode.DIRECT) { throw new SkipException("Failure injection only supported for DIRECT mode"); } - CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig = - new CosmosE2EOperationRetryPolicyConfigBuilder(Duration.ofSeconds(1)) + CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig = + new CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration.ofSeconds(1)) .build(); CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); - options.setCosmosE2EOperationRetryPolicyConfig(endToEndOperationLatencyPolicyConfig); + options.setCosmosEndToEndOperationLatencyPolicyConfig(endToEndOperationLatencyPolicyConfig); TestObject itemToQuery = createdDocuments.get(random.nextInt(createdDocuments.size())); @@ -234,7 +234,7 @@ public void clientLevelEndToEndTimeoutPolicyInOptionsShouldTimeout() { // with injected delay CosmosItemRequestOptions options = new CosmosItemRequestOptions() .setCosmosEndToEndOperationLatencyPolicyConfig( - new CosmosE2EOperationRetryPolicyConfigBuilder(Duration.ofSeconds(1)) + new CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration.ofSeconds(1)) .enable(false) .build()); cosmosItemResponseMono = @@ -247,8 +247,8 @@ public void clientLevelEndToEndTimeoutPolicyInOptionsShouldTimeout() { // Enabling at client level and disabling at the query item operation level should not fail the request even // with injected delay CosmosQueryRequestOptions queryRequestOptions = new CosmosQueryRequestOptions() - .setCosmosE2EOperationRetryPolicyConfig( - new CosmosE2EOperationRetryPolicyConfigBuilder(Duration.ofSeconds(1)) + .setCosmosEndToEndOperationLatencyPolicyConfig( + new CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration.ofSeconds(1)) .enable(false) .build()); queryPagedFlux = container.queryItems(sqlQuerySpec, queryRequestOptions, TestObject.class); diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutWithSpeculationTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutWithSpeculationTest.java index fd45b71c0ab2e..18b79c855ba16 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutWithSpeculationTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/EndToEndTimeOutWithSpeculationTest.java @@ -50,7 +50,7 @@ public class EndToEndTimeOutWithSpeculationTest extends TestSuiteBase { private CosmosAsyncContainer createdContainer; private final Random random; private final List createdDocuments = new ArrayList<>(); - private final CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig; + private final CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig; // These regions should match the ones in test-resources.json // private final List regions = ImmutableList.of("West Central US", "Central US"); @@ -60,7 +60,7 @@ public class EndToEndTimeOutWithSpeculationTest extends TestSuiteBase { public EndToEndTimeOutWithSpeculationTest(CosmosClientBuilder clientBuilder) { super(clientBuilder); random = new Random(); - endToEndOperationLatencyPolicyConfig = new CosmosE2EOperationRetryPolicyConfigBuilder(Duration.ofSeconds(10)) + endToEndOperationLatencyPolicyConfig = new CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration.ofSeconds(10)) .build(); } @@ -126,7 +126,7 @@ public void queryItemWithEndToEndTimeoutPolicyWithSpeculationShouldNotTimeout() } CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); - options.setCosmosE2EOperationRetryPolicyConfig(endToEndOperationLatencyPolicyConfig); + options.setCosmosEndToEndOperationLatencyPolicyConfig(endToEndOperationLatencyPolicyConfig); TestObject itemToQuery = createdDocuments.get(random.nextInt(createdDocuments.size())); diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/HttpTimeoutPolicyTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/HttpTimeoutPolicyTest.java deleted file mode 100644 index 403a4054cec42..0000000000000 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/HttpTimeoutPolicyTest.java +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.cosmos.implementation; - -import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.CosmosException; -import io.netty.handler.timeout.ReadTimeoutException; -import org.mockito.Mockito; -import org.testng.annotations.Test; -import reactor.core.publisher.Mono; - -import java.lang.reflect.Field; -import java.net.URI; -import java.time.Duration; - -import static com.azure.cosmos.implementation.TestUtils.mockDiagnosticsClientContext; -import static org.assertj.core.api.Assertions.assertThat; - - -public class HttpTimeoutPolicyTest { - private final static String BACKOFF_TIME_PROPERTY_NAME = "backoffSecondsTimeout"; - - @Test(groups = "unit") - public void verifyHttpTimeoutPolicyResponseTimeout() throws Exception { - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(new URI("http://localhost:")).when(endpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - Mockito.doReturn(Mono.empty()).when(endpointManager).refreshLocationAsync(Mockito.eq(null), Mockito.eq(true)); - - - Exception exception = ReadTimeoutException.INSTANCE; - CosmosException cosmosException = BridgeInternal.createCosmosException(null, HttpConstants.StatusCodes.REQUEST_TIMEOUT, exception); - BridgeInternal.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_READ_TIMEOUT); - - RxDocumentServiceRequest dsr; - - // Query Plan - HttpTimeoutPolicy Control Plane Hot Path - dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), - OperationType.QueryPlan, "/dbs/db/colls/col/docs/doc", ResourceType.Document); - RetryContext retryContext = new RetryContext(); - WebExceptionRetryPolicy retryPolicy = new WebExceptionRetryPolicy(retryContext); - - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofMillis(500)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(0); - - retryContext.addStatusAndSubStatusCode(408, 10002); - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(5)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(1); - - retryContext.addStatusAndSubStatusCode(408, 10002); - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(10)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(0); - - - // Read - HttpTimeoutPolicy Default - dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), - OperationType.Read, "/dbs/db/colls/col/docs/doc", ResourceType.Document); - retryContext = new RetryContext(); - retryPolicy = new WebExceptionRetryPolicy(retryContext); - - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(60)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(0); - - - retryContext.addStatusAndSubStatusCode(408, 10002); - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(60)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(1); - - retryContext.addStatusAndSubStatusCode(408, 10002); - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(60)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(0); - - - // Database Account - HtHttpTimeoutPolicy Control Plane Read - dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), - OperationType.Read, "/dbs/db/colls/col/docs/doc", ResourceType.DatabaseAccount); - retryContext = new RetryContext(); - retryPolicy = new WebExceptionRetryPolicy(retryContext); - - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(5)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(0); - - - retryContext.addStatusAndSubStatusCode(408, 10002); - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(10)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(1); - - retryContext.addStatusAndSubStatusCode(408, 10002); - retryPolicy.onBeforeSendRequest(dsr); - assertThat(dsr.getResponseTimeout()).isEqualTo(Duration.ofSeconds(20)); - assertThat(getBackOffTime(retryPolicy)).isEqualTo(0); - } - - public int getBackOffTime(WebExceptionRetryPolicy retryPolicy) throws Exception { - Field field = retryPolicy.getClass().getDeclaredField(BACKOFF_TIME_PROPERTY_NAME); - field.setAccessible(true); - return (int) field.get(retryPolicy); - } -} diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java index 775c87e7efe93..688899050b20c 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java @@ -7,7 +7,7 @@ import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosDiagnostics; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.implementation.apachecommons.lang.tuple.ImmutablePair; import com.azure.cosmos.implementation.caches.RxClientCollectionCache; import com.azure.cosmos.implementation.caches.RxPartitionKeyRangeCache; @@ -76,7 +76,7 @@ public class RxDocumentClientImplTest { private RxClientCollectionCache collectionCacheMock; private RxPartitionKeyRangeCache partitionKeyRangeCacheMock; private IRetryPolicyFactory resetSessionTokenRetryPolicyMock; - private CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig; + private CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig; @BeforeClass(groups = "unit") public void setUp() { @@ -96,7 +96,7 @@ public void setUp() { this.collectionCacheMock = Mockito.mock(RxClientCollectionCache.class); this.partitionKeyRangeCacheMock = Mockito.mock(RxPartitionKeyRangeCache.class); this.resetSessionTokenRetryPolicyMock = Mockito.mock(IRetryPolicyFactory.class); - this.endToEndOperationLatencyPolicyConfig = Mockito.mock(CosmosE2EOperationRetryPolicyConfig.class); + this.endToEndOperationLatencyPolicyConfig = Mockito.mock(CosmosEndToEndOperationLatencyPolicyConfig.class); } @Test(groups = {"unit"}) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ContainerThroughputControlGroupPropertiesTests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ContainerThroughputControlGroupPropertiesTests.java index d122c6a1b29f5..b69d1f732bbea 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ContainerThroughputControlGroupPropertiesTests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ContainerThroughputControlGroupPropertiesTests.java @@ -39,7 +39,7 @@ public void enableThroughputControlGroup() { container, 6, null, - PriorityLevel.High, + PriorityLevel.HIGH, true, false); @@ -57,7 +57,7 @@ public void enableThroughputControlGroup() { container, 6, null, - PriorityLevel.High, + PriorityLevel.HIGH, false, false); @@ -71,7 +71,7 @@ public void enableThroughputControlGroup() { container, 6, null, - PriorityLevel.High, + PriorityLevel.HIGH, true, true); @@ -87,7 +87,7 @@ public void enableThroughputControlGroup() { container, 6, null, - PriorityLevel.High, + PriorityLevel.HIGH, true, false); assertThatThrownBy(() -> throughputControlContainerProperties.enableThroughputControlGroup(throughputControlDefaultGroup2, null)) @@ -100,7 +100,7 @@ public void enableThroughputControlGroup() { container, 6, null, - PriorityLevel.High, + PriorityLevel.HIGH, false, false); stateAfterEnabling = @@ -116,7 +116,7 @@ public void enableThroughputControlGroup() { container, newGroup.getTargetThroughput(), newGroup.getTargetThroughputThreshold(), - PriorityLevel.High, + PriorityLevel.HIGH, newGroup.isDefault(), newGroup.isContinueOnInitError()); stateAfterEnabling = @@ -132,7 +132,7 @@ public void enableThroughputControlGroup() { container, newGroup.getTargetThroughput() + 1, newGroup.getTargetThroughputThreshold(), - PriorityLevel.High, + PriorityLevel.HIGH, newGroup.isDefault(), newGroup.isContinueOnInitError()); stateAfterEnabling = diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlGroupConfigConfigurationTests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlGroupConfigConfigurationTests.java index a5658754b0d0d..597286a9883fe 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlGroupConfigConfigurationTests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlGroupConfigConfigurationTests.java @@ -77,7 +77,7 @@ public void validatePriorityThroughputControlGroup() { ThroughputControlGroupConfig groupConfig = new ThroughputControlGroupConfigBuilder() .groupName("group-1") - .priorityLevel(PriorityLevel.High) + .priorityLevel(PriorityLevel.HIGH) .build(); assertThat(groupConfig.getTargetThroughput()).isEqualTo(Integer.MAX_VALUE); } @@ -87,7 +87,7 @@ public void validatePriorityThroughputControlGroupWithThreshold() { ThroughputControlGroupConfig groupConfig = new ThroughputControlGroupConfigBuilder() .groupName("group-1") - .priorityLevel(PriorityLevel.High) + .priorityLevel(PriorityLevel.HIGH) .targetThroughputThreshold(0.5) .build(); assertThat(groupConfig.getTargetThroughputThreshold()).isEqualTo(0.5); diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlTests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlTests.java index 0572ca39d76cc..3260df8fdfcf3 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlTests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlTests.java @@ -214,7 +214,7 @@ public void throughputLocalControlPriorityLevel(OperationType operationType) { ThroughputControlGroupConfig groupConfig = new ThroughputControlGroupConfigBuilder() .groupName("group-" + UUID.randomUUID()) - .priorityLevel(PriorityLevel.Low) + .priorityLevel(PriorityLevel.LOW) .build(); container.enableLocalThroughputControlGroup(groupConfig); diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/controller/LocalThroughputControllerTests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/controller/LocalThroughputControllerTests.java index 6294df0c037f1..ce29af06a8945 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/controller/LocalThroughputControllerTests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/controller/LocalThroughputControllerTests.java @@ -77,11 +77,11 @@ public void beforeClass_LocalThroughputRequestControllerTests() { public static Object[][] throughputControlConfigProvider() { return new Object[][]{ { 6, null, null, 6 }, - { 6, null, PriorityLevel.High, 6 }, + { 6, null, PriorityLevel.HIGH, 6 }, { null, 0.5, null, 3 }, - { null, 0.5, PriorityLevel.High, 3 }, - { Integer.MAX_VALUE, null, PriorityLevel.High, Integer.MAX_VALUE }, - { Integer.MAX_VALUE, 0.5, PriorityLevel.High, 3 } + { null, 0.5, PriorityLevel.HIGH, 3 }, + { Integer.MAX_VALUE, null, PriorityLevel.HIGH, Integer.MAX_VALUE }, + { Integer.MAX_VALUE, 0.5, PriorityLevel.HIGH, 3 } }; } diff --git a/sdk/cosmos/azure-cosmos/CHANGELOG.md b/sdk/cosmos/azure-cosmos/CHANGELOG.md index 7cb46f4c46fb6..9a8e3fbee680e 100644 --- a/sdk/cosmos/azure-cosmos/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos/CHANGELOG.md @@ -1,6 +1,6 @@ ## Release History -### 4.45.0-beta.1 (Unreleased) +### 4.45.0 (2023-05-12) #### Features Added * Added support for priority based throttling - See [PR 34121](https://github.com/Azure/azure-sdk-for-java/pull/34121) @@ -10,8 +10,6 @@ * Added end to end timeout policy for item operations. Requests will be cancelled if they have not finished before the configured timeout - See [PR 34554](https://github.com/Azure/azure-sdk-for-java/pull/34554). * Added capability to sample diagnostics dynamically (without need to reinitialize the app or the Cosmos Client instance). - See [PR 34915](https://github.com/Azure/azure-sdk-for-java/pull/34915). -#### Breaking Changes - #### Bugs Fixed * Fixed `IllegalArgumentException` in changeFeedProcessor when `maxScaleCount` is configured - See [PR 34618](https://github.com/Azure/azure-sdk-for-java/pull/34618) * Removed custom user agent suffix from client telemetry - See [PR 34866](https://github.com/Azure/azure-sdk-for-java/pull/34866) diff --git a/sdk/cosmos/azure-cosmos/README.md b/sdk/cosmos/azure-cosmos/README.md index 8f5f2c9952f34..31351693aae46 100644 --- a/sdk/cosmos/azure-cosmos/README.md +++ b/sdk/cosmos/azure-cosmos/README.md @@ -45,7 +45,7 @@ add the direct dependency to your project as follows. com.azure azure-cosmos - 4.44.0 + 4.45.0 ``` [//]: # ({x-version-update-end}) diff --git a/sdk/cosmos/azure-cosmos/docs/TimeoutAndRetriesConfig.md b/sdk/cosmos/azure-cosmos/docs/TimeoutAndRetriesConfig.md index d9c456eadc934..f50f7131055c4 100644 --- a/sdk/cosmos/azure-cosmos/docs/TimeoutAndRetriesConfig.md +++ b/sdk/cosmos/azure-cosmos/docs/TimeoutAndRetriesConfig.md @@ -3,11 +3,11 @@ ### Timeout config - Gateway | OperationType | Network Request Timeout | Connection Timeout | -| ----------------- |------------------------ |------------------- | -| QueryPlan | .5s, 5s, 10s | 45s | -| AddressRefresh | .5s, 5s, 10s | 45s | -| Database Account | 5s, 10s, 20s | 45s | -| Other Http calls | 60s, 60s, 60s | 45s | +| ----------------- |------------------------|------------------- | +| QueryPlan | 60s | 45s | +| AddressRefresh | 60s | 45s | +| Database Account | 60s | 45s | +| Other Http calls | 60s | 45s | ### Timeout config - Direct diff --git a/sdk/cosmos/azure-cosmos/pom.xml b/sdk/cosmos/azure-cosmos/pom.xml index 3d11c4e78b7d8..9767c0219011a 100644 --- a/sdk/cosmos/azure-cosmos/pom.xml +++ b/sdk/cosmos/azure-cosmos/pom.xml @@ -13,7 +13,7 @@ Licensed under the MIT License. com.azure azure-cosmos - 4.45.0-beta.1 + 4.45.0 Microsoft Azure SDK for SQL API of Azure Cosmos DB Service This Package contains Microsoft Azure Cosmos SDK (with Reactive Extension Reactor support) for Azure Cosmos DB SQL API jar diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java index 5a43490e90c7e..15128795d4cfd 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java @@ -9,11 +9,9 @@ import com.azure.cosmos.implementation.Constants; import com.azure.cosmos.implementation.CosmosError; import com.azure.cosmos.implementation.DatabaseAccount; -import com.azure.cosmos.implementation.DiagnosticsClientContext; import com.azure.cosmos.implementation.Document; import com.azure.cosmos.implementation.FeedResponseDiagnostics; import com.azure.cosmos.implementation.GlobalEndpointManager; -import com.azure.cosmos.implementation.HttpConstants; import com.azure.cosmos.implementation.ImplementationBridgeHelpers; import com.azure.cosmos.implementation.InternalObjectNode; import com.azure.cosmos.implementation.JsonSerializable; @@ -34,7 +32,6 @@ import com.azure.cosmos.implementation.directconnectivity.StoreResponseDiagnostics; import com.azure.cosmos.implementation.directconnectivity.StoreResult; import com.azure.cosmos.implementation.directconnectivity.StoreResultDiagnostics; -import com.azure.cosmos.implementation.directconnectivity.Uri; import com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdChannelAcquisitionTimeline; import com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdEndpointStatistics; import com.azure.cosmos.implementation.query.QueryInfo; @@ -52,7 +49,6 @@ import io.micrometer.core.instrument.MeterRegistry; import java.net.URI; -import java.nio.ByteBuffer; import java.time.Duration; import java.time.Instant; import java.util.Collection; @@ -74,12 +70,6 @@ public final class BridgeInternal { private BridgeInternal() {} - @Warning(value = INTERNAL_USE_ONLY_WARNING) - public static CosmosDiagnostics createCosmosDiagnostics( - DiagnosticsClientContext diagnosticsClientContext, double samplingRateSnapshot) { - return new CosmosDiagnostics(diagnosticsClientContext).setSamplingRateSnapshot(samplingRateSnapshot); - } - @Warning(value = INTERNAL_USE_ONLY_WARNING) public static Set getRegionsContacted(CosmosDiagnostics cosmosDiagnostics) { if (cosmosDiagnostics.clientSideRequestStatistics() == null) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java index 29eefcea7df14..95eeea9fbbb94 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java @@ -118,7 +118,7 @@ public final class CosmosAsyncClient implements Closeable { boolean enableTransportClientSharing = builder.isConnectionSharingAcrossClientsEnabled(); this.proactiveContainerInitConfig = builder.getProactiveContainerInitConfig(); this.nonIdempotentWriteRetryPolicy = builder.getNonIdempotentWriteRetryPolicy(); - CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig = builder.getEndToEndOperationConfig(); + CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig = builder.getEndToEndOperationConfig(); CosmosClientTelemetryConfig effectiveTelemetryConfig = telemetryConfigAccessor .createSnapshot( diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java index 5d306da2e3a4c..a44982233fadf 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java @@ -132,7 +132,7 @@ public class CosmosClientBuilder implements private ApiType apiType = null; private Boolean clientTelemetryEnabledOverride = null; private CosmosContainerProactiveInitConfig proactiveContainerInitConfig; - private CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig; + private CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig; /** * Instantiates a new Cosmos client builder. @@ -790,21 +790,21 @@ public CosmosClientBuilder openConnectionsAndInitCaches(CosmosContainerProactive } /** - * Sets the {@link CosmosE2EOperationRetryPolicyConfig} on the client - * @param cosmosE2EOperationRetryPolicyConfig the {@link CosmosE2EOperationRetryPolicyConfig} + * Sets the {@link CosmosEndToEndOperationLatencyPolicyConfig} on the client + * @param cosmosEndToEndOperationLatencyPolicyConfig the {@link CosmosEndToEndOperationLatencyPolicyConfig} * @return current CosmosClientBuilder */ - public CosmosClientBuilder endToEndOperationLatencyPolicyConfig(CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig){ - this.cosmosE2EOperationRetryPolicyConfig = cosmosE2EOperationRetryPolicyConfig; + public CosmosClientBuilder endToEndOperationLatencyPolicyConfig(CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig){ + this.cosmosEndToEndOperationLatencyPolicyConfig = cosmosEndToEndOperationLatencyPolicyConfig; return this; } /** - * Gets the {@link CosmosE2EOperationRetryPolicyConfig} - * @return the {@link CosmosE2EOperationRetryPolicyConfig} + * Gets the {@link CosmosEndToEndOperationLatencyPolicyConfig} + * @return the {@link CosmosEndToEndOperationLatencyPolicyConfig} */ - CosmosE2EOperationRetryPolicyConfig getEndToEndOperationConfig() { - return this.cosmosE2EOperationRetryPolicyConfig; + CosmosEndToEndOperationLatencyPolicyConfig getEndToEndOperationConfig() { + return this.cosmosEndToEndOperationLatencyPolicyConfig; } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosE2EOperationRetryPolicyConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosEndToEndOperationLatencyPolicyConfig.java similarity index 92% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosE2EOperationRetryPolicyConfig.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosEndToEndOperationLatencyPolicyConfig.java index 6455a8adb585d..9f21354a45f97 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosE2EOperationRetryPolicyConfig.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosEndToEndOperationLatencyPolicyConfig.java @@ -9,7 +9,7 @@ * Represents End to end operation latency policy config * This enables requests to get cancelled by the client once the specified timeout is reached */ -public final class CosmosE2EOperationRetryPolicyConfig { +public final class CosmosEndToEndOperationLatencyPolicyConfig { private final boolean isEnabled; private final Duration endToEndOperationTimeout; @@ -20,7 +20,7 @@ public final class CosmosE2EOperationRetryPolicyConfig { * @param endToEndOperationTimeout the timeout for request cancellation in {@link Duration}. Setting very low timeouts * can cause the request to never succeed. */ - CosmosE2EOperationRetryPolicyConfig( + CosmosEndToEndOperationLatencyPolicyConfig( boolean isEnabled, Duration endToEndOperationTimeout) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosE2EOperationRetryPolicyConfigBuilder.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosEndToEndOperationLatencyPolicyConfigBuilder.java similarity index 60% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosE2EOperationRetryPolicyConfigBuilder.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosEndToEndOperationLatencyPolicyConfigBuilder.java index a94d1b5a3a770..c772ce8019aaf 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosE2EOperationRetryPolicyConfigBuilder.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosEndToEndOperationLatencyPolicyConfigBuilder.java @@ -10,26 +10,26 @@ /** * Builder for CosmosEndToEndOperationLatencyPolicyConfig */ -public class CosmosE2EOperationRetryPolicyConfigBuilder { +public class CosmosEndToEndOperationLatencyPolicyConfigBuilder { private boolean isEnabled = true; private final Duration endToEndOperationTimeout; /** - * Create a builder for {@link CosmosE2EOperationRetryPolicyConfig} with end to end operation timeout + * Create a builder for {@link CosmosEndToEndOperationLatencyPolicyConfig} with end to end operation timeout * @param endToEndOperationTimeout the timeout for request cancellation in Duration. Setting very low timeouts * can cause the request to never succeed. */ - public CosmosE2EOperationRetryPolicyConfigBuilder(Duration endToEndOperationTimeout) { + public CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration endToEndOperationTimeout) { this.endToEndOperationTimeout = endToEndOperationTimeout; } /** - * Builds {@link CosmosE2EOperationRetryPolicyConfig} with specified properties + * Builds {@link CosmosEndToEndOperationLatencyPolicyConfig} with specified properties * - * @return the {@link CosmosE2EOperationRetryPolicyConfig} + * @return the {@link CosmosEndToEndOperationLatencyPolicyConfig} */ - public CosmosE2EOperationRetryPolicyConfig build() { - return new CosmosE2EOperationRetryPolicyConfig(isEnabled, endToEndOperationTimeout); + public CosmosEndToEndOperationLatencyPolicyConfig build() { + return new CosmosEndToEndOperationLatencyPolicyConfig(isEnabled, endToEndOperationTimeout); } /** @@ -39,7 +39,7 @@ public CosmosE2EOperationRetryPolicyConfig build() { * @param isEnabled flag to enable or disable the policy * @return current CosmosEndToEndOperationConfigBuilder */ - public CosmosE2EOperationRetryPolicyConfigBuilder enable( + public CosmosEndToEndOperationLatencyPolicyConfigBuilder enable( boolean isEnabled) { this.isEnabled = isEnabled; return this; diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java index bdb5cacb867fe..ba76b8a428913 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java @@ -6,7 +6,7 @@ import com.azure.core.credential.TokenCredential; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosContainerProactiveInitConfig; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.implementation.batch.ServerBatchRequest; import com.azure.cosmos.implementation.caches.RxClientCollectionCache; @@ -33,7 +33,6 @@ import java.net.URI; import java.net.URISyntaxException; -import java.time.Duration; import java.util.List; import java.util.Map; @@ -101,7 +100,7 @@ class Builder { private ApiType apiType; CosmosClientTelemetryConfig clientTelemetryConfig; private String clientCorrelationId = null; - private CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig; + private CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig; public Builder withServiceEndpoint(String serviceEndpoint) { try { @@ -238,8 +237,8 @@ public Builder withClientTelemetryConfig(CosmosClientTelemetryConfig clientTelem return this; } - public Builder withEndToEndOperationLatencyPolicyConfig(CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig) { - this.cosmosE2EOperationRetryPolicyConfig = endToEndOperationLatencyPolicyConfig; + public Builder withEndToEndOperationLatencyPolicyConfig(CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig) { + this.cosmosEndToEndOperationLatencyPolicyConfig = endToEndOperationLatencyPolicyConfig; return this; } @@ -276,7 +275,7 @@ public AsyncDocumentClient build() { apiType, clientTelemetryConfig, clientCorrelationId, - cosmosE2EOperationRetryPolicyConfig + cosmosEndToEndOperationLatencyPolicyConfig ); client.init(state, null); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java index a6284dff73c3f..edd7488c5a4ab 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java @@ -5,7 +5,7 @@ import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosDiagnostics; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.CosmosException; import com.azure.cosmos.implementation.directconnectivity.StoreResponse; import com.azure.cosmos.implementation.directconnectivity.StoreResult; @@ -45,7 +45,7 @@ public class DocumentServiceRequestContext implements Cloneable { public volatile String throughputControlCycleId; public volatile boolean replicaAddressValidationEnabled = Configs.isReplicaAddressValidationEnabled(); private final Set failedEndpoints = ConcurrentHashMap.newKeySet(); - private CosmosE2EOperationRetryPolicyConfig e2EOperationRetryPolicyConfig; + private CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig; // For cancelled rntbd requests, track the response as OperationCancelledException which later will be used to populate the cosmosDiagnostics public final Map rntbdCancelledRequestMap = new ConcurrentHashMap<>(); @@ -130,16 +130,16 @@ public DocumentServiceRequestContext clone() { context.resourcePhysicalAddress = this.resourcePhysicalAddress; context.throughputControlCycleId = this.throughputControlCycleId; context.replicaAddressValidationEnabled = this.replicaAddressValidationEnabled; - context.e2EOperationRetryPolicyConfig = this.e2EOperationRetryPolicyConfig; + context.endToEndOperationLatencyPolicyConfig = this.endToEndOperationLatencyPolicyConfig; return context; } - public CosmosE2EOperationRetryPolicyConfig getE2EOperationRetryPolicyConfig() { - return e2EOperationRetryPolicyConfig; + public CosmosEndToEndOperationLatencyPolicyConfig getEndToEndOperationLatencyPolicyConfig() { + return endToEndOperationLatencyPolicyConfig; } - public void setEndToEndOperationLatencyPolicyConfig(CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig) { - this.e2EOperationRetryPolicyConfig = endToEndOperationLatencyPolicyConfig; + public void setEndToEndOperationLatencyPolicyConfig(CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig) { + this.endToEndOperationLatencyPolicyConfig = endToEndOperationLatencyPolicyConfig; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ImplementationBridgeHelpers.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ImplementationBridgeHelpers.java index 8f526cd2c10eb..f5b58eb1510cc 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ImplementationBridgeHelpers.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ImplementationBridgeHelpers.java @@ -18,7 +18,7 @@ import com.azure.cosmos.CosmosDiagnosticsContext; import com.azure.cosmos.CosmosDiagnosticsHandler; import com.azure.cosmos.CosmosDiagnosticsThresholds; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.CosmosException; import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.GlobalThroughputControlConfig; @@ -55,6 +55,7 @@ import com.azure.cosmos.models.FeedResponse; import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; +import com.azure.cosmos.models.PriorityLevel; import com.azure.cosmos.util.CosmosPagedFlux; import com.azure.cosmos.util.UtilBridgeInternal; import com.fasterxml.jackson.databind.JsonNode; @@ -78,8 +79,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import static com.azure.cosmos.implementation.Warning.INTERNAL_USE_ONLY_WARNING; - public class ImplementationBridgeHelpers { private final static Logger logger = LoggerFactory.getLogger(ImplementationBridgeHelpers.class); @@ -267,7 +266,7 @@ public interface CosmosQueryRequestOptionsAccessor { RequestOptions toRequestOptions(CosmosQueryRequestOptions queryRequestOptions); CosmosDiagnosticsThresholds getDiagnosticsThresholds(CosmosQueryRequestOptions options); void applyMaxItemCount(CosmosQueryRequestOptions requestOptions, CosmosPagedFluxOptions fluxOptions); - CosmosE2EOperationRetryPolicyConfig getE2EOperationRetryPolicyConfig(CosmosQueryRequestOptions options); + CosmosEndToEndOperationLatencyPolicyConfig getEndToEndOperationLatencyPolicyConfig(CosmosQueryRequestOptions options); } } @@ -1377,6 +1376,45 @@ CosmosClientTelemetryConfig createSnapshot( } } + public static final class PriorityLevelHelper { + private final static AtomicBoolean priorityLevelClassLoaded = new AtomicBoolean(false); + private final static AtomicReference accessor = new AtomicReference<>(); + + private PriorityLevelHelper() { + } + + public static PriorityLevelAccessor getPriorityLevelAccessor() { + if (!priorityLevelClassLoaded.get()) { + logger.debug("Initializing PriorityLevelAccessor..."); + initializeAllAccessors(); + } + + PriorityLevelAccessor snapshot = accessor.get(); + if (snapshot == null) { + logger.error("PriorityLevelAccessor is not initialized yet!"); + System.exit(9728); // Using a unique status code here to help debug the issue. + } + + return snapshot; + } + + public static void setPriorityLevelAccessor(final PriorityLevelAccessor newAccessor) { + + assert(newAccessor != null); + + if (!accessor.compareAndSet(null, newAccessor)) { + logger.debug("PriorityLevelAccessor already initialized!"); + } else { + logger.debug("Setting PriorityLevelAccessor..."); + priorityLevelClassLoaded.set(true); + } + } + + public interface PriorityLevelAccessor { + byte getPriorityValue(PriorityLevel level); + } + } + public static final class CosmosContainerIdentityHelper { private static final AtomicReference cosmosContainerIdentityClassLoaded = new AtomicReference<>(false); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/OperationCancelledException.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/OperationCancelledException.java index 1612f8e90125e..4b332705b50f4 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/OperationCancelledException.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/OperationCancelledException.java @@ -4,7 +4,7 @@ package com.azure.cosmos.implementation; import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.CosmosException; import com.azure.cosmos.implementation.directconnectivity.HttpUtils; import com.azure.cosmos.implementation.http.HttpHeaders; @@ -13,7 +13,7 @@ /** * The type Operation cancelled exception. This is thrown when the operation is cancelled - * by the {@link CosmosE2EOperationRetryPolicyConfig} + * by the {@link CosmosEndToEndOperationLatencyPolicyConfig} */ public final class OperationCancelledException extends CosmosException { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java index 3c17c13ef5080..f23a4401d8c83 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java @@ -6,7 +6,7 @@ import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosDiagnosticsThresholds; import com.azure.cosmos.implementation.spark.OperationContextAndListenerTuple; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.models.DedicatedGatewayRequestOptions; import com.azure.cosmos.models.IndexingDirective; import com.azure.cosmos.models.PartitionKey; @@ -45,7 +45,7 @@ public class RequestOptions { private String trackingId; private boolean nonIdempotentWriteRetriesEnabled = false; - private CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyConfig; + private CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyConfig; /** @@ -445,11 +445,11 @@ public void setDiagnosticsThresholds(CosmosDiagnosticsThresholds thresholds) { this.thresholds = thresholds; } - public void setCosmosEndToEndLatencyPolicyConfig(CosmosE2EOperationRetryPolicyConfig endToEndOperationLatencyPolicyConfig) { + public void setCosmosEndToEndLatencyPolicyConfig(CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyPolicyConfig) { this.endToEndOperationLatencyConfig = endToEndOperationLatencyPolicyConfig; } - public CosmosE2EOperationRetryPolicyConfig getCosmosEndToEndLatencyPolicyConfig(){ + public CosmosEndToEndOperationLatencyPolicyConfig getCosmosEndToEndLatencyPolicyConfig(){ return this.endToEndOperationLatencyConfig; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java index 2c33ec07fa2cb..27a687e680efc 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java @@ -6,7 +6,6 @@ import com.azure.core.credential.SimpleTokenCache; import com.azure.core.credential.TokenCredential; import com.azure.core.credential.TokenRequestContext; -import com.azure.core.util.CoreUtils; import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.ConsistencyLevel; @@ -14,7 +13,7 @@ import com.azure.cosmos.CosmosDiagnostics; import com.azure.cosmos.CosmosException; import com.azure.cosmos.DirectConnectionConfig; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.implementation.batch.BatchResponseParser; import com.azure.cosmos.implementation.batch.PartitionKeyRangeServerBatchRequest; @@ -174,7 +173,7 @@ public class RxDocumentClientImpl implements AsyncDocumentClient, IAuthorization private final int clientId; private ClientTelemetry clientTelemetry; private final ApiType apiType; - private final CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig; + private final CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig; // RetryPolicy retries a request when it encounters session unavailable (see ClientRetryPolicy). // Once it exhausts all write regions it clears the session container, then it uses RxClientCollectionCache @@ -220,7 +219,7 @@ public RxDocumentClientImpl(URI serviceEndpoint, ApiType apiType, CosmosClientTelemetryConfig clientTelemetryConfig, String clientCorrelationId, - CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig) { + CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig) { this( serviceEndpoint, masterKeyOrResourceToken, @@ -237,7 +236,7 @@ public RxDocumentClientImpl(URI serviceEndpoint, apiType, clientTelemetryConfig, clientCorrelationId, - cosmosE2EOperationRetryPolicyConfig); + cosmosEndToEndOperationLatencyPolicyConfig); this.cosmosAuthorizationTokenResolver = cosmosAuthorizationTokenResolver; } @@ -257,7 +256,7 @@ public RxDocumentClientImpl(URI serviceEndpoint, ApiType apiType, CosmosClientTelemetryConfig clientTelemetryConfig, String clientCorrelationId, - CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig) { + CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig) { this( serviceEndpoint, masterKeyOrResourceToken, @@ -274,7 +273,7 @@ public RxDocumentClientImpl(URI serviceEndpoint, apiType, clientTelemetryConfig, clientCorrelationId, - cosmosE2EOperationRetryPolicyConfig); + cosmosEndToEndOperationLatencyPolicyConfig); this.cosmosAuthorizationTokenResolver = cosmosAuthorizationTokenResolver; } @@ -293,7 +292,7 @@ private RxDocumentClientImpl(URI serviceEndpoint, ApiType apiType, CosmosClientTelemetryConfig clientTelemetryConfig, String clientCorrelationId, - CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig) { + CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig) { this( serviceEndpoint, masterKeyOrResourceToken, @@ -309,7 +308,7 @@ private RxDocumentClientImpl(URI serviceEndpoint, apiType, clientTelemetryConfig, clientCorrelationId, - cosmosE2EOperationRetryPolicyConfig); + cosmosEndToEndOperationLatencyPolicyConfig); if (permissionFeed != null && permissionFeed.size() > 0) { this.resourceTokensMap = new HashMap<>(); @@ -367,7 +366,7 @@ private RxDocumentClientImpl(URI serviceEndpoint, ApiType apiType, CosmosClientTelemetryConfig clientTelemetryConfig, String clientCorrelationId, - CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig) { + CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig) { assert(clientTelemetryConfig != null); Boolean clientTelemetryEnabled = ImplementationBridgeHelpers @@ -388,7 +387,7 @@ private RxDocumentClientImpl(URI serviceEndpoint, this.diagnosticsClientConfig.withConnectionSharingAcrossClientsEnabled(connectionSharingAcrossClientsEnabled); this.diagnosticsClientConfig.withConsistency(consistencyLevel); this.throughputControlEnabled = new AtomicBoolean(false); - this.cosmosE2EOperationRetryPolicyConfig = cosmosE2EOperationRetryPolicyConfig; + this.cosmosEndToEndOperationLatencyPolicyConfig = cosmosEndToEndOperationLatencyPolicyConfig; logger.info( "Initializing DocumentClient [{}] with" @@ -965,7 +964,7 @@ private Flux> createQueryInternal( .CosmosQueryRequestOptionsHelper .getCosmosQueryRequestOptionsAccessor() .toRequestOptions(options); - CosmosE2EOperationRetryPolicyConfig endToEndPolicyConfig = + CosmosEndToEndOperationLatencyPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(requestOptions); if (endToEndPolicyConfig != null && endToEndPolicyConfig.isEnabled()) { @@ -979,7 +978,7 @@ private Flux> createQueryInternal( }, Queues.SMALL_BUFFER_SIZE, 1); } - private static Flux> getFeedResponseFluxWithTimeout(Flux> feedResponseFlux, CosmosE2EOperationRetryPolicyConfig endToEndPolicyConfig) { + private static Flux> getFeedResponseFluxWithTimeout(Flux> feedResponseFlux, CosmosEndToEndOperationLatencyPolicyConfig endToEndPolicyConfig) { return feedResponseFlux .timeout(endToEndPolicyConfig.getEndToEndOperationTimeout()) .onErrorMap(throwable -> { @@ -1911,7 +1910,7 @@ private Mono> createDocumentInternal(String collectio Mono responseObservable = requestObs.flatMap(request -> { - CosmosE2EOperationRetryPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); + CosmosEndToEndOperationLatencyPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); Mono rxDocumentServiceResponseMono = create(request, requestRetryPolicy, getOperationContextAndListenerTuple(options)); return getRxDocumentServiceResponseMonoWithE2ETimeout(request, endToEndPolicyConfig, rxDocumentServiceResponseMono); }); @@ -1926,7 +1925,7 @@ private Mono> createDocumentInternal(String collectio } private static Mono getRxDocumentServiceResponseMonoWithE2ETimeout(RxDocumentServiceRequest request, - CosmosE2EOperationRetryPolicyConfig endToEndPolicyConfig, + CosmosEndToEndOperationLatencyPolicyConfig endToEndPolicyConfig, Mono rxDocumentServiceResponseMono) { if (endToEndPolicyConfig != null && endToEndPolicyConfig.isEnabled()) { return rxDocumentServiceResponseMono @@ -1966,7 +1965,7 @@ private Mono> upsertDocumentInternal(String collectio options, disableAutomaticIdGeneration, OperationType.Upsert); Mono responseObservable = reqObs.flatMap(request -> { - CosmosE2EOperationRetryPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); + CosmosEndToEndOperationLatencyPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); return getRxDocumentServiceResponseMonoWithE2ETimeout(request, endToEndPolicyConfig, upsert(request, retryPolicyInstance, getOperationContextAndListenerTuple(options))); }); @@ -2086,14 +2085,14 @@ private Mono> replaceDocumentInternal(String document return requestObs.flatMap(req -> { Mono> resourceResponseMono = replace(request, retryPolicyInstance) .map(resp -> toResourceResponse(resp, Document.class)); - CosmosE2EOperationRetryPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); + CosmosEndToEndOperationLatencyPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); return getRxDocumentServiceResponseMonoWithE2ETimeout(request, endToEndPolicyConfig, resourceResponseMono); }); } - private CosmosE2EOperationRetryPolicyConfig getEndToEndOperationLatencyPolicyConfig(RequestOptions options) { + private CosmosEndToEndOperationLatencyPolicyConfig getEndToEndOperationLatencyPolicyConfig(RequestOptions options) { return (options != null && options.getCosmosEndToEndLatencyPolicyConfig() != null) ? - options.getCosmosEndToEndLatencyPolicyConfig() : this.cosmosE2EOperationRetryPolicyConfig; + options.getCosmosEndToEndLatencyPolicyConfig() : this.cosmosEndToEndOperationLatencyPolicyConfig; } @Override @@ -2273,7 +2272,7 @@ private Mono> readDocumentInternal(String documentLin Mono> collectionObs = this.collectionCache.resolveCollectionAsync(BridgeInternal.getMetaDataDiagnosticContext(request.requestContext.cosmosDiagnostics), request); Mono requestObs = addPartitionKeyInformation(request, null, null, options, collectionObs); - CosmosE2EOperationRetryPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); + CosmosEndToEndOperationLatencyPolicyConfig endToEndPolicyConfig = getEndToEndOperationLatencyPolicyConfig(options); request.requestContext.setEndToEndOperationLatencyPolicyConfig(endToEndPolicyConfig); return requestObs.flatMap(req -> { Mono> resourceResponseMono = this.read(request, retryPolicyInstance).map(serviceResponse -> toResourceResponse(serviceResponse, Document.class)); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentServiceRequest.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentServiceRequest.java index c19d66f2870d5..8d86fdeb90b7a 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentServiceRequest.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentServiceRequest.java @@ -16,9 +16,6 @@ import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.SqlQuerySpec; import com.azure.cosmos.models.PriorityLevel; -import com.azure.cosmos.implementation.directconnectivity.WFConstants; -import com.azure.cosmos.implementation.routing.PartitionKeyInternal; -import com.azure.cosmos.implementation.routing.PartitionKeyRangeIdentity; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import reactor.core.publisher.Flux; @@ -1170,7 +1167,7 @@ public void setNumberOfItemsInBatchRequest(int numberOfItemsInBatchRequest) { public void setPriorityLevel(PriorityLevel priorityLevel) { if (priorityLevel != null) { - this.headers.put(HttpConstants.HttpHeaders.PRIORITY_LEVEL, priorityLevel.name()); + this.headers.put(HttpConstants.HttpHeaders.PRIORITY_LEVEL, priorityLevel.toString()); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java index ab4d82248f3b3..cb07f10c5a665 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java @@ -35,12 +35,14 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; +import java.util.concurrent.Callable; import static com.azure.cosmos.implementation.HttpConstants.HttpHeaders.INTENDED_COLLECTION_RID_HEADER; @@ -237,7 +239,14 @@ public Mono performRequestInternal(RxDocumentServiceR httpHeaders, contentAsByteArray); - Mono httpResponseMono = this.httpClient.send(httpRequest, request.getResponseTimeout()); + Duration responseTimeout = Duration.ofSeconds(Configs.getHttpResponseTimeoutInSeconds()); + if (OperationType.QueryPlan.equals(request.getOperationType())) { + responseTimeout = Duration.ofSeconds(Configs.getQueryPlanResponseTimeoutInSeconds()); + } else if (request.isAddressRefresh()) { + responseTimeout = Duration.ofSeconds(Configs.getAddressRefreshResponseTimeoutInSeconds()); + } + + Mono httpResponseMono = this.httpClient.send(httpRequest, responseTimeout); return toDocumentServiceResponse(httpResponseMono, request, httpRequest); } catch (Exception e) { @@ -475,11 +484,8 @@ private Mono invokeAsyncInternal(RxDocumentServiceReq private Mono invokeAsync(RxDocumentServiceRequest request) { - final WebExceptionRetryPolicy policyInstance = new WebExceptionRetryPolicy(BridgeInternal.getRetryContext(request.requestContext.cosmosDiagnostics)); - return BackoffRetryUtility.executeRetry(() -> { - policyInstance.onBeforeSendRequest(request); - return invokeAsyncInternal(request); - }, policyInstance); + Callable> funcDelegate = () -> invokeAsyncInternal(request).single(); + return BackoffRetryUtility.executeRetry(funcDelegate, new WebExceptionRetryPolicy(BridgeInternal.getRetryContext(request.requestContext.cosmosDiagnostics))); } @Override diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java index adb0e2fe128b5..06a57d3d59087 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java @@ -5,10 +5,6 @@ import com.azure.cosmos.implementation.apachecommons.lang.time.StopWatch; import com.azure.cosmos.implementation.directconnectivity.WebExceptionUtility; -import com.azure.cosmos.implementation.http.HttpTimeoutPolicy; -import com.azure.cosmos.implementation.http.HttpTimeoutPolicyDefault; -import com.azure.cosmos.implementation.http.ResponseTimeoutAndDelays; -import io.netty.handler.codec.http.HttpMethod; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; @@ -16,71 +12,58 @@ import java.time.Duration; import java.util.concurrent.TimeUnit; -public class WebExceptionRetryPolicy extends DocumentClientRetryPolicy { +public class WebExceptionRetryPolicy implements IRetryPolicy { private final static Logger logger = LoggerFactory.getLogger(WebExceptionRetryPolicy.class); + // total wait time in seconds to retry. should be max of primary reconfigrations/replication wait duration etc + private final static int waitTimeInSeconds = 30; + private final static int initialBackoffSeconds = 1; + private final static int backoffMultiplier = 2; + private StopWatch durationTimer = new StopWatch(); - private int backoffSecondsTimeout; + private int attemptCount = 1; + // Don't penalise first retry with delay. + private int currentBackoffSeconds = WebExceptionRetryPolicy.initialBackoffSeconds; private RetryContext retryContext; - private RxDocumentServiceRequest request; - private HttpTimeoutPolicy timeoutPolicy; - private HttpMethod httpMethod; - private int retryCountTimeout = 0; public WebExceptionRetryPolicy() { - this(null); + durationTimer.start(); } public WebExceptionRetryPolicy(RetryContext retryContext) { durationTimer.start(); this.retryContext = retryContext; - this.timeoutPolicy = HttpTimeoutPolicyDefault.INSTANCE; } @Override public Mono shouldRetry(Exception exception) { - boolean isOutOfRetries = isOutOfRetries(); - if (isOutOfRetries) { - this.durationTimer.stop(); - return Mono.just(ShouldRetryResult.noRetry()); - } + Duration backoffTime = Duration.ofSeconds(0); if (!WebExceptionUtility.isWebExceptionRetriable(exception)) { // Have caller propagate original exception. this.durationTimer.stop(); return Mono.just(ShouldRetryResult.noRetryOnNonRelatedException()); } + + // Don't penalise first retry with delay. + if (attemptCount++ > 1) { + int remainingSeconds = WebExceptionRetryPolicy.waitTimeInSeconds - Math.toIntExact(this.durationTimer.getTime(TimeUnit.SECONDS)); + if (remainingSeconds <= 0) { + this.durationTimer.stop(); + return Mono.just(ShouldRetryResult.noRetry()); + } + + backoffTime = Duration.ofSeconds(Math.min(this.currentBackoffSeconds, remainingSeconds)); + this.currentBackoffSeconds *= WebExceptionRetryPolicy.backoffMultiplier; + } + logger.warn("Received retriable web exception, will retry", exception); - return Mono.just(ShouldRetryResult.retryAfter(Duration.ofSeconds(backoffSecondsTimeout))); + return Mono.just(ShouldRetryResult.retryAfter(backoffTime)); } @Override public RetryContext getRetryContext() { return this.retryContext; } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - this.request = request; - if (request.isReadOnlyRequest()) { - this.httpMethod = HttpMethod.GET; - } - this.timeoutPolicy = HttpTimeoutPolicy.getTimeoutPolicy(request); - // Fetching the retryCount to correctly get the retry values from the timeout policy - if (this.retryContext != null) { - this.retryCountTimeout = this.retryContext.getRetryCount(); - } - // Setting the current responseTimeout and delayForNextRequest using the timeout policy being used - if (!isOutOfRetries()) { - ResponseTimeoutAndDelays current = timeoutPolicy.getTimeoutAndDelaysList().get(this.retryCountTimeout); - this.request.setResponseTimeout(current.getResponseTimeout()); - this.backoffSecondsTimeout = current.getDelayForNextRequestInSeconds(); - } - } - - private Boolean isOutOfRetries() { - return this.durationTimer.getTime(TimeUnit.SECONDS) > this.timeoutPolicy.maximumRetryTimeLimit() || - this.retryCountTimeout >= this.timeoutPolicy.totalRetryCount(); - } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ReplicatedResourceClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ReplicatedResourceClient.java index 0f7864c0b476e..195b6ce858b20 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ReplicatedResourceClient.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ReplicatedResourceClient.java @@ -6,7 +6,7 @@ import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosContainerProactiveInitConfig; import com.azure.cosmos.CosmosDiagnostics; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.implementation.BackoffRetryUtility; import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.DiagnosticsClientContext; @@ -27,7 +27,6 @@ import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; import java.net.URI; import java.time.Duration; @@ -158,7 +157,7 @@ public Mono invokeAsync(RxDocumentServiceRequest request, } private Mono getStoreResponseMonoWithSpeculation(RxDocumentServiceRequest request, Quadruple forceRefreshAndTimeout) { - CosmosE2EOperationRetryPolicyConfig config = request.requestContext.getE2EOperationRetryPolicyConfig(); + CosmosEndToEndOperationLatencyPolicyConfig config = request.requestContext.getEndToEndOperationLatencyPolicyConfig(); List> monoList = new ArrayList<>(); List requests = new ArrayList<>(); @@ -200,7 +199,7 @@ private boolean shouldSpeculate(RxDocumentServiceRequest request) { return false; } - CosmosE2EOperationRetryPolicyConfig config = request.requestContext.getE2EOperationRetryPolicyConfig(); + CosmosEndToEndOperationLatencyPolicyConfig config = request.requestContext.getEndToEndOperationLatencyPolicyConfig(); return config != null && config.isEnabled(); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdConstants.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdConstants.java index f3d68147074b5..a4f0ce6ef0709 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdConstants.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdConstants.java @@ -901,18 +901,6 @@ public RntbdTokenType type() { } } - public enum RntbdPriorityLevel { - High((byte) 0x01), - Low((byte) 0x02); - private final byte id; - - RntbdPriorityLevel(final byte id) { - this.id = id; - } - public byte id() { - return this.id; - } - } interface RntbdHeader { boolean isRequired(); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestHeaders.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestHeaders.java index 7e600f44e8f09..c7680e57485e0 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestHeaders.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestHeaders.java @@ -8,6 +8,7 @@ import com.azure.cosmos.implementation.ContentSerializationFormat; import com.azure.cosmos.implementation.EnumerationDirection; import com.azure.cosmos.implementation.FanoutOperationState; +import com.azure.cosmos.implementation.ImplementationBridgeHelpers; import com.azure.cosmos.implementation.MigrateCollectionDirective; import com.azure.cosmos.implementation.Paths; import com.azure.cosmos.implementation.RMResources; @@ -757,9 +758,7 @@ private void addPriorityLevel(final Map headers) final String value = headers.get(HttpHeaders.PRIORITY_LEVEL); if (StringUtils.isNotEmpty(value)) { - final PriorityLevel priorityLevel = EnumUtils.getEnumIgnoreCase( - PriorityLevel.class, - value); + final PriorityLevel priorityLevel = PriorityLevel.fromString(value); if (priorityLevel == null) { final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, @@ -768,16 +767,12 @@ private void addPriorityLevel(final Map headers) throw new IllegalStateException(reason); } - switch (priorityLevel) { - case High: - this.getPriorityLevel().setValue(RntbdConstants.RntbdPriorityLevel.High.id()); - break; - case Low: - this.getPriorityLevel().setValue(RntbdConstants.RntbdPriorityLevel.Low.id()); - break; - default: - assert false; - } + this.getPriorityLevel().setValue( + ImplementationBridgeHelpers + .PriorityLevelHelper + .getPriorityLevelAccessor() + .getPriorityValue(priorityLevel) + ); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/SpeculativeProcessor.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/SpeculativeProcessor.java index e5a7baa7c43e9..dc9665082f6bd 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/SpeculativeProcessor.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/SpeculativeProcessor.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation.directconnectivity.speculativeprocessors; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import java.net.URI; import java.time.Duration; @@ -14,11 +14,11 @@ public interface SpeculativeProcessor { int THOMPSON_SAMPLING_BASED = 2; List getRegionsForPureExploration(); - List getRegionsToSpeculate(CosmosE2EOperationRetryPolicyConfig config, List availableReadEndpoints); + List getRegionsToSpeculate(CosmosEndToEndOperationLatencyPolicyConfig config, List availableReadEndpoints); - Duration getThreshold(CosmosE2EOperationRetryPolicyConfig config); + Duration getThreshold(CosmosEndToEndOperationLatencyPolicyConfig config); - Duration getThresholdStepDuration(CosmosE2EOperationRetryPolicyConfig config, long stepNumber); + Duration getThresholdStepDuration(CosmosEndToEndOperationLatencyPolicyConfig config, long stepNumber); boolean shouldIncludeOriginalRequestRegion(); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/ThresholdBasedSpeculation.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/ThresholdBasedSpeculation.java index df927929d2c6f..623191d6fd37f 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/ThresholdBasedSpeculation.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/speculativeprocessors/ThresholdBasedSpeculation.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation.directconnectivity.speculativeprocessors; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.implementation.Configs; import java.net.URI; @@ -16,17 +16,17 @@ public List getRegionsForPureExploration() { } @Override - public List getRegionsToSpeculate(CosmosE2EOperationRetryPolicyConfig config, List availableReadEndpoints) { + public List getRegionsToSpeculate(CosmosEndToEndOperationLatencyPolicyConfig config, List availableReadEndpoints) { return availableReadEndpoints; } @Override - public Duration getThreshold(CosmosE2EOperationRetryPolicyConfig config) { + public Duration getThreshold(CosmosEndToEndOperationLatencyPolicyConfig config) { return Duration.ofMillis(Configs.speculationThreshold()); } @Override - public Duration getThresholdStepDuration(CosmosE2EOperationRetryPolicyConfig config, long stepNumber) { + public Duration getThresholdStepDuration(CosmosEndToEndOperationLatencyPolicyConfig config, long stepNumber) { return Duration.ofMillis(stepNumber * Configs.speculationThresholdStep()); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneHotPath.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneHotPath.java index b564f3c277937..59dd274c7bcc2 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneHotPath.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneHotPath.java @@ -18,8 +18,8 @@ private HttpTimeoutPolicyControlPlaneHotPath() { } public List getTimeoutList() { - return Collections.unmodifiableList(Arrays.asList(new ResponseTimeoutAndDelays(Duration.ofMillis(500), 0), - new ResponseTimeoutAndDelays(Duration.ofSeconds(5), 1), - new ResponseTimeoutAndDelays(Duration.ofSeconds(10), 0))); + return Collections.unmodifiableList(Arrays.asList(new ResponseTimeoutAndDelays(Duration.ofSeconds(60), 0), + new ResponseTimeoutAndDelays(Duration.ofSeconds(60), 1), + new ResponseTimeoutAndDelays(Duration.ofSeconds(60), 0))); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneRead.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneRead.java index 2ffd975322f94..147d73033a514 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneRead.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpTimeoutPolicyControlPlaneRead.java @@ -2,8 +2,6 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation.http; -import io.netty.handler.codec.http.HttpMethod; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; @@ -18,8 +16,8 @@ private HttpTimeoutPolicyControlPlaneRead() { } public List getTimeoutList() { - return Collections.unmodifiableList(Arrays.asList(new ResponseTimeoutAndDelays(Duration.ofSeconds(5), 0), - new ResponseTimeoutAndDelays(Duration.ofSeconds(10), 1), - new ResponseTimeoutAndDelays(Duration.ofSeconds(20), 0))); + return Collections.unmodifiableList(Arrays.asList(new ResponseTimeoutAndDelays(Duration.ofSeconds(60), 0), + new ResponseTimeoutAndDelays(Duration.ofSeconds(60), 1), + new ResponseTimeoutAndDelays(Duration.ofSeconds(60), 0))); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentQueryExecutionContextBase.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentQueryExecutionContextBase.java index 81bc16558eba2..8b814fbacb548 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentQueryExecutionContextBase.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentQueryExecutionContextBase.java @@ -4,7 +4,7 @@ import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.ConsistencyLevel; -import com.azure.cosmos.CosmosE2EOperationRetryPolicyConfig; +import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.implementation.DiagnosticsClientContext; import com.azure.cosmos.implementation.HttpConstants; import com.azure.cosmos.implementation.ImplementationBridgeHelpers; @@ -121,12 +121,12 @@ protected RxDocumentServiceRequest createDocumentServiceRequestWithFeedRange(Map } request.applyFeedRangeFilter(FeedRangeInternal.convert(feedRange)); - CosmosE2EOperationRetryPolicyConfig e2EOperationRetryConfig = + CosmosEndToEndOperationLatencyPolicyConfig endToEndOperationLatencyConfig = ImplementationBridgeHelpers.CosmosQueryRequestOptionsHelper. getCosmosQueryRequestOptionsAccessor() - .getE2EOperationRetryPolicyConfig(cosmosQueryRequestOptions); - if (e2EOperationRetryConfig != null) { - request.requestContext.setEndToEndOperationLatencyPolicyConfig(e2EOperationRetryConfig); + .getEndToEndOperationLatencyPolicyConfig(cosmosQueryRequestOptions); + if (endToEndOperationLatencyConfig != null) { + request.requestContext.setEndToEndOperationLatencyPolicyConfig(endToEndOperationLatencyConfig); } return request; } @@ -310,12 +310,12 @@ private RxDocumentServiceRequest createQueryDocumentServiceRequest(Map itemFactoryMethod; private String queryName; - private CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig; + private CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig; /** * Instantiates a new query request options. @@ -97,7 +97,7 @@ public CosmosQueryRequestOptions() { this.queryName = options.queryName; this.feedRange = options.feedRange; this.thresholds = options.thresholds; - this.cosmosE2EOperationRetryPolicyConfig = options.cosmosE2EOperationRetryPolicyConfig; + this.cosmosEndToEndOperationLatencyPolicyConfig = options.cosmosEndToEndOperationLatencyPolicyConfig; } void setOperationContextAndListenerTuple(OperationContextAndListenerTuple operationContextAndListenerTuple) { @@ -325,14 +325,14 @@ public int getResponseContinuationTokenLimitInKb() { } /** - * Sets the {@link CosmosE2EOperationRetryPolicyConfig} to be used for the request. If the config is already set + * Sets the {@link CosmosEndToEndOperationLatencyPolicyConfig} to be used for the request. If the config is already set * * on the client, then this will override the client level config for this request * - * @param cosmosE2EOperationRetryPolicyConfig the {@link CosmosE2EOperationRetryPolicyConfig} + * @param cosmosEndToEndOperationLatencyPolicyConfig the {@link CosmosEndToEndOperationLatencyPolicyConfig} * @return the CosmosQueryRequestOptions */ - public CosmosQueryRequestOptions setCosmosE2EOperationRetryPolicyConfig(CosmosE2EOperationRetryPolicyConfig cosmosE2EOperationRetryPolicyConfig) { - this.cosmosE2EOperationRetryPolicyConfig = cosmosE2EOperationRetryPolicyConfig; + public CosmosQueryRequestOptions setCosmosEndToEndOperationLatencyPolicyConfig(CosmosEndToEndOperationLatencyPolicyConfig cosmosEndToEndOperationLatencyPolicyConfig) { + this.cosmosEndToEndOperationLatencyPolicyConfig = cosmosEndToEndOperationLatencyPolicyConfig; return this; } @@ -788,7 +788,7 @@ public RequestOptions toRequestOptions(CosmosQueryRequestOptions queryRequestOpt if (queryRequestOptions.thresholds != null) { requestOptions.setDiagnosticsThresholds(queryRequestOptions.thresholds); } - requestOptions.setCosmosEndToEndLatencyPolicyConfig(queryRequestOptions.cosmosE2EOperationRetryPolicyConfig); + requestOptions.setCosmosEndToEndLatencyPolicyConfig(queryRequestOptions.cosmosEndToEndOperationLatencyPolicyConfig); if (queryRequestOptions.customOptions != null) { for(Map.Entry entry : queryRequestOptions.customOptions.entrySet()) { @@ -821,14 +821,14 @@ public void applyMaxItemCount( } @Override - public CosmosE2EOperationRetryPolicyConfig getE2EOperationRetryPolicyConfig(CosmosQueryRequestOptions options) { - return options.getE2EOperationRetryConfig(); + public CosmosEndToEndOperationLatencyPolicyConfig getEndToEndOperationLatencyPolicyConfig(CosmosQueryRequestOptions options) { + return options.getEndToEndOperationLatencyConfig(); } }); } - private CosmosE2EOperationRetryPolicyConfig getE2EOperationRetryConfig() { - return cosmosE2EOperationRetryPolicyConfig; + private CosmosEndToEndOperationLatencyPolicyConfig getEndToEndOperationLatencyConfig() { + return cosmosEndToEndOperationLatencyPolicyConfig; } static { initialize(); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java index 07001414a92a7..8fc0565b34ffc 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java @@ -964,5 +964,6 @@ public static void initializeAllAccessors() { PartitionKey.initialize(); CosmosClientTelemetryConfig.initialize(); CosmosContainerIdentity.initialize(); + PriorityLevel.initialize(); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/PriorityLevel.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/PriorityLevel.java index d691f1393e75b..72fdf901e9b31 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/PriorityLevel.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/PriorityLevel.java @@ -3,30 +3,130 @@ package com.azure.cosmos.models; +import java.time.Duration; +import java.util.Collection; +import java.util.EnumSet; +import java.util.Locale; +import java.util.Objects; +import java.util.StringJoiner; + +import com.azure.core.http.ProxyOptions; +import com.azure.core.util.tracing.Tracer; +import com.azure.cosmos.CosmosDiagnosticsHandler; +import com.azure.cosmos.CosmosDiagnosticsThresholds; +import com.azure.cosmos.implementation.ImplementationBridgeHelpers; +import com.azure.cosmos.implementation.clienttelemetry.ClientTelemetry; +import com.azure.cosmos.implementation.clienttelemetry.CosmosMeterOptions; +import com.azure.cosmos.implementation.clienttelemetry.MetricCategory; +import com.azure.cosmos.implementation.clienttelemetry.TagName; +import com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdConstants; +import com.fasterxml.jackson.annotation.JsonValue; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tag; + +import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull; + /** * Enumeration specifying Priority Level of requests */ -public enum PriorityLevel { +public final class PriorityLevel { + + private final String name; + private final byte priorityValue; + + private PriorityLevel(String name, byte priorityValue) { + this.name = name; + this.priorityValue = priorityValue; + } + /** * High Priority level */ - High(1), + public static final PriorityLevel HIGH = new PriorityLevel("High", (byte)1); + /** * Low Priority level */ - Low(2); + public static final PriorityLevel LOW = new PriorityLevel("Low", (byte)2); - private final int priorityValue; + /** + * Gets the corresponding priority level from its string representation. + * + * @param name The name of the Cosmos priority level to convert. + * + * @return The corresponding Cosmos priority level. + */ + public static PriorityLevel fromString(String name) { + checkNotNull(name, "Argument 'name' must not be null."); - PriorityLevel(int priorityValue) { - this.priorityValue = priorityValue; + String normalizedName = name.trim().toLowerCase(Locale.ROOT); + switch (normalizedName) { + case "low": return PriorityLevel.LOW; + case "high": return PriorityLevel.HIGH; + + default: + String errorMessage = String.format( + "Argument 'name' has invalid value '%s' - valid values are: %s", + name, + getValidValues()); + + throw new IllegalArgumentException(errorMessage); + } } - /** - * Gets the numerical value of priority level - * @return priority numerical value. - */ - public int getPriorityValue() { + @Override + @JsonValue + public String toString() { + return this.name; + } + + @Override + public int hashCode() { + return Objects.hash(CosmosMetricCategory.class, this.name); + } + + @SuppressWarnings("unchecked") + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } else if (!PriorityLevel.class.isAssignableFrom(obj.getClass())) { + return false; + } else if (obj == this) { + return true; + } else if (this.name == null) { + return ((PriorityLevel) obj).name == null; + } else { + return this.name.equals(((PriorityLevel) obj).name); + } + } + + byte getPriorityValue() { return this.priorityValue; } + + private static String getValidValues() { + return new StringJoiner(", ") + .add(PriorityLevel.HIGH.name) + .add(PriorityLevel.LOW.name) + .toString(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // the following helper/accessor only helps to access this class outside of this package.// + /////////////////////////////////////////////////////////////////////////////////////////// + static void initialize() { + ImplementationBridgeHelpers.PriorityLevelHelper.setPriorityLevelAccessor( + new ImplementationBridgeHelpers.PriorityLevelHelper.PriorityLevelAccessor() { + + @Override + public byte getPriorityValue(PriorityLevel level) { + checkNotNull(level, "Argument 'level' must not be null."); + return level.getPriorityValue(); + } + }); + } + + static { initialize(); } }