Beispiel #1
0
 internal void OnMemberJoined(Address address)
 {
     if (!_activeClusterMbrs.Contains(address.IpAddress))
     {
         _activeClusterMbrs.Add(address.IpAddress);
     }
 }
		/// <summary> Loop: determine coord. If coord is me --> handleLeave().
		/// Else send handleLeave() to coord until success
		/// </summary>
		public override void  leave(Address mbr)
		{
			Address coord;
			int max_tries = 3;
			object result;
			
			leave_promise.Reset();
			
			if (mbr.Equals(gms.local_addr))
				leaving = true;
			
			while ((coord = gms.determineCoordinator()) != null && max_tries-- > 0)
			{
				if (gms.local_addr.Equals(coord))
				{
					// I'm the coordinator
                    gms.becomeCoordinator();
					gms.Impl.handleLeave(mbr, false); // regular leave
					return ;
				}

                gms.Stack.NCacheLog.Debug("sending LEAVE request to " + coord);
				
				sendLeaveMessage(coord, mbr);
				lock (leave_promise)
				{
					result = leave_promise.WaitResult(gms.leave_timeout);
					if (result != null)
						break;
				}
			}
			gms.becomeClient();
		}
Beispiel #3
0
 public BucketTxfrInfo(ArrayList bucketIds, bool isSparsed, Address owner)
 {
     this.bucketIds = bucketIds;
     this.isSparsed = isSparsed;
     this.owner = owner;
     this.end = false;
 }
        internal StateTxfrCorresponder(ClusterCacheBase parent, DistributionManager distMgr, Address requestingNode, byte transferType)
		 {
			 _parent = parent;
			 _distMgr = distMgr;
			 _clientNode = requestingNode;
             _transferType = transferType;
		 }
Beispiel #5
0
 internal NodeLeftEvent(string cacheId, Address clusterAddress, Address serverAddress, string clientid)
 {
     _cacheId = cacheId;
     _clusterAddress = clusterAddress;
     _serverAddress = serverAddress;
     _clientId = clientid;
 }
Beispiel #6
0
 public BucketTxfrInfo(bool end)
 {
     bucketIds = null;
     owner = null;
     isSparsed = false;
     this.end = end;
 }
Beispiel #7
0
 public BucketsPack(ArrayList buckets, Address owner)
 {
     if (buckets != null)
         _bucketIds = buckets;
     
     _owner = owner;
 }
Beispiel #8
0
 public PartNodeInfo()
 {
     _address = new Address();
     _subGroupId = "";
     _isCoordinator = false;
     _priorityIndex = -1;
 }
Beispiel #9
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="own_addr">Local Address</param>
		/// <param name="coord_addr">Coordinator Address</param>
		/// <param name="is_server">if the node is a participant of group</param>
		public PingRsp(Address own_addr, Address coord_addr, bool is_server,bool started) 
		{
			this.own_addr=own_addr;
			this.coord_addr=coord_addr;
			this.is_server = is_server;
            this.started = started;

		}
Beispiel #10
0
 internal NodeJoinedEvent(string cacheId, Address clusterAddress, Address serverAddress, string clientid, bool reconn)
 {
     _cacheId = cacheId;
     _clusterAddress = clusterAddress;
     _serverAddress = serverAddress;
     _clientId = clientid;
     _reconnect = reconn;
 }
Beispiel #11
0
 internal bool ExpectingResponseFrom(Common.Net.Address address)
 {
     lock (_responseMutex)
     {
         bool result = _responses.ContainsKey(address);
         return(result);
     }
 }
Beispiel #12
0
 /// <summary>
 /// Remove connection from pool
 /// </summary>
 /// <param name="ip">ip address of machine to which connection is made</param>
 public void Remove(Alachisoft.NCache.Common.Net.Address ip)
 {
     lock (this._connections.SyncRoot)
     {
         this._connections.Remove(ip);
         this.loadBalancerQueue.Remove(ip);
     }
 }
