Пример #1
0
        public NodeBalanceData(ArrayList hashMap, Hashtable bucketStatistics, ArrayList members)
        {
            _percentWeightPerNode = 100 / members.Count;
            _members = members;
            int memberCount = _members.Count;

            _hashMapData  = new ArrayList(memberCount);
            _cacheDataSum = 1;

            ArrayList _weightIdList = new ArrayList();

            for (int i = 0; i < DistributionManager.TotalBuckets; i++)
            {
                HashMapBucket    hmapBuck  = (HashMapBucket)hashMap[i];
                BucketStatistics buckStats = (BucketStatistics)bucketStatistics[i];
                if (hmapBuck.Status != BucketStatus.UnderStateTxfr) //include only those buckets that are Functional
                {
                    WeightIdPair listItem = new WeightIdPair(hmapBuck.BucketId, buckStats.DataSize, hmapBuck.PermanentAddress);
                    _weightIdList.Add(listItem);
                }
                _cacheDataSum += buckStats.DataSize; //Lets get the TOTAL weight of the cluster.
            }

            _weightPerNode = _cacheDataSum / memberCount;

            _balanceDataListForNodes = new ArrayList(memberCount);
            foreach (Address mbr in _members)
            {
                BalanceDataForNode balanceData = new BalanceDataForNode(_weightIdList, mbr, _cacheDataSum);
                _balanceDataListForNodes.Add(balanceData);
            }
        }
Пример #2
0
 /// <summary>
 /// Removes all entries from the store.
 /// </summary>
 internal override void ClearInternal()
 {
     base.ClearInternal();
     if (_keyList != null)
     {
         _keyList.Clear();
     }
     if (_logMgr != null)
     {
         _logMgr.Dispose();                  //it clears the operation loggers for each bucket
     }
     lock (LocalBuckets)
     {
         //clear the bucket stats
         IDictionaryEnumerator ide = LocalBuckets.GetEnumerator();
         while (ide.MoveNext())
         {
             BucketStatistics stats = ide.Value as BucketStatistics;
             if (stats != null)
             {
                 stats.Clear();
             }
         }
     }
 }
 public void Deserialize(Common.Serialization.IO.CompactReader reader)
 {
     _shards = Common.Util.SerializationUtility.DeserializeList <string>(reader);
     _name   = reader.ReadObject() as string;
     _nonShardedDistribution = reader.ReadObject() as NonShardedDistribution;
     _bucketsStats           = reader.ReadObject() as BucketStatistics;
     _syncLock = new ReaderWriterLock();
 }
