Skip to content

sql: implement SHOW CLUSTER SETTING FOR TENANT#77794

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
knz:20220314-tenant-settings4
Apr 6, 2022
Merged

sql: implement SHOW CLUSTER SETTING FOR TENANT#77794
craig[bot] merged 2 commits intocockroachdb:masterfrom
knz:20220314-tenant-settings4

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Mar 14, 2022

All commits but the last 2 from #77742.
(Reviewers: only the last 2 commits belong to this PR.)

Fixes #77471

Release justification: fixes to high-priority bugs

@knz knz requested a review from a team March 14, 2022 21:05
@knz knz requested a review from a team as a code owner March 14, 2022 21:05
@knz knz requested a review from a team March 14, 2022 21:05
@blathers-crl blathers-crl bot added the T-server-and-security DB Server & Security label Mar 14, 2022
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz force-pushed the 20220314-tenant-settings4 branch 2 times, most recently from aa27649 to 7e74cd5 Compare March 16, 2022 13:12
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 16, 2022

Updated to reflect #77935.

@knz knz force-pushed the 20220314-tenant-settings4 branch from 7e74cd5 to e5dd033 Compare March 21, 2022 21:21
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 21, 2022

RFAL

@knz knz requested a review from RaduBerinde March 21, 2022 22:02
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

no major comments; all just nits or optional feedback

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


-- commits, line 38 at r11:
does this need a release note?


pkg/settings/bool.go, line 49 at r10 (raw file):

// DecodeToString decodes and renders an encoded value.
func (b *BoolSetting) DecodeToString(encoded string) (string, error) {
	bv, err := b.DecodeValue(encoded)

i see it's not related to this PR, but what's the purpose of DecodeToString? it looks like it calls strconv.ParseBool and then calls strconv.FormatBool(b)


pkg/sql/show_cluster_setting.go, line 101 at r10 (raw file):

					}

					res = string(kvRawVal)

it seems fine, but i'm just wondering why this needed to change


pkg/sql/show_cluster_setting.go, line 129 at r10 (raw file):

	setting, ok := val.(settings.NonMaskedSetting)
	if !ok {
		return nil, errors.AssertionFailedf("setting is masked: %v", name)

is this supposed to be an assertion error, or would a user-friendly error be better?


pkg/sql/show_cluster_setting.go, line 143 at r10 (raw file):

}

func planShowClusterSetting(

would this more naturally be a method with a *planner receiver?


pkg/sql/show_cluster_setting.go, line 211 at r10 (raw file):

					}
					d = &tree.DInterval{Duration: duration.MakeDuration(v.Nanoseconds(), 0, 0)}
				case *settings.DurationSettingWithExplicitUnit:

could Duration and DurationWithInterval be combined into one case?


