Beispiel #1
0
        private bool NotifyPartitionsAboutCrashedServerAndReattachNewMaster(string crashedServerId)
        {
            List <string> partitions = PartitionMapping.GetPartitionsThatContainServer(crashedServerId);

            foreach (string partitionName in partitions)
            {
                Console.WriteLine(">>> Notify Servers in Partition about Crash...");
                Console.WriteLine(">>> Partition=" + partitionName);
                string[] partitionNodes = PartitionMapping.GetPartitionAllNodes(partitionName);

                bool newMasterWasReattachedSuccessfully = false;
                foreach (string serverId in partitionNodes)
                {
                    if (serverId == crashedServerId)
                    {
                        continue; // Skip crashed server
                    }

                    else if (TryNotifyServerAboutCrashedServer(partitionName, serverId, crashedServerId))
                    {
                        newMasterWasReattachedSuccessfully = true;
                        break;
                    }
                }

                return(newMasterWasReattachedSuccessfully);
            }

            return(false);
        }
Beispiel #2
0
        private void read(string partition_id, string object_id, string server_id)
        {
            bool got_result = false;

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

            if (debug_console)
            {
                Console.WriteLine("Reading from the server...");
            }

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

            // if the client is attached to a server and that server contains the desired partition
            List <string> available_partitions_in_server = PartitionMapping.GetPartitionsByServerID(attached_server_id);

            if (!string.IsNullOrEmpty(attached_server_id) && available_partitions_in_server.Contains(partition_id))
            {
                if (debug_console)
                {
                    Console.WriteLine("Reading from the Attached Server: " + attached_server_id);
                }

                // read value from attached server
                got_result = TryReadValue(object_key, partition_id);
            }

            // if theres no result yet and there is a valid server_id parameter
            if ((!got_result) && (!server_id.Equals("-1")))
            {
                // check if the server hint even has the partition
                available_partitions_in_server = PartitionMapping.GetPartitionsByServerID(server_id);
                if (available_partitions_in_server.Contains(partition_id))
                {
                    if (debug_console)
                    {
                        Console.WriteLine("Attach to new Server: " + server_id);
                    }
                    reattachServer(server_id);

                    // read value from alternative server
                    got_result = TryReadValue(object_key, partition_id);
                }
            }

            // if theres no result yet, the client should find a server serving partition_id on its own
            // it will try to connect to every single node in that partition
            if (!got_result)
            {
                string[] partition_nodes = PartitionMapping.GetPartitionAllNodes(partition_id);

                foreach (string node_id in partition_nodes)
                {
                    if (debug_console)
                    {
                        Console.WriteLine("Attach to new Server: " + node_id);
                    }
                    reattachServer(node_id);

                    // read value from one of the partition servers
                    got_result = TryReadValue(object_key, partition_id);
                }
            }

            if (got_result == false)
            {
                Console.WriteLine("Read Result: N/A");
            }
        }