Пример #1
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;
                }
            }
        }
Пример #2
0
        private GStoreReadReply ExecuteRead(GStoreReadRequest request)
        {
            Console.WriteLine($"Read request -> PartitionId: {request.ObjectIdentifier.PartitionId} ObjectId: {request.ObjectIdentifier.ObjectId}");
            GStoreObjectIdentifier gStoreObjectIdentifier = new GStoreObjectIdentifier(request.ObjectIdentifier.PartitionId, request.ObjectIdentifier.ObjectId);
            string value = gStore.Read(gStoreObjectIdentifier);

            if (value == null)
            {
                value = "N/A";
            }
            return(new GStoreReadReply
            {
                Object = DataObjectBuilder.FromObjectIdentifier(request.ObjectIdentifier, value)
            });
        }
Пример #3
0
 public override Task <GStoreReadReply> Read(GStoreReadRequest request, ServerCallContext context)
 {
     return(Task.FromResult(ExecuteRead(request)));
 }