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: insert missing public schema entry migration #73537

Conversation

RichardJCai
Copy link
Contributor

@RichardJCai RichardJCai commented Dec 7, 2021

When restoring a database, a namespace entry for the public
schema was not created.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@RichardJCai RichardJCai requested review from ajwerner and a team December 7, 2021 00:11
Copy link
Contributor

@ajwerner ajwerner 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 @ajwerner and @RichardJCai)


pkg/clusterversion/cockroach_versions.go, line 524 at r3 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

@ajwerner not sure if this is okay, I put this ahead since we want the migration keyed on InsertPublicSchemaNamespaceEntryOnRestore to go before PublicSchemasWithDescriptors. Figured it might be okay since v22 is not released at all yet, however playing it safe and just rekeying PublicSchemasWithDescriptor after InsertPublicSchemaNamespaceEntryOnRestore without rearranging the other versions might be better

One option is to use this version for this migration and then just stick PublicSchemaWithDescriptors at the end.

@RichardJCai RichardJCai force-pushed the insert_missing_public_schema_namespace_entry branch 2 times, most recently from ac7d6d6 to 9131ba2 Compare December 9, 2021 20:42
@RichardJCai
Copy link
Contributor Author

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @RichardJCai)

pkg/clusterversion/cockroach_versions.go, line 524 at r3 (raw file):

Previously, RichardJCai (Richard Cai) wrote…
One option is to use this version for this migration and then just stick PublicSchemaWithDescriptors at the end.

Yeah did this instead.

@RichardJCai RichardJCai requested review from ajwerner and a team December 9, 2021 20:42
@RichardJCai RichardJCai changed the title wip: insert missing public schema entry migration sql: insert missing public schema entry migration Dec 9, 2021
@RichardJCai RichardJCai marked this pull request as ready for review December 9, 2021 20:43
@RichardJCai RichardJCai requested review from a team and shermanCRL and removed request for a team December 9, 2021 20:43
@RichardJCai
Copy link
Contributor Author

Relevant issue: #73535
A separate fix has to be made for actually inserting the entry in restores.

@RichardJCai RichardJCai requested review from a team December 9, 2021 20:44
@RichardJCai RichardJCai force-pushed the insert_missing_public_schema_namespace_entry branch 3 times, most recently from 1d3525e to 2e13cab Compare December 14, 2021 16:26
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

I wonder if we can do is make it so that debug doctor will find this. It doesn't seem like a difficult addition and it'd give me some peace of mind.

Reviewed 16 of 21 files at r3, 10 of 10 files at r5, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @RichardJCai and @shermanCRL)


pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go, line 28 at r5 (raw file):

)

func TestPublicSchemaMigration(t *testing.T) {

I'd like to see a lower level test which injects the missing entry.


pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go, line 80 at r5 (raw file):

	// Restore is bugged, the public schemas will not have entries in
	// system.namespace.

Did we not fix this bug to have the restore create the entry? Should we separately fix that bug and backport that fix?


pkg/ccl/backupccl/restore_old_versions_test.go, line 263 at r5 (raw file):

Quoted 4 lines of code…
		fmt.Println(publicSchemaDirs)
		require.NoError(t, err)
		for _, dir := range dirs {
			fmt.Println(dir.Name())

detritus


pkg/clusterversion/cockroach_versions.go, line 296 at r5 (raw file):

	// InsertPublicSchemaNamespaceEntryOnRestore ensures all public schemas
	// have an entry in system.namespace upon being restored.
	InsertPublicSchemaNamespaceEntryOnRestore

is there a TODO to use this in restore?

@RichardJCai RichardJCai force-pushed the insert_missing_public_schema_namespace_entry branch 2 times, most recently from 7e44eac to ef49227 Compare December 14, 2021 21:05
Copy link
Contributor Author

@RichardJCai RichardJCai left a comment

Choose a reason for hiding this comment

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

I'll make a note to add this to debug doctor and actually create the entry during restore

#73535

This PR will be isolated to the migration itself

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @shermanCRL)


pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go, line 28 at r5 (raw file):

Previously, ajwerner wrote…

I'd like to see a lower level test which injects the missing entry.

Updated this test


pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go, line 80 at r5 (raw file):

Previously, ajwerner wrote…
	// Restore is bugged, the public schemas will not have entries in
	// system.namespace.

Did we not fix this bug to have the restore create the entry? Should we separately fix that bug and backport that fix?

Not yet - will do separately


pkg/clusterversion/cockroach_versions.go, line 296 at r5 (raw file):

Previously, ajwerner wrote…

is there a TODO to use this in restore?

Don't think we need a todo since we don't close this issue until we're done.


pkg/ccl/backupccl/restore_old_versions_test.go, line 263 at r5 (raw file):

Previously, ajwerner wrote…
		fmt.Println(publicSchemaDirs)
		require.NoError(t, err)
		for _, dir := range dirs {
			fmt.Println(dir.Name())

detritus

Done.

@RichardJCai RichardJCai requested a review from ajwerner December 15, 2021 16:41
@RichardJCai RichardJCai force-pushed the insert_missing_public_schema_namespace_entry branch from ef49227 to 96179bf Compare December 15, 2021 17:15
@RichardJCai
Copy link
Contributor Author

Also I guess I don't need the backup files to be added in this Pr anymore, will remove after.

@RichardJCai RichardJCai force-pushed the insert_missing_public_schema_namespace_entry branch from 96179bf to 9f8aa85 Compare December 15, 2021 21:16
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm: once you remove the hack from the test and the .DS_Store file.

Reviewed 4 of 12 files at r4, 5 of 5 files at r6, 14 of 14 files at r7, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RichardJCai and @shermanCRL)


pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go, line 61 at r7 (raw file):

	// Give root the ability to delete from system.namespace.
	sqlDB.Exec(t, `INSERT INTO system.users VALUES ('node', '', false);`)
	sqlDB.Exec(t, `GRANT node TO root`)

I'm not in love with this. It doesn't bring me joy. Somebody is going to see this later and then use it to insert instead of delete, which is buggy. Can you use catalog and kv APIs to muck with these keys?

Code quote:

	var db1ID, db2ID int
	row := sqlDB.QueryRow(t, `SELECT id FROM system.namespace WHERE name = 'db1'`)
	row.Scan(&db1ID)
	row = sqlDB.QueryRow(t, `SELECT id FROM system.namespace WHERE name = 'db2'`)
	row.Scan(&db2ID)

	// Remove public schema namespace entries from system.namespace.
	sqlDB.Exec(t, fmt.Sprintf(`DELETE FROM system.namespace WHERE name='public' AND id=29 AND "parentID"=%d`, db1ID))
	sqlDB.Exec(t, fmt.Sprintf(`DELETE FROM system.namespace WHERE name='public' AND id=29 AND "parentID"=%d`, db2ID))

pkg/ccl/backupccl/testdata/restore_old_versions/.DS_Store, line 0 at r7 (raw file):
Added accidentally

@RichardJCai RichardJCai force-pushed the insert_missing_public_schema_namespace_entry branch from 9f8aa85 to c9607b3 Compare December 16, 2021 16:58
When restoring a database, a namespace entry for the public
schema was not created.

Release note: None
@RichardJCai RichardJCai force-pushed the insert_missing_public_schema_namespace_entry branch from c9607b3 to 93be89d Compare December 16, 2021 18:06
Copy link
Contributor

@ajwerner ajwerner 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 1 of 9 files at r8.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @RichardJCai, and @shermanCRL)

@RichardJCai
Copy link
Contributor Author

TFTR
bors r=ajwerner

@craig
Copy link
Contributor

craig bot commented Dec 16, 2021

Already running a review

@RichardJCai RichardJCai reopened this Dec 16, 2021
@RichardJCai
Copy link
Contributor Author

Oops hit the wrong button

TFTR
bors r=ajwerner

@craig
Copy link
Contributor

craig bot commented Dec 16, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Dec 16, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Dec 16, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Dec 16, 2021

This PR was included in a batch that was canceled, it will be automatically retried

@craig
Copy link
Contributor

craig bot commented Dec 17, 2021

Build succeeded:

@craig craig bot merged commit 9edb27f into cockroachdb:master Dec 17, 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.

3 participants