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

schemachanger: zone config refactor #129065

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

annrpom
Copy link
Contributor

@annrpom annrpom commented Aug 15, 2024

This patch refactors some of the zone config logic
in the DSC.

Epic: CRDB-31473
Informs: #129889

Release note: None

Copy link

blathers-crl bot commented Aug 15, 2024

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@annrpom annrpom changed the title Dsc zone config refactor [wip] schemachanger: zone config refactor Aug 15, 2024
@annrpom annrpom force-pushed the dsc-zone-config-refactor branch 2 times, most recently from 4fc5b47 to 5eeeb4c Compare August 15, 2024 16:54
@annrpom annrpom force-pushed the dsc-zone-config-refactor branch from 5eeeb4c to da03426 Compare August 22, 2024 21:02
Copy link

blathers-crl bot commented Aug 22, 2024

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@annrpom annrpom force-pushed the dsc-zone-config-refactor branch 7 times, most recently from f4f6915 to 1f4f1f4 Compare August 29, 2024 17:31
@annrpom annrpom changed the title [wip] schemachanger: zone config refactor schemachanger: zone config refactor Aug 29, 2024
@annrpom
Copy link
Contributor Author

annrpom commented Aug 29, 2024

Ready for review -- the unit tests failing are just error message diffs; will fix!

@annrpom annrpom marked this pull request as ready for review August 29, 2024 18:24
@annrpom annrpom requested a review from a team as a code owner August 29, 2024 18:24
@annrpom annrpom requested a review from spilchen August 29, 2024 18:25
@annrpom
Copy link
Contributor Author

annrpom commented Aug 29, 2024

I'm still not entirely satisfied -- trying to think about what i can do to applyZoneConfig

@annrpom annrpom force-pushed the dsc-zone-config-refactor branch 5 times, most recently from 2394fd6 to d96da2a Compare August 30, 2024 20:54
Copy link
Contributor

@spilchen spilchen left a comment

Choose a reason for hiding this comment

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

I like this refactor—it makes the applyZoneConfig functions easier to follow. There’s still some code duplication between handling index and table/database objects, but I think that's unavoidable.

Reviewed 3 of 7 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @annrpom)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go line 41 at r1 (raw file):

	// - Partition/row
	// - System Ranges
	zoneConfigObject := astToZoneConfigObject(b, n)

I suggest returning the object along with an error. For unsupported modes, we can provide more meaningful error messages. For example, when n.Discard is true, we previously returned an error stating "CONFIGURE ZONE DISCARD is not supported in the DSC." Retaining these specific errors would be beneficial, and returning the error will allow you to do that.


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go line 66 at r1 (raw file):

	return sqlerrors.NewInsufficientPrivilegeOnDescriptorError(b.CurrentUser(),
		reqNonAdminPrivs, string(catalog.Database),
		mustRetrieveNamespaceElem(b, dbElem.DatabaseID).Name)

Will we have a namespace element for a database? I thought those only made sense in the context of table-specific elements.


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 1705 at r1 (raw file):

// mustRetrievePhysicalTableElem will resolve a tableID to a physical table
// element. A "physical" table element includes tables, views, and sequences.
func mustRetrievePhysicalTableElem(b BuildCtx, tableID catid.DescID) scpb.Element {

nit: I suggest renaming tableID to descID or something similar. It won't always be a table ID; for example, it could represent a view or sequence ID.


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go line 71 at r1 (raw file):

	reqNonAdminPrivs := []privilege.Kind{privilege.ZONECONFIG, privilege.CREATE}
	if zs.Database == "system" {

Will ever be true for table zone configs? I thought zs.Database would be an empty string.


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go line 71 at r1 (raw file):

	// getSeqNum returns the sequence number of the zone config object.
	getSeqNum() uint32

Do we use this function anywhere? I couldn't find any usages of it myself.

@annrpom annrpom force-pushed the dsc-zone-config-refactor branch from d96da2a to 64ba635 Compare September 3, 2024 15:13
Copy link
Contributor Author

@annrpom annrpom 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 @spilchen)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go line 41 at r1 (raw file):

Previously, spilchen wrote…

I suggest returning the object along with an error. For unsupported modes, we can provide more meaningful error messages. For example, when n.Discard is true, we previously returned an error stating "CONFIGURE ZONE DISCARD is not supported in the DSC." Retaining these specific errors would be beneficial, and returning the error will allow you to do that.

done -- good point


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go line 66 at r1 (raw file):

Previously, spilchen wrote…

Will we have a namespace element for a database? I thought those only made sense in the context of table-specific elements.

yes; see

// SkipNamespace implements the descriptor interface.
func (desc *immutable) SkipNamespace() bool {
return false
}
and
if !w.desc.SkipNamespace() {
w.ev(scpb.Status_PUBLIC, &scpb.Namespace{
DatabaseID: w.desc.GetParentID(),
SchemaID: w.desc.GetParentSchemaID(),
DescriptorID: w.desc.GetID(),
Name: w.desc.GetName(),
})
}

fwiw, though: the namespace element for a db is just the DescriptorID and Name


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 1705 at r1 (raw file):

Previously, spilchen wrote…

nit: I suggest renaming tableID to descID or something similar. It won't always be a table ID; for example, it could represent a view or sequence ID.

done!


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go line 71 at r1 (raw file):

Previously, spilchen wrote…

Will ever be true for table zone configs? I thought zs.Database would be an empty string.

done -- bad copy & paste


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go line 71 at r1 (raw file):

Previously, spilchen wrote…

Do we use this function anywhere? I couldn't find any usages of it myself.

done -- removed since no longer used!

@annrpom annrpom requested a review from spilchen September 3, 2024 15:14
Copy link
Contributor

@spilchen spilchen left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 6 of 6 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @annrpom)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go line 66 at r1 (raw file):

Previously, annrpom (annie pompa) wrote…

yes; see

// SkipNamespace implements the descriptor interface.
func (desc *immutable) SkipNamespace() bool {
return false
}
and
if !w.desc.SkipNamespace() {
w.ev(scpb.Status_PUBLIC, &scpb.Namespace{
DatabaseID: w.desc.GetParentID(),
SchemaID: w.desc.GetParentSchemaID(),
DescriptorID: w.desc.GetID(),
Name: w.desc.GetName(),
})
}

fwiw, though: the namespace element for a db is just the DescriptorID and Name

Thanks for the explanation.

This patch refactors some of the zone config logic
in the DSC.

Release note: None
@annrpom annrpom force-pushed the dsc-zone-config-refactor branch from 64ba635 to 22d89ca Compare September 3, 2024 18:39
@annrpom
Copy link
Contributor Author

annrpom commented Sep 3, 2024

Needed to rebase to get a test-flake-fix in! TFTR! ('-')7

@annrpom
Copy link
Contributor Author

annrpom commented Sep 3, 2024

bors r=spilchen

@craig craig bot merged commit fd31fbd into cockroachdb:master Sep 3, 2024
23 checks passed
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.

3 participants