Skip to content

Commit

Permalink
backupccl: remove exceptional backups
Browse files Browse the repository at this point in the history
The xDBRef and duplicate-db exceptional backups
can no longer be restored since they were generated
>1 major version in the past. This change does add
a test inspired by the duplicate-db test to expand
coverage.

Release note: None
  • Loading branch information
adityamaru committed Mar 10, 2023
1 parent 9305349 commit 7066e9e
Show file tree
Hide file tree
Showing 24 changed files with 36 additions and 112 deletions.
107 changes: 0 additions & 107 deletions pkg/ccl/backupccl/restore_old_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func TestRestoreOldVersions(t *testing.T) {
exportDirsWithoutInterleave = testdataBase + "/exports-without-interleaved"
fkRevDirs = testdataBase + "/fk-rev-history"
clusterDirs = testdataBase + "/cluster"
exceptionalDirs = testdataBase + "/exceptional"
privilegeDirs = testdataBase + "/privileges"
multiRegionDirs = testdataBase + "/multi-region"
publicSchemaDirs = testdataBase + "/public-schema-remap"
Expand Down Expand Up @@ -129,112 +128,6 @@ func TestRestoreOldVersions(t *testing.T) {
}
})

// exceptional backups are backups that were possible to generate on old
// versions, but are now disallowed, but we should check that we fail
// gracefully with them.
t.Run("exceptional-backups", func(t *testing.T) {
t.Run("duplicate-db-desc", func(t *testing.T) {
backupUnderTest := "doubleDB"
/*
This backup was generated with the following SQL on (v21.1.6):
CREATE DATABASE db1;
DROP DATABASE db1;
CREATE DATABASE db1;
BACKUP TO 'nodelocal://1/doubleDB' WITH revision_history;
*/
dir, err := os.Stat(filepath.Join(exceptionalDirs, backupUnderTest))
require.NoError(t, err)
require.True(t, dir.IsDir())

// We could create tables which reference types in another database on
// 20.2 release candidates.
exportDir, err := filepath.Abs(filepath.Join(exceptionalDirs, dir.Name()))
require.NoError(t, err)

externalDir, dirCleanup := testutils.TempDir(t)
ctx := context.Background()
tc := testcluster.StartTestCluster(t, singleNode, base.TestClusterArgs{
ServerArgs: base.TestServerArgs{
// Disabling the default test tenant due to test cases
// failures. More investigation is required. Tracked with
// #76378.
DisableDefaultTestTenant: true,
ExternalIODir: externalDir,
},
})
sqlDB := sqlutils.MakeSQLRunner(tc.Conns[0])
defer func() {
tc.Stopper().Stop(ctx)
dirCleanup()
}()
err = os.Symlink(exportDir, filepath.Join(externalDir, "foo"))
require.NoError(t, err)

sqlDB.Exec(t, `RESTORE FROM $1`, localFoo)
sqlDB.Exec(t, `DROP DATABASE db1;`)
sqlDB.Exec(t, `RESTORE DATABASE db1 FROM $1`, localFoo)
sqlDB.CheckQueryResults(t,
`SELECT count(*) FROM [SHOW DATABASES] WHERE database_name = 'db1'`,
[][]string{{"1"}},
)
})

t.Run("x-db-type-reference", func(t *testing.T) {
backupUnderTest := "xDbRef"
/*
This backup was generated with the following SQL:
CREATE TYPE t AS ENUM ('foo');
CREATE TABLE tbl (a t);
CREATE DATABASE otherdb;
ALTER TABLE tbl RENAME TO otherdb.tbl;
BACKUP DATABASE otherdb TO 'nodelocal://1/xDbRef';
This was permitted on some release candidates of v20.2. (#55709)
*/
dir, err := os.Stat(filepath.Join(exceptionalDirs, backupUnderTest))
require.NoError(t, err)
require.True(t, dir.IsDir())

// We could create tables which reference types in another database on
// 20.2 release candidates.
exportDir, err := filepath.Abs(filepath.Join(exceptionalDirs, dir.Name()))
require.NoError(t, err)

externalDir, dirCleanup := testutils.TempDir(t)
ctx := context.Background()
tc := testcluster.StartTestCluster(t, singleNode, base.TestClusterArgs{
ServerArgs: base.TestServerArgs{
ExternalIODir: externalDir,
},
})
sqlDB := sqlutils.MakeSQLRunner(tc.Conns[0])
defer func() {
tc.Stopper().Stop(ctx)
dirCleanup()
}()
err = os.Symlink(exportDir, filepath.Join(externalDir, "foo"))
require.NoError(t, err)

// Expect this restore to fail.
sqlDB.ExpectErr(t, `type "t" has unknown ParentID 50`, `RESTORE DATABASE otherdb FROM $1`, localFoo)

// Expect that we don't crash and that we emit NULL for data that we
// cannot resolve (e.g. missing database descriptor, create_statement).
sqlDB.CheckQueryResults(t, `
SELECT
database_name, parent_schema_name, object_name, object_type, create_statement
FROM [SHOW BACKUP SCHEMAS '`+localFoo+`' WITH privileges]
ORDER BY object_type, object_name`, [][]string{
{"NULL", "NULL", "otherdb", "database", "NULL"},
{"otherdb", "public", "tbl", "table", "NULL"},
{"NULL", "public", "_t", "type", "NULL"},
{"NULL", "public", "t", "type", "NULL"},
})
})
})

t.Run("zoneconfig_privilege_restore", func(t *testing.T) {
dirs, err := os.ReadDir(privilegeDirs)
require.NoError(t, err)
Expand Down
36 changes: 36 additions & 0 deletions pkg/ccl/backupccl/testdata/backup-restore/regression-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
new-cluster name=s1
----

subtest double-db

exec-sql
CREATE DATABASE db1;
DROP DATABASE db1;
CREATE DATABASE db1;
----

exec-sql
BACKUP INTO 'nodelocal://1/doubleDB' WITH revision_history;
----

new-cluster name=s2 share-io-dir=s1
----

exec-sql
RESTORE FROM LATEST IN 'nodelocal://1/doubleDB'
----

exec-sql
DROP DATABASE db1;
----

exec-sql
RESTORE DATABASE db1 FROM LATEST IN 'nodelocal://1/doubleDB';
----

query-sql
SELECT count(*) FROM [SHOW DATABASES] WHERE database_name = 'db1'
----
1

subtest end

This file was deleted.

This file was deleted.

Empty file.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Empty file.
Binary file not shown.

This file was deleted.

0 comments on commit 7066e9e

Please sign in to comment.