Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] *: support online downgrade from 3.5 to 3.4 #15990

Draft
wants to merge 1 commit into
base: release-3.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions etcdserver/api/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
"3.2.0": {AuthCapability: true, V3rpcCapability: true},
"3.3.0": {AuthCapability: true, V3rpcCapability: true},
"3.4.0": {AuthCapability: true, V3rpcCapability: true},
//TODO: use EnableCapability and flag to control this dynamically
"3.5.0": {AuthCapability: true, V3rpcCapability: true},
}

enableMapMu sync.RWMutex
Expand Down
6 changes: 4 additions & 2 deletions etcdserver/api/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ func (c *RaftCluster) Recover(onSet func(*zap.Logger, *semver.Version)) {

c.members, c.removed = membersFromStore(c.lg, c.v2store)
c.version = clusterVersionFromStore(c.lg, c.v2store)
mustDetectDowngrade(c.lg, c.version)
// TODO: add flag to control this check
//mustDetectDowngrade(c.lg, c.version)
onSet(c.lg, c.version)

for _, m := range c.members {
Expand Down Expand Up @@ -567,7 +568,8 @@ func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*zap.Logger, *s
}
oldVer := c.version
c.version = ver
mustDetectDowngrade(c.lg, c.version)
// TODO: add flag to control this check
//mustDetectDowngrade(c.lg, c.version)
if c.v2store != nil {
mustSaveClusterVersionToStore(c.v2store, ver)
}
Expand Down
15 changes: 15 additions & 0 deletions mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var (
scheduledCompactKeyName = []byte("scheduledCompactRev")
finishedCompactKeyName = []byte("finishedCompactRev")

// 3.5 meta keys that have to be deleted for downgrade
confStateKeyName = []byte("confState")
termKeyName = []byte("term")

ErrCompacted = errors.New("mvcc: required revision has been compacted")
ErrFutureRev = errors.New("mvcc: required revision is a future revision")
ErrCanceled = errors.New("mvcc: watcher is canceled")
Expand Down Expand Up @@ -148,6 +152,8 @@ func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, ig ConsistentI
tx.Lock()
tx.UnsafeCreateBucket(keyBucketName)
tx.UnsafeCreateBucket(metaBucketName)
// TODO: add flag to control this
downgradeMetaBucket(tx)
tx.Unlock()
s.b.ForceCommit()

Expand Down Expand Up @@ -379,6 +385,9 @@ func (s *store) restore() error {
tx := s.b.BatchTx()
tx.Lock()

// TODO: add flag to control this
downgradeMetaBucket(tx)

_, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0)
if len(finishedCompactBytes) != 0 {
s.revMu.Lock()
Expand Down Expand Up @@ -637,3 +646,9 @@ func appendMarkTombstone(lg *zap.Logger, b []byte) []byte {
func isTombstone(b []byte) bool {
return len(b) == markedRevBytesLen && b[markBytePosition] == markTombstone
}

// downgradeMetaBucket delete 3.5 specific keys to make backend fully compatible with 3.4
func downgradeMetaBucket(tx backend.BatchTx) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part can be done using capabilities of new migrate command from 3.6, cc @serathius

tx.UnsafeDelete(metaBucketName, confStateKeyName)
tx.UnsafeDelete(metaBucketName, termKeyName)
}
2 changes: 2 additions & 0 deletions mvcc/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ func TestStoreRestore(t *testing.T) {
t.Errorf("current rev = %v, want 5", s.currentRev)
}
wact := []testutil.Action{
{Name: "delete", Params: []interface{}{metaBucketName, confStateKeyName}},
{Name: "delete", Params: []interface{}{metaBucketName, termKeyName}},
{Name: "range", Params: []interface{}{metaBucketName, finishedCompactKeyName, []byte(nil), int64(0)}},
{Name: "range", Params: []interface{}{metaBucketName, scheduledCompactKeyName, []byte(nil), int64(0)}},
{Name: "range", Params: []interface{}{keyBucketName, newTestRevBytes(revision{1, 0}), newTestRevBytes(revision{math.MaxInt64, math.MaxInt64}), int64(restoreChunkKeys)}},
Expand Down