Skip to content

Commit 89fb1fc

Browse files
Session timeout 404/1002 HA fixes (Azure#18594)
* HA fixes * removing extra onBefore on read request * incremental change in test case * incremental change in test case * ignoring warning from test case * fixing null pointer in test case on document producer * adding another test case for non preferred list * closing clients * using reflection utils methods * adding 0th index for single master explicity to go to master region, improving code readablity * Removing InternalObjectNode from the test case * Adding seperate CI for multi region and single master * stopping the ci * merge with master and fixing new test pipeline
1 parent c0287b9 commit 89fb1fc

File tree

10 files changed

+573
-11
lines changed

10 files changed

+573
-11
lines changed

sdk/cosmos/azure-cosmos/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,27 @@ Licensed under the MIT License.
366366
</plugins>
367367
</build>
368368
</profile>
369+
<profile>
370+
<!-- integration tests, requires Cosmos DB endpoint with multi region support -->
371+
<id>multi-region</id>
372+
<properties>
373+
<test.groups>multi-region</test.groups>
374+
</properties>
375+
<build>
376+
<plugins>
377+
<plugin>
378+
<groupId>org.apache.maven.plugins</groupId>
379+
<artifactId>maven-failsafe-plugin</artifactId>
380+
<version>2.22.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-failsafe-plugin;external_dependency} -->
381+
<configuration>
382+
<suiteXmlFiles>
383+
<suiteXmlFile>src/test/resources/multi-region-testng.xml</suiteXmlFile>
384+
</suiteXmlFiles>
385+
</configuration>
386+
</plugin>
387+
</plugins>
388+
</build>
389+
</profile>
369390
<profile>
370391
<!-- integration tests, requires Cosmos DB endpoint -->
371392
<id>examples</id>

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientRetryPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private ShouldRetryResult shouldRetryOnSessionNotAvailable() {
168168
// on all locations, then don't retry the request
169169
return ShouldRetryResult.noRetry();
170170
} else {
171-
this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, this.sessionTokenRetryCount > 1);
171+
this.retryContext = new RetryContext(this.sessionTokenRetryCount , true);
172172
return ShouldRetryResult.retryAfter(Duration.ZERO);
173173
}
174174
} else {
@@ -177,7 +177,7 @@ private ShouldRetryResult shouldRetryOnSessionNotAvailable() {
177177
// we have already tried this request on the write location
178178
return ShouldRetryResult.noRetry();
179179
} else {
180-
this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, false);
180+
this.retryContext = new RetryContext(0, false);
181181
return ShouldRetryResult.retryAfter(Duration.ZERO);
182182
}
183183
}

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,9 +1856,6 @@ private Mono<ResourceResponse<Document>> readDocumentInternal(String documentLin
18561856
Mono<RxDocumentServiceRequest> requestObs = addPartitionKeyInformation(request, null, null, options, collectionObs);
18571857

18581858
return requestObs.flatMap(req -> {
1859-
if (retryPolicyInstance != null) {
1860-
retryPolicyInstance.onBeforeSendRequest(request);
1861-
}
18621859
return this.read(request, retryPolicyInstance).map(serviceResponse -> toResourceResponse(serviceResponse, Document.class));
18631860
});
18641861

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentProducer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ public DocumentProducer(
136136
} catch (Exception e) {
137137
return Mono.error(e);
138138
}
139-
retryPolicy.onBeforeSendRequest(request);
140139
}
140+
141+
DocumentClientRetryPolicy finalRetryPolicy = retryPolicy;
141142
return ObservableHelper.inlineIfPossibleAsObs(
142143
() -> {
144+
if(finalRetryPolicy != null) {
145+
finalRetryPolicy.onBeforeSendRequest(request);
146+
}
147+
143148
++retries;
144149
return executeRequestFunc.apply(request);
145150
}, retryPolicy);

sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SessionNotAvailableRetryTest.java

Lines changed: 471 additions & 0 deletions
Large diffs are not rendered by default.

sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public Mono<ResourceResponse<Database>> deleteDatabase(String id) {
134134
}
135135
}
136136

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

