Skip to content

Commit

Permalink
Direct: Adds direct version 3.19 which includes improvements and fixes (
Browse files Browse the repository at this point in the history
#2400)

* bump direct version and wire up

Co-authored-by: Annie Liang <xinlian@microsoft.com>
Co-authored-by: annie-mac <annie-mac@annie-macs-MacBook-Pro.local>
Co-authored-by: j82w <j82w@users.noreply.github.com>
  • Loading branch information
4 people authored Apr 19, 2021
1 parent 56aa533 commit f2b547e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ClientOfficialVersion>3.17.1</ClientOfficialVersion>
<ClientPreviewVersion>3.18.0</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview</ClientPreviewSuffixVersion>
<DirectVersion>3.18.0</DirectVersion>
<DirectVersion>3.19.0</DirectVersion>
<EncryptionVersion>1.0.0-previewV13</EncryptionVersion>
<HybridRowVersion>1.1.0-preview3</HybridRowVersion>
<AboveDirBuildProps>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</AboveDirBuildProps>
Expand Down
22 changes: 20 additions & 2 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
private const string RntbdReceiveHangDetectionTimeConfig = "CosmosDbTcpReceiveHangDetectionTimeSeconds";
private const string RntbdSendHangDetectionTimeConfig = "CosmosDbTcpSendHangDetectionTimeSeconds";
private const string EnableCpuMonitorConfig = "CosmosDbEnableCpuMonitor";
// Env variable
private const string RntbdMaxConcurrentOpeningConnectionCountConfig = "AZURE_COSMOS_TCP_MAX_CONCURRENT_OPENING_CONNECTION_COUNT";

private const int MaxConcurrentConnectionOpenRequestsPerProcessor = 25;
private const int DefaultMaxRequestsPerRntbdChannel = 30;
Expand Down Expand Up @@ -128,6 +130,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
private int rntbdReceiveHangDetectionTimeSeconds = DefaultRntbdReceiveHangDetectionTimeSeconds;
private int rntbdSendHangDetectionTimeSeconds = DefaultRntbdSendHangDetectionTimeSeconds;
private bool enableCpuMonitor = DefaultEnableCpuMonitor;
private int rntbdMaxConcurrentOpeningConnectionCount = 5;

//Consistency
private Documents.ConsistencyLevel? desiredConsistencyLevel;
Expand Down Expand Up @@ -818,8 +821,22 @@ internal virtual void Initialize(Uri serviceEndpoint,
}
#if NETSTANDARD20
}
#endif
#endif
#endif

string rntbdMaxConcurrentOpeningConnectionCountOverrideString = Environment.GetEnvironmentVariable(RntbdMaxConcurrentOpeningConnectionCountConfig);
if (!string.IsNullOrEmpty(rntbdMaxConcurrentOpeningConnectionCountOverrideString))
{
if (Int32.TryParse(rntbdMaxConcurrentOpeningConnectionCountOverrideString, out int rntbdMaxConcurrentOpeningConnectionCountOverrideInt))
{
if (rntbdMaxConcurrentOpeningConnectionCountOverrideInt <= 0)
{
throw new ArgumentException("RntbdMaxConcurrentOpeningConnectionCountConfig should be larger than 0");
}

this.rntbdMaxConcurrentOpeningConnectionCount = rntbdMaxConcurrentOpeningConnectionCountOverrideInt;
}
}

// ConnectionPolicy always overrides appconfig
if (connectionPolicy != null)
Expand Down Expand Up @@ -6490,7 +6507,8 @@ private void InitializeDirectConnectivity(IStoreClientFactory storeClientFactory
enableCpuMonitor: this.enableCpuMonitor,
retryWithConfiguration: this.ConnectionPolicy.RetryOptions?.GetRetryWithConfiguration(),
enableTcpConnectionEndpointRediscovery: this.ConnectionPolicy.EnableTcpConnectionEndpointRediscovery,
addressResolver: this.AddressResolver);
addressResolver: this.AddressResolver,
rntbdMaxConcurrentOpeningConnectionCount: this.rntbdMaxConcurrentOpeningConnectionCount);

if (this.transportClientHandlerFactory != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ private TransportClient GetMockTransportClient(AddressInformation[] addressInfor

mockTransportClient.Setup(
client => client.InvokeResourceOperationAsync(
It.IsAny<Uri>(),
It.IsAny<TransportAddressUri>(),
It.Is<DocumentServiceRequest>(e => this.IsValidDsr(e))))
.Returns((Uri uri, DocumentServiceRequest documentServiceRequest) => Task.FromResult(MockRequestHelper.GetStoreResponse(documentServiceRequest)));
.Returns((TransportAddressUri uri, DocumentServiceRequest documentServiceRequest) => Task.FromResult(MockRequestHelper.GetStoreResponse(documentServiceRequest)));

return mockTransportClient.Object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async Task<HttpResponseMessage> sendFunc(HttpRequestMessage httpRequest)
});
}

StoreResponse sendDirectFunc(Uri uri, DocumentServiceRequest request)
StoreResponse sendDirectFunc(TransportAddressUri uri, DocumentServiceRequest request)
{
return new StoreResponse()
{
Expand Down Expand Up @@ -254,13 +254,13 @@ StoreResponse sendDirectFunc(Uri uri, DocumentServiceRequest request)

private static ServerStoreModel MockServerStoreModel(
object sessionContainer,
Func<Uri, DocumentServiceRequest, StoreResponse> sendDirectFunc)
Func<TransportAddressUri, DocumentServiceRequest, StoreResponse> sendDirectFunc)
{
Mock<TransportClient> mockTransportClient = new Mock<TransportClient>();

mockTransportClient.Setup(
client => client.InvokeResourceOperationAsync(
It.IsAny<Uri>(), It.IsAny<DocumentServiceRequest>()))
It.IsAny<TransportAddressUri>(), It.IsAny<DocumentServiceRequest>()))
.ReturnsAsync(sendDirectFunc);

AddressInformation[] addressInformation = GetMockAddressInformation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private StoreClient GetMockStoreClient()
TransportClient mockTransportClient = this.GetMockTransportClient();
ISessionContainer sessionContainer = new SessionContainer(string.Empty);

StoreReader storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer);
StoreReader storeReader = new StoreReader(mockTransportClient, addressSelector, new AddressEnumerator(), sessionContainer);

Mock<IAuthorizationTokenProvider> mockAuthorizationTokenProvider = new Mock<IAuthorizationTokenProvider>();
mockAuthorizationTokenProvider.Setup(provider => provider.AddSystemAuthorizationHeaderAsync(
Expand Down Expand Up @@ -118,7 +118,7 @@ private TransportClient GetMockTransportClient()
};
mockTransportClient.Setup(
client => client.InvokeResourceOperationAsync(
It.IsAny<Uri>(),
It.IsAny<TransportAddressUri>(),
It.IsAny<DocumentServiceRequest>()))
.ReturnsAsync(mockStoreResponse);

Expand Down
Loading

0 comments on commit f2b547e

Please sign in to comment.