/// <summary> /// Verifies whether a given node is the permanent owner of the bucket or not /// </summary> /// <param name="bucketId"></param> /// <param name="perOwner"></param> /// <returns></returns> public bool VerifyPermanentOwnership(int bucketId, Address perOwner) { try { if (perOwner != null) { Sync.AcquireReaderLock(Timeout.Infinite); try { lock (InstalledHashMap.SyncRoot) { HashMapBucket bucket = (HashMapBucket)InstalledHashMap[bucketId]; return(perOwner.Equals(bucket.TempAddress)); } } finally { Sync.ReleaseReaderLock(); } } } catch (Exception e) { NCacheLog.Error("DistributionMgr.VerifyPermanentOwnership", e.ToString()); } return(false); }
public bool IsBucketFunctional(Address owner, object key) { int bucketId = GetBucketId(key as string); Sync.AcquireReaderLock(Timeout.Infinite); try { if (BucketsOwnershipMap != null && BucketsOwnershipMap.Contains(owner)) { ArrayList buckets = BucketsOwnershipMap[owner] as ArrayList; if (buckets != null) { int index = buckets.IndexOf(new HashMapBucket(null, bucketId)); if (index != -1) { HashMapBucket bucket = buckets[index] as HashMapBucket; if (bucket.Status == BucketStatus.Functional) { return(true); } } } } } finally { Sync.ReleaseReaderLock(); } return(false); }
public override int GetItemSize(object key) { Sync.AcquireReaderLock(Timeout.Infinite); try { return(_storage.GetItemSize(key)); } finally { Sync.ReleaseReaderLock(); } }
/// <summary> /// Determines whether the store contains a specific key. /// </summary> /// <param name="key">The key to locate in the store.</param> /// <returns>true if the store contains an element /// with the specified key; otherwise, false.</returns> public override bool Contains(object key) { Sync.AcquireReaderLock(Timeout.Infinite); try { return(_storage.Contains(key)); } finally { Sync.ReleaseReaderLock(); } }
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); }