Use region instead of datacenter for version checking
This commit is contained in:
parent
f088446d48
commit
045f346293
|
@ -776,7 +776,7 @@ func (s *Server) addRaftPeer(m serf.Member, parts *serverParts) error {
|
|||
// but we want to avoid doing that if possible to prevent useless Raft
|
||||
// log entries. If the address is the same but the ID changed, remove the
|
||||
// old server before adding the new one.
|
||||
minRaftProtocol, err := MinRaftProtocol(s.config.Datacenter, members)
|
||||
minRaftProtocol, err := MinRaftProtocol(s.config.Region, members)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -848,7 +848,7 @@ func (s *Server) removeRaftPeer(m serf.Member, parts *serverParts) error {
|
|||
return err
|
||||
}
|
||||
|
||||
minRaftProtocol, err := MinRaftProtocol(s.config.Datacenter, s.serf.Members())
|
||||
minRaftProtocol, err := MinRaftProtocol(s.config.Region, s.serf.Members())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -854,7 +854,7 @@ func TestLeader_UpgradeRaftVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range []*Server{s1, s3} {
|
||||
minVer, err := MinRaftProtocol("dc1", s.Members())
|
||||
minVer, err := MinRaftProtocol(s1.config.Region, s.Members())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -184,9 +184,9 @@ func (s *Server) maybeBootstrap() {
|
|||
// Attempt a live bootstrap!
|
||||
var configuration raft.Configuration
|
||||
var addrs []string
|
||||
minRaftVersion, err := MinRaftProtocol(s.config.Datacenter, members)
|
||||
minRaftVersion, err := MinRaftProtocol(s.config.Region, members)
|
||||
if err != nil {
|
||||
s.logger.Printf("[ERR] consul: Failed to read server raft versions: %v", err)
|
||||
s.logger.Printf("[ERR] nomad: Failed to read server raft versions: %v", err)
|
||||
}
|
||||
|
||||
for _, server := range servers {
|
||||
|
|
|
@ -149,11 +149,11 @@ func ServersMeetMinimumVersion(members []serf.Member, minVersion *version.Versio
|
|||
}
|
||||
|
||||
// MinRaftProtocol returns the lowest supported Raft protocol among alive servers
|
||||
// in the given datacenter.
|
||||
func MinRaftProtocol(datacenter string, members []serf.Member) (int, error) {
|
||||
// in the given region.
|
||||
func MinRaftProtocol(region string, members []serf.Member) (int, error) {
|
||||
minVersion := -1
|
||||
for _, m := range members {
|
||||
if m.Tags["role"] != "nomad" || m.Tags["dc"] != datacenter || m.Status != serf.StatusAlive {
|
||||
if m.Tags["role"] != "nomad" || m.Tags["region"] != region || m.Status != serf.StatusAlive {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -154,14 +154,14 @@ func TestServersMeetMinimumVersion(t *testing.T) {
|
|||
|
||||
func TestMinRaftProtocol(t *testing.T) {
|
||||
t.Parallel()
|
||||
makeMember := func(version, datacenter string) serf.Member {
|
||||
makeMember := func(version, region string) serf.Member {
|
||||
return serf.Member{
|
||||
Name: "foo",
|
||||
Addr: net.IP([]byte{127, 0, 0, 1}),
|
||||
Tags: map[string]string{
|
||||
"role": "nomad",
|
||||
"region": "aws",
|
||||
"dc": datacenter,
|
||||
"region": region,
|
||||
"dc": "dc1",
|
||||
"port": "10000",
|
||||
"vsn": "1",
|
||||
"raft_vsn": version,
|
||||
|
@ -171,10 +171,10 @@ func TestMinRaftProtocol(t *testing.T) {
|
|||
}
|
||||
|
||||
cases := []struct {
|
||||
members []serf.Member
|
||||
datacenter string
|
||||
expected int
|
||||
err error
|
||||
members []serf.Member
|
||||
region string
|
||||
expected int
|
||||
err error
|
||||
}{
|
||||
// No servers, error
|
||||
{
|
||||
|
@ -185,61 +185,61 @@ func TestMinRaftProtocol(t *testing.T) {
|
|||
// One server
|
||||
{
|
||||
members: []serf.Member{
|
||||
makeMember("1", "dc1"),
|
||||
makeMember("1", "global"),
|
||||
},
|
||||
datacenter: "dc1",
|
||||
expected: 1,
|
||||
region: "global",
|
||||
expected: 1,
|
||||
},
|
||||
// One server, bad version formatting
|
||||
{
|
||||
members: []serf.Member{
|
||||
makeMember("asdf", "dc1"),
|
||||
makeMember("asdf", "global"),
|
||||
},
|
||||
datacenter: "dc1",
|
||||
expected: -1,
|
||||
err: errors.New(`strconv.Atoi: parsing "asdf": invalid syntax`),
|
||||
region: "global",
|
||||
expected: -1,
|
||||
err: errors.New(`strconv.Atoi: parsing "asdf": invalid syntax`),
|
||||
},
|
||||
// One server, wrong datacenter
|
||||
{
|
||||
members: []serf.Member{
|
||||
makeMember("1", "dc1"),
|
||||
makeMember("1", "global"),
|
||||
},
|
||||
datacenter: "dc2",
|
||||
expected: -1,
|
||||
err: errors.New("no servers found"),
|
||||
region: "nope",
|
||||
expected: -1,
|
||||
err: errors.New("no servers found"),
|
||||
},
|
||||
// Multiple servers, different versions
|
||||
{
|
||||
members: []serf.Member{
|
||||
makeMember("1", "dc1"),
|
||||
makeMember("2", "dc1"),
|
||||
makeMember("1", "global"),
|
||||
makeMember("2", "global"),
|
||||
},
|
||||
datacenter: "dc1",
|
||||
expected: 1,
|
||||
region: "global",
|
||||
expected: 1,
|
||||
},
|
||||
// Multiple servers, same version
|
||||
{
|
||||
members: []serf.Member{
|
||||
makeMember("2", "dc1"),
|
||||
makeMember("2", "dc1"),
|
||||
makeMember("2", "global"),
|
||||
makeMember("2", "global"),
|
||||
},
|
||||
datacenter: "dc1",
|
||||
expected: 2,
|
||||
region: "global",
|
||||
expected: 2,
|
||||
},
|
||||
// Multiple servers, multiple datacenters
|
||||
{
|
||||
members: []serf.Member{
|
||||
makeMember("3", "dc1"),
|
||||
makeMember("2", "dc1"),
|
||||
makeMember("1", "dc2"),
|
||||
makeMember("3", "r1"),
|
||||
makeMember("2", "r1"),
|
||||
makeMember("1", "r2"),
|
||||
},
|
||||
datacenter: "dc1",
|
||||
expected: 2,
|
||||
region: "r1",
|
||||
expected: 2,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
result, err := MinRaftProtocol(tc.datacenter, tc.members)
|
||||
result, err := MinRaftProtocol(tc.region, tc.members)
|
||||
if result != tc.expected {
|
||||
t.Fatalf("bad: %v, %v, %v", result, tc.expected, tc)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue