Ejemplo n.º 1
0
        // Token: 0x06000F53 RID: 3923 RVA: 0x00041F2C File Offset: 0x0004012C
        private void Open()
        {
            AmClusterHandle amClusterHandle = null;
            AmSystemManager instance        = AmSystemManager.Instance;

            if (instance != null)
            {
                AmConfig config = instance.Config;
                if (config != null)
                {
                    AmDagConfig dagConfig = config.DagConfig;
                    if (dagConfig != null)
                    {
                        IAmCluster cluster = dagConfig.Cluster;
                        if (cluster != null)
                        {
                            amClusterHandle = cluster.Handle;
                        }
                    }
                }
            }
            if (amClusterHandle == null || amClusterHandle.IsInvalid)
            {
                throw new AmClusterNotRunningException();
            }
            using (IDistributedStoreKey clusterKey = DistributedStore.Instance.GetClusterKey(amClusterHandle, null, null, DxStoreKeyAccessMode.Write, false))
            {
                string keyName = string.Format("{0}\\SafetyNet2\\{1}", "ExchangeActiveManager", this.m_dbGuidStr);
                this.m_dbRegKeyHandle = clusterKey.OpenKey(keyName, DxStoreKeyAccessMode.CreateIfNotExist, false, null);
            }
        }
 // Token: 0x0600053E RID: 1342 RVA: 0x00013C01 File Offset: 0x00011E01
 internal ClusdbSnapshotMaker(AmClusterHandle clusterHandle = null, string[] filterRootKeys = null, string rootKeyName = null, bool isForceIncludeRootProperties = false)
 {
     this.clusterHandle  = clusterHandle;
     this.rootKeyName    = rootKeyName;
     this.filterRootKeys = filterRootKeys;
     this.isForceIncludeRootProperties = isForceIncludeRootProperties;
 }
Ejemplo n.º 3
0
        internal IDistributedStoreKey GetClusterKey(AmClusterHandle clusterHandle, CachedChannelFactory <IDxStoreAccess> channelFactory = null, string nodeName = null, DxStoreKeyAccessMode mode = DxStoreKeyAccessMode.Read, bool isBestEffort = false)
        {
            IDistributedStoreKey result = null;

            try
            {
                if (this.StoreSettings.IsCompositeModeEnabled || RegistryParameters.DistributedStoreIsLogPerformanceForSingleStore)
                {
                    result = this.GetClusterCompositeKey(clusterHandle, channelFactory, nodeName, mode);
                }
                else
                {
                    DistributedStore.Context context = new DistributedStore.Context
                    {
                        ClusterHandle  = clusterHandle,
                        ChannelFactory = channelFactory,
                        NodeName       = nodeName
                    };
                    result = this.GetBaseKeyByStoreKind(mode, context, this.StoreSettings.Primary);
                }
            }
            catch (ClusterException)
            {
                if (!isBestEffort)
                {
                    throw;
                }
            }
            return(result);
        }
 // Token: 0x060007CB RID: 1995 RVA: 0x0002601B File Offset: 0x0002421B
 internal void Copy(AmClusterHandle handle)
 {
     if (handle != null)
     {
         this.m_clusterRegistry.SetClusterHandle(handle);
     }
     this.CopyWorker(this.m_localRegistry, this.m_clusterRegistry);
 }
Ejemplo n.º 5
0
 private IDistributedStoreKey GetClusterCompositeKey(AmClusterHandle clusterHandle, CachedChannelFactory <IDxStoreAccess> channelFactory = null, string nodeName = null, DxStoreKeyAccessMode mode = DxStoreKeyAccessMode.Read)
 {
     DistributedStore.Context context = new DistributedStore.Context
     {
         ClusterHandle  = clusterHandle,
         ChannelFactory = channelFactory,
         NodeName       = nodeName
     };
     return(this.GetBaseKey(mode, context));
 }
