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: add support for discarding subzones #134826

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

annrpom
Copy link
Contributor

@annrpom annrpom commented Nov 11, 2024

schemachanger: fix discards for explicit txns

Previously, discarding a zone config on an object in an
explicit transaction would only discard the latest (categorized by
highest seq num) element associated with it. This would mean for the
following scenario:

BEGIN;
ALTER TABLE t CONFIGURE ZONE USING num_replicas = 11;
ALTER TABLE t CONFIGURE ZONE USING num_replicas = 12;
ALTER TABLE t CONFIGURE ZONE DISCARD;
COMMIT;

The discard would only discard the element with a replication factor of 12,
leaving us with a table with a rep. factor of 11.

This patch ensures we clean up all references of an element when
discarding.

Epic: none
Release note: None


schemachanger: add support for discarding subzones

This patch adds support for discarding a subzone config in the
DSC.

Fixes: #133158
Epic: none

Release note: None

Copy link

blathers-crl bot commented Nov 11, 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 force-pushed the dsc-discard-subzones branch 3 times, most recently from 337b29d to 6444512 Compare November 11, 2024 21:26
@annrpom annrpom force-pushed the dsc-discard-subzones branch 10 times, most recently from 09535d3 to aa1f86e Compare November 21, 2024 02:29
@annrpom annrpom marked this pull request as ready for review November 21, 2024 14:36
@annrpom annrpom requested review from a team as code owners November 21, 2024 14:36
@annrpom annrpom requested a review from fqazi November 21, 2024 14:36
@annrpom
Copy link
Contributor Author

annrpom commented Nov 21, 2024

There's a lot of generated tests here and I think the most valuable thing we get from them (the explain plans) is ensuring that seqNum is tracked correctly for explicit txns. Maybe it would make more sense to just convert these to logictests that test the correctness instead since those can fail if seqNums aren't tracked correctly anyways... thoughts?

Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Great work @annrpom, I had some very minor comments.

:lgtm:

Reviewed 26 of 26 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @annrpom)


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

) ([]scpb.Element, []scpb.Element) {
	var elems []scpb.Element
	if dzo.seqNum > 0 {

Maybe a comment for clarity, but I think this says that all past IDs are dropped. Could we just adjust the loop to do this for us...

for i :=0; i < max(dzo.seqNum), 1), ;i++


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

	_ BuildCtx,
) ([]scpb.Element, []scpb.Element) {
	var elems []scpb.Element

Similar comment here

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 (and 1 stale) (waiting on @fqazi)


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

Previously, fqazi (Faizan Qazi) wrote…

Maybe a comment for clarity, but I think this says that all past IDs are dropped. Could we just adjust the loop to do this for us...

for i :=0; i < max(dzo.seqNum), 1), ;i++

done -- i ended up using a b.QueryByID(dzo.getTargetID()).FilterDatabaseZoneConfig().ForEach


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

Previously, fqazi (Faizan Qazi) wrote…

Similar comment here

done -- similar to above

@annrpom annrpom force-pushed the dsc-discard-subzones branch 2 times, most recently from 9d8f042 to 3e19b8e Compare November 22, 2024 23:56
Previously, discarding a zone config on an object in an
explicit transaction would only discard the latest (categorized by
highest seq num) element associated with it. This would mean for the
following scenario:
```
BEGIN;
ALTER TABLE t CONFIGURE ZONE USING num_replicas = 11;
ALTER TABLE t CONFIGURE ZONE USING num_replicas = 12;
ALTER TABLE t CONFIGURE ZONE DISCARD;
COMMIT;
```
The discard would only discard the element with a replication factor of 12,
leaving us with a table with a rep. factor of 11.

This patch ensures we clean up all references of an element when
discarding.

Epic: none
Release note: None
This patch adds support for discarding a subzone config in the
DSC.

Fixes: cockroachdb#133158
Epic: none

Release note: None
Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Great work @annrpom

Reviewed 4 of 65 files at r3, 12 of 59 files at r5, 3 of 3 files at r6.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@annrpom
Copy link
Contributor Author

annrpom commented Nov 25, 2024

tftr!

bors r+

craig bot pushed a commit that referenced this pull request Nov 25, 2024
134826: schemachanger: add support for discarding subzones r=annrpom a=annrpom

### schemachanger: fix discards for explicit txns
Previously, discarding a zone config on an object in an
explicit transaction would only discard the latest (categorized by
highest seq num) element associated with it. This would mean for the
following scenario:
```
BEGIN;
ALTER TABLE t CONFIGURE ZONE USING num_replicas = 11;
ALTER TABLE t CONFIGURE ZONE USING num_replicas = 12;
ALTER TABLE t CONFIGURE ZONE DISCARD;
COMMIT;
```
The discard would only discard the element with a replication factor of 12,
leaving us with a table with a rep. factor of 11.

This patch ensures we clean up all references of an element when
discarding.

Epic: none
Release note: None

---
### schemachanger: add support for discarding subzones
This patch adds support for discarding a subzone config in the
DSC.

Fixes: #133158
Epic: none

Release note: None

Co-authored-by: Annie Pompa <annie@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Nov 25, 2024

Build failed:

@annrpom
Copy link
Contributor Author

annrpom commented Nov 25, 2024

bors retry

(lint tests didn't get to run -- perhaps infra flake?)
image

@craig craig bot merged commit a06f6af into cockroachdb:master Nov 25, 2024
22 of 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.

schemachanger: support configure zone discard for subzone configs
3 participants