Disallow -v2-deprecation>'not-yet' combined with --enable-v2

This commit is contained in:
Piotr Tabor
2021-05-10 17:44:46 +02:00
parent 7c508741b3
commit ead81df948
9 changed files with 77 additions and 34 deletions

View File

@@ -33,6 +33,7 @@ import (
"go.etcd.io/etcd/client/pkg/v3/types"
"go.etcd.io/etcd/pkg/v3/flags"
"go.etcd.io/etcd/pkg/v3/netutil"
"go.etcd.io/etcd/server/v3/config"
"go.etcd.io/etcd/server/v3/etcdserver"
"go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor"
@@ -402,7 +403,7 @@ type Config struct {
ExperimentalTxnModeWriteWithSharedBuffer bool `json:"experimental-txn-mode-write-with-shared-buffer"`
// V2Deprecation describes phase of API & Storage V2 support
V2Deprecation V2DeprecationEnum `json:"v2-deprecation"`
V2Deprecation config.V2DeprecationEnum `json:"v2-deprecation"`
}
// configYAML holds the config suitable for yaml parsing
@@ -498,7 +499,7 @@ func NewConfig() *Config {
ExperimentalMemoryMlock: false,
ExperimentalTxnModeWriteWithSharedBuffer: true,
V2Deprecation: V2_DEPR_DEFAULT,
V2Deprecation: config.V2_DEPR_DEFAULT,
}
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
return cfg
@@ -800,12 +801,11 @@ func (cfg Config) InitialClusterFromName(name string) (ret string) {
func (cfg Config) IsNewCluster() bool { return cfg.ClusterState == ClusterStateFlagNew }
func (cfg Config) ElectionTicks() int { return int(cfg.ElectionMs / cfg.TickMs) }
func (cfg Config) V2DeprecationEffective() V2DeprecationEnum {
func (cfg Config) V2DeprecationEffective() config.V2DeprecationEnum {
if cfg.V2Deprecation == "" {
return V2_DEPR_DEFAULT
} else {
return cfg.V2Deprecation
return config.V2_DEPR_DEFAULT
}
return cfg.V2Deprecation
}
func (cfg Config) defaultPeerHost() bool {

View File

@@ -226,6 +226,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
ExperimentalMemoryMlock: cfg.ExperimentalMemoryMlock,
ExperimentalTxnModeWriteWithSharedBuffer: cfg.ExperimentalTxnModeWriteWithSharedBuffer,
ExperimentalBootstrapDefragThresholdMegabytes: cfg.ExperimentalBootstrapDefragThresholdMegabytes,
V2Deprecation: cfg.V2DeprecationEffective(),
}
if srvcfg.ExperimentalEnableDistributedTracing {
@@ -696,6 +697,9 @@ func (e *Etcd) serveClients() (err error) {
// Start a client server goroutine for each listen address
var h http.Handler
if e.Config().EnableV2 {
if e.Config().V2DeprecationEffective().IsAtLeast(config.V2_DEPR_1_WRITE_ONLY) {
return fmt.Errorf("--enable-v2 and --v2-deprecation=%s are mutually exclusive", e.Config().V2DeprecationEffective())
}
e.cfg.logger.Warn("Flag `enable-v2` is deprecated and will get removed in etcd 3.6.")
if len(e.Config().ExperimentalEnableV2V3) > 0 {
e.cfg.logger.Warn("Flag `experimental-enable-v2v3` is deprecated and will get removed in etcd 3.6.")

View File

@@ -1,46 +0,0 @@
// Copyright 2021 The etcd Authors
//
// 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 embed
type V2DeprecationEnum string
const (
// Default in v3.5. Issues a warning if v2store have meaningful content.
V2_DEPR_0_NOT_YET = V2DeprecationEnum("not-yet")
// Default in v3.6. Meaningful v2 state is not allowed.
// The V2 files are maintained for v3.5 rollback.
V2_DEPR_1_WRITE_ONLY = V2DeprecationEnum("write-only")
// V2store is WIPED if found !!!
V2_DEPR_1_WRITE_ONLY_DROP = V2DeprecationEnum("write-only-drop-data")
// V2store is neither written nor read. Usage of this configuration is blocking
// ability to rollback to etcd v3.5.
V2_DEPR_2_GONE = V2DeprecationEnum("gone")
V2_DEPR_DEFAULT = V2_DEPR_0_NOT_YET
)
func (e V2DeprecationEnum) IsAtLeast(v2d V2DeprecationEnum) bool {
return e.level() >= v2d.level()
}
func (e V2DeprecationEnum) level() int {
switch e {
case V2_DEPR_0_NOT_YET: return 0
case V2_DEPR_1_WRITE_ONLY: return 1
case V2_DEPR_1_WRITE_ONLY_DROP: return 2
case V2_DEPR_2_GONE: return 3
}
panic("Unknown V2DeprecationEnum: " + e)
}

View File

@@ -1,41 +0,0 @@
// Copyright 2021 The etcd Authors
//
// 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 embed
import "testing"
func TestV2DeprecationEnum_IsAtLeast(t *testing.T) {
tests := []struct {
e V2DeprecationEnum
v2d V2DeprecationEnum
want bool
}{
{V2_DEPR_0_NOT_YET, V2_DEPR_0_NOT_YET, true},
{V2_DEPR_0_NOT_YET, V2_DEPR_1_WRITE_ONLY_DROP, false},
{V2_DEPR_0_NOT_YET, V2_DEPR_2_GONE, false},
{V2_DEPR_2_GONE, V2_DEPR_1_WRITE_ONLY_DROP, true},
{V2_DEPR_2_GONE, V2_DEPR_0_NOT_YET, true},
{V2_DEPR_2_GONE, V2_DEPR_2_GONE, true},
{V2_DEPR_1_WRITE_ONLY, V2_DEPR_1_WRITE_ONLY_DROP, false},
{V2_DEPR_1_WRITE_ONLY_DROP, V2_DEPR_1_WRITE_ONLY, true},
}
for _, tt := range tests {
t.Run(string(tt.e) + " >= " + string(tt.v2d), func(t *testing.T) {
if got := tt.e.IsAtLeast(tt.v2d); got != tt.want {
t.Errorf("IsAtLeast() = %v, want %v", got, tt.want)
}
})
}
}