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

Migrate cluster attributes to use v3 backend #11427

Merged
merged 5 commits into from
Dec 9, 2019
Merged
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: 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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically, if we keep the previous test data, the test cluster will fail to start. It is because the cluster will make several v3 raft requests like cluster version set during start. Old code will use v2 for starting server which will bypass the check.

if len(data) > int(s.Cfg.MaxRequestBytes) {
return nil, ErrRequestTooLarge
}

Changing a larger maxRequestBytesServer will not affect the test behavior as long as maxRequestBytesServer is smaller then valueSize.

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need fallback on v2 version data if v3 version is nil (upgraded etcd process)?

c.version = clusterVersionFromStore(c.lg, c.v2store)
if c.be != nil {
        v3Ver := clusterVersionFromBackend(c.lg, c.be)
	if v3Ver != nil { c.version = v3Ver }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about it. When will v3 version data is nil while v2 is not? If v3 backend is available, the v3 version will not be nil except starting a new server? Setting version will store new version info into both v2 store and v3 backend.

if c.v2store != nil {
mustSaveClusterVersionToStore(c.v2store, ver)
}
if c.be != nil {
mustSaveClusterVersionToBackend(c.be, ver)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that answers my question. Thanks.

}

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