Beispiel #13
0
 //While a node leaves, all those buckets that were in transfer of buckets to the leaving node, should sieze transfer and would 
 // clear up tempAdd to be the same as the perm. addr.
 private static ArrayList ReAllocBucketsInTransfer(ArrayList hashMap, Address leavingNode)
 {
     for (int i = 0; i < hashMap.Count; i++)
     {
         if (((HashMapBucket)hashMap[i]).TempAddress.CompareTo(leavingNode) == 0)
             ((HashMapBucket)hashMap[i]).TempAddress = ((HashMapBucket)hashMap[i]).PermanentAddress;
     }
     return hashMap;
 }
Beispiel #14
0
 public virtual void handleIsClusterInStateTransfer(Address sender)
 {
     Message msg = new Message(sender, null, new byte[0]);
     GMS.HDR hdr = new GMS.HDR(GMS.HDR.IS_NODE_IN_STATE_TRANSFER_RSP);
     gms.Stack.NCacheLog.Debug("gmsImpl.handleIsClusterInStateTransfer", "(state transfer request) sender: " + sender + " ->" + isInStateTransfer);
     hdr.arg = isInStateTransfer;
     msg.putHeader(HeaderType.GMS,hdr);
     gms.passDown(new Event(Event.MSG,msg,Alachisoft.NCache.Common.Enum.Priority.Critical));
 }
 public DistributionInfoData(DistributionMode distMode, ClusterActivity clustActivity, ManualDistType manDistType, int percentMove, Address source, Address[] dests)
 {
     _distMode = distMode;
     _clustActivity = clustActivity;
     _manualDistType = manDistType;
     _percentToMove = percentMove;
     _source = source;
     _destinations = dests;
 }
Beispiel #16
0
 internal void InitializeResponse(Common.Net.Address address)
 {
     lock (_responseMutex)
     {
         if (!_responses.ContainsKey(address))
         {
             _responses.Add(address, new ResponseList());
         }
     }
 }
Beispiel #17
0
 public void RemoveServer(Common.Net.Address server)
 {
     lock (this)
     {
         if (_serverMap.ContainsKey(server))
         {
             _serverMap.Remove(server);
         }
     }
 }
Beispiel #18
0
        internal void AddCommand(Common.Net.Address address, CommandBase command)
        {
            _name          = command.CommandName;
            command.Parent = this;

            if (!_commands.ContainsKey(address))
            {
                _commands.Add(address, command);
            }
        }
Beispiel #19
0
        internal bool RemoveResponse(Common.Net.Address address)
        {
            lock (_responseMutex)
            {
                _responses.Remove(address);

                bool removeRequestFromTable = _responses.Count == 0;

                return(removeRequestFromTable);
            }
        }
Beispiel #20
0
 /// <summary>The coordinator itself wants to leave the group </summary>
 public override void leave(Address mbr)
 {
     if (mbr == null)
     {
         gms.Stack.NCacheLog.Error("CoordGmsImpl.leave", "member's address is null !");
         return;
     }
     if (mbr.Equals(gms.local_addr))
         leaving = true;
     handleLeave(mbr, false); // regular leave
 }
Beispiel #21
0
 internal void ResetFailedResponse(Common.Net.Address ip)
 {
     lock (_responseMutex)
     {
         if (_responses.ContainsKey(ip))
         {
             ResponseList responseList = _responses[ip];
             responseList.Clear();
             responseList.AddResponse(new CommandResponse(true, ip));
         }
     }
 }
Beispiel #22
0
 /// <summary>
 /// Get or set connection in connection pool
 /// </summary>
 /// <param name="ip">ip of system to which connection is made</param>
 /// <returns>connection object</returns>
 public Connection this[Alachisoft.NCache.Common.Net.Address ip]
 {
     get { lock (this._connections.SyncRoot) return(this._connections[ip] as Connection); }
     set
     {
         lock (this._connections.SyncRoot)
         {
             this._connections[ip] = value;
             this.loadBalancerQueue.Enqueue(ip);
         }
     }
 }
