Skip to content

Commit

Permalink
backupccl: make SHOW BACKUP timestamps timestampTZ
Browse files Browse the repository at this point in the history
Release note (sql change): SHOW BACKUP's timestamp columns are now TIMESTAMPTZ, meaning they render in the session offset.
Epic: CRDB-24406.
  • Loading branch information
dt committed Aug 7, 2023
1 parent 3e7991d commit 3744ace
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/ccl/backupccl/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ func backupShowerHeaders(showSchemas bool, opts tree.ShowBackupOptions) colinfo.
{Name: "object_name", Typ: types.String},
{Name: "object_type", Typ: types.String},
{Name: "backup_type", Typ: types.String},
{Name: "start_time", Typ: types.Timestamp},
{Name: "end_time", Typ: types.Timestamp},
{Name: "start_time", Typ: types.TimestampTZ},
{Name: "end_time", Typ: types.TimestampTZ},
{Name: "size_bytes", Typ: types.Int},
{Name: "rows", Typ: types.Int},
{Name: "is_full_cluster", Typ: types.Bool},
Expand Down Expand Up @@ -844,12 +844,12 @@ func backupShowerDefault(
backupType = tree.NewDString("incremental")
}
start := tree.DNull
end, err := tree.MakeDTimestamp(timeutil.Unix(0, manifest.EndTime.WallTime), time.Nanosecond)
end, err := tree.MakeDTimestampTZ(timeutil.Unix(0, manifest.EndTime.WallTime), time.Nanosecond)
if err != nil {
return nil, err
}
if manifest.StartTime.WallTime != 0 {
start, err = tree.MakeDTimestamp(timeutil.Unix(0, manifest.StartTime.WallTime), time.Nanosecond)
start, err = tree.MakeDTimestampTZ(timeutil.Unix(0, manifest.StartTime.WallTime), time.Nanosecond)
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/ccl/backupccl/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ CREATE TABLE data.sc.t2 (a data.welcome);

const full, inc, inc2 = localFoo + "/full", localFoo + "/inc", localFoo + "/inc2"

beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, beforeTS), full)

res := sqlDB.QueryStr(t, `
Expand Down Expand Up @@ -93,7 +93,7 @@ ORDER BY object_type, object_name`, full)

// Backup the changes by appending to the base and by making a separate
// inc backup.
incTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
incTS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, incTS), full)
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s' INCREMENTAL FROM $2`, incTS), inc, full)

Expand Down Expand Up @@ -124,9 +124,9 @@ ORDER BY object_type, object_name`, full)
// Truncate decimal places so Go's very rigid parsing will work.
// TODO(bardin): Consider using a third-party library for this, or some kind
// of time-freezing on the test cluster.
truncateBackupTimeRE := regexp.MustCompile(`^(.*\.[0-9]{2})[0-9]*$`)
truncateBackupTimeRE := regexp.MustCompile(`^(.*\.[0-9]{2})[0-9]*\+00$`)
matchResult := truncateBackupTimeRE.FindStringSubmatch(beforeTS)
require.NotNil(t, matchResult)
require.NotNil(t, matchResult, "%s does not match %s", beforeTS, truncateBackupTimeRE)
backupTime, err := time.Parse("2006-01-02 15:04:05.00", matchResult[1])
require.NoError(t, err)
backupFolder := backupTime.Format(backupbase.DateBasedIntoFolderName)
Expand Down Expand Up @@ -168,7 +168,7 @@ ORDER BY object_type, object_name`, full)

// Backup the changes again, by appending to the base and by making a
// separate inc backup.
inc2TS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
inc2TS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, inc2TS), full)
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s' INCREMENTAL FROM $2, $3`, inc2TS), inc2, full, inc)

Expand Down Expand Up @@ -633,7 +633,7 @@ func TestShowBackupTenants(t *testing.T) {
defer conn10.Close()
tenant10 := sqlutils.MakeSQLRunner(conn10)
tenant10.Exec(t, `CREATE DATABASE foo; CREATE TABLE foo.bar(i int primary key); INSERT INTO foo.bar VALUES (110), (210)`)
beforeTS := systemDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
beforeTS := systemDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0]

systemDB.Exec(t, fmt.Sprintf(`BACKUP TENANT 10 TO 'nodelocal://1/t10' AS OF SYSTEM TIME '%s'`, beforeTS))

Expand Down Expand Up @@ -726,7 +726,7 @@ func TestShowBackupWithDebugIDs(t *testing.T) {

const full = localFoo + "/full"

beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, beforeTS), full)

// extract the object IDs for the database and public schema
Expand Down
22 changes: 22 additions & 0 deletions pkg/ccl/backupccl/testdata/backup-restore/show_backup
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ SELECT sum(size_bytes) FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/' WITH s
----
0

query-sql
SET TIME ZONE 'UTC';
----

query-sql
SELECT end_time, end_time AT TIME ZONE 'MST' FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/' WITH skip size] limit 1;
----
2022-08-03 16:00:28.984252 +0000 UTC 2022-08-03 09:00:28.984252 +0000 +0000

query-sql
SET TIME ZONE 'MST';
----

query-sql
SELECT end_time, end_time AT TIME ZONE 'MST' FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/' WITH skip size] limit 1;
----
2022-08-03 09:00:28.984252 -0700 MST 2022-08-03 09:00:28.984252 +0000 +0000

query-sql
SET TIME ZONE 'UTC';
----

# This backup is completely valid, but has no jobs.
query-sql regex=No\sproblems\sfound!
SELECT * FROM [SHOW BACKUP VALIDATE FROM 'valid-22.2' IN 'nodelocal://1/'];
Expand Down

0 comments on commit 3744ace

Please sign in to comment.