예제 #1
0
        public Task <HttpResponseMessage> TimeoutNow([FromUri] TimeoutNowRequest request)
        {
            var taskCompletionSource = new TaskCompletionSource <HttpResponseMessage>();

            _bus.Publish(request, taskCompletionSource);
            return(taskCompletionSource.Task);
        }
예제 #2
0
        public void Send(NodeConnectionInfo dest, TimeoutNowRequest req)
        {
            if (_linkedTokenSource.IsCancellationRequested)
            {
                return;
            }

            _sender.Send(dest, req);
        }
예제 #3
0
        public void Send(NodeConnectionInfo dest, TimeoutNowRequest req)
        {
            HttpClient client;

            using (GetConnection(dest, out client))
            {
                LogStatus("timeout to " + dest, async() =>
                {
                    var message = await client.GetAsync(string.Format("raft/timeoutNow?term={0}&from={1}&clusterTopologyId={2}", req.Term, req.From, req.ClusterTopologyId));
                    var reply   = await message.Content.ReadAsStringAsync();
                    if (message.IsSuccessStatusCode == false)
                    {
                        _log.Warn("Error appending entries to {0}. Status: {1}\r\n{2}", dest.Name, message.StatusCode, message, reply);
                        return;
                    }
                    SendToSelf(new NothingToDo());
                });
            }
        }
예제 #4
0
        public void Send(NodeConnectionInfo dest, TimeoutNowRequest req)
        {
            LogStatus("timeout to " + dest, async() =>
            {
                var requestUri = string.Format("raft/timeoutNow?term={0}&from={1}&clusterTopologyId={2}", req.Term, req.From, req.ClusterTopologyId);
                using (var request = CreateRequest(dest, requestUri, HttpMethods.Get))
                {
                    var httpResponseMessage = await request.ExecuteAsync().ConfigureAwait(false);
                    UpdateConnectionFailureCounts(dest, httpResponseMessage);

                    var reply = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
                    if (httpResponseMessage.IsSuccessStatusCode == false)
                    {
                        _log.Warn("Error appending entries to {0}. Status: {1}\r\n{2}", dest.Name, httpResponseMessage.StatusCode, httpResponseMessage, reply);
                        return;
                    }
                    SendToSelf(new NothingToDo());
                }
            });
        }
예제 #5
0
        public void Handle(TimeoutNowRequest req)
        {
            if (FromOurTopology(req) == false)
            {
                _log.Info("Got a timeout request message outside my cluster topology (id: {0}), ignoring", req.ClusterTopologyId);
                return;
            }
            if (req.Term < Engine.PersistentState.CurrentTerm)
            {
                _log.Info("Got timeout now request from an older term, ignoring");
                return;
            }
            if (req.From != Engine.CurrentLeader)
            {
                _log.Info("Got timeout now request from {0}, who isn't the current leader, ignoring.",
                          req.From);
                return;
            }

            _log.Info("Got timeout now request from the leader, timing out and forcing immediate election");
            Engine.SetState(RaftEngineState.CandidateByRequest);
        }
예제 #6
0
 public void Send(NodeConnectionInfo dest, TimeoutNowRequest req)
 {
     _sender.Send(dest, req);
 }
예제 #7
0
 public void Send(NodeConnectionInfo dest, TimeoutNowRequest req)
 {
     _parent.AddToQueue(this, dest.Name, req);
 }