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

sctest: Augmented BACKUP/RESTORE tests with table-level restore #87316

Conversation

Xiang-Gu
Copy link
Contributor

@Xiang-Gu Xiang-Gu commented Sep 1, 2022

Commit 1: non-code minor changes (added comments, moved function a little bit)
Commit 2:
Previously, the Backup test in declarative schema changer backups the
whole database and restore the whole database with RESTORE DATABASE.
This PR augments the test by adding another flavor to restore:
RESTORE TABLE tbl1,...,tblN where tblx are all the tables in the
backup. This will nicely give us coverage for RESTORE TABLE when
a declarative schema changer job is restored.

Note that ideally we want to randomly restore only a subset of all the
table. Indeed I tried to implement that but realize it was blocked by
one limitation in the declarative shcema changer: We don't yet support
restore schema changer job that skips missing sequences (E.g. if we
have a table t and a sequence s, and I want to
ALTER TABLE t ADD COLUMN c DEFAULT nextval('s'), we backup database
in PostCommit phase. Later when we restore just t, the schema changer
job will run into error error executing 'missing rewrite for id 109 in <column_default_expression:<table_id:108 column_id:2 embedded_expr:<expr:"nextval(109:::REGCLASS)" uses_sequence_ids:109 >))
This issue is tracked in #87518.

Fixes: #86835

Release justification: test-only changes
Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

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 1 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @Xiang-Gu)


pkg/sql/schemachanger/sctest/cumulative.go line 560 at r2 (raw file):

			// reaches the expected state as if the back/restore had not happened at all.
			// Skip a backup randomly.
			type BackupConsumptionFlavor struct {

nit: don't export this type


pkg/sql/schemachanger/sctest/cumulative.go line 597 at r2 (raw file):

			if len(tablesToRestore) > 0 {
				flavors = append(flavors, BackupConsumptionFlavor{
					name: "restore all tables in database",

nit: add a TODO and/or file an issue to restore a subset?

Added comments around the Backup/Restore test for declarative schema
changer, moved functions here and there, and added some new lines
for better readability.
Copy link
Contributor Author

@Xiang-Gu Xiang-Gu 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! 1 of 0 LGTMs obtained (waiting on @Xiang-Gu)


pkg/sql/schemachanger/sctest/cumulative.go line 560 at r2 (raw file):

Previously, ajwerner wrote…

nit: don't export this type

done


pkg/sql/schemachanger/sctest/cumulative.go line 597 at r2 (raw file):

Previously, ajwerner wrote…

nit: add a TODO and/or file an issue to restore a subset?

done

Previously, the Backup test in declarative schema changer backups the
whole database and restore the whole database with `RESTORE DATABASE`.
This PR augments the test by adding another flavor to restore:
`RESTORE TABLE tbl1,...,tblN` where `tblx` are *all* the tables in the
backup. This will nicely give us coverage for `RESTORE TABLE` when
a declarative schema changer job is running.

Note that ideally we want to randomly restore only a subset of all the
table. Indeed I tried to implement that but realize it was blocked by
one limitation in the declarative shcema changer: We don't yet support
restore schema changer job that skips missing sequences (E.g. if we
have a table `t` and a sequence `s`, and I want to
`ALTER TABLE t ADD COLUMN c DEFAULT nextval('s')`, we backup database
in PostCommit phase. Later when we restore just `t`, the schema changer
job will run into error `error executing 'missing rewrite for id 109 in
<column_default_expression:<table_id:108 column_id:2
embedded_expr:<expr:"nextval(109:::REGCLASS)" uses_sequence_ids:109 >)`)
In other words, we have not implemented the equivalent of
`skip_missing_sequences`, which is an option for RESTORE,
for schema changer job.

Release justification: test-only changes
Release note: None
@Xiang-Gu Xiang-Gu force-pushed the add_table_level_backup_restore_test_for_new_schema_changer branch from d405b27 to f4b248e Compare September 7, 2022 20:50
@Xiang-Gu
Copy link
Contributor Author

Xiang-Gu commented Sep 7, 2022

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 7, 2022

Build succeeded:

@craig craig bot merged commit e39111b into cockroachdb:master Sep 7, 2022
@Xiang-Gu Xiang-Gu deleted the add_table_level_backup_restore_test_for_new_schema_changer branch September 8, 2022 06:49
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.

backupccl: run table BACKUP/RESTORE in sql/schemachanger/sctest/cumulative.go Backup tests
3 participants