示例#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
        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);
            }
        }
示例#3
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);
            }
        }
示例#4
0
        private void InitializeMatrix(int rows, int cols)
        {
            _mDimensions         = new MatrixDimensions(rows, cols);
            _weightMatrix        = new long[rows, cols];
            _idMatrix            = new int[rows, cols];
            _weightPercentMatrix = new long[rows, 2];

            int nLoopCount = 0;

            for (int i = 0; i < rows; i++)
            {
                long rowSum = 0;
                for (int j = 0; j < cols; j++)
                {
                    if (nLoopCount < _filteredWeightIdList.Count)
                    {
                        WeightIdPair tmpPair = (WeightIdPair)_filteredWeightIdList[nLoopCount];
                        _weightMatrix[i, j] = tmpPair.Weight;
                        _idMatrix[i, j]     = tmpPair.BucketId;
                        rowSum += tmpPair.Weight;
                    }
                    else
                    {
                        _weightMatrix[i, j] = -1;
                        _idMatrix[i, j]     = -1;
                    }
                    nLoopCount++;
                }
                _weightPercentMatrix[i, 1] = rowSum; //populate weightPercent Matrix while populating the weight and Id matrices.
                _totalWeight += rowSum;
            }

            //Here I am calculating sum along with %age weight each row is keeping in. This would help while finding the right
            // set of buckets to be given off.
            for (int i = 0; i < _mDimensions.Rows; i++)
            {
                _weightPercentMatrix[i, 0] = Convert.ToInt64(Math.Ceiling(((double)_weightPercentMatrix[i, 1] / (double)_totalWeight) * 100));
            }

            //Calculate how much %age weight THIS NODE is keeping w.r.t overall cluster.
            _percentWeightOfCluster = Convert.ToInt32(((_totalWeight * 100) / _distData.CacheDataSum));


            // Although buckets are sacrificed equally, but data is not.
            // Every node would share w.r.t the percentage that it is keeping in the Cluster.
            // If a node is keeping 50% share of the data, it would give away 50% of the required weight for the coming node.
            _weightToSacrifice        = Convert.ToInt64(Math.Ceiling(((double)_distData.WeightPerNode * (double)_percentWeightOfCluster) / 100));
            _percentWeightToSacrifice = Convert.ToInt32(Math.Ceiling(((double)_weightToSacrifice / (double)_totalWeight) * 100));
        }
示例#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];
                
                //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);
            }
        }
示例#6
0
        //data to be moved from Primary node to the secondary node.
        //As a result priNode and secNode got updated WeightIdPairLists.
        private static void BalanceTwoNodes(BalanceDataForNode priNode, BalanceDataForNode secNode, long dataToMove)
        {
            int       priBucketCount  = priNode.ItemsCount;
            int       secBucketCount  = secNode.ItemsCount;
            ArrayList priWIPairList   = priNode.WeightIdList;
            ArrayList secWIPairList   = secNode.WeightIdList;
            int       cushionFactor   = 10;              // 10% cushion for balancing...   +- 10%
            long      swapWeightGain  = 0;               // weight gain for this swap
            long      cushionWeight   = Convert.ToInt64(((double)(dataToMove * cushionFactor) / (double)100));
            bool      bTargetAchieved = false;           //loop-invariant, in case we need to exit the loop in middle.
            long      movedSoFar      = 0;
            ArrayList usedIndex       = new ArrayList(); //this list would keep all those indicies related to Inner loop that are consumed/used in swap.

            //Making pivot node to be the secondary one, the one that needs to gain weight.
            //swapping or try to swap each element of secNode to all elements of priNode.
            //primary is traversed in Descending order, and secondary is traversed in ascending order.
            for (int i = 0; i < secBucketCount && !bTargetAchieved; i++)
            {
                WeightIdPair secWIPair = (WeightIdPair)secWIPairList[i];

                for (int j = priBucketCount - 1; j >= 0; j--)
                {
                    WeightIdPair priWIPair = (WeightIdPair)priWIPairList[j];

                    //only move when there is a gain.
                    if (priWIPair.Weight > secWIPair.Weight && !usedIndex.Contains(j))
                    {
                        swapWeightGain = priWIPair.Weight - secWIPair.Weight;
                        movedSoFar    += swapWeightGain;

                        if (movedSoFar <= dataToMove)
                        {
                            if (dataToMove - movedSoFar <= cushionWeight)
                            {
                                //swap the buckets and exit
                                secWIPairList[i] = priWIPair;
                                priWIPairList[j] = secWIPair;
                                bTargetAchieved  = true;
                                break;
                            }
                            else
                            {
                                secWIPairList[i] = priWIPair;
                                priWIPairList[j] = secWIPair;
                                usedIndex.Add(j);
                                break; //i need to move fwd now
                            }
                        } //end if
                        else
                        {
                            if (movedSoFar - dataToMove <= cushionWeight)
                            {
                                //swap the buckets an exit
                                secWIPairList[i] = priWIPair;
                                priWIPairList[j] = secWIPair;
                                bTargetAchieved  = true;
                                break;
                            }
                            else
                            {
                                movedSoFar -= swapWeightGain;
                            }
                        } //end else
                    }     //end if for priWeight > seWeight
                }         //end inner for loop
            }             //end outer for loop
            //re-assign the WeightIdPairList to respective BalanceDataForNode
            priNode.WeightIdList = priWIPairList;
            priNode.WeightIdList.Sort();

            secNode.WeightIdList = secWIPairList;
            secNode.WeightIdList.Sort();
        }
示例#7
0
        public int CompareTo(object obj)
        {
            WeightIdPair wiPair = (WeightIdPair)obj;

            return(this._weight.CompareTo(wiPair.Weight));
        }