Ejemplo n.º 1
0
        public LocalShardCheckHeartbeatTask(IShard shard, NodeContext context, MembershipManager membershipManager, ClusterConfigurationManager clusterConfigMgr)
        {
            this._shard                  = shard;
            this._context                = context;
            this._clusterConfigMgr       = clusterConfigMgr;
            _localShardHeartbeatReporter = new LocalShardHeartbeatReporting(_context.LocalAddress);

            this._membershipManager = membershipManager;
            this._membershipManager.HeartbeatReport = _localShardHeartbeatReporter;
            ShardConfiguration sConfig = null;

            if (_clusterConfigMgr != null)
            {
                sConfig = _clusterConfigMgr.GetShardConfiguration(context.LocalShardName);
            }

            if (sConfig != null && sConfig.NodeHeartbeatInterval > 0)
            {
                this._poolingThreshold = (sConfig.NodeHeartbeatInterval * 2) * 1000;
            }
            _running     = false;
            _startSignal = new ManualResetEvent(false);


            //with the initialization of the heartbeat receiver, we start the send heart beat task.
            _sendHearbeatTask = new LocalShardSendHeartbeatTask(context, shard, _membershipManager, clusterConfigMgr);
        }
        //RTD: revisit this logic
        public object Clone()
        {
            LocalShardHeartbeatReporting clone = new LocalShardHeartbeatReporting(_minReplicatedOperation.Key);

            clone._heartbeatReporter = new Dictionary <Address, HeartbeatInfo>();
            IList <Address> nodes = this._heartbeatReporter.Keys.ToList();

            foreach (var node in nodes)
            {
                HeartbeatInfo info = _heartbeatReporter[node];
                lock (info)
                {
                    clone._heartbeatReporter.Add(node, (HeartbeatInfo)info.Clone());
                }
            }
            return(clone);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// function needs to be shifted from here.
        /// this function provides a mini election feasibility check to avoid continuous triggering of the
        /// election mechanism.
        /// Steps:
        /// 1. Does the node possess a majority of the connections.
        /// 2. If yes, proceed to the next step where the primary is hunted for in the existing heartbeat report table.
        /// </summary>
        /// <param name="report"></param>
        /// <returns></returns>
        private bool AreElectionsFeasible(LocalShardHeartbeatReporting report, ShardConfiguration sConfig)
        {
            IList <Address> activeServers = report.GetReportTable.Keys.ToList();

            if (activeServers.Count < (int)Math.Ceiling((double)sConfig.Servers.Nodes.Count / 2))
            {
                return(false);
            }
            else
            {
                if (report.PrimaryExists())
                {
                    // We verify if a primary exists on any of the nodes at any given point in time and if a channel exists
                    // because there is a possibility that the primary is not stepping down and is not a valid primary either
                    // (catering for split - brain scenarios)
                    return(!ChannelExists(report.GetCurrentPrimary()));
                }
            }
            return(true);
        }