Пример #1
0
        public override Task <AppendEntriesReply> AppendEntries(AppendEntriesRequest req, ServerCallContext _)
        {
            man.CheckFreeze();
            var sInfo   = new ServerInfo(req.Mid, req.Tag, req.Term);
            var entries = new List <KeyValuePair <string, string> >();

            foreach (var e in req.Entries)
            {
                entries.Add(new KeyValuePair <string, string>(e.IdObj, e.Val));
            }

            var mySInfo = man.RcvAppendEntries(req.IdPart, sInfo, entries);

            if (mySInfo.Term <= sInfo.Term)
            {
                foreach (var e in entries)
                {
                    store.Write(req.IdPart, e.Key, e.Value);
                }
            }

            var res = new AppendEntriesReply {
                Term = mySInfo.Term,
                Tag  = mySInfo.Tag,
                Mid  = mySInfo.Mid
            };

            Lib.Sleep(new Random().Next(minDelay, maxDelay));
            return(Task.FromResult(res));
        }
Пример #2
0
        public override Task <ReadReply> Read(ReadRequest req, ServerCallContext _)
        {
            man.CheckFreeze();
            ReadReply reply = new ReadReply {
                Val = store.Read(req.IdPart, req.IdObj)
            };

            Lib.Sleep(new Random().Next(minDelay, maxDelay));
            return(Task.FromResult(reply));
        }
Пример #3
0
        public override Task <ReadReply> Read(ReadRequest req, ServerCallContext _)
        {
            man.CheckFreeze();
            ReadReply res = new ReadReply {
                Val = store.Read(req.IdPart, req.IdObj),
                Tag = ServerManager.RInfos[req.IdPart].PInfo.Tag
            };

            Lib.Sleep(new Random().Next(minDelay, maxDelay));
            return(Task.FromResult(res));
        }
Пример #4
0
        public override Task <LockReply> Lock(LockRequest req, ServerCallContext _)
        {
            man.CheckFreeze();
            try {
                store.Lock(req.IdPart, req.IdObj);
            } catch (DomainException e) {
                throw new GRPCException(StatusCode.NotFound, e.Message);
            }

            Lib.Sleep(new Random().Next(minDelay, maxDelay));
            return(Task.FromResult(new LockReply()));
        }