Exemple #1
0
        public override bool Equals(object obj)
        {
            bool result = false;

            if (obj is SubCluster)
            {
                SubCluster other = obj as SubCluster;
                result = this._groupid.CompareTo(other._groupid) == 0;

                if (result)
                {
                    result = this._members.Count == other._members.Count;

                    if (result)
                    {
                        foreach (Address mbr in this._members)
                        {
                            if (!other._members.Contains(mbr))
                            {
                                result = false;
                                break;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Return the next node in call balacing order that is fully functional.
        /// </summary>
        /// <returns></returns>
        internal Address SelectNode(ClusterCacheStatistics clusterStats, SubCluster targetGroup, Address localAddress)
        {
            ArrayList servers     = targetGroup.Servers;
            ArrayList memberInfos = clusterStats.Nodes;

            //lock (servers.SyncRoot)
            {
                int     maxtries = servers.Count;
                Address address  = null;

                //if local node participates as a backup in the
                //target group then return the local node.
                foreach (Address node in servers)
                {
                    if (node.IpAddress.Equals(localAddress.IpAddress))
                    {
                        if (IsNodeRunning(node, memberInfos))
                        {
                            return(node);
                        }
                    }
                }

                //if local node could not be selected then
                //do the call balancing.
                do
                {
                    address   = (Address)servers[_lastServ % servers.Count];
                    _lastServ = ++_lastServ % servers.Count;
                    if (IsNodeRunning(address, memberInfos))
                    {
                        return(address);
                    }
                    maxtries--;
                }while (maxtries > 0);
            }
            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Called when a new member joins the group.
        /// </summary>
        /// <param name="address">address of the joining member</param>
        /// <param name="identity">additional identity information</param>
        /// <returns>true if the node joined successfuly</returns>
        private bool OnMemberJoined(Address address, NodeIdentity identity, ArrayList joiningNowList)
        {
            try
            {
                if (!AuthenticateNode(address, identity))
                {
                    NCacheLog.Warn("ClusterService.OnMemberJoined()", "A non-server attempted to join cluster -> " + address);
                    _validMembers.Remove(address);
                    _servers.Remove(address);
                    return false;
                }

                SubCluster group = null;
                if (identity.HasStorage && identity.SubGroupName != null)
                {
                    lock (_subgroups.SyncRoot)
                    {
                        group = GetSubCluster(identity.SubGroupName);
                        if (group == null)
                        {
                            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterService.OnMemberJoined()", "Formed new sub-cluster -> " + identity.SubGroupName);
                            group = new SubCluster(identity.SubGroupName, this);
                            _subgroups[identity.SubGroupName] = group;
                        }
                        group.OnMemberJoined(address, identity);
                    }
                }
                bool joined = _participant.OnMemberJoined(address, identity);
                if (!joined && group != null)
                {
                    group.OnMemberLeft(address, _distributionPolicyMbr.BucketsOwnershipMap);
                }
                
                if (joined)
                {
                    NCacheLog.CriticalInfo("ClusterService.OnMemberJoined()", "Member joined: " + address);

                    Address renderer = new Address(identity.RendererAddress, identity.RendererPort);

                    string mirrorExplaination = identity.IsStartedAsMirror ? " (replica)" : "";

                    if (joiningNowList.Contains(address) && !_context.IsStartedAsMirror && !address.Equals(LocalAddress))
                    {
                        AppUtil.LogEvent(_cacheserver, "Node \"" + address + mirrorExplaination + "\" has joined to \"" + _context.CacheRoot.Name + "\".", System.Diagnostics.EventLogEntryType.Information, EventCategories.Information, EventID.NodeJoined);
                    }

                    if (!_membersRenders.Contains(address))
                    {
                        _membersRenders.Add(address, renderer);

                        if (_listener != null && !identity.IsStartedAsMirror)
                        {
                            _listener.OnMemberJoined(address, renderer);
                        }
                    }
                }

                return joined;
            }
            catch (Exception exception)
            {
                NCacheLog.Error("ClusterService.OnMemberJoined", exception.ToString());
            }
            return false;
        }