private static MiniServer GetAnyBackEndServer(int versionNumber, bool needsExactVersionMatch) { MiniServer miniServer = null; try { miniServer = ServersCache.GetDeterministicBackEndServerForASite(versionNumber, null, needsExactVersionMatch, null); } catch (ServerHasNotBeenFoundException) { } if (miniServer != null) { return(miniServer); } try { ServersCache.CacheLockForServersDictionary.EnterReadLock(); miniServer = ServersCache.FindMiniServerInListWithoutAffinity(ServersCache.ServersDictionary.Values.ToList <ServersCache.ServerInfo>(), versionNumber, needsExactVersionMatch); } finally { ServersCache.CacheLockForServersDictionary.ExitReadLock(); } if (miniServer != null) { return(miniServer); } MiniServer oneMailboxServerForASite = ServersCache.GetOneMailboxServerForASite(null, versionNumber, needsExactVersionMatch); ServersCache.UpdateMiniServerIntoCache(oneMailboxServerForASite); return(oneMailboxServerForASite); }
private static MiniServer MakeADQueryToGetServer(string serverFQDN) { ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.NonCacheSessionFactory.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 622, "MakeADQueryToGetServer", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SystemConfiguration\\ConfigurationCache\\ServersCache.cs"); MiniServer miniServer = topologyConfigurationSession.FindMiniServerByFqdn(serverFQDN); ServersCache.UpdateMiniServerIntoCache(miniServer); if (miniServer == null) { throw new LocalServerNotFoundException(serverFQDN); } return(miniServer); }
internal static MiniServer GetDeterministicBackEndServerFromSameSite(string sourceServerFQDN, int versionNumber, string identifier, bool needsExactVersionMatch = false) { if (string.IsNullOrWhiteSpace(sourceServerFQDN)) { throw new ArgumentNullException("sourceServerName should not be null"); } bool flag = true; MiniServer serverByFQDN = ServersCache.GetServerByFQDN(sourceServerFQDN, out flag); if (!flag) { ServersCache.UpdateMiniServerIntoCache(serverByFQDN); } ADObjectId serverSite = serverByFQDN.ServerSite; return(ServersCache.GetDeterministicBackEndServerForASite(versionNumber, identifier, needsExactVersionMatch, serverSite)); }
private static MiniServer GetDeterministicBackEndServerForASite(int versionNumber, string identifier, bool needsExactVersionMatch = false, ADObjectId adSiteId = null) { ADObjectId adobjectId = (adSiteId != null) ? adSiteId : ServersCache.LocalSiteId; bool flag = ServersCache.IsLocalSite(adobjectId); MiniServer miniServer = ServersCache.FindAndReturnMiniServerFromCacheForASite(adobjectId, versionNumber, identifier, needsExactVersionMatch); if (miniServer != null) { return(miniServer); } if (flag) { if (ServersCache.SiteToServersDictionary.ContainsKey(adobjectId) && DateTime.UtcNow - ServersCache.LastRefreshTimeForLocalSiteCache <= ServersCache.RefreshInterval) { throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name); } lock (ServersCache.LockForLocalSiteDiscovery) { if (ServersCache.SiteToServersDictionary.ContainsKey(adobjectId) && DateTime.UtcNow - ServersCache.LastRefreshTimeForLocalSiteCache <= ServersCache.RefreshInterval) { MiniServer miniServer2 = ServersCache.FindAndReturnMiniServerFromCacheForASite(adobjectId, versionNumber, identifier, needsExactVersionMatch); if (miniServer2 == null) { ServersCache.Tracer.TraceError(0L, "ServersCache: No server with the version number {0}, identifier '{1}', needsExactVersionMatch {2} and siteId.Name {3} in the cache for local site.", new object[] { versionNumber, identifier, needsExactVersionMatch, adobjectId.Name }); } return(miniServer2); } ADPagedReader <MiniServer> adpagedReader = ServersCache.ReadLocalSiteMailboxServers(); List <ServersCache.ServerInfo> list = null; if (adpagedReader == null) { throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name); } list = new List <ServersCache.ServerInfo>(); foreach (MiniServer miniServer3 in adpagedReader) { ServersCache.ServerInfo item = new ServersCache.ServerInfo(DateTime.UtcNow, miniServer3); list.Add(item); } try { ServersCache.CacheLockForServersDictionary.EnterWriteLock(); foreach (ServersCache.ServerInfo serverInfo in list) { ServersCache.ServersDictionary[serverInfo.MiniServer.Fqdn] = serverInfo; } } finally { ServersCache.CacheLockForServersDictionary.ExitWriteLock(); } if (list.Count == 0) { throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name); } ServersCache.LastRefreshTimeForLocalSiteCache = DateTime.UtcNow; try { ServersCache.CacheLockForSiteToServersDictionary.EnterWriteLock(); ServersCache.SiteToServersDictionary[adobjectId] = list; } finally { ServersCache.CacheLockForSiteToServersDictionary.ExitWriteLock(); } MiniServer miniServer4 = ServersCache.FindAndReturnMiniServerFromCacheForASite(adobjectId, versionNumber, identifier, needsExactVersionMatch); if (miniServer4 == null) { throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name); } return(miniServer4); } } MiniServer oneMailboxServerForASite = ServersCache.GetOneMailboxServerForASite(adobjectId, versionNumber, needsExactVersionMatch); ServersCache.UpdateMiniServerIntoCache(oneMailboxServerForASite); return(oneMailboxServerForASite); }