Skip to content

Commit

Permalink
server: add fields to migrate from 3.5 to 3.4
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Kanivets <[email protected]>
  • Loading branch information
Bogdan Kanivets committed Jun 2, 2023
1 parent 5773d94 commit 10f4667
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions etcdutl/etcdutl/migrate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (o *migrateOptions) Config() (*migrateConfig, error) {
if err != nil {
return nil, fmt.Errorf("failed to parse target version: %v", err)
}
if c.targetVersion.LessThan(version.V3_5) {
return nil, fmt.Errorf(`target version %q not supported. Minimal "3.5"`, storageVersionToString(c.targetVersion))
if c.targetVersion.LessThan(version.V3_4) {
return nil, fmt.Errorf(`target version %q not supported. Minimal "3.4"`, storageVersionToString(c.targetVersion))
}

dbPath := datadir.ToBackendFileName(o.dataDir)
Expand Down
11 changes: 11 additions & 0 deletions server/storage/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,19 @@ var (
version.V3_6: {
addNewField(Meta, MetaStorageVersionName, emptyStorageVersion),
},
version.V3_5: {
// 'migrate' command from v3.4 to v3.5 isn't supported and will fail with `missing confstate information`
// these fields are added for v3.5 -> v3.4 downgrade only
//
// note about emptyValue:
// even if these fields are used for upgrade, it's safe to set emptyValue
// UnsafeReadConsistentIndex and UnsafeConfStateFromBackend checks for zero-length values
addNewField(Meta, MetaTermKeyName, emptyValue),
addNewField(Meta, MetaConfStateName, emptyValue),
},
}
// emptyStorageVersion is used for v3.6 Step for the first time, in all other version StoragetVersion should be set by migrator.
// Adding a addNewField for StorageVersion we can reuse logic to remove it when downgrading to v3.5
emptyStorageVersion = []byte("")
emptyValue = []byte("")
)
23 changes: 23 additions & 0 deletions tests/e2e/utl_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import (
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

type bucketKey struct {
bucket backend.Bucket
key []byte
}

func TestEtctlutlMigrate(t *testing.T) {
lastReleaseBinary := e2e.BinPath.EtcdLastRelease

Expand All @@ -45,6 +50,8 @@ func TestEtctlutlMigrate(t *testing.T) {

expectLogsSubString string
expectStorageVersion *semver.Version

expectNonFoundKeys []bucketKey
}{
{
name: "Invalid target version string",
Expand All @@ -70,6 +77,16 @@ func TestEtctlutlMigrate(t *testing.T) {
expectLogsSubString: `Error: wrong target version format, expected "X.Y", got "3.6.0"`,
expectStorageVersion: &version.V3_6,
},
{
name: "Downgrade v3.5 to v3.4 should work",
clusterVersion: e2e.LastVersion,
targetVersion: "3.4",
expectLogsSubString: "updated storage version\t" + `{"new-storage-version": "3.4.0"}`,
expectNonFoundKeys: []bucketKey{
{bucket: schema.Meta, key: schema.MetaTermKeyName},
{bucket: schema.Meta, key: schema.MetaConfStateName},
},
},
{
name: "Migrate v3.5 to v3.5 is no-op",
clusterVersion: e2e.LastVersion,
Expand Down Expand Up @@ -170,6 +187,12 @@ func TestEtctlutlMigrate(t *testing.T) {

ver := schema.ReadStorageVersion(be.ReadTx())
assert.Equal(t, tc.expectStorageVersion, ver)

for _, bk := range tc.expectNonFoundKeys {
_, vs := be.ReadTx().UnsafeRange(bk.bucket, bk.key, nil, 0)
assert.Zero(t, len(vs))
}

})
}
}

0 comments on commit 10f4667

Please sign in to comment.