Ejemplo n.º 6
0
        // Token: 0x06000533 RID: 1331 RVA: 0x000138B8 File Offset: 0x00011AB8
        internal static IDistributedStoreKey GetBaseKey(AmClusterHandle clusterHandle, DxStoreKeyAccessMode mode)
        {
            RegSAM regSam = ClusterDbKey.GetRegSam(mode);
            AmClusterRegkeyHandle clusterKey = ClusapiMethods.GetClusterKey(clusterHandle, regSam);

            if (clusterKey == null || clusterKey.IsInvalid)
            {
                throw AmExceptionHelper.ConstructClusterApiExceptionNoErr("GetClusterKey", new object[0]);
            }
            return(new ClusterDbKey(clusterKey, clusterHandle));
        }
        // Token: 0x06000756 RID: 1878 RVA: 0x00023E94 File Offset: 0x00022094
        private void DeleteTimeStampsInternal(AmClusterHandle clusterHandle)
        {
            using (IDistributedStoreKey clusterKey = DistributedStore.Instance.GetClusterKey(clusterHandle, null, null, DxStoreKeyAccessMode.Write, false))
            {
                using (IDistributedStoreKey distributedStoreKey = clusterKey.OpenKey("ExchangeActiveManager", DxStoreKeyAccessMode.Write, true, null))
                {
                    if (distributedStoreKey != null)
                    {
                        using (IDistributedStoreKey distributedStoreKey2 = distributedStoreKey.OpenKey("LastLog", DxStoreKeyAccessMode.Write, true, null))
                        {
                            if (distributedStoreKey2 != null)
                            {
                                using (IDistributedStoreBatchRequest distributedStoreBatchRequest = distributedStoreKey2.CreateBatchUpdateRequest())
                                {
                                    foreach (Database database in this.m_databases)
                                    {
                                        string name         = database.Name;
                                        string text         = database.Guid.ToString();
                                        string propertyName = AmDbState.ConstructLastLogTimeStampProperty(text);
                                        string value        = distributedStoreKey2.GetValue(propertyName, null, null);
                                        if (value != null)
                                        {
                                            ClusterBatchLastLogGenDeleter.Tracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "LastLogGeneration time stamp for database [{0} ({1})] found with value '{2}'.", name, text, value);
                                            this.m_logger.AppendLogMessage("Deleting LastLogGeneration time stamp from cluster registry for database [{0} ({1})] with existing value: '{2}'.", new object[]
                                            {
                                                name,
                                                text,
                                                value
                                            });
                                            distributedStoreBatchRequest.DeleteValue(propertyName);
                                        }
                                        else
                                        {
                                            ClusterBatchLastLogGenDeleter.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "LastLogGeneration time stamp for database [{0} ({1})] does not exist.", name, text);
                                        }
                                    }
                                    distributedStoreBatchRequest.Execute(null);
                                    goto IL_151;
                                }
                            }
                            ClusterBatchLastLogGenDeleter.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "ActiveManager LastLog key '{0}\\{1}' does not exist in the cluster registry. Skipping deletion.", "ExchangeActiveManager", "LastLog");
IL_151:
                            goto IL_178;
                        }
                    }
                    ClusterBatchLastLogGenDeleter.Tracer.TraceDebug <string>((long)this.GetHashCode(), "ActiveManager root key '{0}' does not exist in the cluster registry. Skipping deletion.", "ExchangeActiveManager");
                    IL_178 :;
                }
            }
        }
Ejemplo n.º 8
0
 public void SetClusterHandle(AmClusterHandle handle)
 {
     if (this.rootKey != null)
     {
         this.rootKey.Dispose();
         this.rootKey = null;
     }
     this.Handle = null;
     using (IDistributedStoreKey clusterKey = DistributedStore.Instance.GetClusterKey(handle, null, null, DxStoreKeyAccessMode.Write, false))
     {
         this.rootKey = clusterKey.OpenKey(this.Root, DxStoreKeyAccessMode.CreateIfNotExist, false, null);
         this.Handle  = handle;
     }
 }
