Example #1
0
 public DistributionInfoData(DistributionMode distMode, ClusterActivity clustActivity, PartNodeInfo affectedNode, bool underMaintenance)
 {
     _distMode          = distMode;
     _clustActivity     = clustActivity;
     _affectedNode      = affectedNode;
     isUnderMaintenance = underMaintenance;
 }
Example #2
0
 public override bool Equals(object obj)
 {
     if (obj is PartNodeInfo)
     {
         PartNodeInfo other = (PartNodeInfo)obj;
         if ((this.NodeAddress.Equals(other.NodeAddress)) && this._subGroupId == other._subGroupId)
         {
             return(true);
         }
     }
     return(false);
 }
 public DistributionInfoData(DistributionMode distMode, ClusterActivity clustActivity, PartNodeInfo affectedNode)
 {
     _distMode = distMode;
     _clustActivity = clustActivity;
     _affectedNode = affectedNode;
 }
Example #4
0
        private void handleBalanceDataLoad(object info)
        {
            Address requestingNode = info as Address;
            PartNodeInfo partNode = new PartNodeInfo(requestingNode, null, false);
            DistributionInfoData distData = new DistributionInfoData(DistributionMode.Manual, ClusterActivity.None, partNode);
            DistributionMaps maps = GetMaps(distData);

            if (maps.BalancingResult == BalancingResult.Default)
            {
                PublishMaps(maps);
            }
        }
Example #5
0
        public object GetDistributionAndMirrorMaps(object data)
        {
            NCacheLog.Debug("MessageResponder.GetDistributionAndMirrorMaps()",   "here comes the request for hashmap");

            object[] package = data as object[];
            ArrayList members = package[0] as ArrayList;
            bool isJoining = (bool)package[1];
            string subGroup = (string)package[2];
            bool isStartedAsMirror = (bool)package[3];

            ClusterActivity activity = ClusterActivity.None;
            activity = isJoining ? ClusterActivity.NodeJoin : ClusterActivity.NodeLeave;

            DistributionMaps maps = null;

            // if the joining node is mirror and its coordinator/active exists
            {
                PartNodeInfo affectedNode = new PartNodeInfo((Address)members[0], subGroup, !isStartedAsMirror);
                DistributionInfoData info = new DistributionInfoData(DistributionMode.OptimalWeight, activity, affectedNode);
                if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterService.GetDistributionMaps",   "NodeAddress: " + info.AffectedNode.NodeAddress.ToString() + " subGroup: " + subGroup + " isMirror: " + isStartedAsMirror.ToString() + " " + (isJoining ? "joining" : "leaving"));
                maps = _distributionPolicyMbr.GetDistributionMaps(info);
            }

            CacheNode[] mirrors = _distributionPolicyMbr.GetMirrorMap();
            NCacheLog.Debug("MessageResponder.GetDistributionAndMirrorMaps()",   "sending hashmap response back...");

           
            return new object[] { maps, mirrors };
        }
