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 void AskToLeaveCluster(Address leavingMember, string urGmsId) { if (gms.Stack.NCacheLog.IsInfoEnabled) gms.Stack.NCacheLog.Info("CoodGmsImpl.AskToLeaveCluster", leavingMember + " is requested to leave the cluster"); Message msg = new Message(leavingMember, null, new byte[0]); GMS.HDR hdr = new GMS.HDR(GMS.HDR.LEAVE_CLUSTER, gms.local_addr); hdr.arg = urGmsId; msg.putHeader(HeaderType.GMS,hdr); gms.passDown(new Event(Event.MSG, msg, Priority.Critical)); ; }
internal virtual void sendJoinMessage(Address coord, Address mbr, string subGroup_name, bool isStartedAsMirror) { Message msg; GMS.HDR hdr; msg = new Message(coord, null, null); hdr = new GMS.HDR(GMS.HDR.JOIN_REQ, mbr, subGroup_name, isStartedAsMirror); hdr.GMSId = gms.unique_id; msg.putHeader(HeaderType.GMS, hdr); gms.passDown(new Event(Event.MSG_URGENT, msg, Priority.Critical)); }
public override void handleNodeRejoining(Address node) { if (node != null) { if (gms.Stack.NCacheLog.IsInfoEnabled) gms.Stack.NCacheLog.Info("ParticipantGmsImpl.handleNodeRejoining", "I should inform coordinator about node rejoining with " + node); if (gms.members.contains(node)) { //inform coordinator about the node rejoining in the cluster. GMS.HDR header = new GMS.HDR(GMS.HDR.INFORM_NODE_REJOINING, node); Message rejoiningMsg = new Message(gms.determineCoordinator(), null, new byte[0]); rejoiningMsg.putHeader(HeaderType.GMS, header); gms.passDown(new Event(Event.MSG, rejoiningMsg, Priority.Critical)); } } }
public override void handleConnectedNodesRequest(Address src,int reqId) { if (gms.determineCoordinator().Equals(src)) { ArrayList mbrs = gms.members.Members; ArrayList suspected = suspected_mbrs.Clone() as ArrayList; foreach (Address suspect in suspected_mbrs) { mbrs.Remove(suspect); } if (gms.Stack.NCacheLog.IsInfoEnabled) gms.Stack.NCacheLog.Info("ParticipantGmsImp.handleConnectedNodesRequest " + gms.local_addr + " --> " + Global.ArrayListToString(mbrs)); Message rspMsg = new Message(src,null,new byte[0]); GMS.HDR hdr = new GMS.HDR(GMS.HDR.CONNECTED_NODES_RESPONSE,(Object)reqId); hdr.nodeList = mbrs; rspMsg.putHeader(HeaderType.GMS,hdr); gms.passDown(new Event(Event.MSG,rspMsg,Priority.Critical)); } }
public override void down(Event evt) { Message msg; long time_to_wait, start_time; switch (evt.Type) { case Event.FIND_INITIAL_MBRS: // sent by GMS layer, pass up a GET_MBRS_OK event //We pass this event down to tcp so that it can take some measures. passDown(evt); initial_members.Clear(); msg = new Message(null, null, null); msg.putHeader(HeaderType.TCPPING, new PingHeader(PingHeader.GET_MBRS_REQ, (System.Object)local_addr,group_addr)); // if intitial nodes have been specified and static is true, then only those // members will form the cluster, otherwise, nodes having the same IP Multicast and port // will form the cluster dyanamically. mbrDiscoveryInProcess = true; lock (members.SyncRoot) { if( initial_hosts != null) { for (System.Collections.IEnumerator it = initial_hosts.GetEnumerator(); it.MoveNext(); ) { Address addr = (Address) it.Current; msg.Dest = addr; if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("[FIND_INITIAL_MBRS] sending PING request to " + msg.Dest); passDown(new Event(Event.MSG_URGENT, msg.copy(), Priority.Critical)); } } } // 2. Wait 'timeout' ms or until 'num_initial_members' have been retrieved if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.down()", "[FIND_INITIAL_MBRS] waiting for results..............."); lock (initial_members.SyncRoot) { start_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; time_to_wait = timeout; while (initial_members.Count < num_initial_members && time_to_wait > 0) { try { if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.down()", "initial_members Count: " + initial_members.Count + "initialHosts Count: " + num_initial_members); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.down()", "Time to wait for next response: " + time_to_wait); ///Big_clusterd: initial members will be pulsed in case connection is not available. ///so here we dont have to wait till each member is timed out. ///this significantly improves time for initial member discovery. bool timeExpire = System.Threading.Monitor.Wait(initial_members.SyncRoot, TimeSpan.FromMilliseconds(time_to_wait)); } catch (System.Exception e) { Stack.NCacheLog.Error("TCPPing.down(FIND_INITIAL_MBRS)", e.ToString()); } time_to_wait = timeout - ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time); } mbrDiscoveryInProcess = false; } if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.down()", "[FIND_INITIAL_MBRS] initial members are " + Global.CollectionToString(initial_members)); if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.down()", "[FIND_INITIAL_MBRS] initial members count " + initial_members.Count); //remove those which are not functional due to twoPhaseConnect for (int i = initial_members.Count - 1; i >= 0; i--) { PingRsp rsp = initial_members[i] as PingRsp; if (!rsp.IsStarted) initial_members.RemoveAt(i); } // 3. Send response passUp(new Event(Event.FIND_INITIAL_MBRS_OK, initial_members)); break; case Event.TMP_VIEW: case Event.VIEW_CHANGE: System.Collections.ArrayList tmp; if ((tmp = ((View) evt.Arg).Members) != null) { lock (members.SyncRoot) { members.Clear(); members.AddRange(tmp); } } passDown(evt); break; /****************************After removal of NackAck *********************************/ //TCPPING emulates a GET_DIGEST call, which is required by GMS. This is needed //since we have now removed NAKACK from the stack! case Event.GET_DIGEST: pbcast.Digest digest = new pbcast.Digest(members.Count); for (int i = 0; i < members.Count; i++) { Address sender = (Address)members[i]; digest.add(sender, 0, 0); } passUp(new Event(Event.GET_DIGEST_OK, digest)); return; case Event.SET_DIGEST: // Not needed! Just here to let you know that it is needed by GMS! return; /********************************************************************************/ case Event.BECOME_SERVER: // called after client has joined and is fully working group member if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.down()", "received BECOME_SERVER event"); passDown(evt); is_server = true; break; case Event.CONNECT: object[] addrs = ((object[])evt.Arg); group_addr = (string)addrs[0]; subGroup_addr = (string)addrs[1]; twoPhaseConnect = (bool)addrs[3]; if (twoPhaseConnect) timeout = 1000; passDown(evt); break; case Event.DISCONNECT: passDown(evt); break; case Event.HAS_STARTED: hasStarted = true; passDown(evt); break; default: passDown(evt); // Pass on to the layer below us break; } }
public void SendSecondaryAddressofPeer() { Address secondaryAddress = null; Connection.ConnectionHeader header = new ConnectionHeader(ConnectionHeader.GET_SECOND_ADDRESS_RSP); header.MySecondaryAddress = enclosingInstance.local_addr_s; Message msg = new Message(peer_addr, null, new byte[0]); msg.putHeader("ConnectionHeader", header); NCacheLog.Error("Connection.SendSecondaryAddress", "secondaryAddr: " + header.MySecondaryAddress); SendInternal(Util.Util.serializeMessage(msg)); }
/// <summary> /// Sends notification to other node about leaving. /// </summary> public void SendLeaveNotification() { leavingGracefully = true; ConnectionHeader header = new ConnectionHeader(ConnectionHeader.LEAVE); Message leaveMsg = new Message(peer_addr, null, new byte[0]); leaveMsg.putHeader("ConnectionHeader", header); if (NCacheLog.IsInfoEnabled) NCacheLog.Info("Connection.SendSilentCloseNotification", "sending leave request"); try { byte[] binaryMsg = Util.Util.serializeMessage(leaveMsg); SendInternal(binaryMsg); } catch (Exception e) { NCacheLog.Error("Connection.SendLeaveNotification", e.ToString()); } }
/// <summary> Send a unicast message: Add a <code>UCAST</code> header /// /// </summary> /// <param name="msg">the message to unicast /// </param> /// <returns> the message to send /// </returns> private Message _sendUcast(Message msg) { msg.putHeader(HeaderType.TOTAL, new HDR(HDR.UCAST, NULL_ID, NULL_ID, -1)); return (msg); }
/// <summary> Received an mcast request - Ignore if not the sequencer, else send an /// mcast reply /// /// </summary> /// <param name="msg">the multicast request message /// </param> private void _recvMcastRequest(Message msg) { HDR header; Message repMsg; // i. If blocked, discard the mcast request // ii. Assign a seqID to the message and send it back to the requestor if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TOTAL._recvMcastRequest()", "hdr = " + Global.CollectionToString(msg.Headers)); if (!addr.Equals(_groupSequencerAddr)) { Stack.NCacheLog.Error("Received mcast request from " + msg.Src.ToString() + " but not a group sequencer"); return; } if (state == BLOCK) { if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Blocked, discard mcast req"); return; } header = (HDR)msg.getHeader(HeaderType.TOTAL); repMsg = new Message(msg.Src, addr, new byte[0]); repMsg.Priority = msg.Priority; int viewId = -1; try { stateLock.AcquireReaderLock(Timeout.Infinite); viewId = (int)(currentViewId != null ? currentViewId.Id : -1); } finally { stateLock.ReleaseReaderLock(); } HDR reqHdr = new HDR(HDR.REPMCAST, header.localSeqID, NextMCastSeqID, viewId); repMsg.putHeader(HeaderType.TOTAL, reqHdr); repMsg.IsUserMsg = true; repMsg.Type = MsgType.TOKEN_SEEKING; passDown(new Event(Event.MSG, repMsg)); }
internal virtual void sendMergeCancelledMessage(System.Collections.ArrayList coords, object merge_id) { Message msg; GMS.HDR hdr; Address coord; if (coords == null || merge_id == null) { gms.Stack.NCacheLog.Error("coords or merge_id == null"); return; } for (int i = 0; i < coords.Count; i++) { coord = (Address)coords[i]; msg = new Message(coord, null, null); hdr = new GMS.HDR(GMS.HDR.CANCEL_MERGE); hdr.merge_id = merge_id; msg.putHeader(HeaderType.GMS, hdr); gms.passDown(new Event(Event.MSG, msg)); } }
internal virtual void sendMergeRejectedResponse(Address sender) { Message msg = new Message(sender, null, null); GMS.HDR hdr = new GMS.HDR(GMS.HDR.MERGE_RSP); hdr.merge_rejected = true; hdr.merge_id = merge_id; msg.putHeader(HeaderType.GMS, hdr); gms.Stack.NCacheLog.Debug("response=" + hdr); gms.passDown(new Event(Event.MSG, msg)); }
/// <summary> Send back a response containing view and digest to sender</summary> internal virtual void sendMergeResponse(Address sender, View view, Digest digest) { Message msg = new Message(sender, null, null); GMS.HDR hdr = new GMS.HDR(GMS.HDR.MERGE_RSP); hdr.merge_id = merge_id; hdr.view = view; hdr.digest = digest; msg.putHeader(HeaderType.GMS, hdr); gms.Stack.NCacheLog.Debug("response=" + hdr); gms.passDown(new Event(Event.MSG, msg)); }
/// <summary> Sends the new view and digest to all subgroup coordinors in coords. Each coord will in turn /// <ol> /// <li>cast the new view and digest to all the members of its subgroup (MergeView) /// <li>on reception of the view, if it is a MergeView, each member will set the digest and install /// the new view /// </ol> /// </summary> internal virtual void sendMergeView(System.Collections.ArrayList coords, MergeData combined_merge_data) { Message msg; GMS.HDR hdr; Address coord; View v; Digest d; if (coords == null || combined_merge_data == null) return; v = combined_merge_data.view; d = combined_merge_data.digest; if (v == null || d == null) { gms.Stack.NCacheLog.Error("view or digest is null, cannot send consolidated merge view/digest"); return; } for (int i = 0; i < coords.Count; i++) { coord = (Address)coords[i]; msg = new Message(coord, null, null); hdr = new GMS.HDR(GMS.HDR.INSTALL_MERGE_VIEW); hdr.view = v; hdr.digest = d; hdr.merge_id = merge_id; msg.putHeader(HeaderType.GMS, hdr); gms.passDown(new Event(Event.MSG, msg)); } }
/// <summary> Sends a MERGE_REQ to all coords and populates a list of MergeData (in merge_rsps). Returns after coords.size() /// response have been received, or timeout msecs have elapsed (whichever is first).<p> /// If a subgroup coordinator rejects the MERGE_REQ (e.g. because of participation in a different merge), /// <em>that member will be removed from coords !</em> /// </summary> /// <param name="coords">A list of Addresses of subgroup coordinators (inluding myself) /// </param> /// <param name="timeout">Max number of msecs to wait for the merge responses from the subgroup coords /// </param> internal virtual void getMergeDataFromSubgroupCoordinators(System.Collections.ArrayList coords, long timeout) { Message msg; GMS.HDR hdr; Address coord; long curr_time, time_to_wait = 0, end_time; int num_rsps_expected = 0; if (coords == null || coords.Count <= 1) { gms.Stack.NCacheLog.Error("CoordGmsImpl.getMergeDataFromSubgroupCoordinator", "coords == null or size <= 1"); return; } lock (merge_rsps.SyncRoot) { merge_rsps.Clear(); gms.Stack.NCacheLog.Debug("sending MERGE_REQ to " + Global.CollectionToString(coords)); for (int i = 0; i < coords.Count; i++) { coord = (Address)coords[i]; if (gms.local_addr != null && gms.local_addr.Equals(coord)) { merge_rsps.Add(getMergeResponse(gms.local_addr, merge_id)); continue; } msg = new Message(coord, null, null); hdr = new GMS.HDR(GMS.HDR.MERGE_REQ); hdr.mbr = gms.local_addr; hdr.merge_id = merge_id; msg.putHeader(HeaderType.GMS, hdr); gms.passDown(new Event(Event.MSG, msg)); } // wait until num_rsps_expected >= num_rsps or timeout elapsed num_rsps_expected = coords.Count; curr_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; end_time = curr_time + timeout; while (end_time > curr_time) { time_to_wait = end_time - curr_time; gms.Stack.NCacheLog.Debug("waiting for " + time_to_wait + " msecs for merge responses"); if (merge_rsps.Count < num_rsps_expected) { try { System.Threading.Monitor.Wait(merge_rsps.SyncRoot, TimeSpan.FromMilliseconds(time_to_wait)); } catch (System.Exception ex) { gms.Stack.NCacheLog.Error("CoordGmsImpl.getMergeDataFromSubgroupCoordinators()", ex.ToString()); } } // SAL: if (time_to_wait < 0) { gms.Stack.NCacheLog.Fatal("[Timeout]CoordGmsImpl.getMergeDataFromSubgroupCoordinators:" + time_to_wait); } gms.Stack.NCacheLog.Debug("num_rsps_expected=" + num_rsps_expected + ", actual responses=" + merge_rsps.Count); if (merge_rsps.Count >= num_rsps_expected) break; curr_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; } } }
/// <summary> /// Sends the notification to the peer that connection is being closed silently. /// </summary> private void SendSilentCloseNotification() { self_close = true; ConnectionHeader header = new ConnectionHeader(ConnectionHeader.CLOSE_SILENT); Message closeMsg = new Message(peer_addr, null, new byte[0]); closeMsg.putHeader("ConnectionHeader", header); if (NCacheLog.IsInfoEnabled) NCacheLog.Info("Connection.SendSilentCloseNotification", "sending silent close request"); try { byte[] binaryMsg = Util.Util.serializeMessage(closeMsg); SendInternal(binaryMsg); } catch (Exception e) { NCacheLog.Error("Connection.SendSilentCloseNotification", e.ToString()); } }
public bool SendInitializationPhaseRsp(bool initializationPhase) { self_close = true; ConnectionHeader header = new ConnectionHeader(ConnectionHeader.INITIALIZATION_PHASE_RSP); header.InitializationPhase = initializationPhase; Message closeMsg = new Message(peer_addr, null, new byte[0]); closeMsg.putHeader("ConnectionHeader", header); if (NCacheLog.IsInfoEnabled) NCacheLog.Info("Connection.SendSilentCloseNotification", "sending silent close request"); try { lock (initializationPhase_mutex) { byte[] binaryMsg = Util.Util.serializeMessage(closeMsg); SendInternal(binaryMsg); Monitor.Wait(initializationPhase_mutex); return inInitializationPhase; } } catch (Exception e) { NCacheLog.Error("Connection.SendSilentCloseNotification", e.ToString()); } return false; }
private void _sendMcastRequest(Message msg, long id) { // i. Store away the message while waiting for the sequencer's reply // ii. Send a mcast request immediatelly and also schedule a // retransmission Address groupSequencerAddr = addr; ArrayList dests = msg.Dests; groupSequencerAddr = getGroupSequencer(dests); if (groupSequencerAddr == null) return; if (addr.CompareTo(groupSequencerAddr) == 0) { long seqid = NextMCastSeqID; int viewId = -1; try { stateLock.AcquireReaderLock(Timeout.Infinite); viewId = (int)(currentViewId != null ? currentViewId.Id : -1); } finally { stateLock.ReleaseReaderLock(); } //Rent the event Event evt = null; evt = new Event(); evt.Type = Event.MSG; evt.Priority = msg.Priority; evt.Arg = msg; //Rent the header HDR hdr = new HDR(); hdr.type = HDR.MCAST; hdr.localSeqID = id; hdr.seqID = seqid; hdr.viewId = viewId; msg.Type = MsgType.SEQUENCED; msg.putHeader(HeaderType.TOTAL, hdr); //msg.Dest = null; //=================================================== //now the message will contain a list of addrs in case of multicast. //======================================================= passDown(evt); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TOTAL._sendMcastRequest()", "shortcut mcast seq# " + seqid); return; } request_lock.AcquireWriterLock(Timeout.Infinite); try { _mcastReqTbl[(long)id] = msg; } finally { request_lock.ReleaseWriterLock(); } _transmitMcastRequest(id, groupSequencerAddr); _mcastRetransmitter.add(id, msg); }
public Address GetSecondaryAddressofPeer() { Connection.ConnectionHeader header = new ConnectionHeader(ConnectionHeader.GET_SECOND_ADDRESS_REQ); Message msg = new Message(peer_addr, null, new byte[0]); msg.putHeader("ConnectionHeader", header); lock (get_addr_sync) { SendInternal(Util.Util.serializeMessage(msg)); Monitor.Wait(get_addr_sync); } return secondaryAddress; }
/// <summary> Replace the original message with a broadcast request sent to the /// sequencer. The original bcast message is stored locally until a reply /// to bcast is received from the sequencer /// /// </summary> /// <param name="msg">the message to broadcast /// </param> /// <param name="id">the local sequence ID to use /// </param> private void _sendBcastRequest(Message msg, long id) { // i. Store away the message while waiting for the sequencer's reply // ii. Send a bcast request immediatelly and also schedule a // retransmission msg.Dest = null; //Taimoor:FIX: To make sure that this message will be broadcasted. if (addr.CompareTo(this.sequencerAddr) == 0) { long seqid = NextSequenceID; int viewId = -1; try { stateLock.AcquireReaderLock(Timeout.Infinite); viewId = (int)(currentViewId != null ? currentViewId.Id : -1); } finally { stateLock.ReleaseReaderLock(); } //Rent the event Event evt = null; evt = new Event(); evt.Type = Event.MSG; evt.Priority = msg.Priority; evt.Arg = msg; //Rent the header HDR hdr = new HDR(); hdr.type = HDR.BCAST; hdr.localSeqID = id; hdr.seqID = seqid; hdr.viewId = viewId; msg.putHeader(HeaderType.TOTAL, hdr); msg.Dest = null; msg.Type = MsgType.SEQUENCED; passDown(evt); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TOTAL._sendBcastRequest()", "shortcut bcast seq# " + seqid); return; } request_lock.AcquireWriterLock(Timeout.Infinite); try { reqTbl[(long)id] = msg; } finally { request_lock.ReleaseWriterLock(); } _transmitBcastRequest(id); retransmitter.add(id, msg); }
public override void up(Event evt) { Message msg, rsp_msg; System.Object obj; PingHeader hdr, rsp_hdr; PingRsp rsp; Address coord; switch (evt.Type) { case Event.MSG: msg = (Message) evt.Arg; obj = msg.getHeader(HeaderType.TCPPING); if (obj == null || !(obj is PingHeader)) { passUp(evt); return ; } hdr = (PingHeader)msg.removeHeader(HeaderType.TCPPING); switch (hdr.type) { case PingHeader.GET_MBRS_REQ: if( !hdr.group_addr.Equals(group_addr)) { if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.up()", "GET_MBRS_REQ from different group , so discarded"); return; } Address src = (Address) hdr.arg; msg.Src = src; if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "GET_MBRS_REQ from " + msg.Src.ToString()); lock (members.SyncRoot) { coord = members.Count > 0 ? (Address)members[0] : local_addr; } if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "my coordinator is " + coord.ToString()); rsp_msg = new Message(msg.Src, null, null); rsp_hdr = new PingHeader(PingHeader.GET_MBRS_RSP, new PingRsp(local_addr, coord, Stack.IsOperational,Stack.IsOperational)); rsp_msg.putHeader(HeaderType.TCPPING, rsp_hdr); if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "responding to GET_MBRS_REQ back to " + msg.Src.ToString()); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info(local_addr + " - [FIND_INITIAL_MBRS] replying PING request to " + rsp_msg.Dest); passDown(new Event(Event.MSG, rsp_msg, Priority.Critical)); return ; case PingHeader.GET_MBRS_RSP: // add response to vector and notify waiting thread if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "GET_MBRS_RSP from " + msg.Src.ToString()); rsp = (PingRsp) hdr.arg; //muds: //check if the received response is valid i.e. successful security authorization //at other end. if (rsp.OwnAddress == null && rsp.CoordAddress == null && rsp.HasJoined == false) { lock (initial_members.SyncRoot) { if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "I am not authorized to join to " + msg.Src.ToString()); System.Threading.Monitor.PulseAll(initial_members.SyncRoot); } } else { if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "Before Adding initial members response"); lock (initial_members.SyncRoot) { if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response"); if (!initial_members.Contains(rsp)) { initial_members.Add(rsp); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response for " + rsp.OwnAddress); } else if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.up()", "response already received"); System.Threading.Monitor.PulseAll(initial_members.SyncRoot); } } return ; default: Stack.NCacheLog.Warn("got TCPPING header with unknown type (" + hdr.type + ')'); return ; } //goto case Event.SET_LOCAL_ADDRESS; case Event.SET_LOCAL_ADDRESS: passUp(evt); local_addr = (Address) evt.Arg; // Add own address to initial_hosts if not present: we must always be able to ping ourself ! if (initial_hosts != null && local_addr != null) { if (!initial_hosts.Contains(local_addr)) { Stack.NCacheLog.Debug("[SET_LOCAL_ADDRESS]: adding my own address (" + local_addr + ") to initial_hosts; initial_hosts=" + Global.CollectionToString(initial_hosts)); initial_hosts.Add(local_addr); } } break; case Event.CONNECT_OK: obj = evt.Arg; if(obj != null && obj is Address) { tcpServerPort = ((Address)obj).Port; } passUp(evt); break; case Event.CONNECTION_NOT_OPENED: if (mbrDiscoveryInProcess) { Address node = evt.Arg as Address; PingRsp response = new PingRsp(node, node, true, false); lock (initial_members.SyncRoot) { initial_members.Add(response); System.Threading.Monitor.PulseAll(initial_members.SyncRoot); } Stack.NCacheLog.CriticalInfo(Name + ".up", "connection failure with " + node); } break; // end services default: passUp(evt); // Pass up to the layer above us break; } }
/// <summary> Send the bcast request with the given localSeqID /// /// </summary> /// <param name="seqID">the local sequence id of the /// </param> private void _transmitBcastRequest(long seqID) { Message reqMsg; // i. If NULL_STATE, then ignore, just transient state before // shutting down the retransmission thread // ii. If blocked, be patient - reschedule // iii. If the request is not pending any more, acknowledge it // iv. Create a broadcast request and send it to the sequencer if (state == NULL_STATE) { if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Transmit BCAST_REQ[" + seqID + "] in NULL_STATE"); return; } if (state == BLOCK) return; request_lock.AcquireReaderLock(Timeout.Infinite); try { if (!reqTbl.Contains((long)seqID)) { retransmitter.ack(seqID); return; } } finally { request_lock.ReleaseReaderLock(); } reqMsg = new Message(); reqMsg.Dest = sequencerAddr; reqMsg.Src = addr; reqMsg.setBuffer(new byte[0]); HDR hdr = new HDR(); hdr.type = HDR.REQ; hdr.localSeqID = seqID; hdr.seqID = NULL_ID; reqMsg.putHeader(HeaderType.TOTAL, hdr); reqMsg.IsUserMsg = true; reqMsg.Type = MsgType.TOKEN_SEEKING; Event evt = new Event(); evt.Type = Event.MSG; evt.Arg = reqMsg; passDown(evt); }
private void sendMemberLeftNotificationToCoordinator(Address suspected,Address coordinator) { if (gms.Stack.NCacheLog.IsInfoEnabled) gms.Stack.NCacheLog.Info("ParticipantGmsImp.sendMemberLeftNotification", "informing coordinator about abnormal connection breakage with " + suspected); GMS.HDR hdr = new GMS.HDR(GMS.HDR.CONNECTION_BROKEN, suspected); Message nodeLeftMsg = new Message(coordinator, null, new byte[0]); nodeLeftMsg.putHeader(HeaderType.GMS, hdr); gms.passDown(new Event(Event.MSG, nodeLeftMsg, Priority.Critical)); }
/// <summary> /// Checks the status of a node whether he is running or not. We send a status request /// message and wait for the response for a particular timeout. If the node is alive /// it sends backs its status otherwise timeout occurs and we consider hime DEAD. /// </summary> private void CheckStatus() { while (_statusCheckingThread != null) { lock (_checkStatusList.SyncRoot) { if (_checkStatusList.Count > 0) { _currentSuspect = _checkStatusList[0] as Address; _checkStatusList.Remove(_currentSuspect); } else _currentSuspect = null; if (_currentSuspect == null) { _statusCheckingThread = null; continue; } } lock (_status_mutex) { try { NodeStatus nodeStatus = null; if (_enclosingInstance.ct.ConnectionExist(_currentSuspect)) { Message msg = new Message(_currentSuspect, null, new byte[0]); msg.putHeader(HeaderType.KEEP_ALIVE, new HearBeat(HearBeat.ARE_YOU_ALIVE)); if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled) _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.CheckStatus", "sending status request to " + _currentSuspect); _enclosingInstance.sendUnicastMessage(msg, false, msg.Payload, Priority.Critical); _statusReceived = null; //wait for the result or timeout occurs first; Monitor.Wait(_status_mutex, _statusTimeout); if (_statusReceived != null) { HearBeat status = _statusReceived as HearBeat; if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled) _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.CheckStatus", "received status " + status + " from " + _currentSuspect); if (status.Type == HearBeat.I_AM_NOT_DEAD) nodeStatus = new NodeStatus(_currentSuspect, NodeStatus.IS_ALIVE); else if (status.Type == HearBeat.I_AM_LEAVING) nodeStatus = new NodeStatus(_currentSuspect, NodeStatus.IS_LEAVING); else if (status.Type == HearBeat.I_AM_STARTING) nodeStatus = new NodeStatus(_currentSuspect, NodeStatus.IS_DEAD); } else { nodeStatus = new NodeStatus(_currentSuspect, NodeStatus.IS_DEAD); if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled) _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.CheckStatus", "did not receive status from " + _currentSuspect + "; consider him DEAD"); } } else { if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled) _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.CheckStatus", "no connection exists for " + _currentSuspect); nodeStatus = new NodeStatus(_currentSuspect, NodeStatus.IS_DEAD); } Event statusEvent = new Event(Event.GET_NODE_STATUS_OK, nodeStatus); _enclosingInstance.passUp(statusEvent); } catch (Exception e) { _enclosingInstance.Stack.NCacheLog.Error("ConnectionKeepAlive.CheckStatus", e.ToString()); } finally { _currentSuspect = null; _statusReceived = null; } } } }
/// <summary> /// Informs the coodinator about the nodes to which this node can not establish connection /// on receiving the first view.Only the node who has most recently joined the cluster /// should inform the coodinator other nodes will neglect this event. /// </summary> /// <param name="nodes"></param> public override void handleConnectionFailure(System.Collections.ArrayList nodes) { if (nodes != null && nodes.Count > 0) { if (gms.Stack.NCacheLog.IsInfoEnabled) gms.Stack.NCacheLog.Info("ParticipantGmsImp.handleConnectionFailure", "informing coordinator about connection failure with [" + Global.CollectionToString(nodes) + "]"); GMS.HDR header = new GMS.HDR(GMS.HDR.CAN_NOT_CONNECT_TO); header.nodeList = nodes; Message msg = new Message(gms.determineCoordinator(),null,new byte[0]); msg.putHeader(HeaderType.GMS,header); gms.passDown(new Event(Event.MSG,msg,Priority.Critical)); } }
private void AskHeartBeats(ArrayList idleMembers) { Message msg = new Message(null, null, new byte[0]); msg.putHeader(HeaderType.KEEP_ALIVE, new HearBeat(HearBeat.SEND_HEART_BEAT)); msg.Dests = idleMembers.Clone() as ArrayList; _enclosingInstance.sendMulticastMessage(msg, false,Priority.Critical); }
internal virtual void sendLeaveMessage(Address coord, Address mbr) { Message msg = new Message(coord, null, null); GMS.HDR hdr = new GMS.HDR(GMS.HDR.LEAVE_REQ, mbr); msg.putHeader(HeaderType.GMS, hdr); gms.passDown(new Event(Event.MSG, msg)); }
public void ReceivedHeartBeat(Address sender, HearBeat hrtBeat) { Message rspMsg; switch (hrtBeat.Type) { case HearBeat.HEART_BEAT: if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled) _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.ReceivedHeartBeat", "received heartbeat from ->:" + sender.ToString()); lock (_idleConnections.SyncRoot) { _idleConnections.Remove(sender); } break; case HearBeat.SEND_HEART_BEAT: rspMsg = new Message(sender, null, new byte[0]); rspMsg.putHeader(HeaderType.KEEP_ALIVE, new HearBeat(HearBeat.HEART_BEAT)); if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled) _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.ReceivedHeartBeat", "seding heartbeat to ->:" + sender.ToString()); _enclosingInstance.sendUnicastMessage(rspMsg, false, rspMsg.Payload, Priority.Critical); break; case HearBeat.ARE_YOU_ALIVE: rspMsg = new Message(sender, null, new byte[0]); HearBeat rsphrtBeat = (_enclosingInstance.isClosing || _enclosingInstance._leaving) ? new HearBeat(HearBeat.I_AM_LEAVING) : new HearBeat(HearBeat.I_AM_NOT_DEAD); rsphrtBeat = _enclosingInstance.isStarting ? new HearBeat(HearBeat.I_AM_STARTING) : rsphrtBeat; rspMsg.putHeader(HeaderType.KEEP_ALIVE, rsphrtBeat); if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled) _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.ReceivedHeartBeat", "seding status" + rsphrtBeat + " to ->:" + sender.ToString()); _enclosingInstance.sendUnicastMessage(rspMsg, false, rspMsg.Payload, Priority.Critical); break; case HearBeat.I_AM_STARTING: case HearBeat.I_AM_LEAVING: case HearBeat.I_AM_NOT_DEAD: lock (_status_mutex) { if (_currentSuspect != null && _currentSuspect.Equals(sender)) { _statusReceived = hrtBeat; Monitor.Pulse(_status_mutex); } } break; } }
internal virtual void sendSpeicalJoinMessage(Address mbr, ArrayList dests) { Message msg; GMS.HDR hdr; msg = new Message(null, null, new byte[0]); msg.Dests = dests; hdr = new GMS.HDR(GMS.HDR.SPECIAL_JOIN_REQUEST, mbr); hdr.GMSId = gms.unique_id; msg.putHeader(HeaderType.GMS, hdr); gms.passDown(new Event(Event.MSG_URGENT, msg, Priority.Critical)); }
public override void handleInformNodeRejoining(Address sender, Address node) { if (node != null) { if (gms.Stack.NCacheLog.IsInfoEnabled) gms.Stack.NCacheLog.Info("CoordinatorGmsImpl.handleInformNodeRejoining", sender.ToString() + " informed about rejoining with " + node); if (gms.members.contains(node)) { ViewId viewId = gms.GetNextViewId(); GMS.HDR header = new GMS.HDR(GMS.HDR.RESET_ON_NODE_REJOINING, node); header.view = new View(viewId, gms.members.Clone() as ArrayList); header.view.CoordinatorGmsId = gms.unique_id; Message rejoiningMsg = new Message(null, null, new byte[0]); rejoiningMsg.putHeader(HeaderType.GMS, header); gms.passDown(new Event(Event.MSG, rejoiningMsg, Priority.Critical)); } } }