diff --git a/Microsoft.Azure.Cosmos/src/direct/Channel.cs b/Microsoft.Azure.Cosmos/src/direct/Channel.cs index ee4b634b58..e4679e4ec7 100644 --- a/Microsoft.Azure.Cosmos/src/direct/Channel.cs +++ b/Microsoft.Azure.Cosmos/src/direct/Channel.cs @@ -529,14 +529,6 @@ private static void HandleTaskTimeout(Task runawayTask, Guid activityId, Guid co TaskContinuationOptions.OnlyOnFaulted); } - /// - public void SetHealthState( - bool isHealthy) - { - // No implementation is required since the channel health state is managed - // using the State enumeration. - } - private enum State { New, diff --git a/Microsoft.Azure.Cosmos/src/direct/ChannelDictionary.cs b/Microsoft.Azure.Cosmos/src/direct/ChannelDictionary.cs index fee76ad56f..4c699c8150 100644 --- a/Microsoft.Azure.Cosmos/src/direct/ChannelDictionary.cs +++ b/Microsoft.Azure.Cosmos/src/direct/ChannelDictionary.cs @@ -42,8 +42,7 @@ public ChannelDictionary(ChannelProperties channelProperties) /// An instance of containing the . public IChannel GetChannel( Uri requestUri, - bool localRegionRequest, - bool validationRequired = false) + bool localRegionRequest) { this.ThrowIfDisposed(); ServerKey key = new ServerKey(requestUri); @@ -57,7 +56,6 @@ public IChannel GetChannel( new Uri(requestUri.GetLeftPart(UriPartial.Authority)), this.channelProperties, localRegionRequest, - validationRequired, this.singleLoadBalancedPartitionForTest); if (this.channels.TryAdd(key, value)) { diff --git a/Microsoft.Azure.Cosmos/src/direct/IChannel.cs b/Microsoft.Azure.Cosmos/src/direct/IChannel.cs index 079868f8e3..32080ddc03 100644 --- a/Microsoft.Azure.Cosmos/src/direct/IChannel.cs +++ b/Microsoft.Azure.Cosmos/src/direct/IChannel.cs @@ -24,13 +24,6 @@ Task RequestAsync( public Task OpenChannelAsync( Guid activityId); - /// - /// Sets the health state. - /// - /// A boolean flag indicating the health state to be set. - public void SetHealthState( - bool isHealthy); - bool Healthy { get; } void Close(); diff --git a/Microsoft.Azure.Cosmos/src/direct/LoadBalancingChannel.cs b/Microsoft.Azure.Cosmos/src/direct/LoadBalancingChannel.cs index c47fb7f35f..23c26823ff 100644 --- a/Microsoft.Azure.Cosmos/src/direct/LoadBalancingChannel.cs +++ b/Microsoft.Azure.Cosmos/src/direct/LoadBalancingChannel.cs @@ -5,7 +5,6 @@ namespace Microsoft.Azure.Documents.Rntbd { using System; using System.Diagnostics; - using System.Threading; using System.Threading.Tasks; // LoadBalancingChannel encapsulates the management of channels that connect to a single @@ -23,19 +22,13 @@ internal sealed class LoadBalancingChannel : IChannel, IDisposable private bool disposed = false; - private readonly ReaderWriterLockSlim healthStateLock = new(LockRecursionPolicy.NoRecursion); - - private volatile bool healthy; - public LoadBalancingChannel( Uri serverUri, ChannelProperties channelProperties, bool localRegionRequest, - bool validationRequired = false, LoadBalancingPartition singleLoadBalancedPartitionForTest = null) { this.serverUri = serverUri; - this.SetHealthState(!validationRequired); if ((channelProperties.PartitionCount < 1) || (channelProperties.PartitionCount > 8)) @@ -93,30 +86,7 @@ public bool Healthy get { this.ThrowIfDisposed(); - this.healthStateLock.EnterReadLock(); - try - { - return this.healthy; - } - finally - { - this.healthStateLock.ExitReadLock(); - } - } - } - - /// - public void SetHealthState( - bool isHealthy) - { - this.healthStateLock.EnterWriteLock(); - try - { - this.healthy = isHealthy; - } - finally - { - this.healthStateLock.ExitWriteLock(); + return true; } } @@ -152,24 +122,21 @@ public Task RequestAsync( /// /// An unique identifier indicating the current activity id. /// A completed task once the channel is opened. - public async Task OpenChannelAsync( + public Task OpenChannelAsync( Guid activityId) { this.ThrowIfDisposed(); if (this.singlePartition != null) { Debug.Assert(this.partitions == null); - await this.OpenChannelToPartitionAsync( - partition: this.singlePartition, - activityId: activityId); + return this.singlePartition.OpenChannelAsync(activityId); } else { Debug.Assert(this.partitions != null); LoadBalancingPartition partition = this.GetLoadBalancedPartition(activityId); - await this.OpenChannelToPartitionAsync( - partition: partition, - activityId: activityId); + return partition.OpenChannelAsync( + activityId); } } @@ -183,18 +150,7 @@ private async Task OpenChannelToPartitionAsync( LoadBalancingPartition partition, Guid activityId) { - try - { - await partition.OpenChannelAsync(activityId); - this.SetHealthState( - isHealthy: true); - } - catch (Exception) - { - this.SetHealthState( - isHealthy: false); - throw; - } + await partition.OpenChannelAsync(activityId); } /// @@ -234,8 +190,6 @@ void IDisposable.Dispose() this.partitions[i].Dispose(); } } - - this.healthStateLock.Dispose(); } private void ThrowIfDisposed() diff --git a/Microsoft.Azure.Cosmos/src/direct/rntbd2/TransportClient.cs b/Microsoft.Azure.Cosmos/src/direct/rntbd2/TransportClient.cs index f41b98fd9f..041943a873 100644 --- a/Microsoft.Azure.Cosmos/src/direct/rntbd2/TransportClient.cs +++ b/Microsoft.Azure.Cosmos/src/direct/rntbd2/TransportClient.cs @@ -130,7 +130,6 @@ internal override async Task InvokeStoreAsync( options: this.DistributedTracingOptions, request: request); #endif - IChannel channel = null; try { TransportClient.IncrementCounters(); @@ -138,7 +137,7 @@ internal override async Task InvokeStoreAsync( operation = "GetChannel"; // Treat all retries as out of region request for open timeout. This is to prevent too many retries because of the shorter time duration. bool localRegionRequest = request.RequestContext.IsRetry ? false : request.RequestContext.LocalRegionRequest; - channel = this.channelDictionary.GetChannel(physicalAddress.Uri, localRegionRequest); + IChannel channel = this.channelDictionary.GetChannel(physicalAddress.Uri, localRegionRequest); TransportClient.GetTransportPerformanceCounters().IncrementRntbdRequestCount(resourceOperation.resourceType, resourceOperation.operationType); @@ -190,9 +189,6 @@ internal override async Task InvokeStoreAsync( operation, request.ResourceAddress, request.ResourceType, resourceOperation, physicalAddress, ex); - channel?.SetHealthState( - isHealthy: false); - if (request.IsReadOnlyRequest) { DefaultTrace.TraceInformation("Converting to Gone (read-only request)"); @@ -234,9 +230,6 @@ internal override async Task InvokeStoreAsync( } catch (DocumentClientException ex) { - channel?.SetHealthState( - isHealthy: false); - transportResponseStatusCode = (int)TransportResponseStatusCode.DocumentClientException; DefaultTrace.TraceInformation("{0} failed: RID: {1}, Resource Type: {2}, Op: {3}, Address: {4}, " + "Exception: {5}", operation, request.ResourceAddress, request.ResourceType, resourceOperation, @@ -250,9 +243,6 @@ internal override async Task InvokeStoreAsync( } catch (Exception ex) { - channel?.SetHealthState( - isHealthy: false); - transportResponseStatusCode = (int)TransportResponseStatusCode.UnknownException; DefaultTrace.TraceInformation("{0} failed: RID: {1}, Resource Type: {2}, Op: {3}, Address: {4}, " + "Exception: {5}", operation, request.ResourceAddress, request.ResourceType, resourceOperation, @@ -353,8 +343,7 @@ internal override Task OpenConnectionAsync( { IChannel channel = this.channelDictionary.GetChannel( requestUri: physicalAddress, - localRegionRequest: false, - validationRequired: true); + localRegionRequest: false); return channel.Healthy ? Task.FromResult(0)