From 0f2de6385fd212445c04dd8fe65fbac3cfa7c4bc Mon Sep 17 00:00:00 2001 From: Paul Bardea Date: Thu, 22 Jul 2021 11:04:53 -0400 Subject: [PATCH] backupccl: set a low GC TTL on the temporary system tables 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. --- .../full_cluster_backup_restore_test.go | 17 ++++++++++++++++- pkg/ccl/backupccl/restore_job.go | 7 +++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pkg/ccl/backupccl/full_cluster_backup_restore_test.go b/pkg/ccl/backupccl/full_cluster_backup_restore_test.go index 89736c7a078e..149f8fc1154e 100644 --- a/pkg/ccl/backupccl/full_cluster_backup_restore_test.go +++ b/pkg/ccl/backupccl/full_cluster_backup_restore_test.go @@ -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(), } @@ -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) diff --git a/pkg/ccl/backupccl/restore_job.go b/pkg/ccl/backupccl/restore_job.go index 20ebf102d78b..8ec40b75d4ab 100644 --- a/pkg/ccl/backupccl/restore_job.go +++ b/pkg/ccl/backupccl/restore_job.go @@ -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