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

settings: delete StateMachineSetting, introduce VersionSetting #55994

Merged
merged 2 commits into from
Oct 27, 2020

Conversation

irfansharif
Copy link
Contributor

@irfansharif irfansharif commented Oct 26, 2020

We introduced the custom StateMachineSetting type in #17216 to power the
underlying machinery for version upgrades:

SET CLUSTER SETTING version = <major>-<minor>;

At the time we left it generalizable enough to make room for future
settings with arbitrary internal transitions. For cluster versions this
meant only allowing transitions from one major version to the immediate
next, all the while making sure that each binary in the cluster was able
to activate the targeted version (the proposed version fell within the
allowable range ["binary min supported version", "binary version"]).

In the three years since we haven't added any state-machine validated
settings that fit the bill, and the layers of abstractions to get to
validated cluster version updates are one too many for (my) comfort.
This PR introduces a new VersionSetting type that is more tightly
coupled with the ClusterVersion type itself.

VersionSetting uses language that only appropriate for cluster versions,
hopefully clarifying things as we go. We'll depend on this clarification
in future PRs when we remove the use of gossip in disseminating cluster
version bumps.

Release note (sql/cli change): The underlying type for the version
cluster setting has been changed. Previously it was of an internal type
representing "state machine", but now it's simply "version". This has no
operational implications, but it does reflect differently in a few
spots:

  • The Type column in cockroach gen settings-list will now show
    "version" instead of "custom validation"
  • The setting_type column for version in SHOW CLUSTER SETTINGS
    will now show a "v" instead of an "m"
  • The valueType column for version in system.settings will now
    show a "v" instead of an "m"

@irfansharif irfansharif requested a review from a team as a code owner October 26, 2020 19:23
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@irfansharif irfansharif requested review from tbg and knz October 26, 2020 19:23
@irfansharif irfansharif force-pushed the 201025.del-StateMachineSetting branch 2 times, most recently from 76605e1 to 4bac320 Compare October 26, 2020 22:55
Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, 14 of 14 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @irfansharif and @tbg)


pkg/settings/setting.go, line 220 at r2 (raw file):

	// called on the goroutine which handles all settings updates.
	SetOnChange(sv *Values, fn func())
	ErrorHint() (bool, string)

I applaud you for stepping out of your way to add these comments! Maybe ErrorHint() can get one too?


pkg/settings/settings_test.go, line 29 at r2 (raw file):

type dummyVersion struct {
	// Each dummyVersion has a msg1 prefix, and a growsbyone component that

Pull this comment above the struct.

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Looks good. I also think you're on to some additional (deeper?) cleanup regarding the initialization of the setting and perhaps even the Opaque thing.

Reviewed 1 of 1 files at r1, 14 of 14 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @irfansharif)


pkg/settings/version.go, line 71 at r2 (raw file):

// cyclical dependency structure.
type ClusterVersionImpl interface {
	ClusterVersionImpl()

Do we still need Values.opaque after this change?


pkg/settings/version.go, line 79 at r2 (raw file):

// MakeVersionSetting instantiates a version setting instance. See
// VersionSetting for additional commentary.jhk

jhk


pkg/settings/version.go, line 186 at r2 (raw file):

// time.
//
// TODO(irfansharif): Is this true? Shouldn't the default here just the the

Yes, I think there is something there. We call .setToDefault in two places:

  1. in SettingsValues.Init, at which point the cluster version is generally initialized
  2. in the settings updater, which is even later

I think we could pass the default through the (*Settings).Values and use setToDefault here then. I.e. this code

sv := &s.SV
s.Version = clusterversion.MakeVersionHandleWithOverride(
&s.SV, binaryVersion, binaryMinSupportedVersion)
sv.Init(s.Version)

would do something like

ClusterVersionSetting.Override(&st.SV, "19.2-1")
sv.Init(handle)

Also look at this code, it's basically setting the version like any other setting, really looks like everything here should go away and the setting should look like any other:

// InitializeVersion initializes the Version field of this setting. Before this
// method has been called, usage of the Version field is illegal and leads to a
// fatal error.
func (s *Settings) InitializeVersion(cv ClusterVersion) error {
b, err := protoutil.Marshal(&cv)
if err != nil {
return err
}
// Note that we don't call `updater.ResetRemaining()`.
updater := settings.NewUpdater(&s.SV)
if err := updater.Set(KeyVersionSetting, string(b), version.Typ()); err != nil {
return err
}
s.Version.baseVersion.Store(&cv)
return nil
}

Copy link
Contributor Author

@irfansharif irfansharif left a comment

Choose a reason for hiding this comment

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

Thanks for reviewing! Like Tobi mentioned, this paves the way for more deep cleansing here. I have them sitting aside as separate commits that already touch the areas identified below (which is where to TODOs came from). I'll send those out in future PRs. We'll also be able to remove this whole SetBeforeChange callback business and shave the interfaces down even further.

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz and @tbg)


