diff --git a/Microsoft.Azure.Cosmos/src/Routing/LocationCache.cs b/Microsoft.Azure.Cosmos/src/Routing/LocationCache.cs index 208cde6a2d..2beaaaaef3 100644 --- a/Microsoft.Azure.Cosmos/src/Routing/LocationCache.cs +++ b/Microsoft.Azure.Cosmos/src/Routing/LocationCache.cs @@ -79,8 +79,9 @@ public ReadOnlyCollection ReadEndpoints { get { - if (this.locationUnavailablityInfoByEndpoint.Count > 0 - && DateTime.UtcNow - this.lastCacheUpdateTimestamp > this.unavailableLocationsExpirationTime) + // Hot-path: avoid ConcurrentDictionary methods which acquire locks + if (DateTime.UtcNow - this.lastCacheUpdateTimestamp > this.unavailableLocationsExpirationTime + && this.locationUnavailablityInfoByEndpoint.Any()) { this.UpdateLocationCache(); } @@ -98,8 +99,9 @@ public ReadOnlyCollection WriteEndpoints { get { - if (this.locationUnavailablityInfoByEndpoint.Count > 0 - && DateTime.UtcNow - this.lastCacheUpdateTimestamp > this.unavailableLocationsExpirationTime) + // Hot-path: avoid ConcurrentDictionary methods which acquire locks + if (DateTime.UtcNow - this.lastCacheUpdateTimestamp > this.unavailableLocationsExpirationTime + && this.locationUnavailablityInfoByEndpoint.Any()) { this.UpdateLocationCache(); } diff --git a/changelog.md b/changelog.md index 08f06c0945..36838f5cae 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,3 @@ -# Changelog - -All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). @@ -14,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [#548](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/548) Fixed mis-typed message in CosmosException.ToString(); +- [#558](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/558) LocationCache ConcurrentDict lock contention fix ## [3.0.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.0.0) - 2019-07-15