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

Availability: Adds account-level read regions as effective preferred regions when preferred regions is not set on client. #4709

Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4597f2d
Initial changes to LocationCache.
jeet1995 Sep 9, 2024
4b2a455
Intial changes to LocationCache.
jeet1995 Sep 9, 2024
7aeaa20
LocationCacheTests changes.
jeet1995 Sep 9, 2024
5a6c044
Update effective preferred regions count in GlobalEndpointManager.cs
jeet1995 Sep 11, 2024
ab14fff
Revert changes.
jeet1995 Sep 11, 2024
45b3f53
Updated LocationCacheTests and CosmosAvailabilityStrategyTests.
jeet1995 Sep 13, 2024
c6758d8
Revert changes.
jeet1995 Sep 13, 2024
8c14ad4
Fixing tests.
jeet1995 Sep 13, 2024
98c0a67
Additional wiring of effective preferred regions.
jeet1995 Sep 13, 2024
49fd41d
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
jeet1995 Sep 13, 2024
31744c2
Modified GlobalEndpointManagerTest.cs
jeet1995 Sep 13, 2024
6ca25a7
Modify LocationCacheTests.cs
jeet1995 Sep 16, 2024
0fb4202
Fix LocationCacheTests.cs
jeet1995 Sep 16, 2024
d42b3e3
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
jeet1995 Sep 16, 2024
b9860a7
Wiring ExcludeRegions for ReadMany.
jeet1995 Sep 16, 2024
39a4c8c
Attempt at fixing line separators.
jeet1995 Sep 18, 2024
d1be991
Delete global.json.
jeet1995 Sep 19, 2024
bcfc960
Fix PR.
jeet1995 Sep 19, 2024
b43e1e0
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
jeet1995 Sep 19, 2024
1c17033
Fix.
jeet1995 Sep 19, 2024
383be32
Addressing review comments.
jeet1995 Sep 28, 2024
e439379
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
kirankumarkolli Oct 6, 2024
edb0175
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
jeet1995 Oct 9, 2024
cd56556
Fix ClientRetryPolicyTests to assert for cross-region retries even wi…
jeet1995 Oct 9, 2024
0500f1a
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
jeet1995 Oct 9, 2024
4ce40cb
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
jeet1995 Oct 9, 2024
d6c783d
Remove PreferredRegions check for AvailabilityStrategy
NaluTripician Oct 9, 2024
cf23272
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
kirankumarkolli Oct 10, 2024
d83230c
Revert locking changes in GlobalEndpointManager.cs
jeet1995 Oct 10, 2024
154abd0
Merge branch 'users/jeet1995/crossRetryScenariosFixWhenPreferredRegio…
jeet1995 Oct 10, 2024
1e04c5c
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
kirankumarkolli Oct 10, 2024
e0c4f9b
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
kirankumarkolli Oct 11, 2024
b05c3d1
Updated comment to reflect available read / write locations are alos …
jeet1995 Oct 13, 2024
bda28f1
Merge branch 'users/jeet1995/crossRetryScenariosFixWhenPreferredRegio…
jeet1995 Oct 13, 2024
20336f4
Update account-level read / write region API in LocationCache.cs
jeet1995 Oct 13, 2024
9d7b5f9
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
jeet1995 Oct 13, 2024
d1db683
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
kundadebdatta Oct 15, 2024
bb424d4
Addressing review comments.
jeet1995 Oct 16, 2024
fc6c94f
Merge branch 'master' into users/jeet1995/crossRetryScenariosFixWhenP…
jeet1995 Oct 16, 2024
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
12 changes: 1 addition & 11 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,7 @@ internal virtual ConnectionPolicy GetConnectionPolicy(int clientId)
{
this.ValidateDirectTCPSettings();
this.ValidateLimitToEndpointSettings();
this.ValidatePartitionLevelFailoverSettings();
this.ValidateAvailabilityStrategy();
this.ValidatePartitionLevelFailoverSettings();

ConnectionPolicy connectionPolicy = new ConnectionPolicy()
{
Expand Down Expand Up @@ -1096,15 +1095,6 @@ private void ValidatePartitionLevelFailoverSettings()
{
throw new ArgumentException($"{nameof(this.ApplicationPreferredRegions)} is required when {nameof(this.EnablePartitionLevelFailover)} is enabled.");
}
}

private void ValidateAvailabilityStrategy()
{
if (this.AvailabilityStrategy != null
&& this.ApplicationPreferredRegions == null && this.ApplicationRegion == null)
{
throw new ArgumentException($"{nameof(this.ApplicationPreferredRegions)} or {nameof(this.ApplicationRegion)} must be set to use {nameof(this.AvailabilityStrategy)}");
}
}

private void ValidateDirectTCPSettings()
Expand Down
36 changes: 28 additions & 8 deletions Microsoft.Azure.Cosmos/src/Routing/GlobalEndpointManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,16 @@ public GlobalEndpointManager(IDocumentClientInternal owner, ConnectionPolicy con
public ReadOnlyCollection<Uri> AccountReadEndpoints => this.locationCache.AccountReadEndpoints;

public ReadOnlyCollection<Uri> WriteEndpoints => this.locationCache.WriteEndpoints;

public int PreferredLocationCount
{
get
{
IList<string> effectivePreferredLocations = this.GetEffectivePreferredLocations();

public int PreferredLocationCount => this.connectionPolicy.PreferredLocations != null ? this.connectionPolicy.PreferredLocations.Count : 0;
return effectivePreferredLocations.Count;
}
}

public bool IsMultimasterMetadataWriteRequest(DocumentServiceRequest request)
{
Expand Down Expand Up @@ -273,8 +281,7 @@ private async Task TryGetAccountPropertiesFromAllLocationsAsync()
return;
}

await this.GetAndUpdateAccountPropertiesAsync(
endpoint: serviceEndpoint);
await this.GetAndUpdateAccountPropertiesAsync(endpoint: serviceEndpoint);
}
}

Expand Down Expand Up @@ -495,8 +502,8 @@ public virtual void InitializeAccountPropertiesAndStartBackgroundRefresh(Account
if (this.cancellationTokenSource.IsCancellationRequested)
{
return;
}

}
this.locationCache.OnDatabaseAccountRead(databaseAccount);

if (this.isBackgroundAccountRefreshActive)
Expand Down Expand Up @@ -544,7 +551,7 @@ public virtual async Task RefreshLocationAsync(bool forceRefresh = false)
public bool CanSupportMultipleWriteLocations(DocumentServiceRequest request)
{
return this.locationCache.CanUseMultipleWriteLocations()
&& this.locationCache.GetAvailableWriteLocations()?.Count > 1
&& this.locationCache.GetAvailableAccountLevelWriteLocations()?.Count > 1
&& (request.ResourceType == ResourceType.Document ||
(request.ResourceType == ResourceType.StoredProcedure && request.OperationType == OperationType.Execute));
}
Expand Down Expand Up @@ -647,7 +654,10 @@ private async Task RefreshDatabaseAccountInternalAsync(bool forceRefresh)
try
{
this.LastBackgroundRefreshUtc = DateTime.UtcNow;
this.locationCache.OnDatabaseAccountRead(await this.GetDatabaseAccountAsync(true));
AccountProperties accountProperties = await this.GetDatabaseAccountAsync(true);

this.locationCache.OnDatabaseAccountRead(accountProperties);

}
catch (Exception ex)
{
Expand All @@ -671,7 +681,7 @@ internal async Task<AccountProperties> GetDatabaseAccountAsync(bool forceRefresh
obsoleteValue: null,
singleValueInitFunc: () => GlobalEndpointManager.GetDatabaseAccountFromAnyLocationsAsync(
this.defaultEndpoint,
this.connectionPolicy.PreferredLocations,
this.GetEffectivePreferredLocations(),
this.connectionPolicy.AccountInitializationCustomEndpoints,
this.GetDatabaseAccountAsync,
this.cancellationTokenSource.Token),
Expand All @@ -689,6 +699,16 @@ private bool SkipRefresh(bool forceRefresh)
TimeSpan timeSinceLastRefresh = DateTime.UtcNow - this.LastBackgroundRefreshUtc;
return (this.isAccountRefreshInProgress || this.MinTimeBetweenAccountRefresh > timeSinceLastRefresh)
&& !forceRefresh;
}

public IList<string> GetEffectivePreferredLocations()
{
if (this.connectionPolicy.PreferredLocations != null && this.connectionPolicy.PreferredLocations.Count > 0)
jeet1995 marked this conversation as resolved.
Show resolved Hide resolved
{
return this.connectionPolicy.PreferredLocations;
}

return this.locationCache.EffectivePreferredLocations;
}
}
}
Loading