Beispiel #23
0
        public static ArrayList DistributeOrphanBuckets(ArrayList hashMap, Address leavingNode, ArrayList members)
        {
            HashMapBucket tempBuck;
            ArrayList orphanBuckets = new ArrayList();
            hashMap = ReAllocBucketsInTransfer(hashMap, leavingNode);
            int[] bucketsInEachNode = NodeBucketsCount(hashMap, members); //node vs bucket count.
            bool bAssigned = false;
            
            int memberCount = members.Count;
            if (memberCount == 0)
                return null;
            
            int bucketsPerNode = hashMap.Count / members.Count;
            
            for (int i = 0, j = 0; i < hashMap.Count; i++)
            {
                j = (j == memberCount) ? 0 : j;
                tempBuck = (HashMapBucket)hashMap[i];

                if (tempBuck.PermanentAddress.CompareTo(leavingNode) == 0)
                {
                    bAssigned = false;
                    for (int k = 0; k < memberCount; k++)
                    {
                        if (bucketsInEachNode[j] < bucketsPerNode)
                        {
                            Address mbr = members[j] as Address;
                            bucketsInEachNode[j] = (bucketsInEachNode[j])++; //increment bucket count as next j is incremented.
                            tempBuck.PermanentAddress = mbr;
                            tempBuck.TempAddress = mbr;
                            tempBuck.Status = BucketStatus.Functional;
                            j++;
                            bAssigned = true;
                            break;
                        }
                        else
                        {
                            j++;
                            j = (j == memberCount) ? 0 : j;
                        }

                    }
                    //exceptional case when last node gets few more buckets. Assign those leftover buckets to ANY node.
                    if (bAssigned == false)
                    {
                        tempBuck.PermanentAddress = (Address)members[j++];
                    }

                }
            }

            return hashMap;
        }
Beispiel #24
0
 internal void ResetResponseNodeForShutDown(Common.Net.Address ip)
 {
     lock (_responseMutex)
     {
         if (_responses.ContainsKey(ip))
         {
             ResponseList responseList = _responses[ip];
             responseList.Clear();
             responseList.AddResponse(new CommandResponse(false, ip));
             _resend = true;
         }
     }
 }
Beispiel #25
0
        public void addRsp(Address sender, object retval)

        {
            Rsp rsp = find(sender);

            if (rsp != null)
            {
                rsp.sender = sender; rsp.retval = retval; rsp.received = true; rsp.suspected = false;
                return;
            }
            rsp = new Rsp(sender, retval);
            rsps.Add(rsp);
        }
Beispiel #26
0
        public Response AddResponseFragment(Common.Net.Address server, FragmentedResponse responseFragment)
        {
            List <FragmentedResponse> responseList = null;
            Dictionary <long, List <FragmentedResponse> > resposeTable = null;

            lock (this)
            {
                if (!_serverMap.ContainsKey(server))
                {
                    _serverMap.Add(server, new  Dictionary <long, List <FragmentedResponse> >());
                }

                resposeTable = _serverMap[server];

                if (!resposeTable.ContainsKey(responseFragment.messageId))
                {
                    resposeTable.Add(responseFragment.messageId, new List <FragmentedResponse>());
                }
            }

            responseList = resposeTable[responseFragment.messageId];
            responseList.Add(responseFragment);

            if (responseList.Count == responseFragment.totalFragments)
            {
                lock (this)
                {
                    resposeTable.Remove(responseFragment.messageId);
                }

                responseList.Sort(this);
                Response finalResponse = null;

                using (MemoryStream stream = new MemoryStream())
                {
                    foreach (FragmentedResponse fragment in responseList)
                    {
                        stream.Write(fragment.message, 0, fragment.message.Length);
                    }

                    stream.Position = 0;
                    finalResponse   = ProtoBuf.Serializer.Deserialize <Alachisoft.NCache.Common.Protobuf.Response>(stream);
                    stream.Close();
                }
                return(finalResponse);
            }

            return(null);
        }
