Skip to content

Commit

Permalink
backupccl: ensure AOST incremental backup ends after previous backup
Browse files Browse the repository at this point in the history
Informs #79674

Release note (sql change): Previously, a user could run an AS OF SYSTEM TIME
incremental backup with an end time earlier than the previous backup's end time
, which could lead to an out of order incremental backup chain. This PR causes
the incremental backup to fail if the AS OF SYSTEM TIME is less than the
previous backup's end time.
  • Loading branch information
msbutler committed Apr 25, 2022
1 parent 66f3057 commit 4e52ddb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/ccl/backupccl/backup_planning.go
Expand Up @@ -725,6 +725,12 @@ func backupPlanHook(
if err := requireEnterprise("incremental"); err != nil {
return err
}
lastEndTime := prevBackups[len(prevBackups)-1].EndTime
if endTime.Less(lastEndTime) {
return errors.Newf("`AS OF SYSTEM TIME` %s must be greater than "+
"the previous backup's end time of %s.",
endTime.GoTime(), lastEndTime.GoTime())
}
startTime = prevBackups[len(prevBackups)-1].EndTime
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/ccl/backupccl/backup_test.go
Expand Up @@ -3659,8 +3659,18 @@ func TestBackupAsOfSystemTime(t *testing.T) {

beforeDir := LocalFoo + `/beforeTs`
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO '%s' AS OF SYSTEM TIME %s`, beforeDir, beforeTs))

equalDir := LocalFoo + `/equalTs`
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO '%s' AS OF SYSTEM TIME %s`, equalDir, equalTs))
{
// testing UX guardrails for AS OF SYSTEM TIME backups in collections
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data INTO '%s' AS OF SYSTEM TIME %s`, equalDir, equalTs))

sqlDB.ExpectErr(t, "`AS OF SYSTEM TIME` .* must be greater than the previous backup's end time of",
fmt.Sprintf(`BACKUP DATABASE data INTO LATEST IN '%s' AS OF SYSTEM TIME %s`,
equalDir,
beforeTs))
}

sqlDB.Exec(t, `DROP TABLE data.bank`)
sqlDB.Exec(t, `RESTORE data.* FROM $1`, beforeDir)
Expand Down

0 comments on commit 4e52ddb

Please sign in to comment.