Beispiel #1
0
        public void CreateLocalPartitions()
        {
            List <string> partitions = PartitionMapping.getPartitionsByServerID(serverId);

            foreach (string partition_id in partitions)
            {
                server.createPartition(partition_id);
            }
        }
Beispiel #2
0
        private void read(string partition_id, string object_id, string server_id)
        {
            string    result     = "N/A";
            bool      got_result = false;
            ReadReply reply;

            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
                try
                {
                    reply = client.Read(new ReadRequest {
                        ObjectKey = object_key
                    });
                    if (reply.ObjectExists)
                    {
                        result     = reply.Object.Val;
                        got_result = true;
                    }
                    // server is crashed
                } catch
                {
                    handle_crashed_server(attached_server_id);
                    got_result = false;
                }
            }

            // 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
                    try
                    {
                        reply = client.Read(new ReadRequest {
                            ObjectKey = object_key
                        });
                        if (reply.ObjectExists)
                        {
                            result     = reply.Object.Val;
                            got_result = true;
                        }
                        // server is crashed
                    } catch
                    {
                        handle_crashed_server(attached_server_id);
                        got_result = false;
                    }
                }
            }

            // 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
                    try
                    {
                        reply = client.Read(new ReadRequest {
                            ObjectKey = object_key
                        });
                        if (reply.ObjectExists)
                        {
                            result     = reply.Object.Val;
                            got_result = true;
                        }
                        // server is crashed
                    } catch
                    {
                        handle_crashed_server(attached_server_id);
                        got_result = false;
                    }
                }
            }

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