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

sql: add crdb_internal.validate_multi_region_zone_configs builtin #62780

Merged
merged 1 commit into from
Mar 31, 2021

Conversation

otan
Copy link
Contributor

@otan otan commented Mar 30, 2021

In addition to the release note, added some pgcodes to validation errors
as well as minor refactoring to make it work and error nicely with the
"overriding" error message.

Release note (sql change): Add a new builtin
crdb_internal.validate_multi_region_zone_configs which validates all
zone configurations in the current database is correctly configured.

@otan otan requested review from ajstorm, a team and miretskiy and removed request for a team March 30, 2021 01:00
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@otan otan force-pushed the validate_zone_configs branch 2 times, most recently from 54ab5f0 to 3e1b61d Compare March 30, 2021 11:34
Copy link
Collaborator

@ajstorm ajstorm left a comment

Choose a reason for hiding this comment

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

Nit: In release note - "which validates all zone configurations in the current database are correctly configured"

Reviewed 5 of 8 files at r1, 3 of 3 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @miretskiy and @otan)


docs/generated/sql/functions.md, line 881 at r2 (raw file):

table’s zone configuration this will return NULL.</p>
</span></td></tr>
<tr><td><a name="crdb_internal.validate_multi_region_zone_configs"></a><code>crdb_internal.validate_multi_region_zone_configs() &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>Validates all multi-region zone configurations are correctly set

Nit: I believe this should be "setup", not "set up".


pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs, line 42 at r2 (raw file):


statement ok
SELECT crdb_internal.validate_multi_region_zone_configs()

FYI: Longer term, does this mean that we should be removing the calls to SHOW ZONE CONFIGURATION in these tests? Or do you think that there's still value in having them so that the tests are more visually self-describing?


pkg/sql/region_util.go, line 834 at r2 (raw file):

}

// ValidateCurrentDatabaseMultiRegionZoneConfigs is part of the tree.EvalDatabase interface.

Nit: maybe end this line with a comma?


pkg/sql/region_util.go, line 835 at r2 (raw file):

// ValidateCurrentDatabaseMultiRegionZoneConfigs is part of the tree.EvalDatabase interface.
// and as such is intended for DML use. It returns an empty DatabaseRegionConfig

Nit: I think this should read "It returns nil..."


pkg/sql/region_util.go, line 837 at r2 (raw file):

