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

multi-region: Unblock IMPORT into allowable multi-region tables #61192

Merged
merged 1 commit into from
Mar 4, 2021

Conversation

ajstorm
Copy link
Collaborator

@ajstorm ajstorm commented Feb 26, 2021

Unblock IMPORTing into allowable multi-region tables. We only support
importing into GLOBAL and REGIONAL BY TABLE tables as #61133 is blocking
IMPORT into any tables which have columns generated using a user defined
type (which covers REGIONAL BY ROW tables, as they have the crdb_region
column which is generated using the crdb_internal_region type).

This commit includes tests for both IMPORT and IMPORT INTO, as well as
cases which illustrate #61133 for non-multi-region tables.

Of note is the change to remove validation in create_table.go . This change was
required as the validation at this point is not possible from within
IMPORT, and it was uncovered through testing that this validation when
generating the LocalityConfig was not required anyway, as we validate
before writing the descriptors in all cases (i.e. after the
LocalityConfig is generated, but before the descriptors are written to
disk).

Release note: None

Release justification: Fixes bug in interaction between existing functionality and new multi-region feature.

@ajstorm ajstorm requested review from otan, arulajmani, adityamaru and a team February 26, 2021 15:47
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch 2 times, most recently from e946406 to 914ca0e Compare February 26, 2021 16:35
@ajstorm
Copy link
Collaborator Author

ajstorm commented Feb 26, 2021

Hold off on reviewing for now, diagnosing test failures....

@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch 4 times, most recently from 6211cff to 1757254 Compare February 28, 2021 17:05
Copy link
Contributor

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

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


pkg/ccl/importccl/import_stmt_test.go, line 34 at r1 (raw file):

	"github.com/cockroachdb/cockroach/pkg/ccl/backupccl"
	_ "github.com/cockroachdb/cockroach/pkg/ccl/kvccl"
	_ "github.com/cockroachdb/cockroach/pkg/ccl/multiregionccl"

hmm, correcting myself, i think _ "github.com/cockroachdb/cockroach/pkg/ccl" should do it.


