Esempio n. 1
0
        public NodeToCSHeartbeatTask(NodeContext context, MembershipManager manager, IConnectionRestoration connectionRestoration, ClusterConfigurationManager clusterConfigMgr)
        {
            this._context          = context;
            this._clusterConfigMgr = clusterConfigMgr;
            ShardConfiguration sConfig = null;

            if (_clusterConfigMgr != null)
            {
                sConfig = _clusterConfigMgr.GetShardConfiguration(_context.LocalShardName);
                if (_clusterConfigMgr.LatestConfiguration != null && _clusterConfigMgr.LatestConfiguration.Deployment != null)
                {
                    _heartbeatInterval = 1000 * _clusterConfigMgr.LatestConfiguration.Deployment.HeartbeatInterval;
                }
            }
            if (sConfig != null && sConfig.Servers != null)
            {
                _node = sConfig.Servers.GetServerNode(_context.LocalAddress.IpAddress.ToString());
            }

            this._membershipManager = manager;

            this._connectionRestoration = connectionRestoration;

            _running     = false;
            _startSignal = new System.Threading.ManualResetEvent(false);
        }
Esempio n. 2
0
 /// <summary>
 /// All the election related heartbeat tasks begin here.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="shard"></param>
 public void BeginHeartbeatTasks(NodeContext context, IShard shard, IConnectionRestoration connectionRestoration)
 {
     if (_heartbeatManager != null)
     {
         _heartbeatManager.BeginTasks(context, shard, this, connectionRestoration, _clusterConfigMgr);
     }
 }
Esempio n. 3
0
        public bool Stop()
        {
            if (_membershipManager != null)
            {
                _membershipManager.StopHeartbeatTasks();
            }

            if (_connectionRestoration != null)
            {
                _connectionRestoration.Stop();
            }
            _connectionRestoration = null;

            IList <Server> keys = null;

            if (_shardChannels != null)
            {
                keys = _shardChannels.Keys.ToList();
            }
            if (keys != null && keys.Count > 0)
            {
                foreach (var server in keys)
                {
                    try
                    {
                        IDualChannel channel = _shardChannels[server];
                        lock (_shardChannels)
                        {
                            _shardChannels.Remove(server);
                            if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsDebugEnabled)
                            {
                                LoggerManager.Instance.ShardLogger.Debug("Localshard.Stop(): ", server.Address.ToString() + " removed from existing channels.");
                            }
                        }
                        channel.ShouldTryReconnecting = false;
                        channel.Disconnect();
                        if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsDebugEnabled)
                        {
                            LoggerManager.Instance.ShardLogger.Debug("Localshard.Stop(): ", "Connection of local node " + context.LocalAddress.ToString() + " disconected from node " + channel.PeerAddress.ToString());
                        }
                    }
                    catch (ChannelException ex)
                    {
                        if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                        {
                            LoggerManager.Instance.ShardLogger.Error("Error stopping the node " + context.LocalAddress.ToString(), ex.ToString());
                        }
                    }
                }
            }
            lock (_mutexOnnodeRole)
            {
                if (NodeRole != NodeRole.Intermediate)
                {
                    NodeRole = Common.Configuration.Services.NodeRole.None;
                }
            }

            return(true);
        }
Esempio n. 4
0
 public RemoteShard(IChannelFactory factory, IChannelFormatter channelFormatter, NodeContext context, IConnectionRestoration connectionRestoration)
 {
     this.factory                = factory;
     this._channelFormatter      = channelFormatter;
     this.context                = context;
     this._connectionRestoration = connectionRestoration;
     this._threadPool            = new ClrThreadPool();
     this._threadPool.Initialize();
 }
Esempio n. 5
0
        public bool Stop()
        {
            if (LoggerManager.Instance.ServerLogger.IsDebugEnabled)
            {
                LoggerManager.Instance.ServerLogger.Debug("RemoteShard.Stop", "Stopping Remote Shard '" + Name + "'");
            }

            if (this._remoteShardChannel != null)
            {
                ((IDualChannel)_remoteShardChannel).ShouldTryReconnecting = false;
                _remoteShardChannel.Disconnect();
            }
            if (_connectionRestoration != null)
            {
                _connectionRestoration.Stop();
            }
            _connectionRestoration = null;
            IsStarted = false;
            return(true);
        }
