Ejemplo n.º 1
0
        private void TryRemoveFromView(string deadURL)
        {
            lock (SuspectedDead){
                if (SuspectedDead.ContainsKey(deadURL) || !TSMan.ServerView.Contains(deadURL))
                {
                    return;
                }
                SuspectedDead.Add(deadURL, 0);
            }

            Console.WriteLine("Suspect dead: " + deadURL);

            List <string> serversUrl = TSMan.ServerView.DeepUrlsCopy();

            AsyncCallback remoteCallback = new AsyncCallback(RemoveFromViewCallback);

            // Send vote requests to remove suspected dead server from view
            TSpaceAdvServerSMR server;

            foreach (string serverUrl in serversUrl)
            {
                server = (TSpaceAdvServerSMR)Activator.GetObject(typeof(ITSpaceServer), serverUrl);

                RemoteDeletefromViewDelegate remoteDel = new RemoteDeletefromViewDelegate(server.TryConnection);
                try
                {
                    // Call remote method
                    remoteDel.BeginInvoke(deadURL, false, remoteCallback, deadURL);
                }
                catch (Exception) { }
            }

            Monitor.Enter(SuspectedDead);
            //TODO: Change quorum to update on view change and be just variable
            while (SuspectedDead.ContainsKey(deadURL) &&
                   (SuspectedDead[deadURL] < TSMan.Quorum(TSMan.ServerView.GetUrls().Count)))
            {
                Monitor.Wait(SuspectedDead);
            }
            Monitor.Exit(SuspectedDead);

            Console.WriteLine("Confirmed dead: " + deadURL);

            lock (SuspectedDead)
            {
                //Already has been removed
                if (!SuspectedDead.ContainsKey(deadURL))
                {
                    return;
                }
            }

            // Get operation sequence number
            string operationID = TSMan.URL + "_" + (ViewUpdateCounter++);
            int    seqNum      = GetSequenceNumber(operationID, deadURL);


            //Send view update to all servers and wait for majority
            UpdateView(deadURL, operationID, serversUrl, seqNum, false);
        }
Ejemplo n.º 2
0
        private void RemoveFromViewCallback(IAsyncResult result)
        {
            string serverURL = (string)result.AsyncState;
            RemoteDeletefromViewDelegate del = (RemoteDeletefromViewDelegate)((AsyncResult)result).AsyncDelegate;

            // Retrieve results.
            bool isDead = !del.EndInvoke(result);

            lock (SuspectedDead)
            {
                if (isDead && SuspectedDead.ContainsKey(serverURL))
                {
                    SuspectedDead[serverURL]++;
                }
                Monitor.PulseAll(SuspectedDead);
            }
        }