154-
@AfterSuite(groups = {"simple", "long", "direct", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SHUTDOWN_TIMEOUT)
154+
@AfterSuite(groups = {"simple", "long", "direct", "multi-region", "multi-master", "emulator", "non-emulator"}, timeOut = SUITE_SHUTDOWN_TIMEOUT)
155155
public static void afterSuite() {
156156
logger.info("afterSuite Started");
157157
AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build();

sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.azure.cosmos.CosmosClientBuilder;
1010
import com.azure.cosmos.implementation.AsyncDocumentClient;
1111
import com.azure.cosmos.implementation.ConnectionPolicy;
12-
import com.azure.cosmos.implementation.DatabaseAccount;
1312
import com.azure.cosmos.implementation.GlobalEndpointManager;
1413
import com.azure.cosmos.implementation.RxDocumentClientImpl;
1514
import com.azure.cosmos.implementation.RxStoreModel;
@@ -191,4 +190,27 @@ public static void setServerStoreModel (RxDocumentClientImpl client, RxStoreMode
191190
set(client, storeModel, "storeModel");
192191
}
193192

193+
public static ReplicatedResourceClient getReplicatedResourceClient(StoreClient storeClient) {
194+
return get(ReplicatedResourceClient.class, storeClient, "replicatedResourceClient");
195+
}
196+
197+
public static ConsistencyReader getConsistencyReader(ReplicatedResourceClient replicatedResourceClient) {
198+
return get(ConsistencyReader.class, replicatedResourceClient, "consistencyReader");
199+
}
200+
201+
public static ConsistencyWriter getConsistencyWriter(ReplicatedResourceClient replicatedResourceClient) {
202+
return get(ConsistencyWriter.class, replicatedResourceClient, "consistencyWriter");
203+
}
204+
205+
public static StoreReader getStoreReader(ConsistencyReader consistencyReader) {
206+
return get(StoreReader.class, consistencyReader, "storeReader");
207+
}
208+
209+
public static void setTransportClient(StoreReader storeReader, TransportClient transportClient) {
210+
set(storeReader, transportClient, "transportClient");
211+
}
212+
213+
public static void setTransportClient(ConsistencyWriter consistencyWriter, TransportClient transportClient) {
214+
set(consistencyWriter, transportClient, "transportClient");
215+
}
194216
}

sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public CosmosAsyncDatabase getDatabase(String id) {
195195
}
196196
}
197197

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

201201
logger.info("beforeSuite Started");
@@ -211,7 +211,7 @@ public static void beforeSuite() {
211211
}
212212
}
213213

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

217217
logger.info("afterSuite Started");
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!--
2+
~ The MIT License (MIT)
3+
~ Copyright (c) 2018 Microsoft Corporation
4+
~
5+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
6+
~ of this software and associated documentation files (the "Software"), to deal
7+
~ in the Software without restriction, including without limitation the rights
8+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
~ copies of the Software, and to permit persons to whom the Software is
10+
~ furnished to do so, subject to the following conditions:
11+
~
12+
~ The above copyright notice and this permission notice shall be included in all
13+
~ copies or substantial portions of the Software.
14+
~
15+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
~ SOFTWARE.
22+
-->
23+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
24+
<suite name="multi-region">
25+
<test name="multi-region" group-by-instances="true">
26+
<groups>
27+
<run>
28+
<include name="multi-region"/>
29+
</run>
30+
</groups>
31+
<packages>
32+
<package name="com.azure.cosmos.*"/>
33+
</packages>
34+
</test>
35+
</suite>

sdk/cosmos/tests.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ jobs:
248248
ACCOUNT_CONSISTENCY: 'Session'
249249
DESIRED_CONSISTENCIES: '["Session"]'
250250
PREFERRED_LOCATIONS: null
251+
# 15m 10s, expect passed
252+
Session_Single_Master_Multi_Region_Tcp_MultiRegion:
253+
ArmTemplateParameters: "@{ enableMultipleWriteLocations = $false; defaultConsistencyLevel = 'Session'; enableMultipleRegions = $true}"
254+
DisplayName: Single Master Multi Region Multi-Region
255+
Pool: azsdk-pool-mms-ubuntu-1804-general
256+
OSVmImage: MMSUbuntu18.04
257+
ProfileFlag: '-Pmulti-region'
258+
PROTOCOLS: '["Tcp"]'
259+
ACCOUNT_CONSISTENCY: 'Session'
260+
DESIRED_CONSISTENCIES: '["Session"]'
261+
PREFERRED_LOCATIONS: null
251262

252263
PreRunSteps:
253264
- template: /eng/pipelines/templates/steps/install-reporting-tools.yml

0 commit comments

Comments
 (0)