Skip to content

Commit

Permalink
Merge pull request #11427 from YoyinZyc/migration-cluster-attr
Browse files Browse the repository at this point in the history
Migrate cluster attributes to use v3 backend
  • Loading branch information
gyuho authored Dec 9, 2019
2 parents 1f8764b + 7784ca8 commit 9f81002
Show file tree
Hide file tree
Showing 13 changed files with 1,412 additions and 156 deletions.
2 changes: 1 addition & 1 deletion clientv3/integration/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ func TestKVLargeRequests(t *testing.T) {
expectError error
}{
{
maxRequestBytesServer: 1,
maxRequestBytesServer: 256,
maxCallSendBytesClient: 0,
maxCallRecvBytesClient: 0,
valueSize: 1024,
Expand Down
27 changes: 26 additions & 1 deletion etcdserver/api/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ func (c *RaftCluster) Recover(onSet func(*zap.Logger, *semver.Version)) {
defer c.Unlock()

c.members, c.removed = membersFromStore(c.lg, c.v2store)
c.version = clusterVersionFromStore(c.lg, c.v2store)
if c.be != nil {
c.version = clusterVersionFromBackend(c.lg, c.be)
} else {
c.version = clusterVersionFromStore(c.lg, c.v2store)
}

mustDetectDowngrade(c.lg, c.version)
onSet(c.lg, c.version)

Expand Down Expand Up @@ -753,6 +758,26 @@ func clusterVersionFromStore(lg *zap.Logger, st v2store.Store) *semver.Version {
return semver.Must(semver.NewVersion(*e.Node.Value))
}

func clusterVersionFromBackend(lg *zap.Logger, be backend.Backend) *semver.Version {
ckey := backendClusterVersionKey()
tx := be.ReadTx()
tx.RLock()
defer tx.RUnlock()
keys, vals := tx.UnsafeRange(clusterBucketName, ckey, nil, 0)
if len(keys) == 0 {
return nil
}
if len(keys) != 1 {
if lg != nil {
lg.Panic(
"unexpected number of keys when getting cluster version from backend",
zap.Int("number-of-key", len(keys)),
)
}
}
return semver.Must(semver.NewVersion(string(vals[0])))
}

// ValidateClusterAndAssignIDs validates the local cluster by matching the PeerURLs
// with the existing cluster. If the validation succeeds, it assigns the IDs
// from the existing cluster to the local cluster.
Expand Down
Loading

0 comments on commit 9f81002

Please sign in to comment.