Skip to content

Commit

Permalink
backupccl: pause backup schedule in TestFullClusterBackup
Browse files Browse the repository at this point in the history
Currently the backup schedule in TestFullClusterBackup can be processed by the
job scheduler in the original DB after the backup has been taken, thus causing
a difference between the original and restored clusters. Prevent this
processing by setting the first run in the future and pausing the schedule.

Fixes #71435

Release note: None
  • Loading branch information
Rui Hu committed Oct 24, 2021
1 parent 31ccb1c commit 5de7501
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/ccl/backupccl/full_cluster_backup_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"github.com/cockroachdb/cockroach/pkg/base"
_ "github.com/cockroachdb/cockroach/pkg/ccl/partitionccl"
Expand All @@ -32,6 +33,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -144,8 +146,10 @@ CREATE TABLE data2.foo (a int);
sqlDB.Exec(t, `GRANT CREATE, SELECT ON DATABASE data TO system_ops;`)
sqlDB.Exec(t, `GRANT system_ops TO maxroach1;`)

// Populate system.scheduled_jobs table.
sqlDB.Exec(t, `CREATE SCHEDULE FOR BACKUP data.bank INTO $1 RECURRING '@hourly' FULL BACKUP ALWAYS`, LocalFoo)
// Populate system.scheduled_jobs table with a first run in the future to prevent immediate adoption.
firstRun := timeutil.Now().Add(time.Hour).Format(timeutil.TimestampWithoutTZFormat)
sqlDB.Exec(t, `CREATE SCHEDULE FOR BACKUP data.bank INTO $1 RECURRING '@hourly' FULL BACKUP ALWAYS WITH SCHEDULE OPTIONS first_run = $2`, LocalFoo, firstRun)
sqlDB.Exec(t, `PAUSE SCHEDULES SELECT id FROM [SHOW SCHEDULES FOR BACKUP]`)

injectStats(t, sqlDB, "data.bank", "id")
sqlDB.Exec(t, `BACKUP TO $1`, LocalFoo)
Expand Down

0 comments on commit 5de7501

Please sign in to comment.