/// <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); }
/// <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); }