private bool CleanupServers(IADToplogyConfigurationSession adSession, IClusterDB clusdb, HashSet <Guid> serverGuids, Dictionary <Guid, IADServer> validServers) { if (validServers.Count == 0) { ReplayCrimsonEvents.ClusdbPeriodicCleanupSkipped.Log <string, string>("Server", "Could not find a single valid server in the cached list"); return(false); } IADServer value = validServers.First <KeyValuePair <Guid, IADServer> >().Value; if (adSession.FindServerByName(value.Name) == null) { ReplayCrimsonEvents.ClusdbPeriodicCleanupSkipped.Log <string, string>("Server", "Could not find a single valid server in AD"); return(false); } bool result = false; try { this.RemoveStaleServerGuids(clusdb, serverGuids); serverGuids.ExceptWith(this.staleServers); result = true; } catch (Exception ex) { ReplayCrimsonEvents.ClusdbPeriodicCleanupFailed.Log <string, string>("Server", ex.ToString()); } this.staleServers = serverGuids; return(result); }
private bool CleanupDatabases(IADToplogyConfigurationSession adSession, IClusterDB clusdb, HashSet <Guid> dbGuidsToDelete, HashSet <Guid> validDatabaseGuids) { if (validDatabaseGuids.Count == 0) { ReplayCrimsonEvents.ClusdbPeriodicCleanupSkipped.Log <string, string>("Database", "Could not find a single valid database in cached list"); return(false); } if (adSession.FindDatabaseByGuid(validDatabaseGuids.First <Guid>()) == null) { ReplayCrimsonEvents.ClusdbPeriodicCleanupSkipped.Log <string, string>("Database", "Could not find a single valid database in AD"); return(false); } bool result = false; try { this.RemoveStaleDatabaseGuids(clusdb, dbGuidsToDelete); dbGuidsToDelete.ExceptWith(this.staleDatabases); result = true; } catch (Exception ex) { ReplayCrimsonEvents.ClusdbPeriodicCleanupFailed.Log <string, string>("Database", ex.ToString()); } this.staleDatabases = dbGuidsToDelete; return(result); }
internal Dictionary <Guid, AmDbStateInfo> GetAllDbStatesFromClusdb(IClusterDB clusdb) { Dictionary <Guid, AmDbStateInfo> dictionary = new Dictionary <Guid, AmDbStateInfo>(); if (!DistributedStore.Instance.IsKeyExist("ExchangeActiveManager\\DbState", null)) { return(dictionary); } IEnumerable <Tuple <string, RegistryValueKind> > valueInfos = clusdb.GetValueInfos("ExchangeActiveManager\\DbState"); if (valueInfos != null) { foreach (Tuple <string, RegistryValueKind> tuple in valueInfos) { string item = tuple.Item1; string value = clusdb.GetValue <string>("ExchangeActiveManager\\DbState", item, string.Empty); Guid guid; if (!string.IsNullOrEmpty(value) && Guid.TryParse(item, out guid)) { AmDbStateInfo value2 = AmDbStateInfo.Parse(guid, value); dictionary.Add(guid, value2); } } } return(dictionary); }
public static void ReadServerDatabaseSchemaVersionRange(IClusterDB iClusterDB, Guid serverGuid, int defaultMinimum, int defaultMaximum, out int minVersion, out int maxVersion) { string keyName = string.Format("Exchange\\Servers\\{0}\\Schema", serverGuid); minVersion = iClusterDB.GetValue <int>(keyName, "Minimum Version", defaultMinimum); maxVersion = iClusterDB.GetValue <int>(keyName, "Maximum Version", defaultMaximum); }
public static void GetSupporableDatabaseSchemaVersionRange(ITopologyConfigurationSession taskSession, Task.TaskVerboseLoggingDelegate writeLog, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskErrorLoggingDelegate writeError, Database database, out int minVersion, out int maxVersion, out int currentRequestedVersion) { currentRequestedVersion = 0; int num = int.MaxValue; int num2 = 0; DatabaseAvailabilityGroup databaseAvailabilityGroup; using (IClusterDB clusterDB = DatabaseTasksHelper.OpenClusterDatabase(taskSession, writeLog, writeWarning, writeError, database, false, out databaseAvailabilityGroup)) { if (clusterDB != null && clusterDB.IsInitialized) { ClusterDBHelpers.ReadRequestedDatabaseSchemaVersion(clusterDB, database.Guid, 0, out currentRequestedVersion); foreach (ADObjectId adobjectId in databaseAvailabilityGroup.Servers) { int num3; int num4; ClusterDBHelpers.ReadServerDatabaseSchemaVersionRange(clusterDB, adobjectId.ObjectGuid, 121, 121, out num3, out num4); writeLog(Strings.ServerSchemaVersionRange(adobjectId.ObjectGuid.ToString(), num3, num4)); num2 = Math.Max(num3, num2); num = Math.Min(num4, num); } } } if (num2 > num) { writeError(new IncompatibleDatabaseSchemaVersionsInDAGException(), ErrorCategory.MetadataError, database); } minVersion = num2; maxVersion = num; }
protected override void TimerCallbackInternal() { try { if (AmSystemManager.Instance.Config.IsPAM) { using (IClusterDB clusterDB = ClusterDB.Open()) { this.CleanupStaleEntries(clusterDB); } } } catch (Exception ex) { ReplayCrimsonEvents.ClusdbPeriodicCleanupFailed.Log <string, string>("Common", ex.ToString()); } finally { if (this.staleDatabases.Count > 0 || this.staleServers.Count > 0) { ReplayCrimsonEvents.ClusdbPeriodicCleanupFoundStale.Log <int, int>(this.staleDatabases.Count, this.staleServers.Count); } else { ReplayCrimsonEvents.ClusdbPeriodicCleanupNoStale.Log(); } } }
public static void RemoveServerSchemaVersionRange(IClusterDB iClusterDB, Guid serverGuid) { using (IClusterDBWriteBatch clusterDBWriteBatch = iClusterDB.CreateWriteBatch("Exchange\\Servers")) { clusterDBWriteBatch.DeleteKey(serverGuid.ToString()); clusterDBWriteBatch.Execute(); } }
public static void RemoveDatabaseRequestedSchemaVersion(IClusterDB iClusterDB, Guid databaseGuid) { using (IClusterDBWriteBatch clusterDBWriteBatch = iClusterDB.CreateWriteBatch("Exchange\\Databases")) { clusterDBWriteBatch.DeleteKey(databaseGuid.ToString()); clusterDBWriteBatch.Execute(); } }
private void RemoveStaleServerGuids(IClusterDB clusdb, HashSet <Guid> serverGuids) { this.staleServers.IntersectWith(serverGuids); if (this.staleServers.Count == 0) { return; } this.RemoveItemsFromClusdb("Database", clusdb, "Exchange\\Servers", true, this.staleServers, null, 200); }
internal static void RemoveEntryFromClusdb(string serverName, string actionName) { using (IClusterDB clusterDB = ClusterDB.Open()) { string keyName = AmThrottledActionTracker <TData> .ConstructRegKeyName(serverName); clusterDB.DeleteValue(keyName, actionName); } }
public static void WriteRequestedDatabaseSchemaVersion(IClusterDB iClusterDB, Guid databaseGuid, int requestedVersion) { string registryKey = string.Format("Exchange\\Databases\\{0}\\Schema", databaseGuid); using (IClusterDBWriteBatch clusterDBWriteBatch = iClusterDB.CreateWriteBatch(registryKey)) { clusterDBWriteBatch.SetValue("Requested Version", requestedVersion); clusterDBWriteBatch.Execute(); } }
public static void WriteServerDatabaseSchemaVersionRange(IClusterDB iClusterDB, Guid serverGuid, int minVersion, int maxVersion) { string registryKey = string.Format("Exchange\\Servers\\{0}\\Schema", serverGuid); using (IClusterDBWriteBatch clusterDBWriteBatch = iClusterDB.CreateWriteBatch(registryKey)) { clusterDBWriteBatch.SetValue("Minimum Version", minVersion); clusterDBWriteBatch.SetValue("Maximum Version", maxVersion); clusterDBWriteBatch.Execute(); } }
protected override void InternalValidate() { TaskLogger.LogEnter(); base.InternalValidate(); Server server = this.DataObject.GetServer(); bool flag = false; if (server == null) { base.WriteError(new InvalidOperationException(Strings.ErrorDBOwningServerNotFound(this.DataObject.Identity.ToString())), ErrorCategory.InvalidOperation, this.DataObject.Identity); } else { flag = server.IsE15OrLater; } if (!flag) { base.WriteError(new InvalidOperationException(Strings.ErrorModifyE14DatabaseNotAllowed), ErrorCategory.InvalidOperation, this.DataObject.Identity); } DatabaseAvailabilityGroup databaseAvailabilityGroup; using (IClusterDB clusterDB = DatabaseTasksHelper.OpenClusterDatabase((ITopologyConfigurationSession)base.DataSession, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError), this.DataObject, false, out databaseAvailabilityGroup)) { if (clusterDB == null || !clusterDB.IsInstalled) { base.WriteError(new InvalidOperationException(Strings.ErrorSchemaVersionDoesntApply(this.DataObject.Name)), ErrorCategory.InvalidOperation, this.DataObject.Identity); } } if (base.Fields.IsModified("MajorVersion")) { this.version = UpdateDatabaseSchema.VersionFromComponents(this.MajorVersion, this.MinorVersion); int num; int num2; int num3; DatabaseTasksHelper.GetSupporableDatabaseSchemaVersionRange((ITopologyConfigurationSession)base.DataSession, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError), this.DataObject, out num, out num2, out num3); if (this.version < num || this.version > num2) { base.WriteError(new InvalidOperationException(Strings.ErrorSchemaVersionOutOfRange(UpdateDatabaseSchema.VersionString(num), UpdateDatabaseSchema.VersionString(num2))), ErrorCategory.InvalidOperation, this.DataObject.Identity); } if (num3 > this.version) { this.WriteWarning(Strings.RequestedVersionIsLowerThanCurrentVersion(num3)); } } else { this.version = DatabaseTasksHelper.GetMaximumSupportedDatabaseSchemaVersion((ITopologyConfigurationSession)base.DataSession, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError), this.DataObject); } TaskLogger.LogExit(); }
private void RemoveStaleDatabaseGuids(IClusterDB clusdb, HashSet <Guid> dbGuids) { this.staleDatabases.IntersectWith(dbGuids); if (this.staleDatabases.Count == 0) { return; } this.RemoveItemsFromClusdb("Database", clusdb, "ExchangeActiveManager\\LastLog", false, this.staleDatabases, null, 200); this.RemoveItemsFromClusdb("Database", clusdb, "ExchangeActiveManager\\LastLog", false, this.staleDatabases, (string s) => s + "_Time", 200); this.RemoveItemsFromClusdb("Database", clusdb, "ExchangeActiveManager\\Dumpster", true, this.staleDatabases, null, 200); this.RemoveItemsFromClusdb("Database", clusdb, "ExchangeActiveManager\\SafetyNet2", true, this.staleDatabases, null, 200); this.RemoveItemsFromClusdb("Database", clusdb, "Exchange\\Databases", true, this.staleDatabases, null, 200); this.RemoveItemsFromClusdb("Database", clusdb, "MsExchangeIs", true, this.staleDatabases, (string s) => "Private_" + s, 200); this.RemoveItemsFromClusdb("Database", clusdb, "ExchangeActiveManager\\DbState", false, this.staleDatabases, null, 200); }
private HashSet <Guid> GetServersToBeDeleted(IMonitoringADConfig adConfig, IClusterDB clusdb, out Dictionary <Guid, IADServer> validServers) { validServers = new Dictionary <Guid, IADServer>(); HashSet <Guid> allServersInClusdb = this.GetAllServersInClusdb(clusdb); Dictionary <Guid, IADServer> dictionary = adConfig.Servers.ToDictionary((IADServer s) => s.Guid); foreach (Guid key in allServersInClusdb) { IADServer value; if (dictionary.TryGetValue(key, out value)) { validServers.Add(key, value); } } allServersInClusdb.ExceptWith(validServers.Keys); return(allServersInClusdb); }
public static void RemoveDatabaseFromClusterDB(ITopologyConfigurationSession taskSession, Task.TaskVerboseLoggingDelegate writeLog, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskErrorLoggingDelegate writeError, Database database) { try { DatabaseAvailabilityGroup databaseAvailabilityGroup; using (IClusterDB clusterDB = DatabaseTasksHelper.OpenClusterDatabase(taskSession, writeLog, writeWarning, writeError, database, true, out databaseAvailabilityGroup)) { if (clusterDB != null && clusterDB.IsInitialized) { writeLog(Strings.DeleteClusterDBKey(database.Name)); ClusterDBHelpers.RemoveDatabaseRequestedSchemaVersion(clusterDB, database.Guid); } } } catch (ClusterException) { writeWarning(Strings.FailedToRemoveDatabaseSection(database.Name)); } }
private void CleanupStaleEntries(IClusterDB clusdb) { IMonitoringADConfig config = Dependencies.MonitoringADConfigProvider.GetConfig(true); HashSet <Guid> validDatabaseGuids; HashSet <Guid> databasesToBeDeleted = this.GetDatabasesToBeDeleted(config, clusdb, out validDatabaseGuids); Dictionary <Guid, IADServer> validServers; HashSet <Guid> serversToBeDeleted = this.GetServersToBeDeleted(config, clusdb, out validServers); if (databasesToBeDeleted.Count == 0 && serversToBeDeleted.Count == 0) { this.staleDatabases.Clear(); this.staleServers.Clear(); return; } IADToplogyConfigurationSession adSession = ADSessionFactory.CreateIgnoreInvalidRootOrgSession(true); this.CleanupDatabases(adSession, clusdb, databasesToBeDeleted, validDatabaseGuids); this.CleanupServers(adSession, clusdb, serversToBeDeleted, validServers); }
private HashSet <Guid> GetDatabasesToBeDeleted(IMonitoringADConfig adConfig, IClusterDB clusdb, out HashSet <Guid> validDatabaseGuids) { validDatabaseGuids = new HashSet <Guid>(); Dictionary <Guid, AmDbStateInfo> allDbStatesFromClusdb = this.GetAllDbStatesFromClusdb(clusdb); foreach (KeyValuePair <Guid, AmDbStateInfo> keyValuePair in allDbStatesFromClusdb) { Guid key = keyValuePair.Key; DateTime lastMountedTime = keyValuePair.Value.LastMountedTime; IADDatabase iaddatabase; bool flag = adConfig.DatabaseByGuidMap.TryGetValue(key, out iaddatabase); bool flag2 = lastMountedTime > DateTime.UtcNow.AddDays(-5.0); if (flag || flag2) { validDatabaseGuids.Add(key); } } return(new HashSet <Guid>(allDbStatesFromClusdb.Keys.Except(validDatabaseGuids))); }
// Token: 0x06001BD8 RID: 7128 RVA: 0x00078450 File Offset: 0x00076650 internal static ExDateTime GetLastServerUpdateTimeFromClusdb() { ExDateTime exDateTimeMinValueUtc = SharedHelper.ExDateTimeMinValueUtc; try { using (IClusterDB clusterDB = ClusterDB.Open()) { string value = clusterDB.GetValue <string>("ExchangeActiveManager\\LastLog", AmServerName.LocalComputerName.NetbiosName, string.Empty); if (!string.IsNullOrEmpty(value) && !ExDateTime.TryParse(value, out exDateTimeMinValueUtc)) { exDateTimeMinValueUtc = SharedHelper.ExDateTimeMinValueUtc; } } } catch (ClusterException ex) { ClusterBatchWriter.Tracer.TraceError <string>(0L, "GetLastServerUpdateTimeFromClusdb() failed with {0}", ex.Message); } return(exDateTimeMinValueUtc); }
private void InitializeFromClusdbInternal() { AmConfig config = AmSystemManager.Instance.Config; if (config.IsPAM) { AmDagConfig dagConfig = config.DagConfig; using (IClusterDB clusterDB = ClusterDB.Open()) { foreach (AmServerName amServerName in dagConfig.MemberServers) { string keyName = AmThrottledActionTracker <TData> .ConstructRegKeyName(amServerName.NetbiosName); string[] value = clusterDB.GetValue <string[]>(keyName, this.ActionName, null); if (value != null && value.Length > 0) { LinkedList <TData> linkedList = new LinkedList <TData>(); foreach (string text in value) { int num = text.IndexOf('='); if (num != -1) { string s = text.Substring(0, num); string dataStr = null; if (num < text.Length - 1) { dataStr = text.Substring(num + 1); } ExDateTime actionTime = ExDateTime.Parse(s); TData value2 = Activator.CreateInstance <TData>(); value2.Initialize(actionTime, dataStr); linkedList.AddFirst(value2); } } this.actionHistory[amServerName] = linkedList; } } } } }
public static void SetRequestedDatabaseSchemaVersion(ITopologyConfigurationSession taskSession, Task.TaskVerboseLoggingDelegate writeLog, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskErrorLoggingDelegate writeError, Database database, int version) { try { DatabaseAvailabilityGroup databaseAvailabilityGroup; using (IClusterDB clusterDB = DatabaseTasksHelper.OpenClusterDatabase(taskSession, writeLog, writeWarning, writeError, database, false, out databaseAvailabilityGroup)) { if (clusterDB != null && clusterDB.IsInitialized) { writeLog(Strings.SetDatabaseRequestedSchemaVersion(database.Name, version)); ClusterDBHelpers.WriteRequestedDatabaseSchemaVersion(clusterDB, database.Guid, version); } } } catch (ClusterException) { if (writeError != null) { writeError(new FailedToSetRequestedDatabaseSchemaVersionException(database.Name), ErrorCategory.WriteError, database); } } }
private void Persist(AmServerName node) { LinkedList <TData> linkedList; if (this.actionHistory.TryGetValue(node, out linkedList) && linkedList != null && linkedList.Count > 0) { using (IClusterDB clusterDB = ClusterDB.Open()) { List <string> list = new List <string>(); foreach (TData tdata in linkedList) { string arg = tdata.Time.UniversalTime.ToString("o"); string dataStr = tdata.DataStr; string item = string.Format("{0}{1}{2}", arg, '=', dataStr); list.Add(item); } string[] propetyValue = list.ToArray(); string keyName = AmThrottledActionTracker <TData> .ConstructRegKeyName(node.NetbiosName); clusterDB.SetValue <string[]>(keyName, this.ActionName, propetyValue); } } }
internal HashSet <Guid> GetAllServersInClusdb(IClusterDB clusdb) { HashSet <Guid> hashSet = new HashSet <Guid>(); if (!DistributedStore.Instance.IsKeyExist("Exchange\\Servers", null)) { return(hashSet); } IEnumerable <string> subKeyNames = clusdb.GetSubKeyNames("Exchange\\Servers"); if (subKeyNames != null) { foreach (string input in subKeyNames) { Guid item; if (Guid.TryParse(input, out item)) { hashSet.Add(item); } } } return(hashSet); }
public static void ReadRequestedDatabaseSchemaVersion(IClusterDB iClusterDB, Guid databaseGuid, int defaultVersion, out int requestedVersion) { string keyName = string.Format("Exchange\\Databases\\{0}\\Schema", databaseGuid); requestedVersion = iClusterDB.GetValue <int>(keyName, "Requested Version", defaultVersion); }
private int RemoveItemsFromClusdb(string objectName, IClusterDB clusdb, string keyName, bool isDeleteKey, IEnumerable <Guid> collection, Func <string, string> nameGenerator = null, int batchSize = 200) { if (!DistributedStore.Instance.IsKeyExist(keyName, null)) { return(0); } int num = 0; int num2 = 0; HashSet <string> hashSet = new HashSet <string>(collection.Select(delegate(Guid id) { string text2 = id.ToString(); if (nameGenerator != null) { return(nameGenerator(text2)); } return(text2); })); num2 = hashSet.Count; try { if (isDeleteKey) { IEnumerable <string> subKeyNames = clusdb.GetSubKeyNames(keyName); hashSet.IntersectWith(subKeyNames); } else { IEnumerable <string> other = from vi in clusdb.GetValueInfos(keyName) select vi.Item1; hashSet.IntersectWith(other); } } catch (Exception ex) { ReplayCrimsonEvents.ClusdbPeriodicCleanupFailed.Log <string, string>(objectName, ex.ToString()); return(0); } if (hashSet.Count == 0) { return(0); } int num3 = 0; int num4 = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); foreach (IEnumerable <string> enumerable in hashSet.Batch(batchSize)) { num++; int num5 = 0; try { using (IClusterDBWriteBatch clusterDBWriteBatch = clusdb.CreateWriteBatch(keyName)) { foreach (string text in enumerable) { num5++; if (isDeleteKey) { clusterDBWriteBatch.DeleteKey(text); } else { clusterDBWriteBatch.DeleteValue(text); } } clusterDBWriteBatch.Execute(); num3 += num5; } } catch (Exception ex2) { num4++; ReplayCrimsonEvents.ClusdbCleanupBatchOperationFailed.Log <string, string, string, bool, int, int, int, int>(objectName, ex2.Message, keyName, isDeleteKey, num, num5, num2, hashSet.Count); } } long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; ReplayCrimsonEvents.ClusdbPeriodicCleanupCompleted.Log <string, string, int, string, int, int, long>(objectName, keyName, num3, isDeleteKey ? "Key" : "Property", num, num4, elapsedMilliseconds); return(num3); }
// Token: 0x060000B2 RID: 178 RVA: 0x00005148 File Offset: 0x00003348 internal void Flush() { if (AmSystemManager.Instance.Config.IsPAM) { Dictionary <AmServerName, AmCachedLastLogUpdater.ServerRequestInfo> dictionary = this.Cleanup(); if (dictionary.Count > 0) { Exception ex = null; try { using (IClusterDB clusterDB = ClusterDB.Open()) { if (clusterDB.IsInitialized) { using (IClusterDBWriteBatch clusterDBWriteBatch = clusterDB.CreateWriteBatch("ExchangeActiveManager\\LastLog")) { this.PopulateBatch(clusterDBWriteBatch, dictionary); clusterDBWriteBatch.Execute(); ExDateTime now = ExDateTime.Now; foreach (AmServerName key in dictionary.Keys) { this.serverUpdateTimeMap[key] = now; } goto IL_BA; } } ExTraceGlobals.ClusterTracer.TraceError((long)this.GetHashCode(), "Flush(): clusdb is not initialized"); IL_BA :; } } catch (ADExternalException ex2) { ex = ex2; } catch (ADOperationException ex3) { ex = ex3; } catch (ADTransientException ex4) { ex = ex4; } catch (ClusterException ex5) { ex = ex5; } catch (AmServerException ex6) { ex = ex6; } catch (AmServerTransientException ex7) { ex = ex7; } if (ex != null) { ReplayCrimsonEvents.CachedLastLogUpdateFailed.LogPeriodic <int, string>(AmServerName.LocalComputerName.NetbiosName, TimeSpan.FromMinutes(5.0), dictionary.Count, ex.Message); } } } }