-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Etcd Downgrade backend #11492
Etcd Downgrade backend #11492
Conversation
etcdserver/api/membership/cluster.go
Outdated
@@ -778,6 +796,36 @@ func clusterVersionFromBackend(lg *zap.Logger, be backend.Backend) *semver.Versi | |||
return semver.Must(semver.NewVersion(string(vals[0]))) | |||
} | |||
|
|||
func downgradeInfoFromBackend(lg *zap.Logger, be backend.Backend) *DowngradeInfo { | |||
dkey := backendDowngradeKey() | |||
if be != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we panic on be == nil
? So, we can reduce indentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move nil check outside downgradeInfoFromBackend
to reduce indentation.
etcdserver/api/membership/cluster.go
Outdated
} | ||
|
||
if len(keys) != 1 { | ||
if lg != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do we really need nil
checks on logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite get it. Since we haven't deprecated plog and used zap log as default, lg is set to nil as default if flag --logger=zap
is not enabled. I think we can remove all the nil check of log after we enable zap log as default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, if we set logger to https://godoc.org/go.uber.org/zap#NewNop once in the caller, all the downstream calls need not handle this nil
checks?
etcdserver/api/membership/cluster.go
Outdated
if d != nil && d.Enabled && d.TargetVersion != nil { | ||
if isValidDowngrade(d.TargetVersion, lv) { | ||
if cv != nil { | ||
if lg != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. Can previous calls ensure logger is always non-nil?
} | ||
} | ||
} | ||
|
||
// isValidDowngrade checks whether joining local server is a valid downgrade when cluster enables downgrade. | ||
// the validation passes when local version is one minor version higher then target version | ||
func isValidDowngrade(tv *semver.Version, lv *semver.Version) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it has unit test but not in this pr. I thought it will be a big pr if I include all the tests. Should I put them in or just add the unit tests?
etcdserver/api/membership/store.go
Outdated
dkey := backendDowngradeKey() | ||
dvalue, err := json.Marshal(downgrade) | ||
if err != nil { | ||
if lg != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can previous calls ensure logger is non-nil always?
etcdserver/api/membership/store.go
Outdated
} | ||
tx := be.BatchTx() | ||
tx.Lock() | ||
defer tx.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary defer
we can just place it under UnsafePut
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -177,6 +177,21 @@ func getVersions(lg *zap.Logger, cl *membership.RaftCluster, local types.ID, rt | |||
return vers | |||
} | |||
|
|||
// allowedVersionRange decides the available version range of the cluster that local server can join in; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be unit tested?
etcdserver/server.go
Outdated
|
||
targetVersion := d.TargetVersion | ||
if isDowngradeFinished(s.getLogger(), targetVersion, getVersions(s.getLogger(), s.cluster, s.id, s.peerRt)) { | ||
if lg != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well, logger nil checking should be handled at the top level. Downstream packages should not worry about this checks.
@gyuho, regarding the logger, today in master, we use |
@jingyih Sounds good. Let's just keep it that way for now. |
…nitor to server to monitor downgrade status.
7ea1755
to
0fc0a95
Compare
Rebased the current master and removed the
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions. |
The original downgrade PR is too big to review. I will break it down into multiple small PRs.
This pr contains the server side of downgrade. The unit tests will be added in following PRs.
Based on the discussion here, the cluster only allows member with downgrade target version to join in during downgrading.
For more information about the design, please go to #11362
@gyuho @jingyih @wenjiaswe @hexfusion PTAL Thanks:)