pkg/sql/tenant_settings.go, line 259 at r11 (raw file):

	}

	return &delayedNode{

why is this delayedNode needed here? could it instead use the node returned by planShowClusterSetting? and maybe change planShowClusterSetting so that it sets the name as we desire

this part could be done before the call to planShowClusterSetting

			// Evaluate the tenant ID expression.
			_, tenantID, err := resolveTenantID(p, typedTenantID)
			if err != nil {
				return nil, err
			}
			if err := assertTenantExists(ctx, p, tenantID); err != nil {
				return nil, err
			}

pkg/sql/logictest/testdata/logic_test/cluster_settings, line 227 at r11 (raw file):


onlyif config 3node-tenant
statement error SHOW CLUSTER SETTING FOR TENANT can only be called by system operators

would the term "system tenant" be more consistent with the error message below on line 236? (instead of "operator")

@knz knz force-pushed the 20220314-tenant-settings4 branch 2 times, most recently from 1923035 to 257896a Compare April 4, 2022 17:26
Copy link
Copy Markdown
Contributor Author

@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.

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


-- commits, line 38 at r11:

Previously, rafiss (Rafi Shamim) wrote…

does this need a release note?

I'm not sure, since the tenant config override stuff is not accessible to end users? WDYT?


pkg/settings/bool.go, line 49 at r10 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i see it's not related to this PR, but what's the purpose of DecodeToString? it looks like it calls strconv.ParseBool and then calls strconv.FormatBool(b)

it's part of the interface. Other setting types do not use such a trivial function.

Also it checks for syntax errors in the encoded value, in this case e.g. it verifies that "wowow" causes an error and is not just rendered as-is.


pkg/sql/show_cluster_setting.go, line 101 at r10 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

it seems fine, but i'm just wondering why this needed to change

Previously, the function was called showVersionSetting and it was responsible for returning the decoded value.

Now it's called getCurrentEncodedVersionSettingValue and is responsible for returning the encoded value.

Added a comment to clarify.


pkg/sql/show_cluster_setting.go, line 129 at r10 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

is this supposed to be an assertion error, or would a user-friendly error be better?

We'd be encountering a bug in Lookup. added a comment to explain.


pkg/sql/show_cluster_setting.go, line 143 at r10 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

would this more naturally be a method with a *planner receiver?

I wanted to be more specific about the exact data that it needs, instead of leaking all the contents of planner into it. You'll notice that the body of the function doesn't need the planner, it's merely passed through from the constructor closure to the getEncodedValue function. I'd like this property (the fact the body doesn't need planner) to be maintained, which would be hard if the thing was passed as argument.


pkg/sql/show_cluster_setting.go, line 211 at r10 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

could Duration and DurationWithInterval be combined into one case?

I tried but alas, DecodeValue is not part of the interface (it returns a different type for each instance) so when we combine the cases, the call to DecodeValue becomes invalid.


pkg/sql/tenant_settings.go, line 259 at r11 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

why is this delayedNode needed here? could it instead use the node returned by planShowClusterSetting? and maybe change planShowClusterSetting so that it sets the name as we desire

this part could be done before the call to planShowClusterSetting

			// Evaluate the tenant ID expression.
			_, tenantID, err := resolveTenantID(p, typedTenantID)
			if err != nil {
				return nil, err
			}
			if err := assertTenantExists(ctx, p, tenantID); err != nil {
				return nil, err
			}

no, we can't call .Eval() (inside resolveTenantID) on the typed expr during planning, because it's the planning phase, not execution phase. The call to Eval must be delayed until execution (under startExec).

Alternatively, we could remove the call to resolveTenantID / ssertTenantExists entierly, and put the checks inside the SQL statement like what is done in delegate/show_all_cluster_settings.go. WDYT?


pkg/sql/logictest/testdata/logic_test/cluster_settings, line 227 at r11 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

would the term "system tenant" be more consistent with the error message below on line 236? (instead of "operator")

Arguably it's the one saying "system tenant" that's inconsistent with the rest :)

@knz knz force-pushed the 20220314-tenant-settings4 branch 2 times, most recently from 2252473 to aa1431b Compare April 4, 2022 19:07
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

lgtm!

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


pkg/sql/tenant_settings.go, line 259 at r11 (raw file):

Previously, knz (kena) wrote…

no, we can't call .Eval() (inside resolveTenantID) on the typed expr during planning, because it's the planning phase, not execution phase. The call to Eval must be delayed until execution (under startExec).

Alternatively, we could remove the call to resolveTenantID / ssertTenantExists entierly, and put the checks inside the SQL statement like what is done in delegate/show_all_cluster_settings.go. WDYT?

i see, thanks. yes it sounds good to keep the resolveTenantID in the exec phase like this

for consistency with show all i could see it being helpful to do the resolve/assert in SQL, but i don't feel strongly about it

So we can use it later to display a tenant setting.

Release justification: low risk, high benefit changes to existing functionality

Release note: None
@knz knz force-pushed the 20220314-tenant-settings4 branch from aa1431b to 672bb01 Compare April 6, 2022 16:31
Copy link
Copy Markdown
Contributor Author

@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.

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


pkg/sql/tenant_settings.go, line 259 at r11 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i see, thanks. yes it sounds good to keep the resolveTenantID in the exec phase like this

for consistency with show all i could see it being helpful to do the resolve/assert in SQL, but i don't feel strongly about it

ok, simplified.

@knz knz force-pushed the 20220314-tenant-settings4 branch from 672bb01 to 156d754 Compare April 6, 2022 17:45
Release justification: fixes for high-priority bugs

Release note: None
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Apr 6, 2022

TFYR!

bors r=rafiss

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 6, 2022

Build succeeded:

@craig craig bot merged commit d4daa99 into cockroachdb:master Apr 6, 2022
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Apr 6, 2022

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from b39f02a to blathers/backport-release-22.1-77794: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 22.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@knz knz deleted the 20220314-tenant-settings4 branch April 6, 2022 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-server-and-security DB Server & Security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: store tenant settings in new system table

3 participants