/// <summary> creates a copy of this view</summary> /// <returns> a copy of this view /// </returns> public virtual object Clone() { ViewId vid2 = vid != null?(ViewId)vid.Clone():null; System.Collections.ArrayList members2 = _members != null?(System.Collections.ArrayList)_members.Clone():null; View v = new View(vid2, members2); if (SequencerTbl != null) { v.SequencerTbl = SequencerTbl.Clone() as Hashtable; } if (MbrsSubgroupMap != null) { v.MbrsSubgroupMap = MbrsSubgroupMap.Clone() as Hashtable; } v._coordinatorGmsId = _coordinatorGmsId; if (DistributionMaps != null) { v.DistributionMaps = DistributionMaps.Clone() as DistributionMaps; } if (MirrorMapping != null) { v.MirrorMapping = MirrorMapping; } if (nodeGmsIds != null) { v.nodeGmsIds = nodeGmsIds.Clone() as Hashtable; } return(v); }
public virtual void Deserialize(CompactReader reader) { vid = (ViewId)reader.ReadObject(); _members = (ArrayList)reader.ReadObject(); _sequencerTbl = (Hashtable)reader.ReadObject(); _mbrsSubgroupMap = (Hashtable)reader.ReadObject(); _distributionMaps = (DistributionMaps)reader.ReadObject(); _mirrorMapping = reader.ReadObject() as CacheNode[]; nodeGmsIds = reader.ReadObject() as Hashtable; _coordinatorGmsId = reader.ReadObject() as string; }
/// <summary> /// /// </summary> /// <param name="newMap"></param> /// <param name="newBucketsOwnershipMap"></param> /// <param name="leftMbrs"></param> public void InstallHashMap(DistributionMaps distributionMaps, ArrayList leftMbrs) { ArrayList newMap = null; Hashtable newBucketsOwnershipMap = null; _sync.AcquireWriterLock(Timeout.Infinite); try { if (distributionMaps == null) { return; } newMap = distributionMaps.Hashmap; newBucketsOwnershipMap = distributionMaps.BucketsOwnershipMap; if (newMap == null || newBucketsOwnershipMap == null) { return; } if (_installedHashMap != null) { for (int i = 0; i < newMap.Count; i++) { HashMapBucket newBucket = (HashMapBucket)newMap[i]; int index = _installedHashMap.IndexOf(newBucket); HashMapBucket oldBucket = (HashMapBucket)_installedHashMap[index]; if (!oldBucket.PermanentAddress.Equals(newBucket.PermanentAddress) && oldBucket.TempAddress.Equals(newBucket.TempAddress)) { NCacheLog.Error("Install Hasmap", "BucketID: " + index.ToString() + "\toldBucket: " + oldBucket.PermanentAddress.ToString() + "\toldBucket.Temp: " + oldBucket.TempAddress.ToString() + "\tnewBucket: " + newBucket.PermanentAddress.ToString() + "\tnewBucekt.Temp: " + newBucket.TempAddress.ToString()); } else { oldBucket.PermanentAddress = newBucket.PermanentAddress; oldBucket.TempAddress = newBucket.TempAddress; oldBucket.Status = newBucket.Status; } } } else { _installedHashMap = newMap; } _bucketsOwnershipMap = newBucketsOwnershipMap; NotifyBucketUpdate(); } finally { _sync.ReleaseWriterLock(); } }
public DistributionMaps BalanceNodes(DistributionInfoData distInfo, ArrayList hashMap, Hashtable bucketStats, ArrayList members) { _hashMap = hashMap; _nodeBalData = new NodeBalanceData(hashMap, bucketStats, members); //Check if any other state transfer is not in progress... bool bAllFunctional = this.SanityCheckForAllFunctional(hashMap); //Add some status saying that node balancing is not possible at the moment. if (!bAllFunctional) { DistributionMaps result = new DistributionMaps(BalancingResult.AlreadyInBalancing); return(result); } //Check if really the node needs some balancing or not. bool bShouldBalance = this.SanityCheckForCandidateNode((Address)distInfo.AffectedNode.NodeAddress); if (!bShouldBalance) { DistributionMaps result = new DistributionMaps(BalancingResult.NotRequired); return(result); } ArrayList dataListForNodes = _nodeBalData.BalanceDataListForNodes; ArrayList candidates = FilterCandidateNodes(); foreach (AddressWeightPair awPair in candidates) { BalanceDataForNode secNode = GetBalDataForNode(awPair.NodeAddress); BalanceTwoNodes(_primaryNode, secNode, awPair.WeightShare); ApplyChangesInHashMap(secNode); } ApplyChangesInHashMap(_primaryNode); return(new DistributionMaps(_hashMap, null)); }
/// <summary> /// A new map is required when a member leaves or joins the cluster. /// This method returns a new map based on the input paramameters. /// </summary> /// <param name="member">Address of the member that has either left /// or joined the cluster</param> /// <param name="isNew">A flag. True if the member has joined otherwise false.</param> /// <returns>A new hashmap instance</returns> public virtual DistributionMaps GetMaps(DistributionInfoData distInfoData) { ArrayList tmpMap = null; Hashtable bucketsOwnershipMap = null; ArrayList partitionNodes = new ArrayList(); _sync.AcquireWriterLock(Timeout.Infinite); try { if (_installedHashMap == null) { tmpMap = new ArrayList(TotalBuckets); for (int i = 0; i < TotalBuckets; i++) { HashMapBucket bucket = new HashMapBucket(distInfoData.AffectedNode.NodeAddress, i, BucketStatus.Functional); tmpMap.Add(bucket); } _existingMembers.Add(distInfoData.AffectedNode.NodeAddress); _lastCreatedHashMap = tmpMap.Clone() as ArrayList; bucketsOwnershipMap = GetBucketsOwnershipMap(_lastCreatedHashMap); return(new DistributionMaps(_lastCreatedHashMap, bucketsOwnershipMap)); } else if (_lastCreatedHashMap == null) { _lastCreatedHashMap = _installedHashMap.Clone() as ArrayList; } switch (distInfoData.ClustActivity) { case ClusterActivity.NodeJoin: try { return(GetMapsOnNodeJoining(distInfoData)); } catch (Exception e) { if (NCacheLog.IsErrorEnabled) { NCacheLog.Error("DistributionMgr.GetMaps()", e.ToString()); } break; } case ClusterActivity.NodeLeave: try { return(GetMapsOnNodeLeaving(distInfoData)); } catch (Exception e) { if (NCacheLog.IsErrorEnabled) { NCacheLog.Error("DistributionMgr.GetMaps()", e.ToString()); } break; } case ClusterActivity.None: BalanceNodeMgr bnMgr = new BalanceNodeMgr(null); DistributionMaps result = bnMgr.BalanceNodes(distInfoData, _lastCreatedHashMap, _bucketsStats, _existingMembers); if (result.Hashmap != null) { _lastCreatedHashMap = result.Hashmap.Clone() as ArrayList; result.BucketsOwnershipMap = GetBucketsOwnershipMap(_lastCreatedHashMap); } return(result); default: break; } } finally { _sync.ReleaseWriterLock(); } return(null); }
public override DistributionMaps GetMaps(DistributionInfoData distInfoData) { ArrayList tmpMap = null; Hashtable bucketsOwnershipMap = null; ArrayList partitionNodes = new ArrayList(); if (_installedHashMap == null) { tmpMap = new ArrayList(TotalBuckets); for (int i = 0; i < TotalBuckets; i++) { HashMapBucket bucket = new HashMapBucket(distInfoData.AffectedNode.NodeAddress, i, BucketStatus.Functional); tmpMap.Add(bucket); } _existingMembers.Add(distInfoData.AffectedNode.NodeAddress); _subGroupMap[distInfoData.AffectedNode.NodeAddress] = distInfoData.AffectedNode.SubGroup; //for each new group we are keeping list of members. For only Partition it will be one ..for POR can be greater then one. //This is new member, the first one. So create the list here. distInfoData.AffectedNode.IsCoordinator = true; partitionNodes.Add(distInfoData.AffectedNode); _partitionNodesInfo.Add(distInfoData.AffectedNode.SubGroup, partitionNodes); //A hash table keeping list of addresses against each GROUP/Partition. _lastCreatedHashMap = tmpMap.Clone() as ArrayList; bucketsOwnershipMap = GetBucketsOwnershipMap(_lastCreatedHashMap); return(new DistributionMaps(_lastCreatedHashMap, bucketsOwnershipMap)); } //for non-coordinator node that recently becomes coordinator... else if (_lastCreatedHashMap == null) { _lastCreatedHashMap = _installedHashMap.Clone() as ArrayList; } switch (distInfoData.ClustActivity) { case ClusterActivity.NodeJoin: try { //assuming existing members doesnot contain the newly added member. if (!_partitionNodesInfo.ContainsKey(distInfoData.AffectedNode.SubGroup)) { partitionNodes = new ArrayList(); distInfoData.AffectedNode.IsCoordinator = true; partitionNodes.Add(distInfoData.AffectedNode); _subGroupMap[distInfoData.AffectedNode.NodeAddress] = distInfoData.AffectedNode.SubGroup; _partitionNodesInfo.Add(distInfoData.AffectedNode.SubGroup, partitionNodes); //A hash table keeping list of addresses against each GROUP/Partition. if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("DistributionMgr.GetMaps()", "Sending new map as a new node joined the cluster"); } return(GetMapsOnNodeJoining(distInfoData)); } else { partitionNodes = (ArrayList)_partitionNodesInfo[distInfoData.AffectedNode.SubGroup]; partitionNodes.Add(distInfoData.AffectedNode); _subGroupMap[distInfoData.AffectedNode.NodeAddress] = distInfoData.AffectedNode.SubGroup; return(new DistributionMaps(_lastCreatedHashMap, GetBucketsOwnershipMap(_lastCreatedHashMap))); } } catch (Exception e) { if (NCacheLog.IsErrorEnabled) { NCacheLog.Error("DistributionMgr.GetMaps()", e.ToString()); } break; } case ClusterActivity.NodeLeave: //assuming existing members do not containt the node to be removed/left. _existingMembers.Remove(distInfoData.AffectedNode.NodeAddress); _subGroupMap.Remove(distInfoData.AffectedNode.NodeAddress); //Check if this node is the only one in partition or not.So better do distribution if (IsLastNodeInPartition(distInfoData.AffectedNode)) { _partitionNodesInfo.Remove(distInfoData.AffectedNode.SubGroup); return(GetMapsOnNodeLeaving(distInfoData)); } else //this mean we still have nodes available for this partition. { ArrayList groupNodes = (ArrayList)_partitionNodesInfo[distInfoData.AffectedNode.SubGroup]; if (IsCoordinatorNodeInPartition(distInfoData.AffectedNode)) { groupNodes.Remove((object)distInfoData.AffectedNode); ((PartNodeInfo)groupNodes[0]).IsCoordinator = true; _partitionNodesInfo[distInfoData.AffectedNode.SubGroup] = groupNodes; _existingMembers.Add(((PartNodeInfo)groupNodes[0]).NodeAddress); tmpMap = UpgradeToCoordinatorOfReplica(distInfoData.AffectedNode.NodeAddress, ((PartNodeInfo)groupNodes[0]).NodeAddress); _lastCreatedHashMap = tmpMap.Clone() as ArrayList; bucketsOwnershipMap = GetBucketsOwnershipMap(_lastCreatedHashMap); return(new DistributionMaps(_lastCreatedHashMap, bucketsOwnershipMap)); } else { //simply remove the node and get a new bucket ownership map. groupNodes.Remove(distInfoData.AffectedNode); return(new DistributionMaps(_lastCreatedHashMap, GetBucketsOwnershipMap(_lastCreatedHashMap))); } } case ClusterActivity.None: BalanceNodeMgr bnMgr = new BalanceNodeMgr(null); DistributionMaps result = bnMgr.BalanceNodes(distInfoData, _lastCreatedHashMap, _bucketsStats, _existingMembers); if (result.Hashmap != null) { _lastCreatedHashMap = result.Hashmap.Clone() as ArrayList; result.BucketsOwnershipMap = GetBucketsOwnershipMap(_lastCreatedHashMap); } return(result); default: break; } return(null); }