pkg/sql/create_table.go, line 369 at r1 (raw file):

	dg := catalogkv.NewOneLevelUncachedDescGetter(params.p.txn, params.ExecCfg().Codec)
	if desc.LocalityConfig != nil {
		if err := desc.ValidateTableLocalityConfig(params.ctx, dg); err != nil {

are you sure we want to move this to startExec? this means other places which call NewTableDesc doesn't get validation

@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch from 1757254 to d6210fb Compare February 28, 2021 21:14
@blathers-crl blathers-crl bot requested a review from otan February 28, 2021 21:14
Copy link
Collaborator Author

@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 (waiting on @adityamaru, @arulajmani, and @otan)


pkg/ccl/importccl/import_stmt_test.go, line 34 at r1 (raw file):

Previously, otan (Oliver Tan) wrote…

hmm, correcting myself, i think _ "github.com/cockroachdb/cockroach/pkg/ccl" should do it.

No dice. Since we're in importccl, importing the the whole ccl directory causes a circular import.


pkg/sql/create_table.go, line 369 at r1 (raw file):

Previously, otan (Oliver Tan) wrote…

are you sure we want to move this to startExec? this means other places which call NewTableDesc doesn't get validation

Have a look at the update commit record and let me know if this covers your concerns.

@ajstorm
Copy link
Collaborator Author

ajstorm commented Mar 1, 2021

All tests are passing now. @adityamaru, @arulajmani, ready for a look now (and another look from @otan).

Copy link
Contributor

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


pkg/ccl/backupccl/restore_job.go, line 388 at r2 (raw file):

				if table.GetLocalityConfig() != nil {
					return pgerror.Newf(pgcode.FeatureNotSupported,
						"cannot write descriptor for multi-region table %d into non-multi-region database %d",

Let's add the table & database names in addition to the table ID in this error message? It makes the message a lot easier to grok for users.

@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch from d6210fb to a185494 Compare March 1, 2021 16:10
@ajstorm ajstorm requested a review from pbardea March 1, 2021 16:10
Copy link
Collaborator Author

@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 (waiting on @adityamaru, @arulajmani, @otan, and @pbardea)


pkg/ccl/backupccl/restore_job.go, line 388 at r2 (raw file):

Previously, pbardea (Paul Bardea) wrote…

Let's add the table & database names in addition to the table ID in this error message? It makes the message a lot easier to grok for users.

Done.

Copy link
Contributor

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

Reviewed 1 of 1 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @ajstorm, @arulajmani, and @pbardea)


pkg/ccl/importccl/import_stmt_test.go, line 34 at r1 (raw file):

Previously, ajstorm (Adam Storm) wrote…

No dice. Since we're in importccl, importing the the whole ccl directory causes a circular import.

ah it'd work if you renamed the test package to importccl_test, but no biggie

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.

Mostly looks good, just a couple minor suggestions and nits

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


pkg/ccl/backupccl/restore_job.go, line 380 at r3 (raw file):

			}
			if dbDesc.GetRegionConfig() != nil {
				if table.GetLocalityConfig() == nil {

nit: unnecessary nesting, you could revert this diff


pkg/ccl/importccl/import_stmt_test.go, line 1219 at r3 (raw file):

		verifyQuery string
		expected    [][]string
		err         bool

nit: non-empty error string <-> expect an error


pkg/ccl/importccl/import_stmt_test.go, line 6439 at r3 (raw file):

	const (
		nodes = 3

nit: unnecessary braces, you could just: const nodes = 3


pkg/ccl/importccl/import_stmt_test.go, line 6476 at r3 (raw file):

	}

	tc := testcluster.StartTestCluster(t, nodes, clusterArgs)

I'd recommend modifying TestingCreateMultiRegionCluster to accept a baseDir so that you don't have to do this whole setup thing here.


pkg/ccl/importccl/import_stmt_test.go, line 6490 at r3 (raw file):

	// Table schemas for USING
	tableSchemaMR := fmt.Sprintf("nodelocal://0/%s", "simple-schema-multi-region.sql")

Is it worth adding one for GLOBAL tables here as well?


pkg/ccl/importccl/import_stmt_test.go, line 6559 at r3 (raw file):

			if test.err {
				if test.errString == "" {

nit: instead of having a err and an errString, you could make the empty string imply no error.

Copy link
Contributor

@pbardea pbardea 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 @adityamaru and @ajstorm)

@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch 2 times, most recently from 9715453 to a3e800c Compare March 2, 2021 19:40
@ajstorm ajstorm requested review from arulajmani and otan March 2, 2021 20:01
Copy link
Collaborator Author

@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 (waiting on @adityamaru, @ajstorm, @arulajmani, and @otan)


pkg/ccl/backupccl/restore_job.go, line 380 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: unnecessary nesting, you could revert this diff

The reason I wrote it this way was because I wanted to avoid an else if branch below, which we would need to confirm that the RegionConfig was nil. I guess I could reorder it to avoid the nesting.


pkg/ccl/importccl/import_stmt_test.go, line 1219 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: non-empty error string <-> expect an error

good call. Done.


pkg/ccl/importccl/import_stmt_test.go, line 6439 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: unnecessary braces, you could just: const nodes = 3

copy pasta. Fixed.


pkg/ccl/importccl/import_stmt_test.go, line 6476 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I'd recommend modifying TestingCreateMultiRegionCluster to accept a baseDir so that you don't have to do this whole setup thing here.

Good suggestion. If only this had existed when I got start :-/. Done.


pkg/ccl/importccl/import_stmt_test.go, line 6490 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Is it worth adding one for GLOBAL tables here as well?

We can if you feel passionate about it. Was reluctant as the RBR is the most different, and every table type requires a new schema file.


pkg/ccl/importccl/import_stmt_test.go, line 6559 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: instead of having a err and an errString, you could make the empty string imply no error.

Done.

@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch from a3e800c to 827685f Compare March 2, 2021 20:38
@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch 2 times, most recently from 0919414 to 7e80760 Compare March 2, 2021 23:23
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 @adityamaru, @ajstorm, @arulajmani, and @otan)


pkg/ccl/backupccl/restore_job.go, line 380 at r3 (raw file):

Previously, ajstorm (Adam Storm) wrote…

The reason I wrote it this way was because I wanted to avoid an else if branch below, which we would need to confirm that the RegionConfig was nil. I guess I could reorder it to avoid the nesting.

Ah, I missed that part. Discard my nit


pkg/ccl/importccl/import_stmt_test.go, line 6476 at r3 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Good suggestion. If only this had existed when I got start :-/. Done.

Hehe you can blame me for that :P


pkg/ccl/multiregionccl/multiregionccltestutils/testutils.go, line 35 at r4 (raw file):

	}

	b := ""

nit: you could change baseDir to be a string instead of a string pointer and pass in an empty string in all the places where we pass nil.

@ajstorm ajstorm requested a review from arulajmani March 3, 2021 01:39
Copy link
Collaborator Author

@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 (waiting on @adityamaru, @ajstorm, @arulajmani, and @otan)


pkg/ccl/multiregionccl/multiregionccltestutils/testutils.go, line 35 at r4 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: you could change baseDir to be a string instead of a string pointer and pass in an empty string in all the places where we pass nil.

Yeah, contemplated that, but it seemed more intuitive to me to have nil denote that something's not in use, as opposed to "". If you feel strongly about it, I can make the change.

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.

:shipit:

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


pkg/ccl/multiregionccl/multiregionccltestutils/testutils.go, line 35 at r4 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Yeah, contemplated that, but it seemed more intuitive to me to have nil denote that something's not in use, as opposed to "". If you feel strongly about it, I can make the change.

Naa no strong feelings, I'm fine merging as is

@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch from 7e80760 to 92c676f Compare March 3, 2021 03:28
@ajstorm
Copy link
Collaborator Author

ajstorm commented Mar 3, 2021

TFTRs @arulajmani @otan and @pbardea.

Will bors as soon as I can get a clean run through testrace, which is pretty reliably failing due to OOM.

Unblock IMPORTing into allowable multi-region tables.  We only support
importing into GLOBAL and REGIONAL BY TABLE tables as cockroachdb#61133 is blocking
IMPORT into any tables which have columns generated using a user defined
type (which covers REGIONAL BY ROW tables, as they have the crdb_region
column which is generated using the crdb_internal_region type).

This commit includes tests for both IMPORT and IMPORT INTO, as well as
cases which illustrate cockroachdb#61133 for non-multi-region tables.

One thing of note is the removing of the call to
ValidateTableLocalityConfig from NewTableDesc.  This is intentional, and
was required, as the call to NewTableDesc in IMPORT doesn't have the
necessary infrastructure setup (namely, a valid transaction and the
EvalContext Codec) to validate the LocalityConfig at that time. That
being said, IMPORT does perform a proper validation of the full table
descriptor before it's written to disk.

At this point there are no other calls to NewTableDesc which require
validation of the LocalityConfig.

Release note: None

Release justification: Fixes bug in interaction between existing
functionality and new multi-region feature.
@ajstorm ajstorm force-pushed the ajstorm_mr_import_with_locality branch from 92c676f to 94a303d Compare March 3, 2021 22:35
@ajstorm
Copy link
Collaborator Author

ajstorm commented Mar 3, 2021

bors r=otan,arulajmani,pbardea

@craig
Copy link
Contributor

craig bot commented Mar 4, 2021

Build succeeded:

@craig craig bot merged commit cbdce1b into cockroachdb:master Mar 4, 2021
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.

5 participants