Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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));
        }
Example #4
0
        private static MiniServer FindAndReturnMiniServerFromCacheForASite(ADObjectId siteId, int versionNumber, string identifier, bool needsExactVersionMatch)
        {
            int        startIndex = -1;
            int        endIndex   = -1;
            MiniServer miniServer = null;

            if (ServersCache.SiteToServersDictionary.ContainsKey(siteId))
            {
                try
                {
                    ServersCache.CacheLockForSiteToServersDictionary.EnterReadLock();
                    List <ServersCache.ServerInfo> list = ServersCache.SiteToServersDictionary[siteId];
                    if (ServersCache.IsLocalSite(siteId))
                    {
                        if (DateTime.UtcNow - ServersCache.LastRefreshTimeForLocalSiteCache > ServersCache.RefreshInterval)
                        {
                            miniServer = null;
                        }
                        else
                        {
                            bool flag = ServersCache.TryCalculateStartAndEndIndex(list, versionNumber, needsExactVersionMatch, out startIndex, out endIndex);
                            if (flag)
                            {
                                int index = ServersCache.GenerateIndexOfServer(startIndex, endIndex, identifier);
                                miniServer = list[index].MiniServer;
                            }
                        }
                    }
                    else
                    {
                        miniServer = ServersCache.FindMiniServerInListWithoutAffinity(list, versionNumber, needsExactVersionMatch);
                    }
                    if (miniServer == null)
                    {
                        ServersCache.Tracer.TraceError <int>(0L, "ServersCache: No server with the version number {0} in the cache.", versionNumber);
                    }
                    return(miniServer);
                }
                finally
                {
                    ServersCache.CacheLockForSiteToServersDictionary.ExitReadLock();
                }
            }
            return(null);
        }
Example #5
0
 private static void UpdateMiniServerIntoCache(MiniServer miniServer)
 {
     ServersCache.ServerInfo serverInfo = null;
     if (miniServer != null)
     {
         try
         {
             ServersCache.CacheLockForServersDictionary.EnterWriteLock();
             serverInfo = new ServersCache.ServerInfo(DateTime.UtcNow, miniServer);
             ServersCache.ServersDictionary[miniServer.Fqdn] = serverInfo;
         }
         finally
         {
             ServersCache.CacheLockForServersDictionary.ExitWriteLock();
         }
         ADObjectId serverSite = miniServer.ServerSite;
         if (!ServersCache.IsLocalSite(serverSite))
         {
             try
             {
                 ServersCache.CacheLockForSiteToServersDictionary.EnterWriteLock();
                 if (ServersCache.SiteToServersDictionary.ContainsKey(serverSite))
                 {
                     ServersCache.UpdateServerInfoInList(ServersCache.SiteToServersDictionary[serverSite], serverInfo);
                 }
                 else
                 {
                     List <ServersCache.ServerInfo> list = new List <ServersCache.ServerInfo>();
                     list.Add(serverInfo);
                     ServersCache.SiteToServersDictionary[serverSite] = list;
                 }
             }
             finally
             {
                 ServersCache.CacheLockForSiteToServersDictionary.ExitWriteLock();
             }
         }
     }
 }
Example #6
0
        internal static MiniServer GetServerByFQDN(string serverFQDN, out bool isFromCache)
        {
            if (string.IsNullOrWhiteSpace(serverFQDN))
            {
                throw new ArgumentNullException("serverName should not be empty or null.");
            }
            isFromCache = true;
            try
            {
                ServersCache.CacheLockForServersDictionary.EnterReadLock();
                if (ServersCache.ServersDictionary.ContainsKey(serverFQDN) && DateTime.UtcNow - ServersCache.ServersDictionary[serverFQDN].LastRefreshTime <= ServersCache.RefreshInterval)
                {
                    return(ServersCache.ServersDictionary[serverFQDN].MiniServer);
                }
            }
            finally
            {
                ServersCache.CacheLockForServersDictionary.ExitReadLock();
            }
            MiniServer result = ServersCache.MakeADQueryToGetServer(serverFQDN);

            isFromCache = false;
            return(result);
        }
Example #7
0
 internal static MiniServer GetAnyBackEndServerWithMinVersion(int miniversionNumber)
 {
     return(ServersCache.GetAnyBackEndServer(miniversionNumber, false));
 }
Example #8
0
 internal static MiniServer GetAnyBackEndServerWithExactVersion(int versionNumber)
 {
     return(ServersCache.GetAnyBackEndServer(versionNumber, true));
 }
Example #9
0
 internal static MiniServer GetAnyBackEndServerFromASite(ADObjectId adSiteId, int versionNumber, bool needsExactVersionMatch = false)
 {
     return(ServersCache.GetDeterministicBackEndServerForASite(versionNumber, null, needsExactVersionMatch, adSiteId));
 }
Example #10
0
 internal static MiniServer GetAnyBackEndServerFromLocalSite(int versionNumber, bool needsExactVersionMatch = false)
 {
     return(ServersCache.GetDeterministicBackEndServerForASite(versionNumber, null, needsExactVersionMatch, null));
 }
Example #11
0
        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);
        }