///////////////////////////////////////// /* grpc functions */ public override Task <NewLeaderACK> UpdateLeader(NewLeader request, ServerCallContext context) { Console.WriteLine("***********************************************************************************************"); Console.WriteLine("Puppet Master has received an update leader..."); Console.WriteLine("***********************************************************************************************"); return(Task.FromResult(UpdateLeader_aux(request))); }
public NewLeaderACK UpdateLeader_aux(NewLeader request) { string partition_id = request.Partid; string leader_id = request.Leaderid; int pos_partlist = -1; int pos_servlist = -1; //iterate over partition and update foreach (Partition p in partList) { pos_partlist = pos_partlist + 1; if (p.getName() == partition_id) { //partition to update foreach ((string server, bool is_master) in p.getServIDs()) { pos_servlist = pos_servlist + 1; if (server == leader_id) { goto UpdateLead; } } } } UpdateLead: partList.ElementAt(pos_partlist).getServIDs().RemoveAt(pos_servlist); partList.ElementAt(pos_partlist).getServIDs().Add((leader_id, true)); Console.WriteLine($"Puppet Master updated leader {leader_id} at partition {partition_id}"); //propagate this change to clients Console.WriteLine("PuppetMaster is sending the update leader to the clients..."); foreach (Client c in this.cliList) { //do client to server and propagate AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); GrpcChannel channel = GrpcChannel.ForAddress(c.getURL()); var client = new ClientServices.ClientServicesClient(channel); client.UpdateLeaderClient(new LeaderInfo { Partitionid = partition_id, Leaderid = leader_id }); } return(new NewLeaderACK { }); }