From 9dfc9db57b892289b31a388807d2c3e2477aa7d7 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 6 Jul 2017 17:18:18 -0700 Subject: [PATCH] Update raft to get hashicorp/raft#212 fix --- vendor/github.com/hashicorp/raft/Makefile | 2 +- vendor/github.com/hashicorp/raft/api.go | 6 +-- vendor/github.com/hashicorp/raft/peersjson.go | 52 +++++++++++++++++++ vendor/github.com/hashicorp/raft/raft.go | 3 ++ vendor/vendor.json | 6 +-- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/vendor/github.com/hashicorp/raft/Makefile b/vendor/github.com/hashicorp/raft/Makefile index 49f82992397..0910e2ceb21 100644 --- a/vendor/github.com/hashicorp/raft/Makefile +++ b/vendor/github.com/hashicorp/raft/Makefile @@ -4,7 +4,7 @@ test: go test -timeout=60s ./... integ: test - INTEG_TESTS=yes go test -timeout=5s -run=Integ ./... + INTEG_TESTS=yes go test -timeout=25s -run=Integ ./... deps: go get -d -v ./... diff --git a/vendor/github.com/hashicorp/raft/api.go b/vendor/github.com/hashicorp/raft/api.go index 2fd78e78402..147cde295c1 100644 --- a/vendor/github.com/hashicorp/raft/api.go +++ b/vendor/github.com/hashicorp/raft/api.go @@ -979,10 +979,10 @@ func (r *Raft) Stats() map[string]string { } last := r.LastContact() - if last.IsZero() { - s["last_contact"] = "never" - } else if r.getState() == Leader { + if r.getState() == Leader { s["last_contact"] = "0" + } else if last.IsZero() { + s["last_contact"] = "never" } else { s["last_contact"] = fmt.Sprintf("%v", time.Now().Sub(last)) } diff --git a/vendor/github.com/hashicorp/raft/peersjson.go b/vendor/github.com/hashicorp/raft/peersjson.go index c55fdbb43dd..38ca2a8b845 100644 --- a/vendor/github.com/hashicorp/raft/peersjson.go +++ b/vendor/github.com/hashicorp/raft/peersjson.go @@ -44,3 +44,55 @@ func ReadPeersJSON(path string) (Configuration, error) { } 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 +} diff --git a/vendor/github.com/hashicorp/raft/raft.go b/vendor/github.com/hashicorp/raft/raft.go index aa8fe820823..0f89ccaa4d6 100644 --- a/vendor/github.com/hashicorp/raft/raft.go +++ b/vendor/github.com/hashicorp/raft/raft.go @@ -5,6 +5,7 @@ import ( "container/list" "fmt" "io" + "io/ioutil" "time" "github.com/armon/go-metrics" @@ -1238,6 +1239,7 @@ func (r *Raft) installSnapshot(rpc RPC, req *InstallSnapshotRequest) { } var rpcErr error 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) }() @@ -1250,6 +1252,7 @@ func (r *Raft) installSnapshot(rpc RPC, req *InstallSnapshotRequest) { // Ignore an older term 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 } diff --git a/vendor/vendor.json b/vendor/vendor.json index 974466edf35..2a50c6c544a 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -845,10 +845,10 @@ "revision": "a14192a58a694c123d8fe5481d4a4727d6ae82f3" }, { - "checksumSHA1": "wpirHJV/6VEbbD+HyAP2/6Xc0ek=", + "checksumSHA1": "bYn+HDmt7YLFvEV6DagMup8mkZE=", "path": "github.com/hashicorp/raft", - "revision": "aaad9f10266e089bd401e7a6487651a69275641b", - "revisionTime": "2016-11-10T00:52:40Z" + "revision": "e5e581e04af7c46974b99195347cc0c380c0d841", + "revisionTime": "2017-06-09T23:09:26Z" }, { "checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",