mirror of https://github.com/status-im/consul.git
Updates vendored Raft library.
This pulls in https://github.com/hashicorp/raft/pull/207 to get support for the new-style peers.json recovery file.
This commit is contained in:
parent
ae4dfb1e9e
commit
3d43031fbf
|
@ -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
|
||||||
|
}
|
||||||
|
|
|
@ -612,10 +612,10 @@
|
||||||
"revisionTime": "2015-11-16T02:03:38Z"
|
"revisionTime": "2015-11-16T02:03:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "NvFexY/rs9sPfve+ny/rkMkCL5M=",
|
"checksumSHA1": "8Na6qG9taUXHDunMYecGxbHbJKE=",
|
||||||
"path": "github.com/hashicorp/raft",
|
"path": "github.com/hashicorp/raft",
|
||||||
"revision": "6b063a18bfe6e0da3fdc2b9bf6256be9c0a4849a",
|
"revision": "939ebd2103731c2f38c7964d8dd24af0e1b26dc3",
|
||||||
"revisionTime": "2017-03-16T02:42:32Z",
|
"revisionTime": "2017-05-04T20:16:11Z",
|
||||||
"version": "library-v2-stage-one",
|
"version": "library-v2-stage-one",
|
||||||
"versionExact": "library-v2-stage-one"
|
"versionExact": "library-v2-stage-one"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue