@@ -11183,3 +11183,60 @@ CREATE TABLE child_pk (k INT8 PRIMARY KEY REFERENCES parent);
1118311183 sqlDB .Exec (t , `DROP DATABASE test` )
1118411184 }
1118511185}
11186+
11187+ func TestRestoreFailureDeletesComments (t * testing.T ) {
11188+ defer leaktest .AfterTest (t )()
11189+ defer log .Scope (t ).Close (t )
11190+
11191+ _ , sqlDB , cleanupFn := backupRestoreTestSetupEmpty (t , singleNode , "" , InitManualReplication , base.TestClusterArgs {})
11192+ defer cleanupFn ()
11193+
11194+ // Set pause point for after the system tables have been published.
11195+ sqlDB .Exec (t , `SET CLUSTER SETTING jobs.debug.pausepoints = 'restore.after_cleanup_temp_system_tables'` )
11196+
11197+ commentCountQuery := `SELECT count(*) FROM system.comments`
11198+
11199+ var count int
11200+ sqlDB .QueryRow (t , commentCountQuery ).Scan (& count )
11201+ require .Equal (t , 0 , count )
11202+
11203+ // Create a database with tables, types, and schemas that have comments
11204+ sqlDB .Exec (t , `CREATE DATABASE test_db` )
11205+ sqlDB .Exec (t , `USE test_db` )
11206+
11207+ sqlDB .Exec (t , `CREATE TYPE custom_type AS ENUM ('val1', 'val2')` )
11208+ sqlDB .Exec (t , `COMMENT ON TYPE custom_type IS 'This is a custom type comment'` )
11209+
11210+ sqlDB .Exec (t , `CREATE SCHEMA test_schema` )
11211+ sqlDB .Exec (t , `COMMENT ON SCHEMA test_schema IS 'This is a schema comment'` )
11212+
11213+ sqlDB .Exec (t , `CREATE TABLE test_schema.test_table (id INT PRIMARY KEY, name STRING)` )
11214+ sqlDB .Exec (t , `COMMENT ON TABLE test_schema.test_table IS 'This is a table comment'` )
11215+
11216+ sqlDB .Exec (t , `COMMENT ON DATABASE test_db IS 'This is a database comment'` )
11217+
11218+ sqlDB .QueryRow (t , commentCountQuery ).Scan (& count )
11219+ require .Equal (t , 4 , count )
11220+
11221+ sqlDB .Exec (t , `BACKUP INTO 'nodelocal://1/test_backup'` )
11222+
11223+ sqlDB .Exec (t , `USE system` )
11224+
11225+ sqlDB .Exec (t , `DROP DATABASE test_db CASCADE` )
11226+ sqlDB .QueryRow (t , commentCountQuery ).Scan (& count )
11227+ require .Equal (t , 0 , count )
11228+
11229+ var jobID jobspb.JobID
11230+ sqlDB .QueryRow (t , `RESTORE FROM LATEST IN 'nodelocal://1/test_backup' WITH detached` ).Scan (& jobID )
11231+ jobutils .WaitForJobToPause (t , sqlDB , jobID )
11232+
11233+ sqlDB .QueryRow (t , commentCountQuery ).Scan (& count )
11234+ require .Equal (t , 4 , count )
11235+
11236+ // Cancel the restore job
11237+ sqlDB .Exec (t , `CANCEL JOB $1` , jobID )
11238+ jobutils .WaitForJobToCancel (t , sqlDB , jobID )
11239+
11240+ sqlDB .QueryRow (t , commentCountQuery ).Scan (& count )
11241+ require .Equal (t , 0 , count )
11242+ }
0 commit comments