Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backupccl: add is_full_cluster to SHOW BACKUP #45860

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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