@@ -118,6 +118,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
118
118
119
119
private readonly bool IsLocalQuorumConsistency = false ;
120
120
private readonly bool isReplicaAddressValidationEnabled ;
121
+ private readonly bool enableAsyncCacheExceptionNoSharing ;
121
122
122
123
//Fault Injection
123
124
private readonly IChaosInterceptorFactory chaosInterceptorFactory ;
@@ -243,7 +244,9 @@ public DocumentClient(Uri serviceEndpoint,
243
244
}
244
245
245
246
this . Initialize ( serviceEndpoint , connectionPolicy , desiredConsistencyLevel ) ;
246
- this . initTaskCache = new AsyncCacheNonBlocking < string , bool > ( cancellationToken : this . cancellationTokenSource . Token ) ;
247
+ this . initTaskCache = new AsyncCacheNonBlocking < string , bool > (
248
+ cancellationToken : this . cancellationTokenSource . Token ,
249
+ enableAsyncCacheExceptionNoSharing : this . enableAsyncCacheExceptionNoSharing ) ;
247
250
this . isReplicaAddressValidationEnabled = ConfigurationManager . IsReplicaAddressValidationEnabled ( connectionPolicy ) ;
248
251
}
249
252
@@ -444,6 +447,7 @@ internal DocumentClient(Uri serviceEndpoint,
444
447
/// <param name="remoteCertificateValidationCallback">This delegate responsible for validating the third party certificate. </param>
445
448
/// <param name="cosmosClientTelemetryOptions">This is distributed tracing flag</param>
446
449
/// <param name="chaosInterceptorFactory">This is the chaos interceptor used for fault injection</param>
450
+ /// <param name="enableAsyncCacheExceptionNoSharing">A boolean flag indicating if stack trace optimization is enabled.</param>
447
451
/// <remarks>
448
452
/// The service endpoint can be obtained from the Azure Management Portal.
449
453
/// If you are connecting using one of the Master Keys, these can be obtained along with the endpoint from the Azure Management Portal
@@ -472,7 +476,8 @@ internal DocumentClient(Uri serviceEndpoint,
472
476
string cosmosClientId = null ,
473
477
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null ,
474
478
CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null ,
475
- IChaosInterceptorFactory chaosInterceptorFactory = null )
479
+ IChaosInterceptorFactory chaosInterceptorFactory = null ,
480
+ bool enableAsyncCacheExceptionNoSharing = true )
476
481
{
477
482
if ( sendingRequestEventArgs != null )
478
483
{
@@ -491,10 +496,13 @@ internal DocumentClient(Uri serviceEndpoint,
491
496
this . receivedResponse += receivedResponseEventArgs ;
492
497
}
493
498
499
+ this . enableAsyncCacheExceptionNoSharing = enableAsyncCacheExceptionNoSharing ;
494
500
this . cosmosAuthorization = cosmosAuthorization ?? throw new ArgumentNullException ( nameof ( cosmosAuthorization ) ) ;
495
501
this . transportClientHandlerFactory = transportClientHandlerFactory ;
496
502
this . IsLocalQuorumConsistency = isLocalQuorumConsistency ;
497
- this . initTaskCache = new AsyncCacheNonBlocking < string , bool > ( cancellationToken : this . cancellationTokenSource . Token ) ;
503
+ this . initTaskCache = new AsyncCacheNonBlocking < string , bool > (
504
+ cancellationToken : this . cancellationTokenSource . Token ,
505
+ enableAsyncCacheExceptionNoSharing : this . enableAsyncCacheExceptionNoSharing ) ;
498
506
this . chaosInterceptorFactory = chaosInterceptorFactory ;
499
507
this . chaosInterceptor = chaosInterceptorFactory ? . CreateInterceptor ( this ) ;
500
508
@@ -675,8 +683,9 @@ private async Task OpenPrivateAsync(CancellationToken cancellationToken)
675
683
storeModel : this . GatewayStoreModel ,
676
684
tokenProvider : this ,
677
685
retryPolicy : this . retryPolicy ,
678
- telemetryToServiceHelper : this . telemetryToServiceHelper ) ;
679
- this . partitionKeyRangeCache = new PartitionKeyRangeCache ( this , this . GatewayStoreModel , this . collectionCache , this . GlobalEndpointManager ) ;
686
+ telemetryToServiceHelper : this . telemetryToServiceHelper ,
687
+ enableAsyncCacheExceptionNoSharing : this . enableAsyncCacheExceptionNoSharing ) ;
688
+ this . partitionKeyRangeCache = new PartitionKeyRangeCache ( this , this . GatewayStoreModel , this . collectionCache , this . GlobalEndpointManager , this . enableAsyncCacheExceptionNoSharing ) ;
680
689
681
690
DefaultTrace . TraceWarning ( "{0} occurred while OpenAsync. Exception Message: {1}" , ex . ToString ( ) , ex . Message ) ;
682
691
}
@@ -938,7 +947,7 @@ internal virtual void Initialize(Uri serviceEndpoint,
938
947
servicePoint . ConnectionLimit = this . ConnectionPolicy . MaxConnectionLimit ;
939
948
#endif
940
949
941
- this . GlobalEndpointManager = new GlobalEndpointManager ( this , this . ConnectionPolicy ) ;
950
+ this . GlobalEndpointManager = new GlobalEndpointManager ( this , this . ConnectionPolicy , this . enableAsyncCacheExceptionNoSharing ) ;
942
951
this . PartitionKeyRangeLocation = this . ConnectionPolicy . EnablePartitionLevelFailover || this . ConnectionPolicy . EnablePartitionLevelCircuitBreaker
943
952
? new GlobalPartitionEndpointManagerCore (
944
953
this . GlobalEndpointManager ,
@@ -1059,8 +1068,9 @@ private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeCli
1059
1068
storeModel : this . GatewayStoreModel ,
1060
1069
tokenProvider : this ,
1061
1070
retryPolicy : this . retryPolicy ,
1062
- telemetryToServiceHelper : this . telemetryToServiceHelper ) ;
1063
- this . partitionKeyRangeCache = new PartitionKeyRangeCache ( this , this . GatewayStoreModel , this . collectionCache , this . GlobalEndpointManager ) ;
1071
+ telemetryToServiceHelper : this . telemetryToServiceHelper ,
1072
+ enableAsyncCacheExceptionNoSharing : this . enableAsyncCacheExceptionNoSharing ) ;
1073
+ this . partitionKeyRangeCache = new PartitionKeyRangeCache ( this , this . GatewayStoreModel , this . collectionCache , this . GlobalEndpointManager , this . enableAsyncCacheExceptionNoSharing ) ;
1064
1074
this . ResetSessionTokenRetryPolicy = new ResetSessionTokenRetryPolicyFactory ( this . sessionContainer , this . collectionCache , this . retryPolicy ) ;
1065
1075
1066
1076
gatewayStoreModel . SetCaches ( this . partitionKeyRangeCache , this . collectionCache ) ;
@@ -6722,7 +6732,8 @@ private void InitializeDirectConnectivity(IStoreClientFactory storeClientFactory
6722
6732
this . accountServiceConfiguration ,
6723
6733
this . ConnectionPolicy ,
6724
6734
this . httpClient ,
6725
- this . storeClientFactory . GetConnectionStateListener ( ) ) ;
6735
+ this . storeClientFactory . GetConnectionStateListener ( ) ,
6736
+ this . enableAsyncCacheExceptionNoSharing ) ;
6726
6737
6727
6738
this . CreateStoreModel ( subscribeRntbdStatus : true ) ;
6728
6739
}
0 commit comments