Exemple #1
0
 public void Dispose()
 {
     _shardListener      = null;
     _remoteShardChannel = null;
     //_activeChannelsList = null;
     _servers = null;
 }
Exemple #2
0
 public void UnregisterShardListener(String listenerDB, IShardListener listener)
 {
     if (_shardListeners != null)
     {
         _shardListeners.Remove(listenerDB);
     }
 }
Exemple #3
0
        public void RegisterShardListener(String name, IShardListener shardListener)
        {
            if (_shardListeners == null)
            {
                _shardListeners = new Dictionary <String, IShardListener>();
            }

            _shardListeners.Add(name, shardListener);
        }
Exemple #4
0
        public object OnRequest(IRequest request)
        {
            Message     msg     = (Message)request.Message;
            MessageType msgType = msg.MessageType;
            //MessageResponse response = new MessageResponse();
            Server source = null;

            if (request != null)
            {
                if (request.Source != null)
                {
                    source = new Server(request.Source, Status.Running);
                }

                IShardListener listener = null;

                switch (msgType)
                {
                case MessageType.DBOperation:

                    listener = _shardListeners[Common.MiscUtil.CLUSTER_MANAGER];
                    break;

                case MessageType.MembershipOperation:
                    bool isLSOp = IsLocalShardOperation(msg);
                    if (isLSOp)
                    {
                        return(isLSOp);
                    }
                    listener = _shardListeners[Common.MiscUtil.MEMBERSHIP_MANAGER];
                    break;

                case MessageType.Heartbeat:
                    listener = _shardListeners[Common.MiscUtil.MEMBERSHIP_MANAGER];
                    break;

                case MessageType.Replication:
                    listener = _shardListeners[Common.MiscUtil.CONFIGURATION_MANAGER];
                    break;
                }
                if (listener == null)
                {
                    throw new DatabaseException("No Listener for " + msgType.ToString() + " MessageType");
                }
                return(listener.OnMessageReceived(msg, source));
            }

            return(null);
        }
