private void TriggerCacheRefresh(ServiceCache.CachePopulateReason reason, ServiceTopology requestingTopology) { if (requestingTopology != null) { ServiceTopology serviceTopology = this.serviceTopologyInstance; if (requestingTopology != serviceTopology) { return; } if (serviceTopology != null && serviceTopology.CreationTime + ServiceDiscovery.ExchangeTopologyBridge.MinExpirationTimeForCacheDueToCacheMiss > ExDateTime.UtcNow) { return; } } bool flag = false; bool flag2 = this.semaphore.WaitOne(0, false); try { if (flag2 && (requestingTopology == null || requestingTopology == this.serviceTopologyInstance)) { this.StopCacheRefreshTimer(); this.DropCacheIfNeeded(); using (ActivityContext.SuppressThreadScope()) { flag = ThreadPool.QueueUserWorkItem(new WaitCallback(this.PopulateServiceCache), reason); } } } finally { if (flag2 && !flag) { this.semaphore.Release(); } } }
private void PopulateServiceCache(object obj) { ServiceCache.CachePopulateReason cachePopulateReason = (ServiceCache.CachePopulateReason)obj; Exception ex = null; try { try { DateTime dateTime = (cachePopulateReason == ServiceCache.CachePopulateReason.CacheMissDetected || this.serviceTopologyInstance == null) ? DateTime.MinValue : this.serviceTopologyInstance.DiscoveryStarted; bool forceRefresh = false; if (this.dropCacheOnInactivity && dateTime != DateTime.MinValue && this.serviceTopologyInstance.TopologyRequestCount <= 1) { this.DropCache(); return; } if (cachePopulateReason == ServiceCache.CachePopulateReason.CacheMissDetected || (cachePopulateReason == ServiceCache.CachePopulateReason.CacheNotPresent && this.isFirstLoad)) { forceRefresh = true; } ExchangeTopology exchangeTopology = ServiceDiscovery.ExchangeTopologyBridge.ReadExchangeTopology(dateTime, ExchangeTopologyScope.Complete, forceRefresh); if (exchangeTopology != null) { this.serviceTopologyInstance = new ServiceTopology(exchangeTopology, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ServiceDiscovery\\ServiceCache.cs", "PopulateServiceCache", 426); } else if (this.serviceTopologyInstance != null) { this.serviceTopologyInstance.CreationTime = ExDateTime.Now; } this.isFirstLoad = false; if (this.serviceTopologyInstance != null) { this.cachePresentEvent.Set(); } else { ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug(0L, "ServiceCache::ServiceDiscovery.ExchangeTopologyBridge.ReadExchangeTopology returned null. This is unexpected"); } } catch (ServiceDiscoveryPermanentException ex2) { ex = ex2; } catch (ServiceDiscoveryTransientException ex3) { ex = ex3; } this.StartCacheRefreshTimer(); } finally { this.semaphore.Release(); } if (ex == null) { ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <ServiceCache.CachePopulateReason>(0L, "ServiceCache::PopulateServiceCache. Successfully populated ServiceTopology. Reason to populate cache = {0}", cachePopulateReason); ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_PopulatedServiceTopology, null, new object[] { cachePopulateReason }); return; } string text = ex.ToString().TruncateToUseInEventLog(); ExTraceGlobals.ServiceDiscoveryTracer.TraceError <ServiceCache.CachePopulateReason, string>(0L, "ServiceCache::PopulateServiceCache. Failed to populate a ServiceTopology. Reason to populate cache = {0}. Error = {1}.", cachePopulateReason, text); ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorPopulatingServiceTopology, null, new object[] { cachePopulateReason, text }); }