Skip to content

Commit

Permalink
backupccl: add is_full_cluster to SHOW BACKUP
Browse files Browse the repository at this point in the history
Full cluster restores can only be performed on full cluster backups.
Therefore, it is useful if SHOW BACKUP can tell the user if a given
backup is a full cluster backup or not.

Release note (enterprise change): SHOW BACKUP now shows whether a BACKUP
is a full cluster backup or not.

Release justification: low risk, high impact change to existing
functionality.
  • Loading branch information
pbardea committed Mar 16, 2020
1 parent a06be62 commit fe355f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/ccl/backupccl/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func backupShowerHeaders(showSchemas bool) sqlbase.ResultColumns {
{Name: "end_time", Typ: types.Timestamp},
{Name: "size_bytes", Typ: types.Int},
{Name: "rows", Typ: types.Int},
{Name: "is_full_cluster", Typ: types.Bool},
}
if showSchemas {
baseHeaders = append(baseHeaders, sqlbase.ResultColumn{Name: "create_statement", Typ: types.String})
Expand Down Expand Up @@ -205,6 +206,7 @@ func backupShowerDefault(ctx context.Context, p sql.PlanHookState, showSchemas b
tree.MakeDTimestamp(timeutil.Unix(0, manifest.EndTime.WallTime), time.Nanosecond),
tree.NewDInt(tree.DInt(descSizes[table.ID].DataSize)),
tree.NewDInt(tree.DInt(descSizes[table.ID].Rows)),
tree.MakeDBool(manifest.DescriptorCoverage == tree.AllDescriptors),
}
if showSchemas {
schema, err := p.ShowCreate(ctx, dbName, manifest.Descriptors, table, sql.OmitMissingFKClausesFromCreate)
Expand Down
38 changes: 29 additions & 9 deletions pkg/ccl/backupccl/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestShowBackup(t *testing.T) {
beforeTS := sqlDB.QueryStr(t, `SELECT now()::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, beforeTS), full)

res := sqlDB.QueryStr(t, `SELECT table_name, start_time::string, end_time::string, rows FROM [SHOW BACKUP $1]`, full)
require.Equal(t, [][]string{{"bank", "NULL", beforeTS, strconv.Itoa(numAccounts)}}, res)
res := sqlDB.QueryStr(t, `SELECT table_name, start_time::string, end_time::string, rows, is_full_cluster FROM [SHOW BACKUP $1]`, full)
require.Equal(t, [][]string{{"bank", "NULL", beforeTS, strconv.Itoa(numAccounts), "false"}}, res)

// Mess with half the rows.
affectedRows, err := sqlDB.Exec(t,
Expand All @@ -50,10 +50,10 @@ func TestShowBackup(t *testing.T) {
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s' INCREMENTAL FROM $2`, incTS), inc, full)

// Check the appended base backup.
res = sqlDB.QueryStr(t, `SELECT table_name, start_time::string, end_time::string, rows FROM [SHOW BACKUP $1]`, full)
res = sqlDB.QueryStr(t, `SELECT table_name, start_time::string, end_time::string, rows, is_full_cluster FROM [SHOW BACKUP $1]`, full)
require.Equal(t, [][]string{
{"bank", "NULL", beforeTS, strconv.Itoa(numAccounts)},
{"bank", beforeTS, incTS, strconv.Itoa(int(affectedRows * 2))},
{"bank", "NULL", beforeTS, strconv.Itoa(numAccounts), "false"},
{"bank", beforeTS, incTS, strconv.Itoa(int(affectedRows * 2)), "false"},
}, res)

// Check the separate inc backup.
Expand Down Expand Up @@ -161,7 +161,7 @@ COMMENT ON INDEX tablea_b_idx IS 'index'`
expectedCreateSeq,
}
for i, row := range showBackupRows {
createStmt := row[6]
createStmt := row[7]
if !eqWhitespace(createStmt, expected[i]) {
t.Fatalf("mismatched create statement: %s, want %s", createStmt, expected[i])
}
Expand Down Expand Up @@ -196,12 +196,12 @@ COMMENT ON INDEX tablea_b_idx IS 'index'`
)`

showBackupRows = sqlDB.QueryStr(t, fmt.Sprintf(`SHOW BACKUP SCHEMAS '%s'`, includedFK))
createStmtSameDB := showBackupRows[1][6]
createStmtSameDB := showBackupRows[1][7]
if !eqWhitespace(createStmtSameDB, wantSameDB) {
t.Fatalf("mismatched create statement: %s, want %s", createStmtSameDB, wantSameDB)
}

createStmtDiffDB := showBackupRows[2][6]
createStmtDiffDB := showBackupRows[2][7]
if !eqWhitespace(createStmtDiffDB, wantDiffDB) {
t.Fatalf("mismatched create statement: %s, want %s", createStmtDiffDB, wantDiffDB)
}
Expand All @@ -222,12 +222,32 @@ COMMENT ON INDEX tablea_b_idx IS 'index'`
)`

showBackupRows = sqlDB.QueryStr(t, fmt.Sprintf(`SHOW BACKUP SCHEMAS '%s'`, missingFK))
createStmt := showBackupRows[0][6]
createStmt := showBackupRows[0][7]
if !eqWhitespace(createStmt, want) {
t.Fatalf("mismatched create statement: %s, want %s", createStmt, want)
}
}

{
full_cluster := localFoo + "/full_cluster"
sqlDB.Exec(t, `BACKUP TO $1;`, full_cluster)

showBackupRows = sqlDB.QueryStr(t, fmt.Sprintf(`SHOW BACKUP '%s'`, full_cluster))
is_full_cluster := showBackupRows[0][6]
if !eqWhitespace(is_full_cluster, "true") {
t.Fatal("expected show backup to indicate that backup was full cluster")
}

full_cluster_inc := localFoo + "/full_cluster_inc"
sqlDB.Exec(t, `BACKUP TO $1 INCREMENTAL FROM $2;`, full_cluster_inc, full_cluster)

showBackupRows = sqlDB.QueryStr(t, fmt.Sprintf(`SHOW BACKUP '%s'`, full_cluster))
is_full_cluster = showBackupRows[0][6]
if !eqWhitespace(is_full_cluster, "true") {
t.Fatal("expected show backup to indicate that backup was full cluster")
}
}

}

func eqWhitespace(a, b string) bool {
Expand Down

0 comments on commit fe355f3

Please sign in to comment.