Ejemplo n.º 9
0
        public ClusterRegistry(string root, AmClusterHandle handle) : base(root, handle)
        {
            bool flag = true;

            try
            {
                this.SetClusterHandle(handle);
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    base.SuppressDisposeTracker();
                }
            }
        }
Ejemplo n.º 10
0
 // Token: 0x06000520 RID: 1312 RVA: 0x0001341D File Offset: 0x0001161D
 internal ClusterDbKey(AmClusterRegkeyHandle keyHandle, AmClusterHandle clusterHandle)
 {
     this.KeyHandle     = keyHandle;
     this.ClusterHandle = clusterHandle;
 }
Ejemplo n.º 11
0
        private void BackgroundCopy(object data)
        {
            int millisecondsTimeout = 5000;
            RegistryReplicator registryReplicator = null;
            bool flag = false;

            while (!this.stopEvent.WaitOne(millisecondsTimeout, false))
            {
                millisecondsTimeout = 5000;
                AmConfig config = AmSystemManager.Instance.Config;
                if (config.IsPamOrSam)
                {
                    AmClusterHandle handle = null;
                    if (flag)
                    {
                        handle = config.DagConfig.Cluster.Handle;
                        flag   = false;
                    }
                    while (this.workQueue.Count > 0 && !this.stopEvent.WaitOne(0, false))
                    {
                        lock (this.workQueue)
                        {
                            registryReplicator = this.workQueue.Dequeue();
                        }
                        Exception ex = null;
                        try
                        {
                            registryReplicator.Copy(handle);
                        }
                        catch (AmRegistryException ex2)
                        {
                            ex = ex2;
                            lock (this.workQueue)
                            {
                                this.workQueue.Enqueue(registryReplicator);
                            }
                        }
                        catch (ClusterException ex3)
                        {
                            ex = ex3;
                            AmTrace.Warning("Caught AmClusterApiException during registry replication: {0}", new object[]
                            {
                                ex3
                            });
                            lock (this.workQueue)
                            {
                                this.workQueue.Enqueue(registryReplicator);
                                millisecondsTimeout = 30000;
                                flag = true;
                                break;
                            }
                        }
                        finally
                        {
                            if (ex != null)
                            {
                                ReplayEventLogConstants.Tuple_RegistryReplicatorException.LogEvent(null, new object[]
                                {
                                    ex
                                });
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void MonitorRegistry()
        {
            int      num      = 0;
            int      num2     = RegistryParameters.RegistryMonitorPollingIntervalInSec / 5;
            AmConfig amConfig = null;

            Dictionary <Guid, RegistryReplicator> .KeyCollection.Enumerator enumerator = this.replicators.Keys.GetEnumerator();
            try
            {
                bool flag = false;
                RegistryReplicator registryReplicator = null;
                RealRegistry       realRegistry       = null;
                ClusterRegistry    clusterRegistry    = null;
                List <Guid>        list  = new List <Guid>();
                List <WaitHandle>  list2 = new List <WaitHandle>();
                while (!this.stopEvent.WaitOne(5000, false))
                {
                    amConfig = AmSystemManager.Instance.Config;
                    while (!this.stopEvent.WaitOne(0, false) && amConfig.IsPamOrSam)
                    {
                        AmClusterHandle handle = amConfig.DagConfig.Cluster.Handle;
                        if (flag)
                        {
                            enumerator.Dispose();
                            enumerator = this.replicators.Keys.GetEnumerator();
                        }
                        int num3 = 0;
                        list2.Clear();
                        list.Clear();
                        while (num3 < 64 && enumerator.MoveNext())
                        {
                            if (this.replicators[enumerator.Current].IsValid)
                            {
                                list2.Add(this.replicators[enumerator.Current].KeyChanged);
                                list.Add(enumerator.Current);
                                num3++;
                            }
                        }
                        flag = (num3 < 64);
                        if (list2.Count <= 0)
                        {
                            goto IL_205;
                        }
                        int num4 = WaitHandle.WaitAny(list2.ToArray(), 5000, false);
                        if (num4 >= 0 && num4 < list2.Count)
                        {
                            Guid key = list[num4];
                            if (this.replicators[key].IsCopyEnabled)
                            {
                                lock (this.workQueue)
                                {
                                    this.workQueue.Enqueue(this.replicators[key]);
                                    this.replicators[key].KeyChanged.Reset();
                                }
                                try
                                {
                                    DiagnosticsNativeMethods.ErrorCode errorCode = DiagnosticsNativeMethods.RegNotifyChangeKeyValue((SafeRegistryHandle)this.replicators[key].Handle, true, DiagnosticsNativeMethods.RegistryNotifications.ChangeName | DiagnosticsNativeMethods.RegistryNotifications.ChangeAttributes | DiagnosticsNativeMethods.RegistryNotifications.LastSet, this.replicators[key].KeyChanged.SafeWaitHandle, true);
                                    if (errorCode != DiagnosticsNativeMethods.ErrorCode.Success)
                                    {
                                        throw new AmRegistryException("RegNotifyChangeKeyValue", new Win32Exception((int)errorCode));
                                    }
                                    goto IL_21B;
                                }
                                catch (AmRegistryException ex)
                                {
                                    AmTrace.Warning("Registering for registry key change notifications failed. Inner Exception: {0}", new object[]
                                    {
                                        ex
                                    });
                                    goto IL_21B;
                                }
                                goto IL_205;
                            }
                        }
IL_21B:
                        if (num == 0 || this.dbMountedEvent.WaitOne(0, false))
                        {
                            num2 = RegistryParameters.RegistryMonitorPollingIntervalInSec / 5;
                            foreach (KeyValuePair <Guid, RegistryReplicator> keyValuePair in this.replicators)
                            {
                                keyValuePair.Value.SetMarkedForRemoval();
                            }
                            IADDatabase[] databasesToMonitor = this.GetDatabasesToMonitor();
                            if (databasesToMonitor != null)
                            {
                                foreach (IADDatabase iaddatabase in databasesToMonitor)
                                {
                                    if (this.replicators.ContainsKey(iaddatabase.Guid))
                                    {
                                        this.replicators[iaddatabase.Guid].ResetMarkedForRemoval();
                                    }
                                    else
                                    {
                                        Exception ex2 = null;
                                        try
                                        {
                                            if (!flag)
                                            {
                                                enumerator.Dispose();
                                                flag = true;
                                            }
                                            string             text             = iaddatabase.IsPublicFolderDatabase ? RegistryMonitor.publicString : RegistryMonitor.privateString;
                                            string             text2            = string.Format(RegistryMonitor.localRegistryPathFormat, Environment.MachineName, iaddatabase.Guid, text);
                                            string             root             = string.Format(RegistryMonitor.clusterRegistryPathFormat, iaddatabase.Guid, text);
                                            ManualResetEvent   manualResetEvent = new ManualResetEvent(false);
                                            SafeRegistryHandle safeRegistryHandle;
                                            DiagnosticsNativeMethods.ErrorCode errorCode = DiagnosticsNativeMethods.RegOpenKeyEx(SafeRegistryHandle.LocalMachine, text2, 0, 131097, out safeRegistryHandle);
                                            if (DiagnosticsNativeMethods.ErrorCode.FileNotFound == errorCode)
                                            {
                                                RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(text2);
                                                if (registryKey != null)
                                                {
                                                    registryKey.Close();
                                                    errorCode = DiagnosticsNativeMethods.RegOpenKeyEx(SafeRegistryHandle.LocalMachine, text2, 0, 131097, out safeRegistryHandle);
                                                }
                                            }
                                            if (errorCode != DiagnosticsNativeMethods.ErrorCode.Success)
                                            {
                                                throw new AmRegistryException("RegOpenKeyEx", new Win32Exception((int)errorCode));
                                            }
                                            realRegistry       = new RealRegistry(text2, safeRegistryHandle);
                                            clusterRegistry    = new ClusterRegistry(root, amConfig.DagConfig.Cluster.Handle);
                                            registryReplicator = new RegistryReplicator(realRegistry, clusterRegistry, manualResetEvent);
                                            realRegistry       = null;
                                            clusterRegistry    = null;
                                            if (registryReplicator.IsInitialReplication)
                                            {
                                                registryReplicator.Copy(handle);
                                                registryReplicator.SetInitialReplication();
                                            }
                                            else
                                            {
                                                registryReplicator.InverseCopy();
                                            }
                                            errorCode = DiagnosticsNativeMethods.RegNotifyChangeKeyValue(safeRegistryHandle, true, DiagnosticsNativeMethods.RegistryNotifications.ChangeName | DiagnosticsNativeMethods.RegistryNotifications.ChangeAttributes | DiagnosticsNativeMethods.RegistryNotifications.LastSet, manualResetEvent.SafeWaitHandle, true);
                                            if (errorCode != DiagnosticsNativeMethods.ErrorCode.Success)
                                            {
                                                throw new AmRegistryException("RegNotifyChangeKeyValue", new Win32Exception((int)errorCode));
                                            }
                                            this.replicators.Add(iaddatabase.Guid, registryReplicator);
                                            registryReplicator = null;
                                        }
                                        catch (AmRegistryException ex3)
                                        {
                                            ex2 = ex3;
                                            AmTrace.Warning("Failed to add database to monitor: {0}. Exception: {1}", new object[]
                                            {
                                                iaddatabase.Name,
                                                ex3
                                            });
                                        }
                                        catch (ClusterException ex4)
                                        {
                                            ex2 = ex4;
                                            AmTrace.Warning("Failed to add database to monitor: {0}. Exception: {1}", new object[]
                                            {
                                                iaddatabase.Name,
                                                ex4
                                            });
                                        }
                                        finally
                                        {
                                            if (ex2 != null)
                                            {
                                                ReplayEventLogConstants.Tuple_RegistryReplicatorException.LogEvent(null, new object[]
                                                {
                                                    ex2
                                                });
                                            }
                                            if (registryReplicator != null)
                                            {
                                                registryReplicator.Dispose();
                                                registryReplicator = null;
                                            }
                                            if (realRegistry != null)
                                            {
                                                realRegistry.Dispose();
                                                realRegistry = null;
                                            }
                                            if (clusterRegistry != null)
                                            {
                                                clusterRegistry.Dispose();
                                                clusterRegistry = null;
                                            }
                                        }
                                    }
                                }
                            }
                            list.Clear();
                            foreach (KeyValuePair <Guid, RegistryReplicator> keyValuePair2 in this.replicators)
                            {
                                if (keyValuePair2.Value.IsMarkedForRemoval)
                                {
                                    list.Add(keyValuePair2.Key);
                                }
                            }
                            lock (this.workQueue)
                            {
                                foreach (Guid key2 in list)
                                {
                                    registryReplicator = this.replicators[key2];
                                    registryReplicator.SetInvalid();
                                    if (!registryReplicator.IsCopying)
                                    {
                                        if (!flag)
                                        {
                                            flag = true;
                                        }
                                        this.replicators.Remove(key2);
                                        registryReplicator.Dispose();
                                    }
                                }
                            }
                            registryReplicator = null;
                        }
                        num      = (num + 1) % num2;
                        amConfig = AmSystemManager.Instance.Config;
                        continue;
IL_205:
                        if (!this.stopEvent.WaitOne(5000, false))
                        {
                            goto IL_21B;
                        }
                        break;
                    }
                }
                foreach (KeyValuePair <Guid, RegistryReplicator> keyValuePair3 in this.replicators)
                {
                    if (!keyValuePair3.Value.IsCopying)
                    {
                        keyValuePair3.Value.SetInvalid();
                    }
                }
            }
            finally
            {
                enumerator.Dispose();
            }
        }