Example #6
0
        /// <summary>
        /// Notify the target object of a change of membership.
        /// </summary>
        /// <param name="new_view">New view of group</param>
        void MembershipListener.viewAccepted(View newView)
        {
            System.Collections.ArrayList joined_mbrs, left_mbrs, tmp;
            ArrayList joining_mbrs = new ArrayList();

            lock (viewMutex)
            {
                object tmp_mbr;

                if (newView == null)
                    return;

                NCacheLog.CriticalInfo("ClusterService.ViewAccepted", newView.ToString());
                tmp = newView.Members;

                if (newView.Vid != null)
                {
                    this._lastViewId = newView.Vid.Id;
                }

                // get new members
                joined_mbrs = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

                for (int i = 0; i < tmp.Count; i++)
                {
                    tmp_mbr = tmp[i];
                    if (!_members.Contains(tmp_mbr))
                        joined_mbrs.Add(tmp_mbr);
                }
                int localIndex = 0;

                if (joined_mbrs.Contains(LocalAddress))
                    localIndex = joined_mbrs.IndexOf(LocalAddress);

                for (int i = localIndex; i < joined_mbrs.Count; i++)
                {
                    joining_mbrs.Add(joined_mbrs[i]);
                }

                // get members that left
                left_mbrs = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                for (int i = 0; i < _members.Count; i++)
                {
                    tmp_mbr = _members[i];
                    if (!tmp.Contains(tmp_mbr))
                        left_mbrs.Add(tmp_mbr);
                }

                // adjust our own membership
                _members.Clear();
                _members.AddRange(tmp);

                //muds:
                //pick the map from the view and send it to cache.
                //if i am the only member, i can build the map locally.
                if (newView.DistributionMaps == null && newView.Members.Count == 1)
                {
                    if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterService.viewAccepted()", "I am the only member in the view so, building map myself");
                    PartNodeInfo affectedNode = new PartNodeInfo(LocalAddress, _subgroupid, true);
                    DistributionInfoData info = new DistributionInfoData(DistributionMode.OptimalWeight, ClusterActivity.NodeJoin, affectedNode);
                    DistributionMaps maps = _distributionPolicyMbr.GetDistributionMaps(info);
                    if (maps != null)
                    {
                        _distributionPolicyMbr.HashMap = maps.Hashmap;
                        _distributionPolicyMbr.BucketsOwnershipMap = maps.BucketsOwnershipMap;
                    }
                }
                else
                {

                    if (newView.MirrorMapping != null)
                    {
                        _distributionPolicyMbr.InstallMirrorMap(newView.MirrorMapping);
                        NCacheLog.Info("ClusterService.viewAccepted()", "New MirrorMap installed.");
                    }

                    if (newView.DistributionMaps != null)
                    {
                        _distributionPolicyMbr.InstallHashMap(newView.DistributionMaps, left_mbrs);
                        if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterService.viewAccepted()", "New hashmap installed");
                    }
                }

                lock (_servers.SyncRoot)
                {
                    if (left_mbrs.Count > 0)
                    {
                        for (int i = left_mbrs.Count - 1; i >= 0; i--)
                        {
                            Address ipAddr = (Address)((Address)left_mbrs[i]);
                            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterService.viewAccepted", ipAddr.AdditionalData.Length.ToString());
                            ipAddr = (Address)ipAddr.Clone();
                            if (_servers.Contains(ipAddr))
                                _servers.Remove(ipAddr);

                            OnMemberLeft(ipAddr, CompactBinaryFormatter.FromByteBuffer(ipAddr.AdditionalData, _context.SerializationContext) as NodeIdentity);
                            ipAddr.AdditionalData = null;
                        }
                    }

                    _validMembers = (ArrayList)_members.Clone();
                    if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterService.viewAccepted", joining_mbrs.Count.ToString());

                    if (joined_mbrs.Count > 0)
                    {
                        for (int i = 0; i < joined_mbrs.Count; i++)
                        {
                            Address ipAddr = (Address)joined_mbrs[i];
                            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterService.viewAccepted", ipAddr.AdditionalData.Length.ToString());
                            ipAddr = (Address)ipAddr.Clone();

                            if (OnMemberJoined(ipAddr, CompactBinaryFormatter.FromByteBuffer(ipAddr.AdditionalData, _context.SerializationContext) as NodeIdentity, joining_mbrs))
                            {
                                if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ClusterServices.ViewAccepted", ipAddr.ToString() + " is added to _servers list.");
                                _servers.Add(ipAddr);
                            }
                            ipAddr.AdditionalData = null;
                        }
                    }
                }

                if (String.IsNullOrEmpty(_bridgeSourceCacheId))
                    _bridgeSourceCacheId = newView.BridgeSourceCacheId;
                OnAfterMembershipChange();
            }
        }
 public DistributionInfoData(DistributionMode distMode, ClusterActivity clustActivity, PartNodeInfo affectedNode)
 {
     _distMode      = distMode;
     _clustActivity = clustActivity;
     _affectedNode  = affectedNode;
 }
        internal override void AutoLoadBalance()
        {
            if (_distributionMgr.CandidateNodesForBalance.Count > 0)
            {
                DetermineClusterStatus();
                ArrayList candidateNodes = _distributionMgr.CandidateNodesForBalance;
                if (candidateNodes != null && candidateNodes.Count > 0)
                {
                    DistributionMaps maps = null;
                    DistributionManager.CandidateNodeForLoadBalance candidateNode =
                        candidateNodes[0] as DistributionManager.CandidateNodeForLoadBalance;
                    if (NCacheLog.IsInfoEnabled)
                        NCacheLog.Info("PartitionedCache.AutoLoadBalance",
                            "candidate node count: " + candidateNodes.Count + " candidate node :" + candidateNode.Node +
                            " above avg(%) :" + candidateNode.PercentageAboveAverage);
                    PartNodeInfo nodeInfo = new PartNodeInfo(candidateNode.Node as Address, null, false);
                    DistributionInfoData distInfo = new DistributionInfoData(DistributionMode.Manual,
                        ClusterActivity.None, nodeInfo);
                    maps = _distributionMgr.GetMaps(distInfo);

                    if (NCacheLog.IsInfoEnabled)
                        NCacheLog.Info("PartitionedCache.AutoLoadBalance", "result :" + maps.BalancingResult);

                    if (maps.BalancingResult == BalancingResult.Default)
                    {
                        PublishMaps(maps);
                    }
                }
                else if (NCacheLog.IsInfoEnabled)
                    NCacheLog.Info("PartitionedCache.AutoLoadBalance", "No need to load balance");
            }
        }