Beispiel #27
0
		public void  add(Address sender, long low_seqno, long high_seqno, long high_seqno_seen)
		{
			if (index >= senders.Length)
			{
                return ;
			}
			if (sender == null)
			{
                return ;
			}
			senders[index] = sender;
			low_seqnos[index] = low_seqno;
			high_seqnos[index] = high_seqno;
			high_seqnos_seen[index] = high_seqno_seen;
			index++;
		}
Beispiel #28
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="info"></param>
 protected NodeInfo(NodeInfo info)
 {
     this._address = info._address == null ? null : info._address.Clone() as Address;
     this._rendererAddress = info._rendererAddress != null ? info._rendererAddress.Clone() as Address : null;
     this._stats = info._stats == null ? null:info._stats.Clone() as CacheStatistics;
     this._status = info._status;
     this._subgroupName = info._subgroupName;
     this._isInproc = info._isInproc;
     this._dataAffinity = info._dataAffinity == null ? null : info._dataAffinity.Clone() as DataAffinity;
     _isStartedAsMirror = info.IsStartedAsMirror;
     if(info._connectedClients != null)
     {
         lock(info._connectedClients.SyncRoot) 
             this._connectedClients = info._connectedClients.Clone() as ArrayList;
     }
 }
Beispiel #29
0
        public void WaitForStatus(Address tmpOwner, byte status)
        {
            if (tmpOwner != null)
            {

                while (tmpOwner == _tempAddress)
                {
                    if (_stateTxfrLatch.IsAnyBitsSet(status)) return;
                    lock (_status_wait_mutex)
                    {
                        if ((tmpOwner == _tempAddress) || _stateTxfrLatch.IsAnyBitsSet(status))
                            return;
                        Monitor.Wait(_status_wait_mutex);
                    }
                }
            }
        }
        long _totalWeight; //total weight of this node.

        public BalanceDataForNode(ArrayList weightIdList, Address address, long clusterWeight)
        {
            _address = address;
            _filteredWeightIdList = new ArrayList();            
            _totalWeight = 1;

            foreach (WeightIdPair wiPair in weightIdList)
            {
                if (wiPair.Address.compare(address) == 0)
                {
                    _filteredWeightIdList.Add(wiPair);
                    _totalWeight += wiPair.Weight;
                }
            }
            _filteredWeightIdList.Sort();
            _itemsCount = _filteredWeightIdList.Count;
            _percentData = Convert.ToInt32(((double)_totalWeight / (double)clusterWeight) * 100);
        }
Beispiel #31
0
        internal void AddResponse(Common.Net.Address address, CommandResponse response)
        {
            _type = response.Type;

            lock (_responseMutex)
            {
                if (_responses.ContainsKey(address))
                {
                    ResponseList responseList = _responses[address];
                    if (!responseList.IsComplete)
                    {
                        responseList.AddResponse(response);
                    }
                    else
                    {
                        if (_reRoutedAddress != null && !_reRoutedAddress.Equals(address))
                        {
                            if (!_responses.ContainsKey(_reRoutedAddress))
                            {
                                ResponseList rspList = new ResponseList();
                                if (!rspList.IsComplete)
                                {
                                    rspList.AddResponse(response);
                                }

                                _responses.Add(_reRoutedAddress, rspList);
                            }
                            else
                            {
                                responseList = _responses[_reRoutedAddress];
                                if (!responseList.IsComplete)
                                {
                                    responseList.AddResponse(response);
                                }
                            }
                        }
                    }
                }
            }
        }
        private long _weightBalanceThreshold =  0 ; //at what weight should the node be treated as contributor to incoming nodes.
        
        public DistributionMatrix(ArrayList weightIdList, Address address, DistributionData distData, ILogger NCacheLog)
        {            
            _address = address;
            _distData = distData;
            _filteredWeightIdList = new ArrayList();
            _itemsCount = weightIdList.Count;
            _totalWeight = 1;
            _weightToSacrifice = 0;
            _cushionFactor = 10;            
            _percentWeightToSacrifice = 0;
            _weightBalanceThreshold = Convert.ToInt32((_maxCacheSize * WeightBalanceThresholdPercent) / 100); //10%, threshold at which we feel to balance weight for incoming nodes. its value is percent of MaxCacheSize 
            if (NCacheLog.IsInfoEnabled) NCacheLog.Error("DistributionMatrix.ctor", "Address->" + address.ToString() + ", DistributionData->" + distData.ToString());
            //muds:
            //this is the temp code just to put some trace...
            int bucketCount = 0;
            foreach (WeightIdPair wiPair in weightIdList)
            {
                if (wiPair.Address.compare(address) == 0)
                {
                    if(NCacheLog.IsInfoEnabled) NCacheLog.Info("DistributionMatrix.ctor", "waitPair" + wiPair.Address.ToString() + ", wiPait->" + wiPair.BucketId);
                    _filteredWeightIdList.Add(wiPair);
                    bucketCount++;
                }
            }
            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("DistributionMatrix..ctor", address + " owns " + bucketCount + " buckets");
            _filteredWeightIdList.Sort();

            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("DistributionMatrix.ctor", "_filterWeightIdList.Count:" + _filteredWeightIdList.Count + ", distData.BucketPerNode: " + distData.BucketsPerNode);
                    
            //Current bucket count - bucketss count after division gives buckets count to be sacrificed.
            _bucketsToSacrifice = _filteredWeightIdList.Count - distData.BucketsPerNode;
            if (_bucketsToSacrifice <= 0)
            {
                NCacheLog.Error("DistributionMatrix", "Address::" + address.ToString() + " cant sacrifice any bucket. Buckets/Node = " + distData.BucketsPerNode + " My Buckets Count = " + _filteredWeightIdList.Count);
                return;
            }
            int rows = Convert.ToInt32(Math.Ceiling((double)((decimal)_filteredWeightIdList.Count /(decimal)_bucketsToSacrifice)));
            int cols = _bucketsToSacrifice;
            InitializeMatrix(rows, cols);
        }
Beispiel #33
0
		/// <summary>
		/// Returns true, if this view contains a certain member
		/// </summary>
		/// <param name="mbr">The address of the member</param>
		/// <returns>True, if this view contains a certain member</returns>
		public bool containsMember( Address mbr )
		{
			if ( mbr == null || _members == null )
			{
				return false;
			}
			return _members.Contains(mbr);
		}
Beispiel #34
0
 public string GetGmsId(Address node)
 {
     return nodeGmsIds[node] as string;
 }
Beispiel #35
0
 public void RemoveGmsId(Address node)
 {
     if(node != null)
         nodeGmsIds.Remove(node);
 }
Beispiel #36
0
 public void AddGmsId(Address node, string id)
 {
     if(node != null)
         nodeGmsIds[node] = id;
 }
Beispiel #37
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="creator">The creator of this view</param>
		/// <param name="id">The lamport timestamp of this view</param>
		/// <param name="_members">Contains a list of all the _members in the view, can be empty but not null.</param>
		public View(Address creator, long id, ArrayList _members) : this( new ViewId(creator, id), _members)
		{
		}
