/// <summary> /// Set the status of the bucket to state transfer and in this way this /// bucket becomes locked. A locked bucket can not be assigned during /// loadbalancing. /// </summary> /// <param name="buckets"></param> /// <param name="node"></param> public void ChangeBucketStatusToStateTransfer(ArrayList buckets, Address node) { Sync.AcquireWriterLock(Timeout.Infinite); try { if (buckets != null) { IEnumerator ie = buckets.GetEnumerator(); while (ie.MoveNext()) { lock (InstalledHashMap.SyncRoot) { HashMapBucket bucket = (HashMapBucket)InstalledHashMap[(int)ie.Current]; if (node.Equals(bucket.TempAddress)) { bucket.Status = BucketStatus.UnderStateTxfr; if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("DistributionMgr.ChangeBucketStatus", bucket.ToString()); } } } } if (_bucketsOwnershipMap != null) { ArrayList nodeBuckets = _bucketsOwnershipMap[node] as ArrayList; if (nodeBuckets != null) { foreach (int bucketId in buckets) { int indexOfBucket = nodeBuckets.IndexOf(new HashMapBucket(null, bucketId)); if (indexOfBucket != -1) { HashMapBucket bucket = nodeBuckets[indexOfBucket] as HashMapBucket; if (node.Equals(bucket.TempAddress)) { bucket.Status = BucketStatus.UnderStateTxfr; } } } } } } } finally { Sync.ReleaseWriterLock(); } }
public override Hashtable GetBucketsOwnershipMap(ArrayList hashMap) { Hashtable bucketsOwnerShipMap = new Hashtable(); try { Sync.AcquireReaderLock(Timeout.Infinite); Hashtable coordinatorNodesOwnershipMap = base.GetBucketsOwnershipMap(hashMap); Hashtable currentOwnershipMap = _bucketsOwnershipMap != null?_bucketsOwnershipMap.Clone() as Hashtable : null; ArrayList replicas = null; Address partitionCoordinator = null; if (coordinatorNodesOwnershipMap != null) { IDictionaryEnumerator ide = coordinatorNodesOwnershipMap.GetEnumerator(); while (ide.MoveNext()) { partitionCoordinator = ide.Key as Address; ArrayList coordinatorBuckets = ide.Value as ArrayList; string subgroup = _subGroupMap[partitionCoordinator] as string; if (subgroup != null) { replicas = _partitionNodesInfo[subgroup] as ArrayList; if (replicas != null) { foreach (PartNodeInfo node in replicas) { if (node.IsCoordinator) { bucketsOwnerShipMap.Add(node.NodeAddress, coordinatorBuckets); if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("PoRDistMgr.GetBucketsOwnerShipMap", subgroup + ": " + node.NodeAddress.ToString() + " has got " + coordinatorBuckets.Count + " buckets"); } } else { ArrayList currentBuckets = currentOwnershipMap != null ? currentOwnershipMap[node.NodeAddress] as ArrayList : null; ArrayList updatedBucketsList = new ArrayList(); if (currentBuckets != null) { //Node was already in the partitioned. foreach (HashMapBucket bucket in currentBuckets) { //if bucket is not transferred to the replica yet then we //change the temp address to make sure that if the coordinator //of the partitioned is changed, it is reflected in the map. if (coordinatorBuckets.Contains(bucket)) { if (bucket.TempAddress != null && !bucket.PermanentAddress.Equals(bucket.TempAddress)) { bucket.PermanentAddress = partitionCoordinator; } if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("PoRDistMgr.GetBucketsOwnerShipMap", bucket.ToString() + " after coordinator left"); } updatedBucketsList.Add(bucket.Clone()); } } //during loadbalancing; some new buckets may be assigned to a replica coordinator. foreach (HashMapBucket coodinatorBucket in coordinatorBuckets) { if (!currentBuckets.Contains(coodinatorBucket)) { HashMapBucket newNodeBucket = coodinatorBucket.Clone() as HashMapBucket; newNodeBucket.PermanentAddress = partitionCoordinator; newNodeBucket.TempAddress = node.NodeAddress; //replica node need to state transfer from his coordinator. newNodeBucket.Status = BucketStatus.NeedTransfer; updatedBucketsList.Add(newNodeBucket); if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("PoRDistMgr.GetBucketsOwnerShipMap", newNodeBucket.ToString() + " new bucket assigned to replica"); } } } } else { //it is a new replica node,so we create a new bucket list for this node foreach (HashMapBucket coodinatorBucket in coordinatorBuckets) { HashMapBucket newNodeBucket = coodinatorBucket.Clone() as HashMapBucket; newNodeBucket.PermanentAddress = partitionCoordinator; newNodeBucket.TempAddress = node.NodeAddress; //replica node need to state transfer from his coordinator. newNodeBucket.Status = BucketStatus.NeedTransfer; updatedBucketsList.Add(newNodeBucket); if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("PoRDistMgr.GetBucketsOwnerShipMap", newNodeBucket.ToString() + " fresh replica"); } } } if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("PoRDistMgr.GetBucketsOwnerShipMap", subgroup + ": " + node.NodeAddress.ToString() + " has got " + updatedBucketsList.Count + " buckets"); } bucketsOwnerShipMap.Add(node.NodeAddress, updatedBucketsList); } } } } } } } catch (Exception e) { NCacheLog.Error("PoRDistMgr.GetBucketsOwnerShipMap", e.ToString()); } finally { Sync.ReleaseReaderLock(); } return(bucketsOwnerShipMap); }