Skip to content

Conversation

fqazi
Copy link
Collaborator

@fqazi fqazi commented Aug 19, 2025

Previously, the successful backup tests would for each stage of a schema
change would run the full schema change, taking a backup at the target
stage. This patch modifies the TestBackupSuccess variants of the schema
changer test to start the server once, take all the backups and then
restore the stages we should be testing.

Testing show around a ~30% improvement with this change in execution
time.

Fixes: #152076

Release note: None

@fqazi fqazi requested a review from Copilot August 19, 2025 20:39
Copy link

blathers-crl bot commented Aug 19, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the backup success tests for the declarative schema changer to improve performance by ~30%. Instead of starting a server for each test stage and running the full schema change every time, it creates a single server once, takes all necessary backups during the schema change execution, and then reuses those backups across test cases.

  • Introduces a shared server pattern for backup tests with a new TestServer struct
  • Refactors backupSuccess into preparation and execution phases to enable backup reuse
  • Updates the test framework to support optional preparation functions

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/sql/schemachanger/sctest/test_server_factory.go Adds TestServer struct and Start method to enable server reuse across test cases
pkg/sql/schemachanger/sctest/framework.go Updates framework to accept optional preparation function for test setup
pkg/sql/schemachanger/sctest/cumulative.go Updates test calls to pass nil for preparation function where not needed
pkg/sql/schemachanger/sctest/backup.go Refactors backup tests to use preparation phase for taking backups and execution phase for testing
pkg/ccl/schemachangerccl/multiregion_testcluster_factory.go Implements Start method for multi-region test cluster factory

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

key.Phase, key.Ordinal)
backupStmt := fmt.Sprintf("BACKUP DATABASE %s INTO '%s'", dbName, url)
_, err := dbForBackup.Load().Exec(backupStmt)
if err != nil {
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The error check is missing a return statement. If the backup fails, the function should return the error instead of continuing to update the backups map.

Copilot uses AI. Check for mistakes.

@fqazi fqazi force-pushed the speedUpBackupTests branch 2 times, most recently from b1042ac to 2c014b4 Compare August 20, 2025 19:53
Previously, we only supported running a closure against a TestServer in
the schema changer testing framework. This was problematic for tests
that could save time by sharing servers (for example BACKUP / RESTORE).
To address this, this patch introduces a Start method for starting up a
server.

Release note: None
@fqazi fqazi force-pushed the speedUpBackupTests branch 8 times, most recently from d95c1f1 to c16afcf Compare September 30, 2025 19:09
@fqazi fqazi marked this pull request as ready for review September 30, 2025 19:10
@fqazi fqazi requested a review from a team as a code owner September 30, 2025 19:10
@fqazi fqazi force-pushed the speedUpBackupTests branch from c16afcf to 1085591 Compare September 30, 2025 20:32
@rafiss rafiss added backport-25.2.x Flags PRs that need to be backported to 25.2 backport-25.3.x Flags PRs that need to be backported to 25.3 backport-25.4.x Flags PRs that need to be backported to 25.4 labels Sep 30, 2025
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

nice work!

Previously, the successful backup tests would for each stage of a schema
change would run the full schema change, taking a backup at the target
stage. This patch modifies the TestBackupSuccess variants of the schema
changer test to start the server once, take all the backups and then
restore the stages we should be testing.

Testing show around a ~30% improvement with this change in execution
time.

Fixes: cockroachdb#152076

Release note: None
@fqazi fqazi force-pushed the speedUpBackupTests branch from 1085591 to 3af68bd Compare October 2, 2025 21:02
@fqazi
Copy link
Collaborator Author

fqazi commented Oct 3, 2025

@rafiss TFTR

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 3, 2025

@craig craig bot merged commit 287999c into cockroachdb:master Oct 3, 2025
23 checks passed
Copy link

blathers-crl bot commented Oct 3, 2025

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #152076: branch-release-25.2, branch-release-25.3, branch-release-25.4.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Copy link

blathers-crl bot commented Oct 3, 2025

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 09a15e4 to blathers/backport-release-25.2-152112: POST https://api.github.com/repos/fqazi/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 25.2.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

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

Labels

backport-25.2.x Flags PRs that need to be backported to 25.2 backport-25.3.x Flags PRs that need to be backported to 25.3 backport-25.4.x Flags PRs that need to be backported to 25.4 backport-failed target-release-26.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkg/ccl/schemachangerccl/sctestbackupccl/sctestbackupccl_test: TestBackupSuccessMixedVersion_multiregion_add_column_multiple_regional_by_row failed

3 participants