Skip to content

Commit

Permalink
Merge pull request #19350 from aladesawe/server-wal-version-unexporte…
Browse files Browse the repository at this point in the history
…d-return

Migrate WALVersion to fix unexported-return of walVersion
  • Loading branch information
ahrtr authored Feb 10, 2025
2 parents fa2926a + 94758c1 commit ad33010
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion etcdutl/etcdutl/migrate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (o *migrateOptions) Config() (*migrateConfig, error) {
type migrateConfig struct {
lg *zap.Logger
targetVersion *semver.Version
walVersion schema.WALVersion
walVersion wal.Version
dataDir string
force bool
}
Expand Down
10 changes: 3 additions & 7 deletions server/storage/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"go.etcd.io/etcd/api/v3/version"
"go.etcd.io/etcd/server/v3/storage/backend"
"go.etcd.io/etcd/server/v3/storage/wal"
)

// Validate checks provided backend to confirm that schema used is supported.
Expand All @@ -47,21 +48,16 @@ func localBinaryVersion() semver.Version {
return semver.Version{Major: v.Major, Minor: v.Minor}
}

type WALVersion interface {
// MinimalEtcdVersion returns minimal etcd version able to interpret WAL log.
MinimalEtcdVersion() *semver.Version
}

// Migrate updates storage schema to provided target version.
// Downgrading requires that provided WAL doesn't contain unsupported entries.
func Migrate(lg *zap.Logger, tx backend.BatchTx, w WALVersion, target semver.Version) error {
func Migrate(lg *zap.Logger, tx backend.BatchTx, w wal.Version, target semver.Version) error {
tx.LockOutsideApply()
defer tx.Unlock()
return UnsafeMigrate(lg, tx, w, target)
}

// UnsafeMigrate is non thread-safe version of Migrate.
func UnsafeMigrate(lg *zap.Logger, tx backend.UnsafeReadWriter, w WALVersion, target semver.Version) error {
func UnsafeMigrate(lg *zap.Logger, tx backend.UnsafeReadWriter, w wal.Version, target semver.Version) error {
current, err := UnsafeDetectSchemaVersion(lg, tx)
if err != nil {
return fmt.Errorf("cannot detect storage schema version: %w", err)
Expand Down
8 changes: 7 additions & 1 deletion server/storage/wal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ import (
"go.etcd.io/raft/v3/raftpb"
)

// Version defines the wal version interface.
type Version interface {
// MinimalEtcdVersion returns minimal etcd version able to interpret WAL log.
MinimalEtcdVersion() *semver.Version
}

// ReadWALVersion reads remaining entries from opened WAL and returns struct
// that implements schema.WAL interface.
func ReadWALVersion(w *WAL) (*walVersion, error) {
func ReadWALVersion(w *WAL) (Version, error) {
_, _, ents, err := w.ReadAll()
if err != nil {
return nil, err
Expand Down

0 comments on commit ad33010

Please sign in to comment.