/// <summary> creates a copy of this view</summary> /// <returns> a copy of this view /// </returns> public virtual object Clone() { ViewId vid2 = vid != null?(ViewId)vid.Clone():null; System.Collections.ArrayList members2 = _members != null?(System.Collections.ArrayList)_members.Clone():null; View v = new View(vid2, members2); if (SequencerTbl != null) { v.SequencerTbl = SequencerTbl.Clone() as Hashtable; } if (MbrsSubgroupMap != null) { v.MbrsSubgroupMap = MbrsSubgroupMap.Clone() as Hashtable; } v._coordinatorGmsId = _coordinatorGmsId; if (DistributionMaps != null) { v.DistributionMaps = DistributionMaps.Clone() as DistributionMaps; } if (MirrorMapping != null) { v.MirrorMapping = MirrorMapping; } if (nodeGmsIds != null) { v.nodeGmsIds = nodeGmsIds.Clone() as Hashtable; } return(v); }
/// <summary> creates a copy of this view</summary> /// <returns> a copy of this view /// </returns> public override object Clone() { ViewId vid2 = Vid != null ? (ViewId)Vid.Clone() : null; System.Collections.ArrayList members2 = Members != null?(System.Collections.ArrayList)Members.Clone():null; System.Collections.ArrayList subgroups2 = subgroups != null?(System.Collections.ArrayList)subgroups.Clone():null; return(new MergeView(vid2, members2, subgroups2)); }
public virtual void Deserialize(CompactReader reader) { vid = (ViewId)reader.ReadObject(); _members = (ArrayList)reader.ReadObject(); _sequencerTbl = (Hashtable)reader.ReadObject(); _mbrsSubgroupMap = (Hashtable)reader.ReadObject(); _distributionMaps = (DistributionMaps)reader.ReadObject(); _mirrorMapping = reader.ReadObject() as CacheNode[]; nodeGmsIds = reader.ReadObject() as Hashtable; _coordinatorGmsId = reader.ReadObject() as string; }
public static ViewId ReadViewId(CompactReader reader) { byte isNull = reader.ReadByte(); if (isNull == 1) { return(null); } ViewId newId = new ViewId(); newId.Deserialize(reader); return(newId); }
public static void WriteViewId(CompactWriter writer, ViewId vId) { byte isNull = 1; if (vId == null) { writer.Write(isNull); } else { isNull = 0; writer.Write(isNull); vId.Serialize(writer); } return; }
internal virtual void becomeSingletonMember(Address mbr) { Digest initial_digest; ViewId view_id = null; ArrayList mbrs = ArrayList.Synchronized(new ArrayList(1)); // set the initial digest (since I'm the first member) initial_digest = new Digest(1); // 1 member (it's only me) initial_digest.add(gms.local_addr, 0, 0); // initial seqno mcast by me will be 1 (highest seen +1) gms.Digest = initial_digest; view_id = new ViewId(mbr); // create singleton view with mbr as only member mbrs.Add(mbr); View v = new View(view_id, mbrs); v.CoordinatorGmsId = gms.unique_id; ArrayList subgroupMbrs = new ArrayList(); subgroupMbrs.Add(mbr); gms._subGroupMbrsMap[gms.subGroup_addr] = subgroupMbrs; gms._mbrSubGroupMap[mbr] = gms.subGroup_addr; v.SequencerTbl = gms._subGroupMbrsMap.Clone() as Hashtable; v.MbrsSubgroupMap = gms._mbrSubGroupMap.Clone() as Hashtable; v.AddGmsId(mbr, gms.unique_id); gms.installView(v); gms.becomeCoordinator(); // not really necessary - installView() should do it gms.Stack.IsOperational = true; gms.Stack.NCacheLog.Debug("pb.ClientGmsImpl.becomeSingletonMember()", "created group (first member). My view is " + gms.view_id + ", impl is " + gms.Impl.GetType().FullName); }
public static void WriteViewId(CompactWriter writer, ViewId vId) { byte isNull = 1; if (vId == null) writer.Write(isNull); else { isNull = 0; writer.Write(isNull); vId.Serialize(writer); } return; }
/// <summary> /// Constructor /// </summary> /// <param name="vid">The view id of this view (can not be null)</param> /// <param name="_members">Contains a list of all the _members in the view, can be empty but not null.</param> public View(ViewId vid, ArrayList _members, Hashtable sequencerTbl) { this.vid = vid; this._members = _members; this._sequencerTbl = sequencerTbl; }
/// <summary> Creates a new view</summary> /// <param name="vid"> The view id of this view (can not be null) /// </param> /// <param name="members"> Contains a list of all the members in the view, can be empty but not null. /// </param> /// <param name="subgroups">A list of Views representing the former subgroups /// </param> public MergeView(ViewId vid, System.Collections.ArrayList members, System.Collections.ArrayList subgroups) : base(vid, members) { this.subgroups = subgroups; }
/// <summary> Merge all MergeData. All MergeData elements should be disjunct (both views and digests). However, /// this method is prepared to resolve duplicate entries (for the same member). Resolution strategy for /// views is to merge only 1 of the duplicate members. Resolution strategy for digests is to take the higher /// seqnos for duplicate digests.<p> /// After merging all members into a Membership and subsequent sorting, the first member of the sorted membership /// will be the new coordinator. /// </summary> /// <param name="v">A list of MergeData items. Elements with merge_rejected=true were removed before. Is guaranteed /// not to be null and to contain at least 1 member. /// </param> internal virtual MergeData consolidateMergeData(System.Collections.ArrayList v) { MergeData ret = null; MergeData tmp_data; long logical_time = 0; // for new_vid ViewId new_vid, tmp_vid; MergeView new_view; View tmp_view; Membership new_mbrs = new Membership(); int num_mbrs = 0; Digest new_digest = null; Address new_coord; System.Collections.ArrayList subgroups = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(11)); // contains a list of Views, each View is a subgroup for (int i = 0; i < v.Count; i++) { tmp_data = (MergeData)v[i]; gms.Stack.NCacheLog.Debug("merge data is " + tmp_data); tmp_view = tmp_data.View; if (tmp_view != null) { tmp_vid = tmp_view.Vid; if (tmp_vid != null) { // compute the new view id (max of all vids +1) logical_time = System.Math.Max(logical_time, tmp_vid.Id); } } // merge all membership lists into one (prevent duplicates) new_mbrs.add(tmp_view.Members); subgroups.Add(tmp_view.Clone()); } // the new coordinator is the first member of the consolidated & sorted membership list new_mbrs.sort(); num_mbrs = new_mbrs.size(); new_coord = num_mbrs > 0 ? (Address)new_mbrs.elementAt(0) : null; if (new_coord == null) { gms.Stack.NCacheLog.Error("CoordGmsImpl.consolodateMergeData", "new_coord is null."); return null; } // should be the highest view ID seen up to now plus 1 new_vid = new ViewId(new_coord, logical_time + 1); // determine the new view new_view = new MergeView(new_vid, new_mbrs.Members, subgroups); gms.Stack.NCacheLog.Debug("new merged view will be " + new_view); // determine the new digest new_digest = consolidateDigests(v, num_mbrs); if (new_digest == null) { gms.Stack.NCacheLog.Error("CoordGmsImpl.consolidateMergeData", "digest could not be consolidated."); return null; } gms.Stack.NCacheLog.Debug("consolidated digest=" + new_digest); ret = new MergeData(gms.local_addr, new_view, new_digest); return ret; }
/// <summary> Creates a new view</summary> /// <param name="vid"> The view id of this view (can not be null) /// </param> /// <param name="members"> Contains a list of all the members in the view, can be empty but not null. /// </param> /// <param name="subgroups">A list of Views representing the former subgroups /// </param> public MergeView(ViewId vid, System.Collections.ArrayList members, System.Collections.ArrayList subgroups):base(vid, members) { this.subgroups = subgroups; }
public virtual View makeView(System.Collections.ArrayList mbrs, ViewId vid) { Address coord = null; long id = 0; if (vid != null) { coord = vid.CoordAddress; id = vid.Id; } View view = new View(coord, id, mbrs); view.CoordinatorGmsId = unique_id; return view; }
/// <summary> Sets the new view and sends a VIEW_CHANGE event up and down the stack.</summary> public virtual void installView(View new_view) { Stack.NCacheLog.CriticalInfo("GMS.InstallView", "Installing new View " + local_addr.ToString() + " --> " + new_view); Address coord = null; try { //Lest inform coordinator about view receiption SendViewAcknowledgment(new_view.Coordinator); int rc; ViewId vid = new_view.Vid; System.Collections.ArrayList mbrs = new_view.Members; impl.UniqueId = new_view.BridgeSourceCacheId; _uniqueID = new_view.BridgeSourceCacheId; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("[local_addr=" + local_addr + "] view is " + new_view); // Discards view with id lower than our own. Will be installed without check if first view if (view_id != null) { rc = vid.CompareTo(view_id); if (rc <= 0) { Stack.NCacheLog.Error("[" + local_addr + "] received view <= current view;" + " discarding it (current vid: " + view_id + ", new vid: " + vid + ')'); Event viewEvt = new Event(Event.VIEW_CHANGE_OK, null, Priority.Critical); passDown(viewEvt); return; } Address currentCoodinator = determineCoordinator(); Address newCoordinator = new_view.Coordinator; Address sender = vid.CoordAddress; // creater of the view if (!currentCoodinator.Equals(newCoordinator) && !newCoordinator.Equals(local_addr) && !sender.Equals(currentCoodinator)) { Stack.NCacheLog.CriticalInfo("GMS.InstallView", "Force Join Cluster"); if (!new_view.ForceInstall) { if (!VerifySuspect(currentCoodinator)) { Stack.NCacheLog.Error("GMS.installView", "rejecting the view from " + newCoordinator + " as my own coordinator[" + currentCoodinator + "] is not down"); Event viewEvt = new Event(Event.VIEW_CHANGE_OK, null, Priority.Critical); passDown(viewEvt); //we should inform the coordinator of this view that i can't be the member //of your view as my own coordinator is alive. Message msg = new Message(new_view.Coordinator, null, new byte[0]); msg.putHeader(HeaderType.GMS, new GMS.HDR(GMS.HDR.VIEW_REJECTED, local_addr)); passDown(new Event(Event.MSG, msg, Priority.Critical)); return; } } } } ltime = System.Math.Max(vid.Id, ltime); // compute Lamport logical time /* Check for self-inclusion: if I'm not part of the new membership, I just discard it. This ensures that messages sent in view V1 are only received by members of V1 */ if (checkSelfInclusion(mbrs) == false) { Stack.NCacheLog.Error("GMS.InstallView", "CheckSelfInclusion() failed, " + local_addr + " is not a member of view " + new_view + "; discarding view"); // only shun if this member was previously part of the group. avoids problem where multiple // members (e.g. X,Y,Z) join {A,B} concurrently, X is joined first, and Y and Z get view // {A,B,X}, which would cause Y and Z to be shunned as they are not part of the membership // bela Nov 20 2003 if (shun && local_addr != null && prev_members.contains(local_addr)) { Stack.NCacheLog.CriticalInfo("I (" + local_addr + ") am being shunned, will leave and " + "rejoin group (prev_members are " + prev_members + ')'); passUp(new Event(Event.EXIT)); } return; } lock (members) { //@UH Members are same as in the previous view. No need to apply view if (view_id != null) { Membership newMembers = new Membership(mbrs); if (members.Equals(newMembers) && vid.CoordAddress.Equals(view_id.CoordAddress)) { Stack.NCacheLog.Error("GMS.InstallView", "[" + local_addr + "] received view has the same members as current view;" + " discarding it (current vid: " + view_id + ", new vid: " + vid + ')'); Event viewEvt = new Event(Event.VIEW_CHANGE_OK, null, Priority.Critical); //#usama@15-4-2013 joining, leaving and tmp_members are needed to be synchronized even if view is same Global.ICollectionSupport.RemoveAll(joining, mbrs); // remove all members in mbrs from joining // remove all elements from 'leaving' that are not in 'mbrs' Global.ICollectionSupport.RetainAll(leaving, mbrs); tmp_members.add(joining); // add members that haven't yet shown up in the membership tmp_members.remove(leaving); // remove members that haven't yet been removed from the membership passDown(viewEvt); return; } } //========================================= // Stack.NCacheLog.CriticalInfo("GMS.InstallView", "Installing view in gms"); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("GMS.InstallView " + new_view.ToString() + "\\n" + "seq tble : " + new_view.SequencerTbl.Count); this._subGroupMbrsMap = new_view.SequencerTbl.Clone() as System.Collections.Hashtable; this._mbrSubGroupMap = new_view.MbrsSubgroupMap.Clone() as System.Collections.Hashtable; //========================================= // serialize access to views // assign new_view to view_id view_id = vid.Copy(); Stack.NCacheLog.CriticalInfo("GMS.InstallView", "=== View ID = " + view_id.ToString()); // Set the membership. Take into account joining members if (mbrs != null && mbrs.Count > 0) { for (int i = 0; i < members.size(); i++) { Address mbr = members.elementAt(i); if (!mbrs.Contains(mbr)) RemoveGmsId(mbr); } Hashtable gmsIds = new_view.GmsIds; if (gmsIds != null) { IDictionaryEnumerator ide = gmsIds.GetEnumerator(); while (ide.MoveNext()) { if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("GMS.InstallView", "mbr = " + ide.Key + " ; gms_id = " + ide.Value); AddGmsId((Address)ide.Key, (string)ide.Value); } } for (int i = 0; i < mbrs.Count; i++) { Stack.NCacheLog.CriticalInfo("GMS.InstallView", "Members.set = " + mbrs[i] != null ? mbrs[i].ToString() : null); } members.set(mbrs); tmp_members.set(members); Global.ICollectionSupport.RemoveAll(joining, mbrs); // remove all members in mbrs from joining // remove all elements from 'leaving' that are not in 'mbrs' Global.ICollectionSupport.RetainAll(leaving, mbrs); tmp_members.add(joining); // add members that haven't yet shown up in the membership tmp_members.remove(leaving); // remove members that haven't yet been removed from the membership // add to prev_members for (System.Collections.IEnumerator it = mbrs.GetEnumerator(); it.MoveNext(); ) { Address addr = (Address)it.Current; if (!prev_members.contains(addr)) prev_members.add(addr); } } // Send VIEW_CHANGE event up and down the stack: if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("GMS.installView", "broadcasting view change within stack"); coord = determineCoordinator(); // changed on suggestion by yaronr and Nicolas Piedeloupe if (coord != null && coord.Equals(local_addr) && !haveCoordinatorRole()) { becomeCoordinator(); } else { if (haveCoordinatorRole() && !local_addr.Equals(coord)) becomeParticipant(); } if (string.IsNullOrEmpty(new_view.BridgeSourceCacheId)) new_view.BridgeSourceCacheId = impl.UniqueId; MarkStateTransferInProcess(); Event view_event = new Event(Event.VIEW_CHANGE, new_view.Clone(), Priority.Critical); passDown(view_event); // needed e.g. by failure detector or UDP } } finally { } }
public void handleResetOnNodeRejoining(Address sender, Address node, View view) { ViewId vid = view.Vid; int rc; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("GMS.handleResetOnNodeRejoining", "Sequence reset request"); if (view_id != null) { rc = vid.CompareTo(view_id); if (rc <= 0) { return; } ltime = System.Math.Max(vid.Id, ltime); // compute Lamport logical time lock (members) { view_id = vid.Copy(); } } Event evt = new Event(Event.RESET_SEQUENCE, vid); passUp(evt); }
internal virtual void initState() { becomeClient(); view_id = null; }
/// <summary> /// Constructor /// </summary> /// <param name="vid">The view id of this view (can not be null)</param> /// <param name="_members">Contains a list of all the _members in the view, can be empty but not null.</param> public View(ViewId vid, ArrayList _members) { this.vid = vid; this._members = _members; }
/// <summary> Handle view changes /// /// param event the VIEW_CHANGE event /// </summary> /// <returns> true if the event should be forwarded to the layer above /// </returns> private bool _upViewChange(Event evt) { object oldSequencerAddr; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange()", "received VIEW_CHANGE"); // *** Get an exclusive lock try { stateLock.AcquireWriterLock(Timeout.Infinite); try { state = RUN; // i. See if this member is the sequencer // ii. If this is the sequencer, reset the sequencer's sequence ID // iii. Reset the last received sequence ID // // iv. Replay undelivered bcasts: Put all the undelivered bcasts // sent by us back to the req queue and discard the rest oldSequencerAddr = sequencerAddr; sequencerAddr = (Address)((View)evt.Arg).Members[0]; currentViewId = ((View)evt.Arg).Vid.Copy(); //============================================ //copy the sequencer table from the new view. this._sequencerTbl = ((View)evt.Arg).SequencerTbl.Clone() as Hashtable; this._mbrsSubgroupMap = ((View)evt.Arg).MbrsSubgroupMap.Clone() as Hashtable; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange()", "this._sequencerTbl.count = " + this._sequencerTbl.Count); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange()", "this._mbrsSubgroupMap.count = " + this._mbrsSubgroupMap.Count); ArrayList groupMbrs = (ArrayList)_sequencerTbl[subGroup_addr]; if (groupMbrs != null) { if (groupMbrs.Count != 0) { this._groupSequencerAddr = groupMbrs[0] as Address; } } if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange()", subGroup_addr + " old mbrs count = " + _groupMbrsCount); int newCount = groupMbrs.Count; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange()", "new mbrs count = " + newCount); if (newCount != _groupMbrsCount) { // i. the group this member belongs to, has changed // ii. therefore reset the _mcastSeqID // iii. if this node is new group sequencer, reset the // _mcastSequencerSeqID. // iii. Reset the last received mcast sequence ID // iv. Replay undelivered mcasts if (addr.Equals(_groupSequencerAddr)) { _mcastSequencerSeqID = NULL_ID; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange()", "resetting _mcastSequencerSeqID"); } _mcastSeqID = NULL_ID; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange()", "resetting _mcastSeqID"); _groupMbrsCount = newCount; _replayMcast(); } if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upViewChange", "my group sequencer is " + this._groupSequencerAddr.ToString()); //============================================ if (addr.Equals(sequencerAddr)) { sequencerSeqID = NULL_ID; if ((oldSequencerAddr == null) || (!addr.Equals(oldSequencerAddr))) if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("I'm the new sequencer"); } lock (upTbl.SyncRoot) { seqID = NULL_ID; } _replayBcast(); if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total.upViewChange()", "VIEW_CHANGE_OK"); Event viewEvt = new Event(Event.VIEW_CHANGE_OK, null, Priority.Critical); passDown(viewEvt); // *** Revoke the exclusive lock } finally { stateLock.ReleaseWriterLock(); } } catch (ThreadInterruptedException ex) { Stack.NCacheLog.Error("Protocols.TOTAL._upViewChange", ex.ToString()); } return (true); }
private bool _upResetSequence(Event evt) { _seqResetRequestCount++; ViewId vid = evt.Arg as ViewId; if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("Total._upResetSequence()", "Sequence reset request received :" + _seqResetRequestCount); // *** Get an exclusive lock try { stateLock.AcquireWriterLock(Timeout.Infinite); try { currentViewId = vid.Copy(); _msgAfterReset = 0; _msgArrived = 0; state = RUN; lock (_mcastSeqIDMutex) { _mcastSequencerSeqID = NULL_ID; } lock (_mcastUpTbl.SyncRoot) { _mcastSeqID = NULL_ID; } _replayMcast(); lock (seqIDMutex) { sequencerSeqID = NULL_ID; } lock (upTbl.SyncRoot) { seqID = NULL_ID; } _replayBcast(); } finally { stateLock.ReleaseWriterLock(); } } catch (ThreadInterruptedException ex) { Stack.NCacheLog.Error("Protocols.TOTAL._upResetSequence", ex.ToString()); } return (true); }
public virtual void Deserialize(CompactReader reader) { vid = (ViewId) reader.ReadObject(); _members = (ArrayList) reader.ReadObject(); _sequencerTbl = (Hashtable)reader.ReadObject(); _mbrsSubgroupMap = (Hashtable)reader.ReadObject(); _distributionMaps = (DistributionMaps)reader.ReadObject(); _mirrorMapping = reader.ReadObject() as CacheNode[]; _bridgeSourceCacheId = reader.ReadObject() as string; nodeGmsIds = reader.ReadObject() as Hashtable; _coordinatorGmsId = reader.ReadObject() as string; }
public static ViewId ReadViewId(CompactReader reader) { byte isNull = reader.ReadByte(); if (isNull == 1) return null; ViewId newId = new ViewId(); newId.Deserialize(reader); return newId; }