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: prevent REGIONAL BY ROW and ADD/DROP REGION concurrent transitions #64117

Merged
merged 3 commits into from
Apr 27, 2021

Conversation

otan
Copy link
Contributor

@otan otan commented Apr 23, 2021

see individual commits for details

resolves #63368
resolves #63462
resolves #64011
resolves #63974

@otan otan requested review from arulajmani, ajstorm and a team April 23, 2021 01:45
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@otan otan force-pushed the block_round_2 branch 2 times, most recently from 4bd477a to 6329066 Compare April 23, 2021 06:10
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.

Reviewed 4 of 4 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @arulajmani, and @otan)


pkg/ccl/multiregionccl/region_test.go, line 255 at r2 (raw file):

		expectedIndexes []string
	}{
		{

Looks like this is only testing a CREATE REGIONAL BY ROW table now, so we can probably simplify this test a bit?


pkg/sql/region_util.go, line 1697 at r1 (raw file):

	// forEachTableDesc touches all the table keys, which prevents a race
	// with ADD/REGION committing at the same time as the user transaction.
	return forEachTableDesc(

forEachTableDesc is no good here, as it filters out descriptors the user doesn't have privileges on. You probably want forEachMutableTableInDatabase here instead.

This is helpful for error messages which allows the schema name to be
output in the error message.

Release note: None
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 @arulajmani)


pkg/ccl/multiregionccl/region_test.go, line 255 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Looks like this is only testing a CREATE REGIONAL BY ROW table now, so we can probably simplify this test a bit?

i'd rather keep it, since it's easier to add cases if we find out we need them at a later point.
also, don't think the simplification makes it that much easier to read :P


pkg/sql/region_util.go, line 1697 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

forEachTableDesc is no good here, as it filters out descriptors the user doesn't have privileges on. You probably want forEachMutableTableInDatabase here instead.

nice cathc, done

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.

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


pkg/ccl/multiregionccl/region_test.go, line 255 at r2 (raw file):

Previously, otan (Oliver Tan) wrote…

i'd rather keep it, since it's easier to add cases if we find out we need them at a later point.
also, don't think the simplification makes it that much easier to read :P

You have hope we'll need this at a later point after last week? haha, I'm fine keeping the structure as is, just update the comment above the test which explains why there's only one op so that readers aren't confused?


pkg/sql/region_util.go, line 1757 at r5 (raw file):

// database are currently being modified.
func (p *planner) checkNoRegionChangeUnderway(
	ctx context.Context, dbID descpb.ID, op string,

nit: consider wrap the error at the call-site instead of passing in this op string?

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.

:lgtm: minus the nits. 🎉

Reviewed 12 of 12 files at r3, 4 of 4 files at r4, 8 of 8 files at r5.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @otan)


pkg/ccl/multiregionccl/regional_by_row_test.go, line 708 at r4 (raw file):

	regionalByRowChanges := []struct {
		setup                          string
		alterCmd                       string

Nit: We might want to generalize the name of this, since some of the below operations aren't "ALTER"s.


pkg/ccl/multiregionccl/regional_by_row_test.go, line 778 at r4 (raw file):

	for _, rbrChange := range regionalByRowChanges {
		for _, regionChange := range regionChanges {
			t.Run(fmt.Sprintf("from %s to %s with racing %s", rbrChange.setup, rbrChange.alterCmd, regionChange.cmd), func(t *testing.T) {

Nit: Should this be "statement %s with concurrent %s, racing with %s"?


pkg/ccl/multiregionccl/regional_by_row_test.go, line 804 at r4 (raw file):

				setupDB(sqlDB, rbrChange.setup)

				// Perform the alter table command asynchronously; this will be interrupted.

Nit: generalize alter table command?


pkg/sql/region_util.go, line 1710 at r4 (raw file):

						detailSuffix,
					),
					"cancel the existing job or try again when the change is complete",

Nit: Any chance we can pull the job id for easier reference?


pkg/sql/region_util.go, line 1735 at r4 (raw file):

			}
			// Disallow index changes for REGIONAL BY ROW tables.
			// We do this on the second loop, as index changes may be a precede to the actual PRIMARY KEY swap.

Nit: I think we can drop "be a" and "to". What do you mean by "precede" here? Might be good to provide a bit more context in this comment.

@ajstorm
Copy link
Collaborator

ajstorm commented Apr 26, 2021

@otan just a heads-up that this is one of the last GA blockers needed for the RC that they're hoping to cut Tuesday (EDT). Any chance we can get this in sometime before then?

otan added 2 commits April 27, 2021 06:39
Release note (sql change): Disallow ADD/DROP REGION whilst a
REGIONAL BY ROW table has index changes underway or a table is
transitioning to or from REGIONAL BY ROW.
Release note (sql change): Prevent index modification on REGIONAL BY ROW
tables and locality to/from REGIONAL BY ROW changes during a ADD/DROP
REGION.
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 (and 1 stale) (waiting on @ajstorm, @arulajmani, and @otan)


pkg/sql/region_util.go, line 1710 at r4 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Nit: Any chance we can pull the job id for easier reference?

that is not straightforward, so i'm not doing that.
there's a bunch of TODOs all over the place to do this for other things.


pkg/sql/region_util.go, line 1757 at r5 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: consider wrap the error at the call-site instead of passing in this op string?

i'd rather not, because that pushes a lot of lines of code and setup up at the call sites.

@otan
Copy link
Contributor Author

otan commented Apr 26, 2021

bors r=ajstorm,arulajmani

@craig
Copy link
Contributor

craig bot commented Apr 27, 2021

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment