public NotifyCrashReply NotifyCrashHandler(NotifyCrashRequest request) { lock (_syncRoot) { string partitionName = request.PartitionId; string crashedMasterServerId = request.CrashedMasterServerId; string currentMasterServerId = PartitionMapping.GetPartitionMaster(partitionName); Console.WriteLine(">>> Received Message from the client about crashed server: PartitionName=" + partitionName + ", CrashedServerId=" + crashedMasterServerId); // check if the crashed server has been dealt with already string[] serversOfThePartition = PartitionMapping.partitionMapping[partitionName]; if (!serversOfThePartition.Contains(crashedMasterServerId)) { // this means an election already happened and the crashed server was deleted. the current partition master is the election result // another possibility is that the master detected a replica failure. In this case the partition master didn't actually change saying that it did no harm. Console.WriteLine(">>> Election Process Has Already Happened, CurrentMasterServerId=" + currentMasterServerId); return(new NotifyCrashReply { Status = "OK", MasterId = currentMasterServerId }); } // confirm that server is actually crashed SendValueToReplica svr = new SendValueToReplica(server); return(svr.HandleServerCrash(partitionName, crashedMasterServerId)); } }
// ---------- Handlers public WriteReply WriteHandler(WriteRequest request) { SendValueToReplica svr = new SendValueToReplica(server, request); server.tpool.AssyncInvoke(new ThrWork(svr.doWork)); WriteReply reply = server.getWriteResult(request); return(reply); }