private ActiveManager(bool enableRpcCaching, IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IFindAdObject <IADServer> serverLookup, IFindMiniServer miniServerLookup, IFindAdObject <IADClientAccessArray> casLookup, IFindMiniClientAccessServerOrArray miniCasArrayLookup, IFindAdObject <IADDatabase> databaseLookup, ITopologyConfigurationSession adSession, bool isService) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <bool>((long)this.GetHashCode(), "Active Manager is instantiated (cacheEnabled={0})", enableRpcCaching); if (adSession == null) { throw new ArgumentNullException("adSession"); } IADToplogyConfigurationSession adSession2 = ADSessionFactory.CreateWrapper(adSession); this.m_isCacheEnabled = enableRpcCaching; this.m_adSession = adSession; this.m_disposeTracker = this.GetDisposeTracker(); if (this.m_isCacheEnabled) { this.m_dagLookup = (dagLookup ?? new AdObjectLookupCache <IADDatabaseAvailabilityGroup>(adSession2, AdObjectLookupCache <IADDatabaseAvailabilityGroup> .TimeToLive, AdObjectLookupCache <IADDatabaseAvailabilityGroup> .TimeToNegativeLive, ActiveManager.s_cacheLockTimeout, AdObjectLookupCache <IADDatabaseAvailabilityGroup> .AdOperationTimeout)); this.m_casLookup = (casLookup ?? new AdObjectLookupCache <IADClientAccessArray>(adSession2, AdObjectLookupCache <IADClientAccessArray> .TimeToLive, AdObjectLookupCache <IADClientAccessArray> .TimeToNegativeLive, ActiveManager.s_cacheLockTimeout, AdObjectLookupCache <IADClientAccessArray> .AdOperationTimeout)); this.m_miniServerLookup = (miniServerLookup ?? new MiniServerLookupCache(adSession2, MiniServerLookupCache.TimeToLive, MiniServerLookupCache.TimeToNegativeLive, ActiveManager.s_cacheLockTimeout, MiniServerLookupCache.AdOperationTimeout)); this.m_miniCasArrayLookup = (miniCasArrayLookup ?? new MiniClientAccessServerOrArrayLookupCache(this.m_adSession, MiniClientAccessServerOrArrayLookupCache.TimeToLive, MiniClientAccessServerOrArrayLookupCache.TimeToNegativeLive, ActiveManager.s_cacheLockTimeout, MiniClientAccessServerOrArrayLookupCache.AdOperationTimeout)); this.m_databaseLookup = (databaseLookup ?? new AdObjectLookupCache <IADDatabase>(adSession2, AdObjectLookupCache <IADDatabase> .TimeToLive, AdObjectLookupCache <IADDatabase> .TimeToNegativeLive, ActiveManager.s_cacheLockTimeout, AdObjectLookupCache <IADDatabase> .AdOperationTimeout)); if (!isService) { this.EnableMinimization(); } } else { this.m_dagLookup = (dagLookup ?? new SimpleAdObjectLookup <IADDatabaseAvailabilityGroup>(adSession2)); this.m_casLookup = (casLookup ?? new SimpleAdObjectLookup <IADClientAccessArray>(adSession2)); this.m_miniServerLookup = (miniServerLookup ?? new SimpleMiniServerLookup(adSession2)); this.m_miniCasArrayLookup = (miniCasArrayLookup ?? new SimpleMiniClientAccessServerOrArrayLookup(this.m_adSession)); this.m_databaseLookup = (databaseLookup ?? new SimpleAdObjectLookup <IADDatabase>(adSession2)); } this.CacheUpdateInterval = new TimeSpan(0, 0, 60); this.m_isRunningInService = isService; }
internal static List <ADObjectId> GetOrderedServerIdsForDatabase(IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IADDatabase database, out Exception exception) { List <ADObjectId> masterServerIdsForDatabase = ActiveManagerUtil.GetMasterServerIdsForDatabase(dagLookup, database, out exception); if (exception != null) { return(masterServerIdsForDatabase); } if (masterServerIdsForDatabase == null || masterServerIdsForDatabase.Count == 0) { ExTraceGlobals.ActiveManagerClientTracer.TraceError <string>(0L, "Database {0} master is pointing to a non-existent/deleted server or DAG, the database has been deleted, or the database object is corrupted in the AD.", database.Name); exception = new AmDatabaseMasterIsInvalid(database.Name); return(masterServerIdsForDatabase); } int num = -1; string local = MachineName.Local; for (int i = 0; i < masterServerIdsForDatabase.Count; i++) { if (string.Equals(masterServerIdsForDatabase[i].Name, local, StringComparison.OrdinalIgnoreCase)) { num = i; break; } } if (num > 0) { ADObjectId value = masterServerIdsForDatabase[num]; masterServerIdsForDatabase[num] = masterServerIdsForDatabase[0]; masterServerIdsForDatabase[0] = value; } return(masterServerIdsForDatabase); }
private static IADDatabase GetDatabaseByGuidEx(IFindAdObject <IADDatabase> databaseLookup, Guid databaseId, AdObjectLookupFlags flags, IPerformanceDataLogger perfLogger) { IADDatabase iaddatabase = databaseLookup.FindAdObjectByGuidEx(databaseId, flags, perfLogger); if (iaddatabase == null) { throw new DatabaseNotFoundException(databaseId.ToString()); } return(iaddatabase); }
public static ActiveManager CreateCustomActiveManager(bool cacheRpcRequests, IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IFindAdObject <IADServer> serverLookup, IFindMiniServer miniServerLookup, IFindAdObject <IADClientAccessArray> casLookup, IFindMiniClientAccessServerOrArray miniCasArrayLookup, IFindAdObject <IADDatabase> databaseLookup, ITopologyConfigurationSession adSession, bool isService) { if (adSession == null) { adSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 1200, "CreateCustomActiveManager", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ActiveManager\\ActiveManager.cs"); } IADToplogyConfigurationSession adSession2 = ADSessionFactory.CreateWrapper(adSession); dagLookup = (dagLookup ?? new SimpleAdObjectLookup <IADDatabaseAvailabilityGroup>(adSession2)); serverLookup = (serverLookup ?? new SimpleAdObjectLookup <IADServer>(adSession2)); miniServerLookup = (miniServerLookup ?? new SimpleMiniServerLookup(adSession2)); casLookup = (casLookup ?? new SimpleAdObjectLookup <IADClientAccessArray>(adSession2)); miniCasArrayLookup = (miniCasArrayLookup ?? new SimpleMiniClientAccessServerOrArrayLookup(adSession)); databaseLookup = (databaseLookup ?? new SimpleAdObjectLookup <IADDatabase>(adSession2)); return(new ActiveManager(cacheRpcRequests, dagLookup, serverLookup, miniServerLookup, casLookup, miniCasArrayLookup, databaseLookup, adSession, isService)); }
public static IADDatabase[] GetAllDatabases(IFindAdObject <IADDatabase> databaseLookup, IADServer server) { List <IADDatabase> list = new List <IADDatabase>(20); QueryFilter filter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, server.Name); IADDatabaseCopy[] array = databaseLookup.AdSession.Find <IADDatabaseCopy>(null, QueryScope.SubTree, filter, null, 0); foreach (IADDatabaseCopy iaddatabaseCopy in array) { ADObjectId parent = iaddatabaseCopy.Id.Parent; IADDatabase iaddatabase = databaseLookup.ReadAdObjectByObjectId(parent); if (iaddatabase != null) { list.Add(iaddatabase); } } return((list.Count <IADDatabase>() > 0) ? list.ToArray() : null); }
private static List <ADObjectId> GetMasterServerIdsForDatabase(IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IADDatabase database, out Exception exception) { IADToplogyConfigurationSession adSession = dagLookup.AdSession; List <ADObjectId> list = new List <ADObjectId>(16); exception = null; try { ADObjectId masterServerOrAvailabilityGroup = database.MasterServerOrAvailabilityGroup; if (masterServerOrAvailabilityGroup == null) { return(null); } if (masterServerOrAvailabilityGroup.IsDeleted) { ActiveManagerUtil.Tracer.TraceError <string, string>(0L, "GetMasterServerIdsForDatabase() for database '{0}' found the MasterServerOrAvailabilityGroup to be a link to a deleted object. Returning an empty collection. MasterServerOrAvailabilityGroup = [{1}]", database.Name, masterServerOrAvailabilityGroup.Name); return(null); } IADDatabaseAvailabilityGroup iaddatabaseAvailabilityGroup = dagLookup.ReadAdObjectByObjectId(masterServerOrAvailabilityGroup); if (iaddatabaseAvailabilityGroup != null) { list.AddRange(iaddatabaseAvailabilityGroup.Servers); } else { IADDatabase iaddatabase = adSession.ReadADObject <IADDatabase>(database.Id); ADObjectId adobjectId = null; if (iaddatabase != null) { adobjectId = iaddatabase.MasterServerOrAvailabilityGroup; if (!masterServerOrAvailabilityGroup.Equals(adobjectId)) { ActiveManagerUtil.Tracer.TraceDebug <ADObjectId, ADObjectId>(0L, "GetMasterServerIdsForDatabase() re-read the Database object and it made a difference. MasterServerOrDag was {0} and is now {1}", masterServerOrAvailabilityGroup, adobjectId); iaddatabaseAvailabilityGroup = adSession.ReadADObject <IADDatabaseAvailabilityGroup>(adobjectId); if (iaddatabaseAvailabilityGroup == null) { goto IL_165; } HashSet <string> hashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (string fqdn in iaddatabaseAvailabilityGroup.StoppedMailboxServers) { hashSet.Add(MachineName.GetNodeNameFromFqdn(fqdn)); } using (MultiValuedProperty <ADObjectId> .Enumerator enumerator2 = iaddatabaseAvailabilityGroup.Servers.GetEnumerator()) { while (enumerator2.MoveNext()) { ADObjectId adobjectId2 = enumerator2.Current; if (!hashSet.Contains(adobjectId2.Name)) { list.Add(adobjectId2); } } goto IL_165; } } ActiveManagerUtil.Tracer.TraceDebug <ADObjectId>(0L, "GetMasterServerIdsForDatabase: re-reading the Database object made no difference. MasterServerOrDag is still {0}.", masterServerOrAvailabilityGroup); } IL_165: if (iaddatabaseAvailabilityGroup == null && adobjectId != null) { IADServer iadserver = adSession.ReadMiniServer(adobjectId); if (iadserver != null) { list.Add(adobjectId); } } } } catch (DataValidationException ex) { exception = ex; } catch (ADTransientException ex2) { exception = ex2; } catch (ADOperationException ex3) { exception = ex3; } catch (ADTopologyUnexpectedException ex4) { exception = ex4; } catch (ADTopologyPermanentException ex5) { exception = ex5; } if (exception != null) { ActiveManagerUtil.Tracer.TraceDebug <Exception>(0L, "GetMasterServerIdsForDatabase() got exception: {0}", exception); list = null; } return(list); }
private static IADDatabase GetDatabaseByGuid(IFindAdObject <IADDatabase> databaseLookup, Guid databaseId) { return(ActiveManager.GetDatabaseByGuidEx(databaseLookup, databaseId, AdObjectLookupFlags.None, NullPerformanceDataLogger.Instance)); }
internal static DatabaseLocationInfo GetServerNameForDatabaseInternal(IADDatabase database, NetworkCredential networkCredential, IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IFindMiniServer findMiniServer, ActiveManagerClientPerfmonInstance perfCounters, bool throwOnErrors, bool isService) { Guid guid = database.Guid; string serverFqdn = null; string lastMountedServerFqdn = null; bool isDatabaseHighlyAvailable = false; DateTime mountedTime = DateTime.MinValue; DatabaseLocationInfoResult requestResult = DatabaseLocationInfoResult.Unknown; ServerVersion serverVersion = null; if (ActiveManagerImplementation.TestHookHangGsfdForMilliseconds > 0) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <int>(0L, "TestHook is hanging GetServerNameForDatabaseInternal for {0} milliseconds", ActiveManagerImplementation.TestHookHangGsfdForMilliseconds); Thread.Sleep(ActiveManagerImplementation.TestHookHangGsfdForMilliseconds); } if (Interlocked.Increment(ref ActiveManagerImplementation.NumberOfConcurrentRPCthreads) <= 3000) { try { if (!ActiveManagerImplementation.IsActiveManagerRpcSupported(database)) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Database {0} doesn't support RPC's for ActiveManager", database.Name); } else { try { ActiveManagerImplementation.s_perfCounters.GetServerForDatabaseClientRpcCalls.Increment(); AmDbStatusInfo2 amDbStatusInfo = AmRpcClientHelper.RpcchGetServerForDatabase(database, networkCredential, dagLookup, findMiniServer, perfCounters, isService, out serverVersion); isDatabaseHighlyAvailable = (amDbStatusInfo.IsHighlyAvailable != 0); serverFqdn = amDbStatusInfo.MasterServerFqdn; lastMountedServerFqdn = amDbStatusInfo.LastMountedServerFqdn; mountedTime = amDbStatusInfo.MountedTime; requestResult = DatabaseLocationInfoResult.Success; } catch (AmDatabaseNeverMountedException innerException) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Database {0} was never mounted on any of the servers (defaulting to owner server)", string.Empty); if (throwOnErrors) { throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), innerException); } } catch (AmServerException ex) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Encountered AM Server exception: {0} (defaulting to owner server)", ex.Message); if (throwOnErrors) { throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), ex); } } catch (AmServerTransientException ex2) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Encountered AM Server exception: {0} (defaulting to owner server)", ex2.Message); if (throwOnErrors) { throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), ex2); } } } goto IL_1CF; } finally { Interlocked.Decrement(ref ActiveManagerImplementation.NumberOfConcurrentRPCthreads); } } Interlocked.Decrement(ref ActiveManagerImplementation.NumberOfConcurrentRPCthreads); ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <int>(0L, "Maximum number ({0}) of concurrent RPC threads reached.", 3000); if (throwOnErrors) { throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), new TooManyActiveManagerClientRPCsException(3000)); } IL_1CF: return(new DatabaseLocationInfo(serverFqdn, null, lastMountedServerFqdn, null, null, null, database.Name, false, database.Recovery, Guid.Empty, mountedTime, null, null, serverVersion, MailboxRelease.None, requestResult, isDatabaseHighlyAvailable)); }
public static LegacyDN FindClientAccessArrayOrServerFromSite(ADObjectId site, ADObjectId preferredServer, IFindAdObject <IADClientAccessArray> findClientAccessArray, IFindMiniClientAccessServerOrArray findMiniClientAccessServer, AdObjectLookupFlags adObjectLookupFlags) { if (site == null) { return(null); } QueryFilter queryFilter = new ComparisonFilter(ComparisonOperator.Equal, ServerSchema.ServerSite, site); IADClientAccessArray iadclientAccessArray = findClientAccessArray.FindAdObjectByQueryEx(QueryFilter.AndTogether(new QueryFilter[] { queryFilter, ClientAccessArray.PriorTo15ExchangeObjectVersionFilter }), adObjectLookupFlags); if (iadclientAccessArray != null) { return(LegacyDN.Parse(iadclientAccessArray.ExchangeLegacyDN)); } IADMiniClientAccessServerOrArray iadminiClientAccessServerOrArray = findMiniClientAccessServer.FindMiniClientAccessServerOrArrayWithClientAccess(site, preferredServer); if (iadminiClientAccessServerOrArray != null) { return(LegacyDN.Parse(iadminiClientAccessServerOrArray.ExchangeLegacyDN)); } return(null); }
internal static void CalculatePreferredHomeServerInternal(ActiveManager activeManager, IADDatabase database, ITopologyConfigurationSession adSession, IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IFindAdObject <IADClientAccessArray> findClientAccessArray, IFindMiniClientAccessServerOrArray findMiniClientAccessServer, out LegacyDN preferredRpcClientAccessServerLegacyDN, out ADObjectId preferredServerSite) { Util.ThrowOnNullArgument(activeManager, "activeManager"); preferredRpcClientAccessServerLegacyDN = LegacyDN.Parse(database.RpcClientAccessServerLegacyDN); ADObjectId masterServerOrAvailabilityGroup = database.MasterServerOrAvailabilityGroup; IADDatabaseAvailabilityGroup iaddatabaseAvailabilityGroup = (masterServerOrAvailabilityGroup != null) ? dagLookup.ReadAdObjectByObjectId(masterServerOrAvailabilityGroup) : null; if (iaddatabaseAvailabilityGroup == null || !iaddatabaseAvailabilityGroup.AllowCrossSiteRpcClientAccess) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <ADObjectId, ADObjectId>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal: Cross-site is not allowed. Database = '{0}', DAG = '{1}'", database.Id, masterServerOrAvailabilityGroup); DatabaseLocationInfo databaseLocationInfo = null; preferredServerSite = null; try { databaseLocationInfo = activeManager.GetServerForDatabase(database.Guid, GetServerForDatabaseFlags.IgnoreAdSiteBoundary, NullPerformanceDataLogger.Instance); if (databaseLocationInfo != null) { preferredServerSite = databaseLocationInfo.ServerSite; } } catch (DatabaseNotFoundException arg) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <ADObjectId, DatabaseNotFoundException>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal: The database '{0}' does not exist. Exception = {1}", database.Id, arg); preferredServerSite = null; } catch (ObjectNotFoundException arg2) { ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <ADObjectId, ObjectNotFoundException>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal: Server hosting the database {0} cannot be found. Exception = {1}", database.Id, arg2); preferredServerSite = null; } if (preferredServerSite == null) { preferredRpcClientAccessServerLegacyDN = null; return; } IADMiniClientAccessServerOrArray iadminiClientAccessServerOrArray = findMiniClientAccessServer.FindMiniClientAccessServerOrArrayByLegdn(databaseLocationInfo.RpcClientAccessServerLegacyDN); if (iadminiClientAccessServerOrArray != null && iadminiClientAccessServerOrArray.ServerSite != null && iadminiClientAccessServerOrArray.ServerSite.Equals(preferredServerSite)) { preferredRpcClientAccessServerLegacyDN = LegacyDN.Parse(databaseLocationInfo.RpcClientAccessServerLegacyDN); return; } preferredRpcClientAccessServerLegacyDN = ActiveManagerImplementation.FindClientAccessArrayOrServerFromSite(preferredServerSite, database.HostServerForPreference1, findClientAccessArray, findMiniClientAccessServer, AdObjectLookupFlags.None); return; } else { IADMiniClientAccessServerOrArray iadminiClientAccessServerOrArray2 = findMiniClientAccessServer.FindMiniClientAccessServerOrArrayByLegdn(preferredRpcClientAccessServerLegacyDN.ToString()); ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <LegacyDN, string>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal. preferredRpcClientAccessServerLegacyDN = {0}, preferredMiniServer = {1}.", preferredRpcClientAccessServerLegacyDN, (iadminiClientAccessServerOrArray2 == null) ? "<null>" : iadminiClientAccessServerOrArray2.Fqdn); if (iadminiClientAccessServerOrArray2 == null) { preferredServerSite = null; preferredRpcClientAccessServerLegacyDN = null; return; } preferredRpcClientAccessServerLegacyDN = LegacyDN.Parse(iadminiClientAccessServerOrArray2.ExchangeLegacyDN); preferredServerSite = iadminiClientAccessServerOrArray2.ServerSite; return; } }
public static IADDatabase[] GetAllDatabases(IADToplogyConfigurationSession adSession, IFindAdObject <IADDatabase> databaseLookup, MiniServer miniServer, out Exception exception) { IADDatabaseCopy[] copies = null; QueryFilter serverFilter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, miniServer.Name); exception = ADUtils.RunADOperation(delegate() { copies = adSession.Find <IADDatabaseCopy>(null, QueryScope.SubTree, serverFilter, null, 0); }, 2); if (exception != null) { return(null); } List <IADDatabase> list = new List <IADDatabase>(20); foreach (IADDatabaseCopy iaddatabaseCopy in copies) { ADObjectId parent = iaddatabaseCopy.Id.Parent; IADDatabase iaddatabase = databaseLookup.ReadAdObjectByObjectIdEx(parent, out exception); if (exception != null) { return(null); } if (iaddatabase != null) { list.Add(iaddatabase); } } return((list.Count > 0) ? list.ToArray() : null); }
public static IADServer FindLocalServer(IFindAdObject <IADServer> serverLookup) { string localComputerFqdn = NativeHelpers.GetLocalComputerFqdn(true); return(serverLookup.FindServerByFqdn(localComputerFqdn)); }