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));
            }
        }
Esempio n. 2
0
        public void createPartition(string partition_id)
        {
            string master_id       = PartitionMapping.GetPartitionMaster(partition_id);
            bool   is_master       = master_id.Equals(server_id);
            int    partition_clock = PartitionMapping.GetPartitionClock(partition_id);

            Partition p = new Partition(partition_id, is_master, partition_clock);

            partitions.Add(p);
        }
Esempio n. 3
0
        private void write(string partition_id, string object_id, string value)
        {
            WriteReply reply;

            if (debug_console)
            {
                Console.WriteLine("Get Partition Master from Partition Named: " + partition_id);
            }
            string partition_master_server_id = PartitionMapping.GetPartitionMaster(partition_id);

            if (debug_console)
            {
                Console.WriteLine("Partition Master Server ID: " + partition_master_server_id);
            }
            reattachServer(partition_master_server_id);

            var object_key = new DataStoreKeyDto
            {
                PartitionId = partition_id,
                ObjectId    = object_id
            };

            var object_value = new DataStoreValueDto
            {
                Val = value
            };

            Console.WriteLine(">>> Write request...");

            try
            {
                reply = client.Write(new WriteRequest {
                    ObjectKey = object_key, Object = object_value
                });
                Console.WriteLine("Write result: " + reply);
            }
            catch
            {
                bool canRetryOperation = HandleCrashedServer(attached_server_id);
                if (canRetryOperation)
                {
                    Console.WriteLine(">>> Retrying <Write> after reattaching to new master");
                    write(partition_id, object_id, value);
                }

                return;
            }
        }
Esempio n. 4
0
 public string getMasterID()
 {
     return(PartitionMapping.GetPartitionMaster(this.id));
 }