// and as such is intended for DML use. It returns an empty DatabaseRegionConfig
// if the current database is not multi-region enabled.
func (p *planner) ValidateCurrentDatabaseMultiRegionZoneConfigs(ctx context.Context) error {

Nit: Should there be a mention somewhere in the comment above that this also validates tables? Alternatively, should the function name be changed to ValidateMultRegionZoneConfigsForCurrentDatabaseAndTables?


pkg/sql/region_util.go, line 842 at r2 (raw file):

		p.txn,
		p.CurrentDatabase(),
		tree.DatabaseLookupFlags{Required: true},

Nit: AvoidCached? IncludeOffline?


pkg/sql/region_util.go, line 1172 at r2 (raw file):

					// the ID.
					indexName := fmt.Sprintf("unknown with ID = %s",
						strconv.FormatUint(uint64(s.IndexID), 10))

I have to admit, I have not idea why I wrote it this way the first time 🤦


pkg/sql/region_util.go, line 1185 at r2 (raw file):

// validateZoneConfigForMultiRegionDatabase validates that the zone config
//for the databases matches the exact expectations as the multi-region

Nit: space at beginning of row.

Nit: I think we can probably remove "the exact expectations as the", as it's somewhat implied.


pkg/sql/region_util.go, line 1212 at r2 (raw file):

	if !same {
		dbName := tree.Name(dbDesc.GetName())
		return validateZoneConfigForMultiRegionErrorHandler.newError(

Nice. I like this encapsulation of the error message.


pkg/sql/region_util.go, line 1300 at r2 (raw file):

					return validateZoneConfigForMultiRegionErrorHandler.newError(
						"index",
						fmt.Sprintf("%s@%s", tableName.String(), indexName),

Nit: Since we're using tableName.String() down here already, might want to use indexTreeName.String() so that we don't need indexName at all. If you do this, might want to change indexTreeName to indexName.


pkg/sql/sem/builtins/builtins.go, line 5075 at r2 (raw file):

					evalCtx.Context,
				); err != nil {
					return nil, err

Should this return false here?

@otan otan force-pushed the validate_zone_configs branch 2 times, most recently from 2fe5ad2 to 4430b01 Compare March 30, 2021 22:04
Copy link
Contributor Author

@otan otan 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 @ajstorm and @miretskiy)


pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs, line 42 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

FYI: Longer term, does this mean that we should be removing the calls to SHOW ZONE CONFIGURATION in these tests? Or do you think that there's still value in having them so that the tests are more visually self-describing?

i reckon there's value in having both.


pkg/sql/region_util.go, line 1172 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

I have to admit, I have not idea why I wrote it this way the first time 🤦

hehe


pkg/sql/region_util.go, line 1300 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Nit: Since we're using tableName.String() down here already, might want to use indexTreeName.String() so that we don't need indexName at all. If you do this, might want to change indexTreeName to indexName.

i can't do tree.Name(name).String() in one pop because Name has a pointer receiver, so this has to be as it is.


pkg/sql/sem/builtins/builtins.go, line 5075 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Should this return false here?

the error will supercede all else :P

Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

For all this validation we seem to be either reading descriptors from the store or using the DDL variants when constructing zone configs -- is this what we want for a builtin? I think it should be fine to used leased descriptors for the builtin, right?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @miretskiy, and @otan)


pkg/sql/region_util.go, line 842 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Nit: AvoidCached? IncludeOffline?

I don't fully understand, why do we need these flags here?


pkg/sql/region_util.go, line 888 at r3 (raw file):

		tree.DatabaseLookupFlags{
			Required:       true,
			AvoidCached:    true,

Are you sure you want AvoidCached here? This method is called from the DefaultToDatabasePrimaryRegionBuiltinName, which means any insert into a Regional By Row table without an explicit value for crdb_region. A roundtrip here wouldn't fly, will it?

Copy link
Contributor Author

@otan otan 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 @ajstorm, @arulajmani, and @miretskiy)


pkg/sql/region_util.go, line 842 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I don't fully understand, why do we need these flags here?

Thinking about it more, yeah I don't think we do. We don't mind using the lease in the case, and no offline job code goes through this logic (yet).


pkg/sql/region_util.go, line 888 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Are you sure you want AvoidCached here? This method is called from the DefaultToDatabasePrimaryRegionBuiltinName, which means any insert into a Regional By Row table without an explicit value for crdb_region. A roundtrip here wouldn't fly, will it?

oops, good catch, didn't intend this to be here.

@otan otan force-pushed the validate_zone_configs branch 2 times, most recently from 44562f5 to 0c5760e Compare March 31, 2021 02:06
In addition to the release note, added some pgcodes to validation errors
as well as minor refactoring to make it work and error nicely with the
"overriding" error message.

Also fix up some of the string escaping to use tree.Name.

Release note (sql change): Add a new builtin
`crdb_internal.validate_multi_region_zone_configs` which validates all
zone configurations in the current database are correctly configured.
Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

I think @ajstorm already approved this, but :lgtm: to me too after your changes

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajstorm, @arulajmani, and @miretskiy)

@otan
Copy link
Contributor Author

otan commented Mar 31, 2021

bors r=ajstorm,arulajmani

@craig
Copy link
Contributor

craig bot commented Mar 31, 2021

Build failed:

@otan
Copy link
Contributor Author

otan commented Mar 31, 2021

bors r=ajstorm,arulajmani

@craig
Copy link
Contributor

craig bot commented Mar 31, 2021

Build succeeded:

@craig craig bot merged commit fe14895 into cockroachdb:master Mar 31, 2021
Copy link
Collaborator

@ajstorm ajstorm 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 (and 1 stale)


pkg/sql/region_util.go, line 888 at r3 (raw file):

Previously, otan (Oliver Tan) wrote…

oops, good catch, didn't intend this to be here.

Good catch @arulajmani!

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