Esempio n. 6
0
 public LocalShard(NodeContext context, IConnectionRestoration connectionRestoration, ClusterConfigurationManager clusterConfigMgr)
 {
     this.context = context;
     this._connectionRestoration = connectionRestoration;
     this._clusterConfigMgr      = clusterConfigMgr;
 }
Esempio n. 7
0
        ////RTD: Needs to be moved.
        //public ShardInfo ThisShard
        //{
        //    get { return _localShardInfo; }
        //}

        //public IDictionary<String, ShardInfo> Shards
        //{
        //    get { return _remoteShardsInfo; }
        //}

        public bool Initialize(ClusterConfiguration configuration)

        //public bool Initialize(String clusterName, DeploymentConfiguration configuration)
        {
            #region Getting Local Address Logic; might be replace with getting address from service config

            if (configuration == null)
            {
                throw new ArgumentNullException("cluster configuration can not be null");
            }

            if (configuration.Deployment == null)
            {
                throw new ArgumentNullException("deployment configuration can not be null");
            }

            if (configuration.Deployment.Shards == null)
            {
                throw new ArgumentNullException("topology configuration can not be null");
            }

            if (context != null)
            {
                context.ClusterName = configuration.Name;
            }
            if (string.IsNullOrWhiteSpace(context.LocalShardName))
            {
                //Get Local Shard Name from config
                //string shardName = ConfigurationManager.AppSettings["ShardName"];

                //if (String.IsNullOrEmpty(shardName))
                //{
                throw new ArgumentNullException("Shard Name Can not be null or empty");
                //}

                //RTD: Needs to be moved.
                //context.LocalShardName = shardName;
            }
            //Get Base Data Path from config
            string basePath = ConfigurationSettings <DBHostSettings> .Current.BasePath;

            if (String.IsNullOrEmpty(basePath))
            {
                throw new ArgumentNullException("Data Path Can not be null or empty");
            }

            context.DataPath = basePath;
            context.BasePath = basePath + context.LocalShardName + Common.MiscUtil.DATA_FOLDERS_SEPERATION;
            //Get Base Data Path from config
            string deploymentPath = ConfigurationSettings <DBHostSettings> .Current.DeploymentPath;

            if (String.IsNullOrEmpty(deploymentPath))
            {
                throw new ArgumentNullException("Deployment Path Can not be null or empty");
            }

            context.DeploymentPath = deploymentPath;

            ShardConfiguration localShardConfig = null;
            IDictionary <String, ShardConfiguration> remoteShardConfigs = null;

            SetShardConfigs(configuration.Deployment, out localShardConfig, out remoteShardConfigs);



            _clusterConfigMgr = new ClusterConfigurationManager(context.ConfigurationSession, configuration);

            _connectionRestoration = new ConnectionRestorationManager();
            _connectionRestoration.Initialize(context);

            if (localShardConfig != null)
            {
                _localShard = new LocalShard(context, _connectionRestoration, _clusterConfigMgr);
                _localShard.Initialize(localShardConfig);
                _localShard.RegisterShardListener(Common.MiscUtil.CLUSTER_MANAGER, this);
            }

            if (context != null)
            {
                context.ShardServer.RegisterSessionListener(SessionTypes.Shard, this);
            }

            if (remoteShardConfigs != null && remoteShardConfigs.Keys.Count > 0)
            {
                foreach (KeyValuePair <String, ShardConfiguration> pair in remoteShardConfigs)
                {
                    IShard remoteShard = new RemoteShard(new DualChannelFactory(), new ShardChannelFormatter(), context, _connectionRestoration);
                    remoteShard.Initialize(pair.Value);
                    remoteShard.RegisterShardListener(Common.MiscUtil.CLUSTER_MANAGER, this);
                    lock (_remoteShards)
                    {
                        _remoteShards.Add(pair.Key, remoteShard);
                    }
                }
            }

            return(true);

            #endregion
        }
Esempio n. 8
0
        /// <summary>
        /// All the heartbeat tasks begin here.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="shard"></param>
        public void BeginTasks(NodeContext context, IShard shard, MembershipManager manager, IConnectionRestoration connectionRestoration, ClusterConfigurationManager clusterConfigMgr)
        {
            _nodeToCSReportingTask = new NodeToCSHeartbeatTask(context, manager, connectionRestoration, clusterConfigMgr);
            _nodeToCSReportingTask.Start();

            //Start the shard level heartbeat tasks.
            _checkHeartbeatTask = new LocalShardCheckHeartbeatTask(shard, context, manager, clusterConfigMgr);
            _checkHeartbeatTask.Start();
        }