Merge branch 'master' of https://github.com/goraft/raft
commit
14c4999b1c
4
event.go
4
event.go
|
@ -7,8 +7,8 @@ const (
|
|||
AddPeerEventType = "addPeer"
|
||||
RemovePeerEventType = "removePeer"
|
||||
|
||||
HeartbeatTimeoutEventType = "heartbeatTimeout"
|
||||
ElectionTimeoutThresholdEventType = "electionTimeoutThreshold"
|
||||
HeartbeatTimeoutEventType = "heartbeatTimeout"
|
||||
ElectionTimeoutThresholdEventType = "electionTimeoutThreshold"
|
||||
)
|
||||
|
||||
// Event represents an action that occurred within the Raft library.
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Parts from this transporter were heavily influenced by Peter Bougon's
|
||||
|
@ -45,7 +44,7 @@ func NewHTTPTransporter(prefix string) *HTTPTransporter {
|
|||
prefix: prefix,
|
||||
appendEntriesPath: fmt.Sprintf("%s%s", prefix, "/appendEntries"),
|
||||
requestVotePath: fmt.Sprintf("%s%s", prefix, "/requestVote"),
|
||||
transport: &http.Transport{DisableKeepAlives: false},
|
||||
transport: &http.Transport{DisableKeepAlives: false},
|
||||
}
|
||||
t.httpClient.Transport = t.transport
|
||||
return t
|
||||
|
@ -166,7 +165,6 @@ func (t *HTTPTransporter) appendEntriesHandler(server Server) http.HandlerFunc {
|
|||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
traceln(server.Name(), "RECV /appendEntries")
|
||||
|
||||
time.Sleep(testHeartbeatTimeout * 2)
|
||||
req := &AppendEntriesRequest{}
|
||||
if _, err := req.Decode(r.Body); err != nil {
|
||||
http.Error(w, "", http.StatusBadRequest)
|
||||
|
|
|
@ -40,7 +40,7 @@ const (
|
|||
// ElectionTimeoutThresholdPercent specifies the threshold at which the server
|
||||
// will dispatch warning events that the heartbeat RTT is too close to the
|
||||
// election timeout.
|
||||
const ElectionTimeoutThresholdPercent = 0.8
|
||||
const ElectionTimeoutThresholdPercent = 0.8
|
||||
|
||||
var stopValue interface{}
|
||||
|
||||
|
@ -606,7 +606,7 @@ func (s *server) followerLoop() {
|
|||
case *AppendEntriesRequest:
|
||||
// If heartbeats get too close to the election timeout then send an event.
|
||||
elapsedTime := time.Now().Sub(since)
|
||||
if elapsedTime > time.Duration(float64(electionTimeout) * ElectionTimeoutThresholdPercent) {
|
||||
if elapsedTime > time.Duration(float64(electionTimeout)*ElectionTimeoutThresholdPercent) {
|
||||
s.DispatchEvent(newEvent(ElectionTimeoutThresholdEventType, elapsedTime, nil))
|
||||
}
|
||||
e.returnValue, update = s.processAppendEntriesRequest(req)
|
||||
|
@ -864,6 +864,8 @@ func (s *server) processCommand(command Command, e *ev) {
|
|||
s.debugln("server.command.timeout")
|
||||
e.c <- CommandTimeoutError
|
||||
}
|
||||
|
||||
entry.commit = nil
|
||||
}()
|
||||
|
||||
// Issue an append entries response for the server.
|
||||
|
@ -982,7 +984,6 @@ func (s *server) processAppendEntriesResponse(resp *AppendEntriesResponse) {
|
|||
default:
|
||||
panic("server unable to send signal to commit channel")
|
||||
}
|
||||
entry.commit = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue