Skip to content

Commit

Permalink
Allow v2deprecation mode of write-only
Browse files Browse the repository at this point in the history
Signed-off-by: Geeta Gharpure <geetagh@amazon.com>
  • Loading branch information
Geeta Gharpure committed Jun 1, 2023
1 parent f7b83bd commit 338f747
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion server/config/v2_deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const (
// V2store is neither written nor read for 3.6. v2snapshot is published only for backward compatibility
V2_DEPR_2_GONE = V2DeprecationEnum("gone")

V2_DEPR_DEFAULT = V2_DEPR_2_GONE
//TODO geetasg does thie default need to change
V2_DEPR_DEFAULT = V2_DEPR_1_WRITE_ONLY
)

func (e V2DeprecationEnum) IsAtLeast(v2d V2DeprecationEnum) bool {
Expand Down
4 changes: 4 additions & 0 deletions server/etcdserver/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ func recoverSnapshot(cfg config.ServerConfig, st v2store.Store, be backend.Backe
}

if snapshot != nil {
if err := serverstorage.AssertV2DeprecationStage(cfg.Logger, cfg.V2Deprecation); err != nil {
cfg.Logger.Panic("illegal v2store content", zap.Error(err))
}

if be, err = serverstorage.RecoverSnapshotBackend(cfg, be, *snapshot, beExist, beHooks); err != nil {
cfg.Logger.Panic("failed to recover v3 backend from snapshot", zap.Error(err))
}
Expand Down
1 change: 1 addition & 0 deletions server/etcdserver/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func TestBootstrapBackend(t *testing.T) {
DataDir: dataDir,
BackendFreelistType: bolt.FreelistArrayType,
Logger: zaptest.NewLogger(t),
V2Deprecation: config.V2_DEPR_DEFAULT,
}

if tt.prepareData != nil {
Expand Down
4 changes: 4 additions & 0 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,10 @@ func (s *EtcdServer) applySnapshot(ep *etcdProgress, toApply *toApply) {
lg.Info("restored auth store")
}

if err := serverstorage.AssertV2DeprecationStage(lg, s.Cfg.V2Deprecation); err != nil {
lg.Panic("illegal v2store content", zap.Error(err))
}

s.cluster.SetBackend(schema.NewMembershipBackend(lg, newbe))

lg.Info("restoring cluster configuration")
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ func TestSnapshotOrdering(t *testing.T) {
s := &EtcdServer{
lgMu: new(sync.RWMutex),
lg: lg,
Cfg: config.ServerConfig{Logger: lg, DataDir: testdir, SnapshotCatchUpEntries: DefaultSnapshotCatchUpEntries, V2Deprecation: config.V2_DEPR_2_GONE},
Cfg: config.ServerConfig{Logger: lg, DataDir: testdir, SnapshotCatchUpEntries: DefaultSnapshotCatchUpEntries, V2Deprecation: config.V2_DEPR_DEFAULT},
r: *r,
snapshotter: snap.New(lg, snapdir),
cluster: cl,
Expand Down
12 changes: 9 additions & 3 deletions server/storage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ import (
// AssertNoV2StoreContent -> depending on the deprecation stage, warns or report an error
// if the v2store contains custom content.
func AssertNoV2StoreContent(lg *zap.Logger, st v2store.Store, deprecationStage config.V2DeprecationEnum) error {
//TODO remove this method.
metaOnly, err := membership.IsMetaStoreOnly(st)
if err != nil {
return err
}
if metaOnly {
return nil
}
if deprecationStage.IsAtLeast(config.V2_DEPR_1_WRITE_ONLY) {
return fmt.Errorf("detected disallowed custom content in v2store for stage --v2-deprecation=%s", deprecationStage)
return AssertV2DeprecationStage(lg, deprecationStage)
}

func AssertV2DeprecationStage(lg *zap.Logger, deprecationStage config.V2DeprecationEnum) error {
//TODO geetasg should the write-only be supported? Update TestV2DeprecationFlags accordingly
//supported stages are "write-only", "write-only-drop-data" and "gone"
if !deprecationStage.IsAtLeast(config.V2_DEPR_1_WRITE_ONLY) {
return fmt.Errorf("Unsupported stage --v2-deprecation=%s", deprecationStage)
}
lg.Warn("detected custom v2store content. Etcd v3.5 is the last version allowing to access it using API v2. Please remove the content.")
return nil
}

Expand Down
9 changes: 6 additions & 3 deletions tests/e2e/v2store_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ func TestV2DeprecationFlags(t *testing.T) {
assertVerifyCannotStartV2deprecationNotYet(t, memberDataDir)
})

t.Run("--v2-deprecation=write-only fails", func(t *testing.T) {
assertVerifyCannotStartV2deprecationWriteOnly(t, memberDataDir)
})
//It is ok to start with write-only in 3.6
/*
t.Run("--v2-deprecation=write-only fails", func(t *testing.T) {
assertVerifyCannotStartV2deprecationWriteOnly(t, memberDataDir)
})
*/

}

Expand Down

0 comments on commit 338f747

Please sign in to comment.