Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void OnBeforeSendRequest(DocumentServiceRequest request)
// Resolve the endpoint for the request and pin the resolution to the resolved endpoint
// This enables marking the endpoint unavailability on endpoint failover/unreachability
this.locationEndpoint = this.isThinClientEnabled
&& ThinClientStoreModel.IsOperationSupportedByThinClient(request)
&& GatewayStoreModel.IsOperationSupportedByThinClient(request)
? this.globalEndpointManager.ResolveThinClientEndpoint(request)
: this.globalEndpointManager.ResolveServiceEndpoint(request);

Expand Down
116 changes: 49 additions & 67 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,16 +1040,16 @@ internal virtual void Initialize(Uri serviceEndpoint,
desiredConsistencyLevel != null ? desiredConsistencyLevel.ToString() : "null"));

this.QueryCompatibilityMode = QueryCompatibilityMode.Default;
}

// Always called from under the lock except when called from Intilialize method during construction.
private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeClientFactory)
{
await this.InitializeGatewayConfigurationReaderAsync();

if (this.desiredConsistencyLevel.HasValue)
{
this.EnsureValidOverwrite(this.desiredConsistencyLevel.Value);
}
// Always called from under the lock except when called from Intilialize method during construction.
private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeClientFactory)
{
await this.InitializeGatewayConfigurationReaderAsync();
if (this.desiredConsistencyLevel.HasValue)
{
this.EnsureValidOverwrite(this.desiredConsistencyLevel.Value);
}

if (!this.ConnectionPolicy.DisablePartitionLevelFailoverClientLevelOverride
Expand All @@ -1058,14 +1058,14 @@ private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeCli
this.ConnectionPolicy.EnablePartitionLevelFailover = this.accountServiceConfiguration.AccountProperties.EnablePartitionLevelFailover.Value;
}

this.isThinClientEnabled = (this.accountServiceConfiguration.AccountProperties?.ThinClientWritableLocationsInternal?.Count ?? 0) > 0;

this.isThinClientEnabled = (this.ConnectionPolicy.ConnectionMode == ConnectionMode.Gateway) &&
(this.accountServiceConfiguration.AccountProperties?.ThinClientWritableLocationsInternal?.Count ?? 0) > 0;
this.ConnectionPolicy.EnablePartitionLevelCircuitBreaker |= this.ConnectionPolicy.EnablePartitionLevelFailover;
this.ConnectionPolicy.UserAgentContainer.AppendFeatures(this.GetUserAgentFeatures());
this.InitializePartitionLevelFailoverWithDefaultHedging();

this.PartitionKeyRangeLocation =
this.ConnectionPolicy.EnablePartitionLevelFailover
this.PartitionKeyRangeLocation =
this.ConnectionPolicy.EnablePartitionLevelFailover
|| this.ConnectionPolicy.EnablePartitionLevelCircuitBreaker
? new GlobalPartitionEndpointManagerCore(
this.GlobalEndpointManager,
Expand All @@ -1074,68 +1074,50 @@ private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeCli
this.isThinClientEnabled)
: GlobalPartitionEndpointManagerNoOp.Instance;

this.retryPolicy = new RetryPolicy(
globalEndpointManager: this.GlobalEndpointManager,
connectionPolicy: this.ConnectionPolicy,
this.retryPolicy = new RetryPolicy(
Comment thread
kundadebdatta marked this conversation as resolved.
Outdated
globalEndpointManager: this.GlobalEndpointManager,
connectionPolicy: this.ConnectionPolicy,
partitionKeyRangeLocationCache: this.PartitionKeyRangeLocation,
isThinClientEnabled: this.isThinClientEnabled);

this.ResetSessionTokenRetryPolicy = this.retryPolicy;

GatewayStoreModel gatewayStoreModel = new GatewayStoreModel(
this.GlobalEndpointManager,
this.sessionContainer,
(Cosmos.ConsistencyLevel)this.accountServiceConfiguration.DefaultConsistencyLevel,
this.eventSource,
this.serializerSettings,
this.httpClient,
this.PartitionKeyRangeLocation,
isPartitionLevelFailoverEnabled: this.ConnectionPolicy.EnablePartitionLevelFailover || this.ConnectionPolicy.EnablePartitionLevelCircuitBreaker);

this.GatewayStoreModel = gatewayStoreModel;

this.collectionCache = new ClientCollectionCache(
sessionContainer: this.sessionContainer,
storeModel: this.GatewayStoreModel,
tokenProvider: this,
retryPolicy: this.retryPolicy,
telemetryToServiceHelper: this.telemetryToServiceHelper,
enableAsyncCacheExceptionNoSharing: this.enableAsyncCacheExceptionNoSharing);
isThinClientEnabled: this.isThinClientEnabled);

this.ResetSessionTokenRetryPolicy = this.retryPolicy;

GatewayStoreModel gatewayStoreModel = new GatewayStoreModel(
endpointManager: this.GlobalEndpointManager,
sessionContainer: this.sessionContainer,
defaultConsistencyLevel: (Cosmos.ConsistencyLevel)this.accountServiceConfiguration.DefaultConsistencyLevel,
eventSource: this.eventSource,
serializerSettings: this.serializerSettings,
httpClient: this.httpClient,
globalPartitionEndpointManager: this.PartitionKeyRangeLocation,
isPartitionLevelFailoverEnabled: this.ConnectionPolicy.EnablePartitionLevelFailover || this.ConnectionPolicy.EnablePartitionLevelCircuitBreaker,
enableThinClientMode: this.isThinClientEnabled,
userAgentContainer: this.ConnectionPolicy.UserAgentContainer);

this.GatewayStoreModel = gatewayStoreModel;

this.collectionCache = new ClientCollectionCache(
sessionContainer: this.sessionContainer,
storeModel: this.GatewayStoreModel,
tokenProvider: this,
retryPolicy: this.retryPolicy,
telemetryToServiceHelper: this.telemetryToServiceHelper,
enableAsyncCacheExceptionNoSharing: this.enableAsyncCacheExceptionNoSharing);
this.partitionKeyRangeCache = new PartitionKeyRangeCache(this, this.GatewayStoreModel, this.collectionCache, this.GlobalEndpointManager, this.enableAsyncCacheExceptionNoSharing);
this.ResetSessionTokenRetryPolicy = new ResetSessionTokenRetryPolicyFactory(this.sessionContainer, this.collectionCache, this.retryPolicy);

gatewayStoreModel.SetCaches(this.partitionKeyRangeCache, this.collectionCache);

if (this.ConnectionPolicy.ConnectionMode == ConnectionMode.Gateway)
{
if (this.isThinClientEnabled)
{
ThinClientStoreModel thinClientStoreModel = new (
endpointManager: this.GlobalEndpointManager,
this.PartitionKeyRangeLocation,
this.sessionContainer,
(Cosmos.ConsistencyLevel)this.accountServiceConfiguration.DefaultConsistencyLevel,
this.eventSource,
this.serializerSettings,
this.httpClient,
this.ConnectionPolicy.UserAgentContainer,
isPartitionLevelFailoverEnabled: this.ConnectionPolicy.EnablePartitionLevelFailover || this.ConnectionPolicy.EnablePartitionLevelCircuitBreaker);

thinClientStoreModel.SetCaches(this.partitionKeyRangeCache, this.collectionCache);
this.StoreModel = this.GatewayStoreModel;
}
else
{
this.InitializeDirectConnectivity(storeClientFactory);
}

this.StoreModel = thinClientStoreModel;
}
else
{
this.StoreModel = this.GatewayStoreModel;
}
}
else
{
this.InitializeDirectConnectivity(storeClientFactory);
}

return true;
return true;
}

private async Task InitializeCachesAsync(string databaseName, DocumentCollection collection, CancellationToken cancellationToken)
Expand Down
Loading
Loading