private static bool MaximumTimeToLiveExpired(MiniServerCacheEntry entry) { return(DateTime.UtcNow.CompareTo(entry.MaximumTimeToExpire) > 0); }
private IADServer LookupOrFindMiniServer(string serverShortName, FindMiniServerCacheFailure serverLookup) { ExTraceGlobals.ActiveManagerClientTracer.TraceFunction <string>(0L, "LookupOrFindMiniServer({0})", serverShortName); MiniServerCacheEntry miniServerCacheEntry = null; bool flag = false; bool flag2 = false; try { flag = this.m_rwLock.TryEnterReadLock(MiniServerLookupCache.CacheLockTimeout); if (flag) { bool flag3 = this.m_cache.TryGetValue(serverShortName, out miniServerCacheEntry); bool flag4 = false; if (flag3) { flag4 = MiniServerLookupCache.ShouldExpireCacheEntry(miniServerCacheEntry); ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string, MiniServerCacheEntry, bool>((long)this.GetHashCode(), "LookupOrFindMiniServer( {0} ) was found in the cache: {1}, and shouldExpireEntry={2}", serverShortName, miniServerCacheEntry, flag4); } if (!flag3 || flag4) { flag2 = true; MiniServerLookupCache.m_perfCounters.GetServerForDatabaseClientServerInformationCacheMisses.Increment(); } else { MiniServerLookupCache.m_perfCounters.GetServerForDatabaseClientServerInformationCacheHits.Increment(); } } else { MiniServerLookupCache.Tracer.TraceError((long)this.GetHashCode(), "Timeout waiting for the read lock in MiniServerLookupCache.LookupOrFindAdObject()"); flag2 = true; } } finally { if (flag) { this.m_rwLock.ExitReadLock(); } } if (flag2) { bool flag5 = false; IADServer updatedServer = null; try { InvokeWithTimeout.Invoke(delegate() { updatedServer = serverLookup(); }, this.m_adOperationTimeout); } catch (TimeoutException ex) { StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_ErrorActiveManagerClientADTimeout, serverShortName, new object[] { serverShortName, this.m_adOperationTimeout }); MiniServerLookupCache.Tracer.TraceError <string>((long)this.GetHashCode(), "Timeout on ad query: {0}", ex.Message); flag5 = true; } if (updatedServer != null && this.MinimizeObjects) { updatedServer.Minimize(); } miniServerCacheEntry = new MiniServerCacheEntry(updatedServer, this.m_timeToLive, this.m_timeToNegativeLive, this.m_maximumTimeToLive); bool flag6 = false; try { flag6 = this.m_rwLock.TryEnterWriteLock(MiniServerLookupCache.CacheLockTimeout); if (flag6) { if (updatedServer == null && flag5) { MiniServerCacheEntry miniServerCacheEntry2 = null; bool flag7 = this.m_cache.TryGetValue(serverShortName, out miniServerCacheEntry2); if (flag7 && !MiniServerLookupCache.MaximumTimeToLiveExpired(miniServerCacheEntry2)) { miniServerCacheEntry = miniServerCacheEntry2; ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <IADServer, MiniServerCacheEntry>((long)this.GetHashCode(), "New ad object was not found, but found possibly stale result '{0}' in the cache as {1}.", miniServerCacheEntry.MiniServerData, miniServerCacheEntry); } else { flag5 = false; } } if (!flag5) { this.m_cache[serverShortName] = miniServerCacheEntry; ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <IADServer, MiniServerCacheEntry>((long)this.GetHashCode(), "Stored server '{0}' in the cache as {1}.", miniServerCacheEntry.MiniServerData, miniServerCacheEntry); } } else { MiniServerLookupCache.Tracer.TraceError((long)this.GetHashCode(), "Timeout waiting for write lock in MiniServerLookupCache.LookupOrFindAdObject()"); } } finally { if (flag6) { this.m_rwLock.ExitWriteLock(); } } } MiniServerLookupCache.m_perfCounters.GetServerForDatabaseClientServerInformationCacheEntries.RawValue = (long)this.m_cache.Count; return(miniServerCacheEntry.MiniServerData); }
private static bool ShouldExpireCacheEntry(MiniServerCacheEntry entry) { return(DateTime.UtcNow.CompareTo(entry.TimeToExpire) > 0); }