private void UpdateView(string updateServer, string operationID, List <string> allServers, int seqNum, bool insert) { // Clear previous responses ViewAcksCounter = 0; majorityHasView = false; AsyncCallback remoteCallback = new AsyncCallback(UpdateViewCallback); TSpaceAdvServerSMR server; RemoteUpdateViewDelegate remoteDel; foreach (string serverUrl in allServers) { server = (TSpaceAdvServerSMR)Activator.GetObject(typeof(ITSpaceServer), serverUrl); //Add new server if (insert) { remoteDel = new RemoteUpdateViewDelegate(server.AddToView); } //Remove server else { remoteDel = new RemoteUpdateViewDelegate(server.RemoveFromView); } try { // Call remote method remoteDel.BeginInvoke(updateServer, operationID, seqNum, remoteCallback, null); } catch (Exception) { } } // Wait for all Monitor.Enter(UpdateViewLock); while (ViewAcksCounter < TSMan.Quorum(allServers.Count)) { Monitor.Wait(UpdateViewLock); } Monitor.Exit(UpdateViewLock); }
private void TryRemoveFromView(string deadURL) { lock (SuspectedDead) { if (SuspectedDead.ContainsKey(deadURL) || !TSMan.ServerView.Contains(deadURL)) { return; } SuspectedDead.Add(deadURL, 0); TSpaceAdvManager.RWL.AcquireWriterLock(Timeout.Infinite); } Console.WriteLine("Suspected dead " + deadURL); List <string> servers = new List <string>(); for (int i = 0; i < TSMan.ServerView.GetUrls().Count; i++) { servers.Add(TSMan.ServerView.GetUrls()[i]); } Monitor.Enter(SuspectedDead); while (SuspectedDead.ContainsKey(deadURL) && (SuspectedDead[deadURL] < TSMan.Quorum(TSMan.ServerView.GetUrls().Count))) { TSpaceAdvServerXL server; DeleteFromViewDel del; AsyncCallback callback = new AsyncCallback(TryRemoveFromViewCallback); foreach (string serverUrl in servers) { server = (TSpaceAdvServerXL)Activator.GetObject(typeof(ITSpaceServer), serverUrl); del = new DeleteFromViewDel(server.TryConnection); try { del.BeginInvoke(deadURL, false, callback, deadURL); } catch (Exception) { } } //Releases until it acquires the lock or timeout elapses Monitor.Wait(SuspectedDead, 2000); } Monitor.Exit(SuspectedDead); Console.WriteLine("Confirmed Dead " + deadURL); lock (SuspectedDead) { //Already has been removed if (!SuspectedDead.ContainsKey(deadURL)) { Console.WriteLine("Already has been removed"); TSpaceAdvManager.RWL.ReleaseWriterLock(); return; } } //TODO add variable refering current remove //Only inc ack if in that remove Console.WriteLine("Entering wait"); Monitor.Enter(RemoveFromViewLock); UpdateViewCounter = 0; while (UpdateViewCounter < TSMan.Quorum(servers.Count)) { TSpaceAdvServerXL server; UpdateViewDel del; AsyncCallback callback = new AsyncCallback(RemoveFromViewCallback); List <string> testServers = new List <string>(servers); foreach (string serverUrl in testServers) { server = (TSpaceAdvServerXL)Activator.GetObject(typeof(ITSpaceServer), serverUrl); del = new UpdateViewDel(server.RemoveFromView); try { del.BeginInvoke(deadURL, callback, serverUrl); } catch (Exception) { } } Monitor.Wait(RemoveFromViewLock, 2000); } Monitor.Exit(RemoveFromViewLock); TSpaceAdvManager.RWL.ReleaseWriterLock(); Console.WriteLine("Confirm remove of server " + deadURL + " => " + UpdateViewCounter); }