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); }
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); }