pkg/settings/setting.go, line 220 at r2 (raw file):

Previously, knz (kena) wrote…

I applaud you for stepping out of your way to add these comments! Maybe ErrorHint() can get one too?

Done.


pkg/settings/settings_test.go, line 29 at r2 (raw file):

Previously, knz (kena) wrote…

Pull this comment above the struct.

Done.


pkg/settings/version.go, line 71 at r2 (raw file):

Previously, tbg (Tobias Grieger) wrote…

Do we still need Values.opaque after this change?

Nope, see top-level comment.


pkg/settings/version.go, line 79 at r2 (raw file):

Previously, tbg (Tobias Grieger) wrote…

jhk

imap jhk <Esc>l

Done


pkg/settings/version.go, line 186 at r2 (raw file):

Previously, tbg (Tobias Grieger) wrote…

Yes, I think there is something there. We call .setToDefault in two places:

  1. in SettingsValues.Init, at which point the cluster version is generally initialized
  2. in the settings updater, which is even later

I think we could pass the default through the (*Settings).Values and use setToDefault here then. I.e. this code

sv := &s.SV
s.Version = clusterversion.MakeVersionHandleWithOverride(
&s.SV, binaryVersion, binaryMinSupportedVersion)
sv.Init(s.Version)

would do something like

ClusterVersionSetting.Override(&st.SV, "19.2-1")
sv.Init(handle)

Also look at this code, it's basically setting the version like any other setting, really looks like everything here should go away and the setting should look like any other:

// InitializeVersion initializes the Version field of this setting. Before this
// method has been called, usage of the Version field is illegal and leads to a
// fatal error.
func (s *Settings) InitializeVersion(cv ClusterVersion) error {
b, err := protoutil.Marshal(&cv)
if err != nil {
return err
}
// Note that we don't call `updater.ResetRemaining()`.
updater := settings.NewUpdater(&s.SV)
if err := updater.Set(KeyVersionSetting, string(b), version.Typ()); err != nil {
return err
}
s.Version.baseVersion.Store(&cv)
return nil
}

See top-level comment, slated for future PRs that changes even more things about cluster settings.

@craig
Copy link
Contributor

craig bot commented Oct 27, 2020

Build failed (retrying...):

@irfansharif
Copy link
Contributor Author

bors r-

@craig
Copy link
Contributor

craig bot commented Oct 27, 2020

Canceled.

Motivates the next commit.

Release note: None
@irfansharif
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 27, 2020

🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

We introduced the custom StateMachineSetting type in cockroachdb#17216 to power the
underlying machinery for version upgrades:

  SET CLUSTER SETTING version = <major>-<minor>;

At the time we left it generalizable enough to make room for future
settings with arbitrary internal transitions. For cluster versions this
meant only allowing transitions from one major version to the immediate
next, all the while making sure that each binary in the cluster was able
to activate the targeted version (the proposed version fell within the
allowable range ["binary min supported version", "binary version"]).

In the three years since we haven't added any state-machine validated
settings that fit the bill, and the layers of abstractions to get to
validated cluster version updates are one too many for (my) comfort.
This PR introduces a new VersionSetting type that is more tightly
coupled with the ClusterVersion type itself.

VersionSetting uses language that only appropriate for cluster versions,
hopefully clarifying things as we go. We'll depend on this clarification
in future PRs when we remove the use of gossip in disseminating cluster
version bumps.

Release note (sql/cli change): The underlying type for the version
cluster setting has been changed. Previously it was of an internal type
representing "state machine", but now it's simply "version". This has no
operational implications, but it does reflect differently in a few
spots:
  - The `Type` column in `cockroach gen settings-list` will now show
    "version" instead of "custom validation"
  - The `setting_type` column for `version` in `SHOW CLUSTER SETTINGS`
    will now show a "v" instead of an "m"
  - The `valueType` column for `version` in `system.settings` will now
    show a "v" instead of an "m"
@irfansharif
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 27, 2020

Build succeeded:

@craig craig bot merged commit b319a0b into cockroachdb:master Oct 27, 2020
@irfansharif irfansharif deleted the 201025.del-StateMachineSetting branch October 27, 2020 17:54
irfansharif added a commit to irfansharif/cockroach that referenced this pull request Nov 11, 2020
We introduced a regression in cockroachdb#55994. In mixed-version clusters, when
the 21.1 node attempts to refresh settings, it expects to find a type
"v" for the version setting, but finds "m" already present in 20.2. We
revert the bits of cockroachdb#55994 that introduced this regression.

Release note (sql, cli change): In an earlier commit (3edd70b, not part
of any release, yet) we introduced a regression by representing the
shortened form of the cluster version setting's type as "v", from an
earlier "m". It's now back to what it was. Specifically:
    - The `setting_type` column for `version` in `SHOW CLUSTER SETTINGS`
      will now show an "m" instead of a "v"
    - The `valueType` column for `version` in `system.settings` will now
      show an "m" instead of a "v"
irfansharif added a commit to irfansharif/cockroach that referenced this pull request Nov 11, 2020
We introduced a regression in cockroachdb#55994. In mixed-version clusters, when
the 21.1 node attempts to refresh settings, it expects to find a type
"v" for the version setting, but finds "m" already present in 20.2. We
revert the bits of cockroachdb#55994 that introduced this regression.

Release note (sql, cli change): In an earlier commit (3edd70b, not part
of any release, yet) we introduced a regression by representing the
shortened form of the cluster version setting's type as "v", from an
earlier "m". It's now back to what it was. Specifically:
    - The `setting_type` column for `version` in `SHOW CLUSTER SETTINGS`
      will now show an "m" instead of a "v"
    - The `valueType` column for `version` in `system.settings` will now
      show an "m" instead of a "v"
craig bot pushed a commit that referenced this pull request Nov 11, 2020
56546: settings: patch backwards incompatible short type identifier change r=irfansharif a=irfansharif

We introduced a regression in #55994. In mixed-version clusters, when
the 21.1 node attempts to refresh settings, it expects to find a type
"v" for the version setting, but finds "m" already present in 20.2. We
revert the bits of #55994 that introduced this regression.

Release note (sql, cli change): In an earlier commit (3edd70b, not part
of any release, yet) we introduced a regression by representing the
shortened form of the cluster version setting's type as "v", from an
earlier "m". It's now back to what it was. Specifically:
    - The `setting_type` column for `version` in `SHOW CLUSTER SETTINGS`
      will now show an "m" instead of a "v"
    - The `valueType` column for `version` in `system.settings` will now
      show an "m" instead of a "v"

---

First commit is from #56480.

Co-authored-by: irfan sharif <irfanmahmoudsharif@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants