Update raft to get hashicorp/raft#212 fix
This commit is contained in:
parent
39edf23fd5
commit
a1bdc26464
|
@ -4,7 +4,7 @@ test:
|
||||||
go test -timeout=60s ./...
|
go test -timeout=60s ./...
|
||||||
|
|
||||||
integ: test
|
integ: test
|
||||||
INTEG_TESTS=yes go test -timeout=5s -run=Integ ./...
|
INTEG_TESTS=yes go test -timeout=25s -run=Integ ./...
|
||||||
|
|
||||||
deps:
|
deps:
|
||||||
go get -d -v ./...
|
go get -d -v ./...
|
||||||
|
|
|
@ -979,10 +979,10 @@ func (r *Raft) Stats() map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
last := r.LastContact()
|
last := r.LastContact()
|
||||||
if last.IsZero() {
|
if r.getState() == Leader {
|
||||||
s["last_contact"] = "never"
|
|
||||||
} else if r.getState() == Leader {
|
|
||||||
s["last_contact"] = "0"
|
s["last_contact"] = "0"
|
||||||
|
} else if last.IsZero() {
|
||||||
|
s["last_contact"] = "never"
|
||||||
} else {
|
} else {
|
||||||
s["last_contact"] = fmt.Sprintf("%v", time.Now().Sub(last))
|
s["last_contact"] = fmt.Sprintf("%v", time.Now().Sub(last))
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,3 +44,55 @@ func ReadPeersJSON(path string) (Configuration, error) {
|
||||||
}
|
}
|
||||||
return configuration, nil
|
return configuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// configEntry is used when decoding a new-style peers.json.
|
||||||
|
type configEntry struct {
|
||||||
|
// ID is the ID of the server (a UUID, usually).
|
||||||
|
ID ServerID `json:"id"`
|
||||||
|
|
||||||
|
// Address is the host:port of the server.
|
||||||
|
Address ServerAddress `json:"address"`
|
||||||
|
|
||||||
|
// NonVoter controls the suffrage. We choose this sense so people
|
||||||
|
// can leave this out and get a Voter by default.
|
||||||
|
NonVoter bool `json:"non_voter"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadConfigJSON reads a new-style peers.json and returns a configuration
|
||||||
|
// structure. This can be used to perform manual recovery when running protocol
|
||||||
|
// versions that use server IDs.
|
||||||
|
func ReadConfigJSON(path string) (Configuration, error) {
|
||||||
|
// Read in the file.
|
||||||
|
buf, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return Configuration{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse it as JSON.
|
||||||
|
var peers []configEntry
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(buf))
|
||||||
|
if err := dec.Decode(&peers); err != nil {
|
||||||
|
return Configuration{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map it into the new-style configuration structure.
|
||||||
|
var configuration Configuration
|
||||||
|
for _, peer := range peers {
|
||||||
|
suffrage := Voter
|
||||||
|
if peer.NonVoter {
|
||||||
|
suffrage = Nonvoter
|
||||||
|
}
|
||||||
|
server := Server{
|
||||||
|
Suffrage: suffrage,
|
||||||
|
ID: peer.ID,
|
||||||
|
Address: peer.Address,
|
||||||
|
}
|
||||||
|
configuration.Servers = append(configuration.Servers, server)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We should only ingest valid configurations.
|
||||||
|
if err := checkConfiguration(configuration); err != nil {
|
||||||
|
return Configuration{}, err
|
||||||
|
}
|
||||||
|
return configuration, nil
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/armon/go-metrics"
|
"github.com/armon/go-metrics"
|
||||||
|
@ -1238,6 +1239,7 @@ func (r *Raft) installSnapshot(rpc RPC, req *InstallSnapshotRequest) {
|
||||||
}
|
}
|
||||||
var rpcErr error
|
var rpcErr error
|
||||||
defer func() {
|
defer func() {
|
||||||
|
io.Copy(ioutil.Discard, rpc.Reader) // ensure we always consume all the snapshot data from the stream [see issue #212]
|
||||||
rpc.Respond(resp, rpcErr)
|
rpc.Respond(resp, rpcErr)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -1250,6 +1252,7 @@ func (r *Raft) installSnapshot(rpc RPC, req *InstallSnapshotRequest) {
|
||||||
|
|
||||||
// Ignore an older term
|
// Ignore an older term
|
||||||
if req.Term < r.getCurrentTerm() {
|
if req.Term < r.getCurrentTerm() {
|
||||||
|
r.logger.Printf("[INFO] raft: Ignoring installSnapshot request with older term of %d vs currentTerm %d", req.Term, r.getCurrentTerm())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -845,10 +845,10 @@
|
||||||
"revision": "a14192a58a694c123d8fe5481d4a4727d6ae82f3"
|
"revision": "a14192a58a694c123d8fe5481d4a4727d6ae82f3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "wpirHJV/6VEbbD+HyAP2/6Xc0ek=",
|
"checksumSHA1": "bYn+HDmt7YLFvEV6DagMup8mkZE=",
|
||||||
"path": "github.com/hashicorp/raft",
|
"path": "github.com/hashicorp/raft",
|
||||||
"revision": "aaad9f10266e089bd401e7a6487651a69275641b",
|
"revision": "e5e581e04af7c46974b99195347cc0c380c0d841",
|
||||||
"revisionTime": "2016-11-10T00:52:40Z"
|
"revisionTime": "2017-06-09T23:09:26Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",
|
"checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",
|
||||||
|
|
Loading…
Reference in New Issue