Beispiel #1
0
 void ICompactSerializable.Deserialize(CompactReader reader)
 {
     type           = reader.ReadByte();
     view           = View.ReadView(reader);
     mbr            = Address.ReadAddress(reader);
     join_rsp       = (JoinRsp)reader.ReadObject();
     digest         = (Digest)reader.ReadObject();
     merge_id       = reader.ReadObject();
     merge_rejected = reader.ReadBoolean();
     subGroup_name  = reader.ReadString();
     nodeList       = reader.ReadObject() as ArrayList;
     arg            = reader.ReadObject();
     gms_id         = reader.ReadObject() as string;
 }
Beispiel #2
0
 public abstract void  handleJoinResponse(JoinRsp join_rsp);
Beispiel #3
0
		public abstract void  handleJoinResponse(JoinRsp join_rsp);
Beispiel #4
0
        /// <summary> Joins this process to a group. Determines the coordinator and sends a unicast
        /// handleJoin() message to it. The coordinator returns a JoinRsp and then broadcasts the new view, which
        /// contains a message digest and the current membership (including the joiner). The joiner is then
        /// supposed to install the new view and the digest and starts accepting mcast messages. Previous
        /// mcast messages were discarded (this is done in PBCAST).<p>
        /// If successful, impl is changed to an instance of ParticipantGmsImpl.
        /// Otherwise, we continue trying to send join() messages to	the coordinator,
        /// until we succeed (or there is no member in the group. In this case, we create our own singleton group).
        /// <p>When GMS.disable_initial_coord is set to true, then we won't become coordinator on receiving an initial
        /// membership of 0, but instead will retry (forever) until we get an initial membership of > 0.
        /// </summary>
        /// <param name="mbr">Our own address (assigned through SET_LOCAL_ADDRESS)
        /// </param>
        public override void  join(Address mbr, bool isStartedAsMirror)
        {
            Address coord            = null;
            Address last_tried_coord = null;
            JoinRsp rsp        = null;
            Digest  tmp_digest = null;

            leaving = false;
            int join_retries = 1;



            join_promise.Reset();
            while (!leaving)
            {
                findInitialMembers();


                gms.Stack.NCacheLog.Debug("pb.ClientGmsImpl.join()", "initial_mbrs are " + Global.CollectionToString(initial_mbrs));
                if (initial_mbrs.Count == 0)
                {
                    if (gms.disable_initial_coord)
                    {
                        gms.Stack.NCacheLog.Debug("pb.ClientGmsImpl.join()", "received an initial membership of 0, but cannot become coordinator (disable_initial_coord=" + gms.disable_initial_coord + "), will retry fetching the initial membership");
                        continue;
                    }
                    gms.Stack.NCacheLog.CriticalInfo("pb.ClientGmsImpl.join()", "no initial members discovered: creating group as first member");

                    becomeSingletonMember(mbr);
                    return;
                }

                coord = determineCoord(initial_mbrs);
                if (coord == null)
                {
                    gms.Stack.NCacheLog.Error("pb.ClientGmsImpl.join()", "could not determine coordinator from responses " + Global.CollectionToString(initial_mbrs));
                    continue;
                }
                if (coord.CompareTo(gms.local_addr) == 0)
                {
                    gms.Stack.NCacheLog.Error("pb.ClientGmsImpl.join()", "coordinator anomaly. More members exist yet i am the coordinator " + Global.CollectionToString(initial_mbrs));

                    ArrayList members = new ArrayList();
                    for (int i = 0; i < initial_mbrs.Count; i++)
                    {
                        PingRsp ping_rsp = (PingRsp)initial_mbrs[i];
                        if (ping_rsp.OwnAddress != null && gms.local_addr != null && !ping_rsp.OwnAddress.Equals(gms.local_addr))
                        {
                            members.Add(ping_rsp.OwnAddress);
                        }
                    }

                    gms.InformOthersAboutCoordinatorDeath(members, coord);

                    if (last_tried_coord == null)
                    {
                        last_tried_coord = coord;
                    }
                    else
                    {
                        if (last_tried_coord.Equals(coord))
                        {
                            join_retries++;
                        }
                        else
                        {
                            last_tried_coord = coord;
                            join_retries     = 1;
                        }
                    }

                    Util.Util.sleep(gms.join_timeout);
                    continue;
                    //becomeSingletonMember(mbr);
                    //return ;
                }

                try
                {
                    gms.Stack.NCacheLog.Debug("pb.ClientGmsImpl.join()", "sending handleJoin(" + mbr + ") to " + coord);

                    if (last_tried_coord == null)
                    {
                        last_tried_coord = coord;
                    }
                    else
                    {
                        if (last_tried_coord.Equals(coord))
                        {
                            join_retries++;
                        }
                        else
                        {
                            last_tried_coord = coord;
                            join_retries     = 1;
                        }
                    }



                    sendJoinMessage(coord, mbr, gms.subGroup_addr, isStartedAsMirror);
                    rsp = (JoinRsp)join_promise.WaitResult(gms.join_timeout);


                    gms._doReDiscovery = false; //block the re-discovery of members as we have found initial members

                    if (rsp == null)
                    {
                        if (join_retries >= gms.join_retry_count)
                        {
                            gms.Stack.NCacheLog.Error("ClientGmsImpl.Join", "received no joining response after " + join_retries + " tries, so becoming a singlton member");
                            becomeSingletonMember(mbr);

                            return;
                        }
                        else
                        {
                            //I did not receive join response, so there is a chance that coordinator is down
                            //Lets verifiy it.
                            if (gms.VerifySuspect(coord, false))
                            {
                                if (gms.Stack.NCacheLog.IsErrorEnabled)
                                {
                                    gms.Stack.NCacheLog.CriticalInfo("ClientGmsImpl.Join()", "selected coordinator " + coord + " seems down; Lets inform others");
                                }
                                //Coordinator is not alive;Lets inform the others
                                ArrayList members = new ArrayList();
                                for (int i = 0; i < initial_mbrs.Count; i++)
                                {
                                    PingRsp ping_rsp = (PingRsp)initial_mbrs[i];

                                    if (ping_rsp.OwnAddress != null && gms.local_addr != null && !ping_rsp.OwnAddress.Equals(gms.local_addr))
                                    {
                                        members.Add(ping_rsp.OwnAddress);
                                    }
                                }
                                gms.InformOthersAboutCoordinatorDeath(members, coord);
                            }
                        }
                        gms.Stack.NCacheLog.Error("ClientGmsImpl.Join()", "handleJoin(" + mbr + ") failed, retrying; coordinator:" + coord + " ;No of retries : " + (join_retries + 1));
                    }
                    else
                    {
                        if (rsp.JoinResult == JoinResult.Rejected)
                        {
                            gms.Stack.NCacheLog.Error("ClientGmsImpl.Join", "joining request rejected by coordinator");
                            becomeSingletonMember(mbr);

                            return;
                        }

                        if (rsp.JoinResult == JoinResult.MembershipChangeAlreadyInProgress)
                        {
                            gms.Stack.NCacheLog.CriticalInfo("Coord.CheckOwnClusterHealth", "Reply: JoinResult.MembershipChangeAlreadyInProgress");
                            Util.Util.sleep(gms.join_timeout);
                            continue;
                        }

                        gms.Stack.NCacheLog.Debug("pb.ClientGmsImpl.join()", "Join successfull");

                        // 1. Install digest
                        tmp_digest = rsp.Digest;
                        if (tmp_digest != null)
                        {
                            tmp_digest.incrementHighSeqno(coord);                             // see DESIGN for an explanantion
                            gms.Stack.NCacheLog.Debug("pb.ClientGmsImpl.join()", "digest is " + tmp_digest);
                            gms.Digest = tmp_digest;
                        }
                        else
                        {
                            gms.Stack.NCacheLog.Error("pb.ClientGmsImpl.join()", "digest of JOIN response is null");
                        }

                        // 2. Install view
                        gms.Stack.NCacheLog.Debug("pb.ClientGmsImpl.join()", "[" + gms.local_addr + "]: JoinRsp=" + rsp.View + " [size=" + rsp.View.size() + "]\n\n");

                        if (rsp.View != null)
                        {
                            if (!installView(rsp.View))
                            {
                                gms.Stack.NCacheLog.Error("pb.ClientGmsImpl.join()", "view installation failed, retrying to join group");
                                continue;
                            }
                            gms.Stack.IsOperational = true;
                            return;
                        }
                        else
                        {
                            gms.Stack.NCacheLog.Error("pb.ClientGmsImpl.join()", "view of JOIN response is null");
                        }
                    }
                }
                catch (System.Exception e)
                {
                    gms.Stack.NCacheLog.Error("ClientGmsImpl.join()", e.Message + ", retrying");
                }

                Util.Util.sleep(gms.join_retry_timeout);
            }
        }
Beispiel #5
0
 public override void  handleJoinResponse(JoinRsp join_rsp)
 {
     join_promise.SetResult(join_rsp);             // will wake up join() method
 }
Beispiel #6
0
 public override void  handleJoinResponse(JoinRsp join_rsp)
 {
     join_promise.SetResult(join_rsp); // will wake up join() method
     gms.Stack.NCacheLog.CriticalInfo("CoordGMSImpl.handleJoin called at startup");
     wrongMethod("handleJoinResponse");
 }
		public override void  handleJoinResponse(JoinRsp join_rsp)
		{
            join_promise.SetResult(join_rsp); // will wake up join() method
            gms.Stack.NCacheLog.CriticalInfo("CoordGMSImpl.handleJoin called at startup");
			wrongMethod("handleJoinResponse");
		}
Beispiel #8
0
		public override void  handleJoinResponse(JoinRsp join_rsp)
		{
			join_promise.SetResult(join_rsp); // will wake up join() method
		}
Beispiel #9
0
        /// <summary> Computes the new view (including the newly joined member) and get the digest from PBCAST.
        /// Returns both in the form of a JoinRsp
        /// </summary>
        public override JoinRsp handleJoin(Address mbr, string subGroup_name, bool isStartedAsMirror, string gmsId, ref bool acquireHashmap)
        {
            lock (this)
            {

                System.Collections.ArrayList new_mbrs = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(1));
                View v = null;
                Digest d, tmp;


                gms.Stack.NCacheLog.CriticalInfo("CoordGmsImpl.handleJoin", "mbr=" + mbr);

                if (gms.local_addr.Equals(mbr))
                {
                    
                    gms.Stack.NCacheLog.Error("CoordGmsImpl.handleJoin", "cannot join myself !");
                    return null;
                }

                if (gms.members.contains(mbr))
                {
                    gms.Stack.NCacheLog.Error("CoordGmsImpl.handleJoin()", "member " + mbr + " already present; returning existing view " + Global.CollectionToString(gms.members.Members));
                    acquireHashmap = false;
                    View view = new View(gms.view_id, gms.members.Members);
                    view.CoordinatorGmsId = gms.unique_id;
                    JoinRsp rsp = new JoinRsp(view, gms.Digest);
                    rsp.View.SequencerTbl = gms._subGroupMbrsMap;
                    rsp.View.MbrsSubgroupMap = gms._mbrSubGroupMap;
                    return rsp;
                    // already joined: return current digest and membership
                }
                new_mbrs.Add(mbr);
                //=====================================
                // update the subGroupMbrsMap and mbrSubGroupMap
                if (gms._subGroupMbrsMap.Contains(subGroup_name))
                {
                    lock (gms._subGroupMbrsMap.SyncRoot)
                    {
                        System.Collections.ArrayList groupMbrs = (System.Collections.ArrayList)gms._subGroupMbrsMap[subGroup_name];
                        if (!groupMbrs.Contains(mbr))
                            groupMbrs.Add(mbr);
                    }
                }
                else
                {
                    lock (gms._subGroupMbrsMap.SyncRoot)
                    {
                        System.Collections.ArrayList groupMbrs = new System.Collections.ArrayList();
                        groupMbrs.Add(mbr);
                        gms._subGroupMbrsMap[subGroup_name] = groupMbrs;
                    }
                }

                if (!gms._mbrSubGroupMap.Contains(mbr))
                {
                    lock (gms._mbrSubGroupMap.SyncRoot)
                    {
                        gms._mbrSubGroupMap[mbr] = subGroup_name;
                    }
                }
                //=====================================
                tmp = gms.Digest; // get existing digest
                if (tmp == null)
                {
                    gms.Stack.NCacheLog.Error("CoordGmsImpl.handleJoin", "received null digest from GET_DIGEST: will cause JOIN to fail");
                    return null;
                }

                gms.Stack.NCacheLog.Debug("got digest=" + tmp);

                d = new Digest(tmp.size() + 1);
                // create a new digest, which contains 1 more member
                d.add(tmp); // add the existing digest to the new one
                d.add(mbr, 0, 0);
                // ... and add the new member. it's first seqno will be 1
                v = gms.getNextView(new_mbrs, null, null);
                v.SequencerTbl = gms._subGroupMbrsMap;
                v.MbrsSubgroupMap = gms._mbrSubGroupMap;
                v.AddGmsId(mbr, gmsId);

                //add coordinator own's gms id[bug fix]; so that new member could know cordinator id
                v.AddGmsId(gms.local_addr, gms.unique_id);

                if (gms.GmsIds != null)
                {
                    Hashtable gmsIds = gms.GmsIds.Clone() as Hashtable;
                    IDictionaryEnumerator ide = gmsIds.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        v.AddGmsId((Address)ide.Key,(string) ide.Value);
                    }
                }

                gms.Stack.NCacheLog.Debug("joined member " + mbr + ", view is " + v);

               
                return new JoinRsp(v, d);
            }
        }
Beispiel #10
0
 /// <summary>Used for JOIN_RSP header </summary>
 public GmsHDR(byte type, JoinRsp join_rsp)
 {
     this.type     = type;
     this.join_rsp = join_rsp;
 }
Beispiel #11
0
 void ICompactSerializable.Deserialize(CompactReader reader)
 {
     type = reader.ReadByte();
     view = View.ReadView(reader);
     mbr = Address.ReadAddress(reader);
     join_rsp = (JoinRsp)reader.ReadObject();
     digest = (Digest)reader.ReadObject();
     merge_id = reader.ReadObject();
     merge_rejected = reader.ReadBoolean();
     subGroup_name = reader.ReadString();
     nodeList = reader.ReadObject() as ArrayList;
     arg = reader.ReadObject();
     isStartedAsMirror = reader.ReadBoolean();
     gms_id = reader.ReadObject() as string;
 }
Beispiel #12
0
 /// <summary>Used for JOIN_RSP header </summary>
 public HDR(byte type, JoinRsp join_rsp)
 {
     this.type = type;
     this.join_rsp = join_rsp;
 }
Beispiel #13
0
        internal virtual void handleJoinRequest(Address mbr, string subGroup_name, bool isStartedAsMirror, string gmsId)
        {
          
            JoinRsp join_rsp = null;
            Message m;
            HDR hdr;

            if (mbr == null)
            {
                Stack.NCacheLog.Error( "mbr is null");
                return;
            }

            Stack.NCacheLog.Debug("pbcast.GMS.handleJoinRequest()", "mbr=" + mbr);

            if (!isStartedAsMirror)
            {
                lock (join_mutex)
                {
                   
                    if (_nodeJoiningInProgress || _isLeavingInProgress || (_isStarting && !local_addr.IpAddress.Equals(mbr.IpAddress)))
                    {
                        Stack.NCacheLog.CriticalInfo("GMS.HandleJoinRequest()", "node join already in progess" + mbr);
                       
                        join_rsp = new JoinRsp(null, null);
                        join_rsp.JoinResult = JoinResult.MembershipChangeAlreadyInProgress;
                        
                        m = new Message(mbr, null, null);
                        hdr = new HDR(HDR.JOIN_RSP, join_rsp);
                        m.putHeader(HeaderType.GMS, hdr);
                        passDown(new Event(Event.MSG, m, Priority.Critical));
                        return;
                    }
                    else
                    {
                        _nodeJoiningInProgress = true;
                    }
                } 
            }

           
            // 1. Get the new view and digest
            if (members.contains(mbr))
            {

                string oldGmsId = GetGmsId(mbr);

                if (oldGmsId != null && oldGmsId != gmsId)
                {
                    Stack.NCacheLog.Error("pbcast.GMS.handleJoinRequest()", mbr + " has sent a joining request while it is already in member list and has wrong gmsID");
                    
                   
                    join_rsp = null;
                    m = new Message(mbr, null, null);
                    hdr = new HDR(HDR.JOIN_RSP, join_rsp);
                    m.putHeader(HeaderType.GMS, hdr);
                    passDown(new Event(Event.MSG, m, Priority.Critical));

                    
                    impl.handleSuspect(mbr);
                    
                    lock (join_mutex)
                    {
                        _nodeJoiningInProgress = false;
                    }
                    return;
                }
                else
                {

                    Stack.NCacheLog.Error("pbcast.GMS.handleJoinRequest()", mbr + " has sent a joining request while it is already in member list - Resending current view and digest");
                   
                    View view = new View(this.view_id, members.Members);
                    view.CoordinatorGmsId = unique_id;
                    join_rsp = new JoinRsp(view, this.digest, JoinResult.Success);
                    m = new Message(mbr, null, null);
                    hdr = new HDR(HDR.JOIN_RSP, join_rsp);
                    m.putHeader(HeaderType.GMS, hdr);
                    passDown(new Event(Event.MSG, m, Priority.Critical));
                    lock (join_mutex)
                    {
                        _nodeJoiningInProgress = false;
                    }
                    return;
                }
            }

            

            if (allowJoin(mbr, isStartedAsMirror))
            {
                Stack.NCacheLog.Debug("pbcast.GMS.handleJoinRequest()", " joining allowed");
                bool acauireHashmap = true;

                join_rsp = impl.handleJoin(mbr, subGroup_name, isStartedAsMirror, gmsId, ref acauireHashmap);

                if (join_rsp == null)
                    Stack.NCacheLog.Error("pbcast.GMS.handleJoinRequest()", impl.GetType().ToString() + ".handleJoin(" + mbr + ") returned null: will not be able to multicast new view");

                //muds:
                //sends a request to the caching layer for the new hashmap after this member joins.
                System.Collections.ArrayList mbrs = new System.Collections.ArrayList(1);
                mbrs.Add(mbr);

                //muds:
                //some time coordinator gms impl returns the same existing view in join response. 
                //we dont need to acquire the hashmap again in this case coz that hashmap has already been acquired.
                if (acauireHashmap)
                    acquireHashmap(mbrs, true, subGroup_name, isStartedAsMirror);

                // 2. Send down a local TMP_VIEW event. This is needed by certain layers (e.g. NAKACK) to compute correct digest
                //    in case client's next request (e.g. getState()) reaches us *before* our own view change multicast.
                // Check NAKACK's TMP_VIEW handling for details
                if (join_rsp != null && join_rsp.View != null)
                {
                    //muds:
                    //add the hash map as part of view.
                    if (_hashmap != null)
                    {
                        Object[] mapsArray = (Object[])_hashmap;
                        DistributionMaps maps = (DistributionMaps)mapsArray[0];
                        if (maps != null)
                        {
                           
                            join_rsp.View.DistributionMaps = maps;
                        }
                        

                        join_rsp.View.MirrorMapping = mapsArray[1] as CacheNode[];

                    }
                    passDown(new Event(Event.TMP_VIEW, join_rsp.View));
                } 
            }
            else
                Stack.NCacheLog.Debug("pbcast.GMS.handleJoinRequest()", " joining not allowed");

            // 3. Return result to client
            m = new Message(mbr, null, null);
            hdr = new HDR(HDR.JOIN_RSP, join_rsp);
            m.putHeader(HeaderType.GMS, hdr);
            passDown(new Event(Event.MSG, m, Priority.Critical));

            // 4. Bcast the new view
            if (join_rsp != null)
                castViewChange(join_rsp.View);

            lock (join_mutex)
            {
                _nodeJoiningInProgress = false;
            }

           
        }