Skip to content

Commit

Permalink
etcdserver: remove v2 version set; e2e: fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
YoyinZyc committed Dec 6, 2019
1 parent ed5a01a commit 5b86d3d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
7 changes: 6 additions & 1 deletion etcdserver/api/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ func (c *RaftCluster) Recover(onSet func(*zap.Logger, *semver.Version)) {
defer c.Unlock()

c.members, c.removed = membersFromStore(c.lg, c.v2store)
c.version = clusterVersionFromBackend(c.lg, c.be)
if c.be != nil {
c.version = clusterVersionFromBackend(c.lg, c.be)
} else {
c.version = clusterVersionFromStore(c.lg, c.v2store)
}

mustDetectDowngrade(c.lg, c.version)
onSet(c.lg, c.version)

Expand Down
6 changes: 1 addition & 5 deletions etcdserver/apply_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import (
"path"
"time"

"go.etcd.io/etcd/etcdserver/api"
"go.etcd.io/etcd/etcdserver/api/membership"
"go.etcd.io/etcd/etcdserver/api/v2store"
"go.etcd.io/etcd/pkg/pbutil"

"github.com/coreos/go-semver/semver"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -91,10 +89,8 @@ func (a *applierV2store) Put(r *RequestV2) Response {
// return an empty response since there is no consumer.
return Response{}
}
// remove v2 version set to avoid the conflict between v2 and v3.
if r.Path == membership.StoreClusterVersionKey() {
if a.cluster != nil {
a.cluster.SetVersion(semver.Must(semver.NewVersion(r.Val)), api.UpdateCapability)
}
// return an empty response since there is no consumer.
return Response{}
}
Expand Down
2 changes: 1 addition & 1 deletion etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func (s *EtcdServer) adjustTicks() {
func (s *EtcdServer) Start() {
s.start()
s.goAttach(func() { s.adjustTicks() })
s.goAttach(func() { s.publishV3(s.Cfg.ReqTimeout()) })
s.goAttach(func() { s.publish(s.Cfg.ReqTimeout()) })
s.goAttach(s.purgeFile)
s.goAttach(func() { monitorFileDescriptor(s.getLogger(), s.stopping) })
s.goAttach(s.monitorVersions)
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro
for i := range etcdCfgs {
etcdCfgs[i].initialCluster = strings.Join(initialCluster, ",")
etcdCfgs[i].args = append(etcdCfgs[i].args, initialClusterArgs...)
etcdCfgs[i].args = append(etcdCfgs[i].args, "--logger=zap")
}

return etcdCfgs
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/ctl_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func testCtlV2Backup(t *testing.T, snapCount int, v3 bool) {

if v3 {
// v3 must lock the db to backup, so stop process
time.Sleep(time.Second)
if err := epc1.Stop(); err != nil {
t.Fatal(err)
}
Expand Down
23 changes: 16 additions & 7 deletions tests/e2e/ctl_v3_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import (
func TestCtlV3Migrate(t *testing.T) {
defer testutil.AfterTest(t)

epc := setupEtcdctlTest(t, &configNoTLS, false)
cfg := configNoTLS
cfg.enableV2 = true
epc := setupEtcdctlTest(t, &cfg, false)
defer func() {
if errC := epc.Close(); errC != nil {
t.Fatalf("error closing etcd processes (%v)", errC)
Expand Down Expand Up @@ -69,10 +71,6 @@ func TestCtlV3Migrate(t *testing.T) {
t.Fatal(err)
}

// to ensure revision increment is continuous from migrated v2 data
if err := ctlV3Put(cx, "test", "value", ""); err != nil {
t.Fatal(err)
}
cli, err := clientv3.New(clientv3.Config{
Endpoints: epc.EndpointsV3(),
DialTimeout: 3 * time.Second,
Expand All @@ -85,11 +83,22 @@ func TestCtlV3Migrate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
rev := resp.Header.Revision
// to ensure revision increment is continuous from migrated v2 data
if err := ctlV3Put(cx, "test", "value", ""); err != nil {
t.Fatal(err)
}

resp, err = cli.Get(context.TODO(), "test")
if err != nil {
t.Fatal(err)
}
if len(resp.Kvs) != 1 {
t.Fatalf("len(resp.Kvs) expected 1, got %+v", resp.Kvs)
}
if resp.Kvs[0].CreateRevision != 7 {
t.Fatalf("resp.Kvs[0].CreateRevision expected 7, got %d", resp.Kvs[0].CreateRevision)

if resp.Kvs[0].CreateRevision <= rev {
t.Fatalf("expected revision increment is continuous from migrated v2, got %d", resp.Kvs[0].CreateRevision)
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/etcd_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
const exampleConfigFile = "../../etcd.conf.yml.sample"

func TestEtcdExampleConfig(t *testing.T) {
proc, err := spawnCmd([]string{binDir + "/etcd", "--config-file", exampleConfigFile})
proc, err := spawnCmd([]string{binDir + "/etcd", "--config-file", exampleConfigFile, "--logger=zap"})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -70,6 +70,7 @@ func TestEtcdMultiPeer(t *testing.T) {
"--listen-peer-urls", fmt.Sprintf("http://127.0.0.1:%d,http://127.0.0.1:%d", etcdProcessBasePort+i, etcdProcessBasePort+len(peers)+i),
"--initial-advertise-peer-urls", fmt.Sprintf("http://127.0.0.1:%d", etcdProcessBasePort+i),
"--initial-cluster", ic,
"--logger=zap",
}
p, err := spawnCmd(args)
if err != nil {
Expand Down Expand Up @@ -100,6 +101,7 @@ func TestEtcdUnixPeers(t *testing.T) {
"--listen-peer-urls", "unix://etcd.unix:1",
"--initial-advertise-peer-urls", "unix://etcd.unix:1",
"--initial-cluster", "e1=unix://etcd.unix:1",
"--logger=zap",
},
)
defer os.Remove("etcd.unix:1")
Expand Down Expand Up @@ -148,6 +150,7 @@ func TestEtcdPeerCNAuth(t *testing.T) {
"--listen-peer-urls", fmt.Sprintf("https://127.0.0.1:%d,https://127.0.0.1:%d", etcdProcessBasePort+i, etcdProcessBasePort+len(peers)+i),
"--initial-advertise-peer-urls", fmt.Sprintf("https://127.0.0.1:%d", etcdProcessBasePort+i),
"--initial-cluster", ic,
"--logger=zap",
}

var args []string
Expand Down Expand Up @@ -225,6 +228,7 @@ func TestEtcdPeerNameAuth(t *testing.T) {
"--listen-peer-urls", fmt.Sprintf("https://127.0.0.1:%d,https://127.0.0.1:%d", etcdProcessBasePort+i, etcdProcessBasePort+len(peers)+i),
"--initial-advertise-peer-urls", fmt.Sprintf("https://127.0.0.1:%d", etcdProcessBasePort+i),
"--initial-cluster", ic,
"--logger=zap",
}

var args []string
Expand Down

0 comments on commit 5b86d3d

Please sign in to comment.