Пример #4
0
        public void UpdateBucketStats(NodeInfo localNode)
        {
            try
            {
                Sync.AcquireWriterLock(Timeout.Infinite);

                if (localNode == null)
                {
                    return;
                }

                if (_bucketsStats == null)
                {
                    _bucketsStats = new Hashtable();
                }

                if (localNode.Statistics != null && localNode.Statistics.LocalBuckets != null)
                {
                    Hashtable bucketStats = localNode.Statistics.LocalBuckets.Clone() as Hashtable;
                    if (bucketStats != null)
                    {
                        IDictionaryEnumerator ide = bucketStats.GetEnumerator();
                        while (ide.MoveNext())
                        {
                            //muds:
                            //see if this node is the permanent owner of the bucket
                            //otherwise its quite possible that we override the
                            //stats of the bucket from the temporary owner.
                            HashMapBucket bucket = (HashMapBucket)_installedHashMap[(int)ide.Key];
                            if (bucket.PermanentAddress.Equals(localNode.Address))
                            {
                                BucketStatistics stats = ide.Value as BucketStatistics;
                                _bucketsStats[ide.Key] = ide.Value;
                            }
                            else
                            {
                            }
                        }
                    }

                    if (NCacheLog.IsInfoEnabled)
                    {
                        NCacheLog.Info("DistributionMgr.UpdateBucketStats()", "bucketStats = " + _bucketsStats == null ? "null" : _bucketsStats.Count.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                if (NCacheLog.IsErrorEnabled)
                {
                    NCacheLog.Error("DistributionMgr.UpdateBucketStats()", e.ToString());
                }
            }
            finally
            {
                Sync.ReleaseWriterLock();
            }
        }
Пример #5
0
        public DistributionData(ArrayList hashMap, Hashtable bucketStatistics, ArrayList members, ILogger NCacheLog, long cacheSizePerNode)
        {
            _members = members;
            int memberCount = _members.Count;

            _hashMapData  = new ArrayList(memberCount);
            _cacheDataSum = 1;

            ArrayList _weightIdList = new ArrayList();

            for (int i = 0; i < DistributionManager.TotalBuckets; i++)
            {
                HashMapBucket    hmapBuck  = (HashMapBucket)hashMap[i];
                BucketStatistics buckStats = (BucketStatistics)bucketStatistics[i];

                if (buckStats == null)
                {
                    buckStats = new BucketStatistics();
                }

                //Catering for situations when two nodes are balancing and a new node joins in OR
                // two nodes joins one after the other, first one started state transfer while second jumped in.
                if (hmapBuck.Status != BucketStatus.UnderStateTxfr) //include only those buckets that are Functional/NeedStateTr
                {
                    //We are selecting buckets based on temp address; although it is possible that these buckets
                    //might have not been transfered to TEMP owner but algorithm consider these are owned by TEMP owner.
                    WeightIdPair listItem = new WeightIdPair(hmapBuck.BucketId, buckStats.DataSize, hmapBuck.TempAddress);
                    _weightIdList.Add(listItem);
                }

                _cacheDataSum += buckStats.DataSize; //Lets get the TOTAL weight of the cluster.
            }

            if (NCacheLog.IsInfoEnabled)
            {
                NCacheLog.Info("DistributionData()", "cacheDataSum = " + _cacheDataSum.ToString());
            }

            //Initialize the two very important data pieces. All distribution is based on this.
            _bucketsPerNode = DistributionManager.TotalBuckets / (memberCount + 1);
            _weightPerNode  = _cacheDataSum / (memberCount + 1);

            _distMatrixForNodes = new ArrayList(memberCount);
            long maxCacheSize = cacheSizePerNode * memberCount; //in bytes..CacheSize/node is the one user has entered while creating the cluster

            foreach (Address mbr in _members)
            {
                DistributionMatrix distMatrix = new DistributionMatrix(_weightIdList, mbr, this, NCacheLog);
                distMatrix.MaxCacheSize = maxCacheSize;
                _distMatrixForNodes.Add(distMatrix);
            }
        }
        public void UpdateBucketStats(Common.Stats.ShardInfo shardInfo)
        {
            _syncLock.AcquireWriterLock(Timeout.Infinite);
            try
            {
                if (shardInfo == null)
                {
                    return;
                }

                if (_bucketsStats == null)
                {
                    _bucketsStats = new BucketStatistics();
                }

                if (shardInfo.Statistics != null && shardInfo.Statistics.LocalBuckets != null)
                {
                    var bucketStats = shardInfo.Statistics.LocalBuckets;
                    if (bucketStats != null)
                    {
                        IEnumerator <KeyValuePair <HashMapBucket, BucketStatistics> > ide = bucketStats.GetEnumerator();
                        while (ide.MoveNext())
                        {
                            if (_nonShardedDistribution.Bucket.CurrentShard.Equals(shardInfo.ShardName))
                            {
                                BucketStatistics stats = ide.Current.Value;

                                _bucketsStats = stats;
                            }
                        }
                    }
                }
            }

            /* catch (Exception e)
             * {
             *   if (NCacheLog != null && NCacheLog.IsErrorEnabled) NCacheLog.Error("DistributionMgr.UpdateBucketStats()", e.ToString());
             * }*/
            finally
            {
                _syncLock.ReleaseWriterLock();
            }
        }
Пример #7
0
        public override void UpdateLocalBuckets(ArrayList bucketIds)
        {
            IEnumerator ie = bucketIds.GetEnumerator();

            while (ie.MoveNext())
            {
                if (LocalBuckets == null)
                {
                    LocalBuckets = new BucketStatistics[AppUtil.MAX_BUCKETS];
                }

                lock (LocalBuckets)
                {
                    if (LocalBuckets[(int)ie.Current] == null)
                    {
                        LocalBuckets[(int)ie.Current] = new BucketStatistics();
                    }
                }
            }
        }