Skip to content

Commit

Permalink
backupccl: set a low GC TTL on the temporary system tables
Browse files Browse the repository at this point in the history
Cluster restore creates a temporary system table to hold system table
data before transactionally writing it to the real system tables. This
table is only persisted during the lifetime of the restore and is
dropped at the end of the restore. It should be GC'd quickly since it's
of no use after the restore finishes.

Release note (bug fix): Ensure that auxilary tables used during cluster
restore are GC'd quickly afterwards.

Release justification: bug fix and UX improvement.
  • Loading branch information
pbardea committed Sep 2, 2021
1 parent 8418f43 commit 0f2de63
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 16 additions & 1 deletion pkg/ccl/backupccl/full_cluster_backup_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ CREATE TABLE data2.foo (a int);
systemschema.TableStatisticsTable.GetName(),
systemschema.UITable.GetName(),
systemschema.UsersTable.GetName(),
systemschema.ZonesTable.GetName(),
systemschema.ScheduledJobsTable.GetName(),
}

Expand Down Expand Up @@ -315,6 +314,22 @@ CREATE TABLE data2.foo (a int);
}
})

t.Run("zone_configs", func(t *testing.T) {
// The restored zones should be a superset of the zones in the backed up
// cluster.
zoneIDsResult := sqlDB.QueryStr(t, `SELECT id FROM system.zones`)
var q strings.Builder
q.WriteString("SELECT * FROM system.zones WHERE id IN (")
for i, restoreZoneIDRow := range zoneIDsResult {
if i > 0 {
q.WriteString(", ")
}
q.WriteString(restoreZoneIDRow[0])
}
q.WriteString(")")
sqlDBRestore.CheckQueryResults(t, q.String(), sqlDB.QueryStr(t, q.String()))
})

t.Run("ensure that tables can be created at the excepted ID", func(t *testing.T) {
var maxID, dbID, tableID int
sqlDBRestore.QueryRow(t, "SELECT max(id) FROM system.namespace").Scan(&maxID)
Expand Down
7 changes: 5 additions & 2 deletions pkg/ccl/backupccl/restore_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2523,9 +2523,12 @@ func (r *restoreResumer) cleanupTempSystemTables(ctx context.Context) error {
executor := r.execCfg.InternalExecutor
// After restoring the system tables, drop the temporary database holding the
// system tables.
gcTTLQuery := fmt.Sprintf("ALTER DATABASE %s CONFIGURE ZONE USING gc.ttlseconds=1", restoreTempSystemDB)
if _, err := executor.Exec(ctx, "altering-gc-ttl-temp-system" /* opName */, nil /* txn */, gcTTLQuery); err != nil {
log.Errorf(ctx, "failed to update the GC TTL of %q: %+v", restoreTempSystemDB, err)
}
dropTableQuery := fmt.Sprintf("DROP DATABASE %s CASCADE", restoreTempSystemDB)
_, err := executor.Exec(ctx, "drop-temp-system-db" /* opName */, nil /* txn */, dropTableQuery)
if err != nil {
if _, err := executor.Exec(ctx, "drop-temp-system-db" /* opName */, nil /* txn */, dropTableQuery); err != nil {
return errors.Wrap(err, "dropping temporary system db")
}
return nil
Expand Down

0 comments on commit 0f2de63

Please sign in to comment.