@@ -118,6 +118,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
118118
119119 private readonly bool IsLocalQuorumConsistency = false ;
120120 private readonly bool isReplicaAddressValidationEnabled ;
121+ private readonly bool enableAsyncCacheExceptionNoSharing ;
121122
122123 //Fault Injection
123124 private readonly IChaosInterceptorFactory chaosInterceptorFactory ;
@@ -243,7 +244,9 @@ public DocumentClient(Uri serviceEndpoint,
243244 }
244245
245246 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 ) ;
247250 this . isReplicaAddressValidationEnabled = ConfigurationManager . IsReplicaAddressValidationEnabled ( connectionPolicy ) ;
248251 }
249252
@@ -444,6 +447,7 @@ internal DocumentClient(Uri serviceEndpoint,
444447 /// <param name="remoteCertificateValidationCallback">This delegate responsible for validating the third party certificate. </param>
445448 /// <param name="cosmosClientTelemetryOptions">This is distributed tracing flag</param>
446449 /// <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>
447451 /// <remarks>
448452 /// The service endpoint can be obtained from the Azure Management Portal.
449453 /// 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,
472476 string cosmosClientId = null ,
473477 RemoteCertificateValidationCallback remoteCertificateValidationCallback = null ,
474478 CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null ,
475- IChaosInterceptorFactory chaosInterceptorFactory = null )
479+ IChaosInterceptorFactory chaosInterceptorFactory = null ,
480+ bool enableAsyncCacheExceptionNoSharing = true )
476481 {
477482 if ( sendingRequestEventArgs != null )
478483 {
@@ -491,10 +496,13 @@ internal DocumentClient(Uri serviceEndpoint,
491496 this . receivedResponse += receivedResponseEventArgs ;
492497 }
493498
499+ this . enableAsyncCacheExceptionNoSharing = enableAsyncCacheExceptionNoSharing ;
494500 this . cosmosAuthorization = cosmosAuthorization ?? throw new ArgumentNullException ( nameof ( cosmosAuthorization ) ) ;
495501 this . transportClientHandlerFactory = transportClientHandlerFactory ;
496502 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 ) ;
498506 this . chaosInterceptorFactory = chaosInterceptorFactory ;
499507 this . chaosInterceptor = chaosInterceptorFactory ? . CreateInterceptor ( this ) ;
500508
@@ -675,8 +683,9 @@ private async Task OpenPrivateAsync(CancellationToken cancellationToken)
675683 storeModel : this . GatewayStoreModel ,
676684 tokenProvider : this ,
677685 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 ) ;
680689
681690 DefaultTrace . TraceWarning ( "{0} occurred while OpenAsync. Exception Message: {1}" , ex . ToString ( ) , ex . Message ) ;
682691 }
@@ -938,7 +947,7 @@ internal virtual void Initialize(Uri serviceEndpoint,
938947 servicePoint . ConnectionLimit = this . ConnectionPolicy . MaxConnectionLimit ;
939948#endif
940949
941- this . GlobalEndpointManager = new GlobalEndpointManager ( this , this . ConnectionPolicy ) ;
950+ this . GlobalEndpointManager = new GlobalEndpointManager ( this , this . ConnectionPolicy , this . enableAsyncCacheExceptionNoSharing ) ;
942951 this . PartitionKeyRangeLocation = this . ConnectionPolicy . EnablePartitionLevelFailover || this . ConnectionPolicy . EnablePartitionLevelCircuitBreaker
943952 ? new GlobalPartitionEndpointManagerCore (
944953 this . GlobalEndpointManager ,
@@ -1059,8 +1068,9 @@ private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeCli
10591068 storeModel : this . GatewayStoreModel ,
10601069 tokenProvider : this ,
10611070 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 ) ;
10641074 this . ResetSessionTokenRetryPolicy = new ResetSessionTokenRetryPolicyFactory ( this . sessionContainer , this . collectionCache , this . retryPolicy ) ;
10651075
10661076 gatewayStoreModel . SetCaches ( this . partitionKeyRangeCache , this . collectionCache ) ;
@@ -6722,7 +6732,8 @@ private void InitializeDirectConnectivity(IStoreClientFactory storeClientFactory
67226732 this . accountServiceConfiguration ,
67236733 this . ConnectionPolicy ,
67246734 this . httpClient ,
6725- this . storeClientFactory . GetConnectionStateListener ( ) ) ;
6735+ this . storeClientFactory . GetConnectionStateListener ( ) ,
6736+ this . enableAsyncCacheExceptionNoSharing ) ;
67266737
67276738 this . CreateStoreModel ( subscribeRntbdStatus : true ) ;
67286739 }
0 commit comments