Пример #1
0
        internal void OnConfigurationChanged(ConfigChangeEventArgs arguments)
        {
            if (arguments != null && _clusterConfigMgr != null)
            {
                _clusterConfigMgr.UpdateClusterConfiguration();
                Address affectedNode = null;
                if (arguments.EventParameters != null && arguments.EventParameters.ContainsKey(EventParamName.NodeAddress))
                {
                    affectedNode = arguments.GetParamValue <Address>(EventParamName.NodeAddress);
                }

                ChangeType type = arguments.GetParamValue <ChangeType>(EventParamName.ConfigurationChangeType);

                if ((type != ChangeType.NodeLeft && type != ChangeType.PrimaryGone) && affectedNode == null)
                {
                    return;
                }

                if (_membershipManager != null)
                {
                    switch (type)
                    {
                    //RTD: look for a better way to handle this scenario.
                    case ChangeType.NodeAdded:
                        _membershipManager.OnMemberJoined(new Server(affectedNode, Status.Running));
                        break;

                    case ChangeType.NodeRemoved:
                        _membershipManager.OnMemberLeft(new Server(affectedNode, Status.Running));
                        break;

                    case ChangeType.PriorityChanged:
                        _membershipManager.SanityCheckForTakeoverElect();
                        break;

                    case ChangeType.NodeLeft:
                    //this is the event received by the CS when the leaving node is a primary. Tada-- Why
                    case ChangeType.PrimaryGone:
                        Membership membership = null;
                        if (arguments.EventParameters.ContainsKey(EventParamName.Membership))
                        {
                            membership = arguments.GetParamValue <Membership>(EventParamName.Membership);
                        }

                        if (membership != null && membership.Servers != null)
                        {
                            ShardConfiguration sConfig = _clusterConfigMgr.GetShardConfiguration(context.LocalShardName);
                            if (sConfig != null && sConfig.Servers != null)
                            {
                                foreach (KeyValuePair <string, ServerNode> node in sConfig.Servers.Nodes)
                                {
                                    if (!membership.Servers.Contains(node.Value))
                                    {
                                        affectedNode = new Address(node.Value.Name, sConfig.Port);
                                        break;
                                    }
                                }
                            }
                            if (affectedNode != null && _shardChannels != null && !_shardChannels.ContainsKey(new Server(affectedNode, Status.Running)))
                            {
                                _membershipManager.OnActivityTriggered(Activity.NodeLeaving, affectedNode);
                                _membershipManager.OnMemberLeft(new Server(affectedNode, Status.Running));
                                _membershipManager.OnActivityComplete();
                            }
                        }

                        break;
                    }
                }
            }
        }