Exemple #5
0
        public void ChannelDisconnected(IRequestResponseChannel channel, string reason)
        {
            try
            {
                if (_shardChannels != null)
                {
                    bool connected = false;

                    if (channel != null)
                    {
                        Server server = new Server(channel.PeerAddress, Status.Stopped);
                        Server key    = null;
                        if (_shardChannels != null)
                        {
                            IList <Server> shardchannelKeys = _shardChannels.Keys.ToList();
                            if (server != null && server.Address != null && !server.Address.Equals(context.LocalAddress) && shardchannelKeys != null && shardchannelKeys.Count > 0)
                            {
                                foreach (Server node in shardchannelKeys)
                                {
                                    if (_shardChannels[node].PeerAddress != null && _shardChannels[node].PeerAddress.Equals(channel.PeerAddress))
                                    {
                                        key = node;
                                        break;
                                    }
                                }
                            }
                            IDualChannel tempChannel = channel as IDualChannel;
                            if (tempChannel != null && key != null && tempChannel.ShouldTryReconnecting)
                            {
                                lock (_shardChannels)
                                {
                                    //_shardChannels[key].Disconnect();
                                    _shardChannels.Remove(key);
                                    if (LoggerManager.Instance.ShardLogger != null &&
                                        LoggerManager.Instance.ShardLogger.IsDebugEnabled)
                                    {
                                        LoggerManager.Instance.ShardLogger.Debug("Localshard.Channeldisconnected(): ",
                                                                                 server.Address.ToString() + " removed from existing channels.");
                                    }
                                }
                                if (!key.Address.Equals(context.LocalAddress))
                                {
                                    BrokenConnectionInfo info = new BrokenConnectionInfo();
                                    info.BrokenAddress = key.Address;
                                    info.SessionType   = SessionTypes.Shard;

                                    _connectionRestoration.RegisterListener(info, this, context.LocalShardName);
                                }
                            }
                        }


                        try
                        {
                            if (!connected)
                            {
                                IShardListener listener = _shardListeners[Common.MiscUtil.CONFIGURATION_MANAGER];
                                listener.OnMemberLeft(new Server(channel.PeerAddress, Status.Stopped));
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #6
0
        public bool OnMembershipChanged(MembershipChangeArgs args)
        {
            if (args != null)
            {
                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsDebugEnabled)
                {
                    LoggerManager.Instance.ShardLogger.Debug("LocalShard.OnMembershipChanged()", "Membership change type: " + args.ChangeType);
                }

                switch (args.ChangeType)
                {
                case MembershipChangeArgs.MembershipChangeType.PrimarySet:
                case MembershipChangeArgs.MembershipChangeType.PrimarySelected:
                    if (args.ServerName != null)
                    {
                        if (args.ServerName.Equals(context.LocalAddress))
                        {
                            lock (_mutexOnnodeRole)
                            {
                                NodeRole = Common.Configuration.Services.NodeRole.Primary;
                            }
                        }
                        else
                        {
                            lock (_mutexOnnodeRole)
                            {
                                if (NodeRole != NodeRole.Intermediate)
                                {
                                    NodeRole = Common.Configuration.Services.NodeRole.Secondary;
                                }
                            }
                        }
                        Primary = new Server(args.ServerName, Status.Running);

                        if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsInfoEnabled && args.ElectionId != null)
                        {
                            LoggerManager.Instance.ShardLogger.Info("LocalShard.OnMembershipChanged()", "This term's election id is: " + args.ElectionId.Id);
                        }


                        if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsInfoEnabled)
                        {
                            if (args.ChangeType.Equals(MembershipChangeArgs.MembershipChangeType.PrimarySet))
                            {
                                LoggerManager.Instance.ShardLogger.Info("LocalShard.OnMembershipChanged()", "Node " + args.ServerName.IpAddress.ToString() + " set as the primary node for the shard.");
                            }
                            else if (args.ChangeType.Equals(MembershipChangeArgs.MembershipChangeType.PrimarySelected))
                            {
                                LoggerManager.Instance.ShardLogger.Info("LocalShard.OnMembershipChanged()", "Node " + args.ServerName.IpAddress.ToString() + " selected as the primary node for the shard.");
                            }
                        }

                        AppUtil.LogEvent(AppUtil.EventLogSource, string.Format("Node {0} is selected as primary for shard \"{1}\"", args.ServerName.ToString(), context.LocalShardName),
                                         EventLogEntryType.Information, EventCategories.Information, EventID.PrimaySelected);
                    }
                    break;

                case MembershipChangeArgs.MembershipChangeType.PrimaryLost:
                case MembershipChangeArgs.MembershipChangeType.PrimaryDemoted:
                case MembershipChangeArgs.MembershipChangeType.NodeLeft:

                    if (args.ServerName != null && Primary != null && args.ServerName.Equals(Primary.Address))
                    {
                        lock (_mutexOnnodeRole)
                        {
                            if (NodeRole != NodeRole.Intermediate)
                            {
                                NodeRole = Common.Configuration.Services.NodeRole.None;
                            }
                        }
                        Primary = null;

                        if (args.ServerName != null)
                        {
                            if (args.ChangeType.Equals(MembershipChangeArgs.MembershipChangeType.PrimaryDemoted))
                            {
                                AppUtil.LogEvent(AppUtil.EventLogSource, string.Format("Primary Node {0} is demoted for shard \"{1}\"", args.ServerName.ToString(), context.LocalShardName),
                                                 EventLogEntryType.Warning, EventCategories.Warning, EventID.PrimaryLost);

                                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsWarnEnabled)
                                {
                                    LoggerManager.Instance.ShardLogger.Warn("LocalShard.OnMembershipChanged()", "The primary " + args.ServerName.ToString() + " is demoted.");
                                }
                            }

                            else if (args.ChangeType.Equals(MembershipChangeArgs.MembershipChangeType.PrimaryLost))
                            {
                                AppUtil.LogEvent(AppUtil.EventLogSource, string.Format("Connection with the primary node {0} lost \"{1}\"", args.ServerName.ToString(), context.LocalShardName),
                                                 EventLogEntryType.Warning, EventCategories.Warning, EventID.PrimaryLost);
                                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsWarnEnabled)
                                {
                                    LoggerManager.Instance.ShardLogger.Warn("LocalShard.OnMembershipChanged()", "The primary " + args.ServerName.ToString() + " is lost.");
                                }
                            }
                        }
                    }

                    _clusterConfigMgr.UpdateClusterConfiguration();
                    if (args.ServerName != null)
                    {
                        ShardConfiguration sConfig = null;
                        if (_clusterConfigMgr != null && _clusterConfigMgr.LatestConfiguration != null && _clusterConfigMgr.LatestConfiguration.Deployment != null)
                        {
                            sConfig = _clusterConfigMgr.LatestConfiguration.Deployment.GetShardConfiguration(context.LocalShardName);
                        }
                        {
                            ServerNode node = null;
                            if (sConfig != null && sConfig.Servers != null)
                            {
                                node = sConfig.Servers.GetServerNode(args.ServerName.IpAddress.ToString());
                            }
                            if (node == null)
                            {
                                if (_connectionRestoration != null)
                                {
                                    BrokenConnectionInfo info = new BrokenConnectionInfo();
                                    info.BrokenAddress = args.ServerName;
                                    info.SessionType   = SessionTypes.Shard;
                                    _connectionRestoration.UnregisterListener(info);
                                }
                            }
                        }
                    }
                    break;

                case MembershipChangeArgs.MembershipChangeType.TimeoutOnRestrictedPrimary:
                    return(_membershipManager.AbortTakeoverMechanismTask(args));

                case MembershipChangeArgs.MembershipChangeType.ForcefullyDemotePrimary:
                    return(_membershipManager.OnForcefulPrimaryDemotion(args));
                }

                if (_membershipManager != null)
                {
                    _membershipManager.UpdateLocalMembership(args);
                    if (context != null && context.DatabasesManager != null &&
                        (args.ChangeType == MembershipChangeArgs.MembershipChangeType.PrimarySet ||
                         (args.ChangeType == MembershipChangeArgs.MembershipChangeType.PrimarySelected)))
                    {
                        context.DatabasesManager.ElectionResult = _membershipManager.LatestMembership.ElectionId;
                        context.ElectionResult            = new ElectionResult();
                        context.ElectionResult.ElectionId = _membershipManager.LatestMembership.ElectionId;
                    }

                    DatabaseMessage primaryChangedMessage = new DatabaseMessage();
                    primaryChangedMessage.OpCode = OpCode.PrimaryChanged;
                    IShardListener listener = _shardListeners[Common.MiscUtil.CLUSTER_MANAGER];
                    listener.OnMessageReceived(primaryChangedMessage, new Server(context.LocalAddress, Status.Running));
                }
            }
            return(false);
        }
Exemple #7
0
 public ShardEventDeliverTask(Message message, IShardListener shardlistener)
 {
     _message       = message;
     _shardListener = shardlistener;
 }
Exemple #8
0
        /// <summary>
        ///
        /// UnRegister Remote Shard Listener, for now its cluster manager and it will be the only listener for
        /// indiviual remote shard so no need for having list of listener
        /// </summary>
        /// <param name="name"> name of listener</param>
        /// <param name="shardListener"> listener instance</param>

        public void UnregisterShardListener(String name, IShardListener shardListener)
        {
            _shardListener = null;
        }
Exemple #9
0
 /// <summary>
 ///
 /// RegisterQuery Remote Shard Listener, for now its cluster manager and it will be the only listener for
 /// indiviual remote shard so no need for having list of listener
 /// </summary>
 /// <param name="name"> name of listener</param>
 /// <param name="shardListener"> listener instance</param>
 public void RegisterShardListener(string name, IShardListener shardListener)
 {
     _shardListener = shardListener;
 }
 public void UnregisterShardListener(string name, IShardListener shardListener)
 {
     throw new NotImplementedException();
 }