Ejemplo n.º 1
0
        public async Task <Dictionary <string, ListServerReply> > ListGlobalAsync(ListServerRequest request)
        {
            var previousId = this.ServerId;

            var reply = new Dictionary <string, ListServerReply>(_serversCount);

            foreach (var id in _servers.Keys)
            {
                try
                {
                    EstablishChannel(id);
                    reply[id] = await ClientListServerAsync(request);
                }
                catch (RpcException e)
                {
                    Console.WriteLine($"RpcException: {e.StatusCode}");
                    await CheckCurrentServerStatus();

                    reply[id] = new ListServerReply(); // empty reply
                }
            }

            Console.WriteLine($"Establish a channel with the server that preceded the ListGlobal operation (id: {previousId}).");
            EstablishChannel(previousId);
            return(reply);
        }
Ejemplo n.º 2
0
        public override Task <ListServerReply> ListServer(ListServerRequest req, ServerCallContext _)
        {
            man.CheckFreeze();
            var res  = new ListServerReply();
            var objs = store.ListObjs();

            lock (objs) {
                foreach (KeyValuePair <string, string> e in objs)
                {
                    res.Objs.Add(e.Key, e.Value);
                }
            }
            Lib.Sleep(new Random().Next(minDelay, maxDelay));
            return(Task.FromResult(res));
        }
Ejemplo n.º 3
0
        public override Task <ListServerReply> ListServerAdvanced(ListServerRequest request, ServerCallContext context)
        {
            var currentServerId = _gigaStorage.ServerId;

            var reply   = new ListServerReply();
            var objects = _gigaStorage.ListServerAdvanced();

            foreach (var o in objects)
            {
                var masterId = _gigaStorage.GetMaster(o.PartitionId);
                var inMaster = (currentServerId == masterId);

                var obj = new ListServerReply.Types.Object {
                    PartitionId = o.PartitionId,
                    ObjectId    = o.ObjectId,
                    Value       = o.Value,
                    InMaster    = inMaster
                };
                reply.Objects.Add(obj);
            }
            return(Task.FromResult(reply));
        }
        public ListServerReply ListServerHandler(ListServerRequest request)
        {
            ListServerReply reply = null;
            List <DataStorePartitionDto> partitionList = new List <DataStorePartitionDto>();

            foreach (Partition p in server.getPartitions())
            {
                List <DataStoreObjectDto> objectList = new List <DataStoreObjectDto>();
                DataStore store = p.getDataStore();

                foreach (DataStoreKey key in store.getKeys())
                {
                    Shared.GrpcDataStore.DataStoreObjectDto dto_obj = new Shared.GrpcDataStore.DataStoreObjectDto
                    {
                        Key   = DataStoreServer.Util.Utilities.ConvertKeyDomainToDto(key),
                        Value = DataStoreServer.Util.Utilities.ConvertValueDomainToDto(store.getObject(key))
                    };

                    objectList.Add(dto_obj);
                }

                Shared.GrpcDataStore.DataStorePartitionDto dto_part = new Shared.GrpcDataStore.DataStorePartitionDto
                {
                    PartitionId = p.getName(),
                    IsMaster    = p.is_master,
                    ObjectList  = { objectList }
                };

                partitionList.Add(dto_part);
            }

            reply = new ListServerReply
            {
                PartitionList = { partitionList }
            };

            return(reply);
        }
Ejemplo n.º 5
0
        public async Task <ListServerReply> ListServerAsync(ListServerRequest request, string serverId)
        {
            var previousId = this.ServerId;

            ListServerReply reply;

            try
            {
                EstablishChannel(serverId);
                reply = await ClientListServerAsync(request);
            }
            catch (RpcException e)
            {
                Console.WriteLine($"RpcException: {e.StatusCode}");
                await CheckCurrentServerStatus();

                reply = new ListServerReply(); // empty reply;
            }

            Console.WriteLine($"Establish a channel with the server that preceded the ListServer operation (id: {previousId}).");
            EstablishChannel(previousId);
            return(reply);
        }