Skip to content

Commit eb71fce

Browse files
xinlian12Annie Liang
andauthored
Rename API for get/setPreferredLocations and get/setUseMultipleWriteLocations (#10680)
* rename api for get/setPreferredLocations and get/setUseMultipleWriteLocations * clean Co-authored-by: Annie Liang <[email protected]>
1 parent 0162523 commit eb71fce

File tree

10 files changed

+68
-68
lines changed

10 files changed

+68
-68
lines changed

sdk/cosmos/azure-cosmos-examples/src/main/java/com/azure/cosmos/rx/examples/multimaster/samples/MultiMasterScenario.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public MultiMasterScenario() {
5151

5252
for (String region : regions) {
5353
ConnectionPolicy policy = new ConnectionPolicy();
54-
policy.setUsingMultipleWriteLocations(true);
55-
policy.setPreferredLocations(Collections.singletonList(region));
54+
policy.setUsingMultipleWriteRegions(true);
55+
policy.setPreferredRegions(Collections.singletonList(region));
5656

5757
AsyncDocumentClient client =
5858
new AsyncDocumentClient.Builder()

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ public static boolean isEnableMultipleWriteLocations(DatabaseAccount account) {
221221
}
222222

223223
public static boolean getUseMultipleWriteLocations(ConnectionPolicy policy) {
224-
return policy.isUsingMultipleWriteLocations();
224+
return policy.isUsingMultipleWriteRegions();
225225
}
226226

227227
public static void setUseMultipleWriteLocations(ConnectionPolicy policy, boolean value) {
228-
policy.setUsingMultipleWriteLocations(value);
228+
policy.setUsingMultipleWriteRegions(value);
229229
}
230230

231231
public static <E extends CosmosClientException> Uri getRequestUri(CosmosClientException cosmosClientException) {

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConnectionPolicy.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public final class ConnectionPolicy {
2929
private String userAgentSuffix;
3030
private ThrottlingRetryOptions throttlingRetryOptions;
3131
private boolean endpointDiscoveryEnabled = true;
32-
private List<String> preferredLocations;
33-
private boolean usingMultipleWriteLocations = true;
32+
private List<String> preferredRegions;
33+
private boolean usingMultipleWriteRegions = true;
3434
private InetSocketAddress inetSocketProxyAddress;
3535
private Boolean readRequestsFallbackEnabled;
3636

@@ -222,22 +222,22 @@ public ConnectionPolicy setEndpointDiscoveryEnabled(boolean endpointDiscoveryEna
222222
}
223223

224224
/**
225-
* Gets the flag to enable writes on any locations (regions) for geo-replicated database accounts in the Azure
225+
* Gets the flag to enable writes on any regions for geo-replicated database accounts in the Azure
226226
* Cosmos DB service.
227227
* <p>
228228
* When the value of this property is true, the SDK will direct write operations to
229-
* available writable locations of geo-replicated database account. Writable locations
230-
* are ordered by PreferredLocations property. Setting the property value
231-
* to true has no effect until EnableMultipleWriteLocations in DatabaseAccount
229+
* available writable regions of geo-replicated database account. Writable regions
230+
* are ordered by PreferredRegions property. Setting the property value
231+
* to true has no effect until EnableMultipleWriteRegions in DatabaseAccount
232232
* is also set to true.
233233
* <p>
234234
* DEFAULT value is true indicating that writes are directed to
235-
* available writable locations of geo-replicated database account.
235+
* available writable regions of geo-replicated database account.
236236
*
237-
* @return flag to enable writes on any locations (regions) for geo-replicated database accounts.
237+
* @return flag to enable writes on any regions for geo-replicated database accounts.
238238
*/
239-
public boolean isUsingMultipleWriteLocations() {
240-
return this.usingMultipleWriteLocations;
239+
public boolean isUsingMultipleWriteRegions() {
240+
return this.usingMultipleWriteRegions;
241241
}
242242

243243
/**
@@ -257,24 +257,24 @@ public Boolean isReadRequestsFallbackEnabled() {
257257
}
258258

259259
/**
260-
* Sets the flag to enable writes on any locations (regions) for geo-replicated database accounts in the Azure
260+
* Sets the flag to enable writes on any regions for geo-replicated database accounts in the Azure
261261
* Cosmos DB service.
262262
* <p>
263263
* When the value of this property is true, the SDK will direct write operations to
264-
* available writable locations of geo-replicated database account. Writable locations
265-
* are ordered by PreferredLocations property. Setting the property value
266-
* to true has no effect until EnableMultipleWriteLocations in DatabaseAccount
264+
* available writable regions of geo-replicated database account. Writable regions
265+
* are ordered by PreferredRegions property. Setting the property value
266+
* to true has no effect until EnableMultipleWriteRegions in DatabaseAccount
267267
* is also set to true.
268268
* <p>
269269
* DEFAULT value is false indicating that writes are only directed to
270-
* first region in PreferredLocations property.
270+
* first region in PreferredRegions property.
271271
*
272-
* @param usingMultipleWriteLocations flag to enable writes on any locations (regions) for geo-replicated
272+
* @param usingMultipleWriteRegions flag to enable writes on any regions for geo-replicated
273273
* database accounts.
274274
* @return the ConnectionPolicy.
275275
*/
276-
public ConnectionPolicy setUsingMultipleWriteLocations(boolean usingMultipleWriteLocations) {
277-
this.usingMultipleWriteLocations = usingMultipleWriteLocations;
276+
public ConnectionPolicy setUsingMultipleWriteRegions(boolean usingMultipleWriteRegions) {
277+
this.usingMultipleWriteRegions = usingMultipleWriteRegions;
278278
return this;
279279
}
280280

@@ -298,29 +298,29 @@ public ConnectionPolicy setReadRequestsFallbackEnabled(Boolean readRequestsFallb
298298
}
299299

300300
/**
301-
* Gets the preferred locations for geo-replicated database accounts
301+
* Gets the preferred regions for geo-replicated database accounts
302302
*
303-
* @return the list of preferred location.
303+
* @return the list of preferred region.
304304
*/
305-
public List<String> getPreferredLocations() {
306-
return this.preferredLocations != null ? preferredLocations : Collections.emptyList();
305+
public List<String> getPreferredRegions() {
306+
return this.preferredRegions != null ? this.preferredRegions : Collections.emptyList();
307307
}
308308

309309
/**
310-
* Sets the preferred locations for geo-replicated database accounts. For example,
311-
* "East US" as the preferred location.
310+
* Sets the preferred regions for geo-replicated database accounts. For example,
311+
* "East US" as the preferred region.
312312
* <p>
313313
* When EnableEndpointDiscovery is true and PreferredRegions is non-empty,
314-
* the SDK will prefer to use the locations in the collection in the order
314+
* the SDK will prefer to use the regions in the collection in the order
315315
* they are specified to perform operations.
316316
* <p>
317317
* If EnableEndpointDiscovery is set to false, this property is ignored.
318318
*
319-
* @param preferredLocations the list of preferred locations.
319+
* @param preferredRegions the list of preferred regions.
320320
* @return the ConnectionPolicy.
321321
*/
322-
public ConnectionPolicy setPreferredLocations(List<String> preferredLocations) {
323-
this.preferredLocations = preferredLocations;
322+
public ConnectionPolicy setPreferredRegions(List<String> preferredRegions) {
323+
this.preferredRegions = preferredRegions;
324324
return this;
325325
}
326326

@@ -357,8 +357,8 @@ public String toString() {
357357
+ ", userAgentSuffix='" + userAgentSuffix + '\''
358358
+ ", retryOptions=" + throttlingRetryOptions
359359
+ ", enableEndpointDiscovery=" + endpointDiscoveryEnabled
360-
+ ", preferredLocations=" + preferredLocations
361-
+ ", usingMultipleWriteLocations=" + usingMultipleWriteLocations
360+
+ ", preferredRegions=" + preferredRegions
361+
+ ", usingMultipleWriteRegions=" + usingMultipleWriteRegions
362362
+ ", inetSocketProxyAddress=" + inetSocketProxyAddress
363363
+ '}';
364364
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public GlobalEndpointManager(DatabaseAccountManagerInternal owner, ConnectionPol
5050
this.backgroundRefreshLocationTimeIntervalInMS = configs.getUnavailableLocationsExpirationTimeInSeconds() * 1000;
5151
try {
5252
this.locationCache = new LocationCache(
53-
new ArrayList<>(connectionPolicy.getPreferredLocations() != null ?
54-
connectionPolicy.getPreferredLocations():
53+
new ArrayList<>(connectionPolicy.getPreferredRegions() != null ?
54+
connectionPolicy.getPreferredRegions():
5555
Collections.emptyList()
5656
),
5757
owner.getServiceEndpoint(),
@@ -138,7 +138,7 @@ public Mono<Void> refreshLocationAsync(DatabaseAccount databaseAccount, boolean
138138
if (forceRefresh) {
139139
Mono<DatabaseAccount> databaseAccountObs = getDatabaseAccountFromAnyLocationsAsync(
140140
this.defaultEndpoint,
141-
new ArrayList<>(this.connectionPolicy.getPreferredLocations()),
141+
new ArrayList<>(this.connectionPolicy.getPreferredRegions()),
142142
this::getDatabaseAccountAsync);
143143

144144
return databaseAccountObs.map(dbAccount -> {
@@ -186,7 +186,7 @@ private Mono<Void> refreshLocationPrivateAsync(DatabaseAccount databaseAccount)
186186

187187
Mono<DatabaseAccount> databaseAccountObs = getDatabaseAccountFromAnyLocationsAsync(
188188
this.defaultEndpoint,
189-
new ArrayList<>(this.connectionPolicy.getPreferredLocations()),
189+
new ArrayList<>(this.connectionPolicy.getPreferredRegions()),
190190
this::getDatabaseAccountAsync);
191191

192192
return databaseAccountObs.map(dbAccount -> {
@@ -246,7 +246,7 @@ private Mono<Void> startRefreshLocationTimerAsync(boolean initialization) {
246246
}
247247

248248
logger.debug("startRefreshLocationTimerAsync() - Invoking refresh, I was registered on [{}]", now);
249-
Mono<DatabaseAccount> databaseAccountObs = GlobalEndpointManager.getDatabaseAccountFromAnyLocationsAsync(this.defaultEndpoint, new ArrayList<>(this.connectionPolicy.getPreferredLocations()),
249+
Mono<DatabaseAccount> databaseAccountObs = GlobalEndpointManager.getDatabaseAccountFromAnyLocationsAsync(this.defaultEndpoint, new ArrayList<>(this.connectionPolicy.getPreferredRegions()),
250250
this::getDatabaseAccountAsync);
251251

252252
return databaseAccountObs.flatMap(dbAccount -> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private void initializeGatewayConfigurationReader() {
258258
// this.globalEndpointManager.init() must have been already called
259259
// hence asserting it
260260
assert(databaseAccount != null);
261-
this.useMultipleWriteLocations = this.connectionPolicy.isUsingMultipleWriteLocations() && BridgeInternal.isEnableMultipleWriteLocations(databaseAccount);
261+
this.useMultipleWriteLocations = this.connectionPolicy.isUsingMultipleWriteRegions() && BridgeInternal.isEnableMultipleWriteLocations(databaseAccount);
262262

263263
// TODO: add support for openAsync
264264
// https://msdata.visualstudio.com/CosmosDB/_workitems/edit/332589
@@ -3017,7 +3017,7 @@ public Flux<DatabaseAccount> getDatabaseAccountFromEndpoint(URI endpoint) {
30173017
logger.warn(message);
30183018
}).map(rsp -> rsp.getResource(DatabaseAccount.class))
30193019
.doOnNext(databaseAccount -> {
3020-
this.useMultipleWriteLocations = this.connectionPolicy.isUsingMultipleWriteLocations()
3020+
this.useMultipleWriteLocations = this.connectionPolicy.isUsingMultipleWriteRegions()
30213021
&& BridgeInternal.isEnableMultipleWriteLocations(databaseAccount);
30223022
});
30233023
});

sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionPolicyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public Object[][] connectionProtocolModeArgProvider() {
3636
}
3737

3838
@Test(groups = { "unit" })
39-
public void usingMultipleWriteLocations() {
39+
public void usingMultipleWriteRegions() {
4040
ConnectionPolicy policy = new ConnectionPolicy();
41-
assertThat(policy.isUsingMultipleWriteLocations()).isEqualTo(true);
42-
policy.setUsingMultipleWriteLocations(false);
43-
assertThat(policy.isUsingMultipleWriteLocations()).isEqualTo(false);
41+
assertThat(policy.isUsingMultipleWriteRegions()).isEqualTo(true);
42+
policy.setUsingMultipleWriteRegions(false);
43+
assertThat(policy.isUsingMultipleWriteRegions()).isEqualTo(false);
4444
}
4545
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ static protected Builder createGatewayHouseKeepingDocumentClient() {
921921
static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consistencyLevel, boolean multiMasterEnabled, List<String> preferredLocations) {
922922
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
923923
connectionPolicy.setConnectionMode(ConnectionMode.GATEWAY);
924-
connectionPolicy.setUsingMultipleWriteLocations(multiMasterEnabled);
925-
connectionPolicy.setPreferredLocations(preferredLocations);
924+
connectionPolicy.setUsingMultipleWriteRegions(multiMasterEnabled);
925+
connectionPolicy.setPreferredRegions(preferredLocations);
926926
return new Builder().withServiceEndpoint(TestConfigurations.HOST)
927927
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
928928
.withConnectionPolicy(connectionPolicy)
@@ -936,16 +936,16 @@ static protected Builder createGatewayRxDocumentClient() {
936936
static protected Builder createDirectRxDocumentClient(ConsistencyLevel consistencyLevel,
937937
Protocol protocol,
938938
boolean multiMasterEnabled,
939-
List<String> preferredLocations) {
939+
List<String> preferredRegions) {
940940
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
941941
connectionPolicy.setConnectionMode(ConnectionMode.DIRECT);
942942

943-
if (preferredLocations != null) {
944-
connectionPolicy.setPreferredLocations(preferredLocations);
943+
if (preferredRegions != null) {
944+
connectionPolicy.setPreferredRegions(preferredRegions);
945945
}
946946

947947
if (multiMasterEnabled && consistencyLevel == ConsistencyLevel.SESSION) {
948-
connectionPolicy.setUsingMultipleWriteLocations(true);
948+
connectionPolicy.setUsingMultipleWriteRegions(true);
949949
}
950950

951951
Configs configs = Mockito.spy(new Configs());

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ public void refreshLocationAsyncForConnectivityIssue() throws Exception {
129129
* switching to different preferredLocation region
130130
*/
131131
@Test(groups = {"unit"}, timeOut = TIMEOUT)
132-
public void refreshLocationAsyncForConnectivityIssueWithPreferredLocation() throws Exception {
132+
public void refreshLocationAsyncForConnectivityIssueWithPreferredRegions() throws Exception {
133133
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
134134
connectionPolicy.setEndpointDiscoveryEnabled(true);
135-
List<String> preferredLocation = new ArrayList<>();
136-
preferredLocation.add("East US");
137-
preferredLocation.add("East Asia");
138-
connectionPolicy.setPreferredLocations(preferredLocation);
139-
connectionPolicy.setUsingMultipleWriteLocations(true);
135+
List<String> preferredRegions = new ArrayList<>();
136+
preferredRegions.add("East US");
137+
preferredRegions.add("East Asia");
138+
connectionPolicy.setPreferredRegions(preferredRegions);
139+
connectionPolicy.setUsingMultipleWriteRegions(true);
140140
DatabaseAccount databaseAccount = new DatabaseAccount(dbAccountJson1);
141141
Mockito.when(databaseAccountManagerInternal.getDatabaseAccountFromEndpoint(Matchers.any())).thenReturn(Flux.just(databaseAccount));
142142
Mockito.when(databaseAccountManagerInternal.getServiceEndpoint()).thenReturn(new URI("https://testaccount.documents.azure.com:443"));
@@ -225,7 +225,7 @@ public void refreshLocationAsyncForWriteForbidden() throws Exception {
225225
public void backgroundRefreshForMultiMaster() throws Exception {
226226
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
227227
connectionPolicy.setEndpointDiscoveryEnabled(true);
228-
connectionPolicy.setUsingMultipleWriteLocations(true);
228+
connectionPolicy.setUsingMultipleWriteRegions(true);
229229
DatabaseAccount databaseAccount = new DatabaseAccount(dbAccountJson4);
230230
Mockito.when(databaseAccountManagerInternal.getDatabaseAccountFromEndpoint(Matchers.any())).thenReturn(Flux.just(databaseAccount));
231231
Mockito.when(databaseAccountManagerInternal.getServiceEndpoint()).thenReturn(new URI("https://testaccount.documents.azure.com:443"));
@@ -244,7 +244,7 @@ public void backgroundRefreshForMultiMaster() throws Exception {
244244
public void startRefreshLocationTimerAsync() throws Exception {
245245
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
246246
connectionPolicy.setEndpointDiscoveryEnabled(true);
247-
connectionPolicy.setUsingMultipleWriteLocations(true);
247+
connectionPolicy.setUsingMultipleWriteRegions(true);
248248
DatabaseAccount databaseAccount = new DatabaseAccount(dbAccountJson1);
249249
Mockito.when(databaseAccountManagerInternal.getDatabaseAccountFromEndpoint(Matchers.any())).thenReturn(Flux.just(databaseAccount));
250250
Mockito.when(databaseAccountManagerInternal.getServiceEndpoint()).thenReturn(new URI("https://testaccount.documents.azure.com:443"));
@@ -340,7 +340,7 @@ private void setBackgroundRefreshLocationTimeIntervalInMS(GlobalEndpointManager
340340
private GlobalEndpointManager getGlobalEndPointManager() throws Exception {
341341
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
342342
connectionPolicy.setEndpointDiscoveryEnabled(true);
343-
connectionPolicy.setUsingMultipleWriteLocations(true); // currently without this proper, background refresh will not work
343+
connectionPolicy.setUsingMultipleWriteRegions(true); // currently without this proper, background refresh will not work
344344
DatabaseAccount databaseAccount = new DatabaseAccount(dbAccountJson1);
345345
Mockito.when(databaseAccountManagerInternal.getDatabaseAccountFromEndpoint(Matchers.any())).thenReturn(Flux.just(databaseAccount));
346346
Mockito.when(databaseAccountManagerInternal.getServiceEndpoint()).thenReturn(new URI("https://testaccount.documents.azure.com:443"));

sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/routing/LocationCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void initialize(
154154
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
155155
connectionPolicy.setEndpointDiscoveryEnabled(enableEndpointDiscovery);
156156
BridgeInternal.setUseMultipleWriteLocations(connectionPolicy, useMultipleWriteLocations);
157-
connectionPolicy.setPreferredLocations(this.preferredLocations);
157+
connectionPolicy.setPreferredRegions(this.preferredLocations);
158158

159159
this.endpointManager = new GlobalEndpointManager(mockedClient, connectionPolicy, configs);
160160
}

0 commit comments

Comments
 (0)