Beispiel #38
0
        internal void MergeResponse(Common.Net.Address address, CommandResponse response)
        {
            if (_finalResponse == null && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK)
            {
                _finalResponse = response;

                if (response.IsBrokerReset)
                {
                    MergeFailedResponse(response);
                }
            }
            else
            {
                if (response.IsBrokerReset)
                {
                    MergeFailedResponse(response);
                }
                else
                {
                    IDictionaryEnumerator ide = null;
                    switch (response.Type)
                    {
                    case Alachisoft.NCache.Common.Protobuf.Response.Type.ADD_BULK:
                    case Alachisoft.NCache.Common.Protobuf.Response.Type.INSERT_BULK:
                    case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_BULK:
                    case Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE_BULK:
                        ide = response.KeyValueDic.GetEnumerator();
                        while (ide.MoveNext())
                        {
                            _finalResponse.KeyValueDic[ide.Key] = ide.Value;
                        }
                        break;

                    case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH:

                        if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) ||
                            (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND))
                        {
                            _finalResponse = response;
                            break;
                        }

                        switch (response.ResultSet.AggregateFunctionType)
                        {
                        case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE:
                            _finalResponse.KeyList.AddRange(response.KeyList);
                            break;

                        default:
                            if (!_finalResponse.ResultSet.IsInitialized)
                            {
                                SetAggregateFunctionResult();
                                _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet);
                            }
                            _finalResponse.ResultSet.Compile(response.ResultSet);
                            break;
                        }
                        break;

                    case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES:

                        if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) ||
                            (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND))
                        {
                            _finalResponse = response;
                            break;
                        }
                        switch (response.ResultSet.AggregateFunctionType)
                        {
                        case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE:
                            ide = response.KeyValueDic.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                _finalResponse.KeyValueDic[ide.Key] = ide.Value;
                            }
                            break;

                        default:
                            if (!_finalResponse.ResultSet.IsInitialized)
                            {
                                SetAggregateFunctionResult();
                                _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet);
                            }
                            _finalResponse.ResultSet.Compile(response.ResultSet);
                            break;
                        }
                        break;

                    case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK:
                        if (_finalResponse == null)
                        {
                            _finalResponse = response;
                        }

                        EnumerationDataChunk chunk = null;
                        if (_chunks.ContainsKey(address))
                        {
                            chunk = _chunks[address];
                        }
                        else
                        {
                            chunk      = new EnumerationDataChunk();
                            chunk.Data = new List <string>();
                            _chunks.Add(address, chunk);
                        }

                        for (int i = 0; i < response.NextChunk.Count; i++)
                        {
                            chunk.Data.AddRange(response.NextChunk[i].Data);
                            chunk.Pointer = response.NextChunk[i].Pointer;
                            if (chunk.Pointer.NodeIpAddress == null)
                            {
                                chunk.Pointer.NodeIpAddress = address;
                            }
                        }

                        _finalResponse.NextChunk = new List <EnumerationDataChunk>(_chunks.Values);

                        break;

                    case Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION:
                        if (response.ExceptionType == Common.Enum.ExceptionType.STATE_TRANSFER_EXCEPTION)
                        {
                            _finalResponse = response;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Beispiel #39
0
 public virtual void handleInformAboutNodeDeath(Address sender, Address deadNode) { }
Beispiel #40
0
		public abstract void  handleSuspect(Address mbr);
Beispiel #41
0
		public abstract void  handleLeave(Address mbr, bool suspected);
Beispiel #42
0
        } // only processed by participants


        public abstract JoinRsp handleJoin(Address mbr, string subGroup_name, bool isStartedAsMirror, string gmsId, ref bool acquireHashmap);
Beispiel #43
0
 /// <summary>
 /// Remove connection from pool
 /// </summary>
 /// <param name="ip">ip address of machine to which connection is made</param>
 public void Remove(Alachisoft.NCache.Common.Net.Address ip)
 {
     lock (this._connections.SyncRoot) this._connections.Remove(ip);
 }
Beispiel #44
0
 /// <summary>
 /// Get or set connection in connection pool
 /// </summary>
 /// <param name="ip">ip of system to which connection is made</param>
 /// <returns>connection object</returns>
 public Connection this[Alachisoft.NCache.Common.Net.Address ip]
 {
     get { lock (this._connections.SyncRoot) return(this._connections[ip] as Connection); }
     set { lock (this._connections.SyncRoot) this._connections[ip] = value; }
 }