Exemplo n.º 1
0
        public static async Task Execute(ConnectionManager connectionManager, string partitionId, string objectId, string value)
        {
            while (true)
            {
                Server server = connectionManager.ChooseServerForWrite(partitionId);
                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)
                {
                    await connectionManager.DeclareDead(server.Id);
                }
            }
        }
Exemplo n.º 2
0
        private async Task <Empty> ExecuteWrite(GStoreWriteRequest request)
        {
            Console.WriteLine($"Write request -> PartitionId: {request.Object.ObjectIdentifier.PartitionId} ObjectId: {request.Object.ObjectIdentifier} Value: {request.Object.Value}");

            GStoreObjectIdentifier gStoreObjectIdentifier = new GStoreObjectIdentifier(request.Object.ObjectIdentifier.PartitionId, request.Object.ObjectIdentifier.ObjectId);
            await gStore.Write(gStoreObjectIdentifier, request.Object.Value);

            return(new Empty());
        }
Exemplo n.º 3
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;
                }
            }
        }
Exemplo n.º 4
0
 public override Task <Empty> Write(GStoreWriteRequest request, ServerCallContext context)
 {
     return(Task.FromResult(ExecuteWrite(request)));
 }