Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session timeout 404/1002 HA fixes #18594

Merged
merged 15 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sdk/cosmos/azure-cosmos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,27 @@ Licensed under the MIT License.
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB endpoint with multi region support -->
<id>multi-region</id>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the CIs provide multi-region account to the existing test group.
Why do we need this additional test group?
also is there a specific consistency configured in the CI for the test group?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any group which runs only multi-region single master. My test need that case explicitly

<properties>
<test.groups>multi-region</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-failsafe-plugin;external_dependency} -->
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/multi-region-testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB endpoint -->
<id>examples</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private ShouldRetryResult shouldRetryOnSessionNotAvailable() {
// on all locations, then don't retry the request
return ShouldRetryResult.noRetry();
} else {
this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, this.sessionTokenRetryCount > 1);
this.retryContext = new RetryContext(this.sessionTokenRetryCount , true);
return ShouldRetryResult.retryAfter(Duration.ZERO);
}
} else {
Expand All @@ -177,7 +177,7 @@ private ShouldRetryResult shouldRetryOnSessionNotAvailable() {
// we have already tried this request on the write location
return ShouldRetryResult.noRetry();
} else {
this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, false);
ealsur marked this conversation as resolved.
Show resolved Hide resolved
this.retryContext = new RetryContext(0, false);
return ShouldRetryResult.retryAfter(Duration.ZERO);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,9 +1856,6 @@ private Mono<ResourceResponse<Document>> readDocumentInternal(String documentLin
Mono<RxDocumentServiceRequest> requestObs = addPartitionKeyInformation(request, null, null, options, collectionObs);

return requestObs.flatMap(req -> {
if (retryPolicyInstance != null) {
retryPolicyInstance.onBeforeSendRequest(request);
}
return this.read(request, retryPolicyInstance).map(serviceResponse -> toResourceResponse(serviceResponse, Document.class));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ public DocumentProducer(
} catch (Exception e) {
return Mono.error(e);
}
retryPolicy.onBeforeSendRequest(request);
}

DocumentClientRetryPolicy finalRetryPolicy = retryPolicy;
return ObservableHelper.inlineIfPossibleAsObs(
() -> {
if(finalRetryPolicy != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch. thanks

finalRetryPolicy.onBeforeSendRequest(request);
}

++retries;
return executeRequestFunc.apply(request);
}, retryPolicy);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Mono<ResourceResponse<Database>> deleteDatabase(String id) {
}
}

@BeforeSuite(groups = {"simple", "long", "direct", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SETUP_TIMEOUT)
@BeforeSuite(groups = {"simple", "long", "direct", "multi-region", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SETUP_TIMEOUT)
public static void beforeSuite() {
logger.info("beforeSuite Started");
AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build();
Expand All @@ -151,7 +151,7 @@ public static void beforeSuite() {
}
}

@AfterSuite(groups = {"simple", "long", "direct", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SHUTDOWN_TIMEOUT)
@AfterSuite(groups = {"simple", "long", "direct", "multi-region", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SHUTDOWN_TIMEOUT)
public static void afterSuite() {
logger.info("afterSuite Started");
AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.implementation.AsyncDocumentClient;
import com.azure.cosmos.implementation.ConnectionPolicy;
import com.azure.cosmos.implementation.DatabaseAccount;
import com.azure.cosmos.implementation.GlobalEndpointManager;
import com.azure.cosmos.implementation.RxDocumentClientImpl;
import com.azure.cosmos.implementation.RxStoreModel;
Expand Down Expand Up @@ -191,4 +190,27 @@ public static void setServerStoreModel (RxDocumentClientImpl client, RxStoreMode
set(client, storeModel, "storeModel");
}

public static ReplicatedResourceClient getReplicatedResourceClient(StoreClient storeClient) {
return get(ReplicatedResourceClient.class, storeClient, "replicatedResourceClient");
}

public static ConsistencyReader getConsistencyReader(ReplicatedResourceClient replicatedResourceClient) {
return get(ConsistencyReader.class, replicatedResourceClient, "consistencyReader");
}

public static ConsistencyWriter getConsistencyWriter(ReplicatedResourceClient replicatedResourceClient) {
return get(ConsistencyWriter.class, replicatedResourceClient, "consistencyWriter");
}

public static StoreReader getStoreReader(ConsistencyReader consistencyReader) {
return get(StoreReader.class, consistencyReader, "storeReader");
}

public static void setTransportClient(StoreReader storeReader, TransportClient transportClient) {
set(storeReader, transportClient, "transportClient");
}

public static void setTransportClient(ConsistencyWriter consistencyWriter, TransportClient transportClient) {
set(consistencyWriter, transportClient, "transportClient");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public CosmosAsyncDatabase getDatabase(String id) {
}
}

@BeforeSuite(groups = {"simple", "long", "direct", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SETUP_TIMEOUT)
@BeforeSuite(groups = {"simple", "long", "direct", "multi-region", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SETUP_TIMEOUT)
public static void beforeSuite() {

logger.info("beforeSuite Started");
Expand All @@ -211,7 +211,7 @@ public static void beforeSuite() {
}
}

@AfterSuite(groups = {"simple", "long", "direct", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SHUTDOWN_TIMEOUT)
@AfterSuite(groups = {"simple", "long", "direct", "multi-region", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SHUTDOWN_TIMEOUT)
public static void afterSuite() {

logger.info("afterSuite Started");
Expand Down
35 changes: 35 additions & 0 deletions sdk/cosmos/azure-cosmos/src/test/resources/multi-region-testng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
~ The MIT License (MIT)
~ Copyright (c) 2018 Microsoft Corporation
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="multi-region">
<test name="multi-region" group-by-instances="true">
<groups>
<run>
<include name="multi-region"/>
</run>
</groups>
<packages>
<package name="com.azure.cosmos.*"/>
</packages>
</test>
</suite>
11 changes: 11 additions & 0 deletions sdk/cosmos/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ jobs:
ACCOUNT_CONSISTENCY: 'Session'
DESIRED_CONSISTENCIES: '["Session"]'
PREFERRED_LOCATIONS: null
# 15m 10s, expect passed
Session_Single_Master_Multi_Region_Tcp_MultiRegion:
ArmTemplateParameters: "@{ enableMultipleWriteLocations = $false; defaultConsistencyLevel = 'Session'; enableMultipleRegions = $true}"
DisplayName: Single Master Multi Region Multi-Region
Pool: azsdk-pool-mms-ubuntu-1804-general
OSVmImage: MMSUbuntu18.04
ProfileFlag: '-Pmulti-region'
PROTOCOLS: '["Tcp"]'
ACCOUNT_CONSISTENCY: 'Session'
DESIRED_CONSISTENCIES: '["Session"]'
PREFERRED_LOCATIONS: null

PreRunSteps:
- template: /eng/pipelines/templates/steps/install-reporting-tools.yml
Expand Down