Beispiel #1
0
        public static async Task Execute(ConnectionManager connectionManager, string partitionId, string objectId, string value)
        {
            Server server = null;

            try
            {
                server = connectionManager.ChooseServer(partitionId, "-1");
                if (!server.Alive)
                {
                    server = null;
                }
            }
            catch (ServerBindException)
            {
                // nothing
            }

            while (true)
            {
                if (server == null)
                {
                    IImmutableSet <Server> replicas = connectionManager.GetAliveServers(partitionId);
                    Random rnd = new Random();
                    server = replicas.ElementAt(rnd.Next(0, replicas.Count));
                    connectionManager.Attach(server);
                }

                Console.WriteLine($"Trying: {server.Id}");
                GStoreWriteRequest writeRequest = new GStoreWriteRequest()
                {
                    Object = new DataObject()
                    {
                        ObjectIdentifier = new DataObjectIdentifier
                        {
                            PartitionId = partitionId,
                            ObjectId    = objectId
                        },
                        Value = value
                    }
                };

                try
                {
                    await server.Stub.WriteAsync(writeRequest);

                    return;
                }
                catch (Grpc.Core.RpcException e) when(e.StatusCode == Grpc.Core.StatusCode.Internal)
                {
                    connectionManager.DeclareDead(server.Id);
                    server = null;
                }
            }
        }
Beispiel #2
0
        public static async Task <GStoreObject> Execute(ConnectionManager connectionManager, string partitionId, string serverId, string objectId)
        {
            Server server = null;

            try
            {
                server = connectionManager.ChooseServerForRead(partitionId, serverId);
                if (!server.Alive)
                {
                    server = null;
                }
            }
            catch (ServerBindException)
            {
                // nothing
            }

            while (true)
            {
                if (server == null)
                {
                    IImmutableSet <Server> replicas = connectionManager.GetPartitionAliveReplicas(partitionId);
                    Random rnd = new Random();
                    server = replicas.ElementAt(rnd.Next(0, replicas.Count));
                }

                Console.WriteLine($"Trying: {server.Id}");
                GStoreReadRequest gStoreReadRequest = new GStoreReadRequest()
                {
                    ObjectIdentifier = new DataObjectIdentifier
                    {
                        PartitionId = partitionId,
                        ObjectId    = objectId
                    }
                };

                try
                {
                    GStoreReadReply gStoreReadReply = await server.Stub.ReadAsync(gStoreReadRequest);

                    return(CreateObject(gStoreReadReply.Object));
                }
                catch (Grpc.Core.RpcException e) when(e.StatusCode == Grpc.Core.StatusCode.Internal)
                {
                    await connectionManager.DeclareDead(server.Id);

                    server = null;
                }
            }
        }