etcd/etcdserver/cluster_util_test.go
Xiang Li 6699107f61 *: add cluster version and cluster version detection.
Cluster version is the min major.minor of all members in
the etcd cluster. Cluster version is set to the min version
that a etcd member is compatible with when first bootstrapp.

During a rolling upgrades, the cluster version will be updated
automatically.

For example:

```
Cluster [a:1, b:1 ,c:1] -> clusterVersion 1

update a -> 2, b -> 2

after a detection

Cluster [a:2, b:2 ,c:1] -> clusterVersion 1, since c is still 1

update c -> 2

after a detection

Cluster [a:2, b:2 ,c:2] -> clusterVersion 2
```

The API/raft component can utilize clusterVersion to determine if
it can accept a client request or a raft RPC.

We choose polling rather than pushing since we want to use the same
logic for cluster version detection and (TODO) cluster version checking.

Before a member actually joins a etcd cluster, it should check the version
of the cluster. Push does not work since the other members cannot push
version info to it before it actually joins. Moreover, we do not want our
raft RPC system (which is doing the heartbeat pushing) to coordinate cluster version.
2015-04-29 11:31:59 -07:00

59 lines
1.5 KiB
Go

// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package etcdserver
import (
"reflect"
"testing"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
)
func TestDecideClusterVersion(t *testing.T) {
tests := []struct {
vers map[string]string
wdver *semver.Version
}{
{
map[string]string{"a": "2.0.0"},
semver.Must(semver.NewVersion("2.0.0")),
},
// unknow
{
map[string]string{"a": ""},
nil,
},
{
map[string]string{"a": "2.0.0", "b": "2.1.0", "c": "2.1.0"},
semver.Must(semver.NewVersion("2.0.0")),
},
{
map[string]string{"a": "2.1.0", "b": "2.1.0", "c": "2.1.0"},
semver.Must(semver.NewVersion("2.1.0")),
},
{
map[string]string{"a": "", "b": "2.1.0", "c": "2.1.0"},
nil,
},
}
for i, tt := range tests {
dver := decideClusterVersion(tt.vers)
if !reflect.DeepEqual(dver, tt.wdver) {
t.Errorf("#%d: ver = %+v, want %+v", i, dver, tt.wdver)
}
}
}