-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
109048: settings: allow setting names to diverge from the key r=stevendanna a=knz Informs #109046. Epic: CRDB-28893 This patch makes it possible to change the name of cluster settings over time while preserving backward-compatibility. For example: ```go var s = RegisterDurationSetting( "server.web_session_timeout", // <- this is the key; it is immutable. settings.WithName("server.web_session.timeout"), // <- user-visible name ) ``` When the name is not specified, the key is used as name. If the name is specified, it must not exist already - neither as a key, nor as a name for another setting, nor as a previously-known name. If later, it becomes necessary to change the name again, the `WithRetiredName` option can be used. This is necessary to properly redirect users to the new name. For example: ```go var s = RegisterDurationSetting( "server.web_session_timeout", // <- this is the key; it is immutable. settings.WithName("http.web_session.timeout"), // <- new user-visible name settings.WithRetiredName("server.web_session.timeout"), // <- past name ) ``` A pgwire notice is sent to the user if they attempt to use SHOW/SET CLUSTER SETTING using a retired name. Release note: None Co-authored-by: Raphael 'kena' Poss <[email protected]>
- Loading branch information
Showing
14 changed files
with
296 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package settings_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/settings" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAliasedSettings(t *testing.T) { | ||
defer settings.TestingSaveRegistry()() | ||
|
||
_ = settings.RegisterBoolSetting(settings.SystemOnly, "s1key", "desc", false) | ||
_ = settings.RegisterBoolSetting(settings.SystemOnly, "s2key", "desc", false, settings.WithName("s2name")) | ||
_ = settings.RegisterBoolSetting(settings.SystemOnly, "s3key", "desc", false, | ||
settings.WithName("s3name-new"), settings.WithRetiredName("s3name-old")) | ||
|
||
k, found, _ := settings.NameToKey("unknown") | ||
assert.False(t, found) | ||
assert.Equal(t, settings.InternalKey(""), k) | ||
|
||
k, found, status := settings.NameToKey("s1key") | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s1key"), k) | ||
assert.Equal(t, settings.NameActive, status) | ||
|
||
k, found, status = settings.NameToKey("s2key") | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s2key"), k) | ||
assert.Equal(t, settings.NameRetired, status) | ||
|
||
k, found, status = settings.NameToKey("s2name") | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s2key"), k) | ||
assert.Equal(t, settings.NameActive, status) | ||
|
||
k, found, status = settings.NameToKey("s3key") | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s3key"), k) | ||
assert.Equal(t, settings.NameRetired, status) | ||
|
||
k, found, status = settings.NameToKey("s3name-new") | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s3key"), k) | ||
assert.Equal(t, settings.NameActive, status) | ||
|
||
k, found, status = settings.NameToKey("s3name-old") | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s3key"), k) | ||
assert.Equal(t, settings.NameRetired, status) | ||
|
||
s, found, status := settings.LookupForLocalAccess("s1key", true) | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s1key"), s.InternalKey()) | ||
assert.Equal(t, settings.NameActive, status) | ||
|
||
s, found, status = settings.LookupForLocalAccess("s2key", true) | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s2key"), s.InternalKey()) | ||
assert.Equal(t, settings.SettingName("s2name"), s.Name()) | ||
assert.Equal(t, settings.NameRetired, status) | ||
|
||
s, found, status = settings.LookupForLocalAccess("s2name", true) | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s2key"), s.InternalKey()) | ||
assert.Equal(t, settings.NameActive, status) | ||
|
||
s, found, status = settings.LookupForLocalAccess("s3key", true) | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s3key"), s.InternalKey()) | ||
assert.Equal(t, settings.SettingName("s3name-new"), s.Name()) | ||
assert.Equal(t, settings.NameRetired, status) | ||
|
||
s, found, status = settings.LookupForLocalAccess("s3name-old", true) | ||
assert.True(t, found) | ||
assert.Equal(t, settings.InternalKey("s3key"), s.InternalKey()) | ||
assert.Equal(t, settings.SettingName("s3name-new"), s.Name()) | ||
assert.Equal(t, settings.NameRetired, status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.