Skip to content

Commit

Permalink
backupccl: update cluster fixture and remove 20.1 zcfg fixutre
Browse files Browse the repository at this point in the history
This change removes old cluster restore fixtures, and replaces them
with a cluster backup from 22.2.0. It also removes a 20.1 fixture that
tested restore of a zoneconfig privilege that was overwritten as the usage
privilege in 20.2+ versions. This test has been migrated to a regular
test instead.

Release note: None
  • Loading branch information
adityamaru committed Mar 10, 2023
1 parent f25c02d commit fbdcca5
Show file tree
Hide file tree
Showing 73 changed files with 53 additions and 140 deletions.
111 changes: 1 addition & 110 deletions pkg/ccl/backupccl/restore_old_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func TestRestoreOldVersions(t *testing.T) {
var (
exportDirsWithoutInterleave = testdataBase + "/exports-without-interleaved"
clusterDirs = testdataBase + "/cluster"
privilegeDirs = testdataBase + "/privileges"
multiRegionDirs = testdataBase + "/multi-region"
publicSchemaDirs = testdataBase + "/public-schema-remap"
systemUsersDirs = testdataBase + "/system-users-restore"
Expand All @@ -94,12 +93,6 @@ func TestRestoreOldVersions(t *testing.T) {
exportDir, err := filepath.Abs(filepath.Join(clusterDirs, dir.Name()))
require.NoError(t, err)

// TODO(adityamaru): Figure out how to generate a 20.1.7 fixture using the
// updated `create_cluster.sql` file.
if strings.Contains(dir.Name(), "v20.1.7") {
t.Run(dir.Name(), deprecatedRestoreOldVersionClusterTest(exportDir))
continue
}
t.Run(dir.Name(), restoreOldVersionClusterTest(exportDir))
}
})
Expand All @@ -116,17 +109,6 @@ func TestRestoreOldVersions(t *testing.T) {
}
})

t.Run("zoneconfig_privilege_restore", func(t *testing.T) {
dirs, err := os.ReadDir(privilegeDirs)
require.NoError(t, err)
for _, dir := range dirs {
require.True(t, dir.IsDir())
exportDir, err := filepath.Abs(filepath.Join(privilegeDirs, dir.Name()))
require.NoError(t, err)
t.Run(dir.Name(), restoreV201ZoneconfigPrivilegeTest(exportDir))
}
})

t.Run("public_schema_remap", func(t *testing.T) {
dirs, err := os.ReadDir(publicSchemaDirs)
require.NoError(t, err)
Expand Down Expand Up @@ -300,97 +282,6 @@ func restoreOldVersionTest(exportDir string) func(t *testing.T) {
}
}

// restoreV201ZoneconfigPrivilegeTest checks that privilege descriptors with
// ZONECONFIG from tables and databases are correctly restored.
// The ZONECONFIG bit was overwritten to be USAGE in 20.2 onwards.
// We only need to test restoring with full cluster backup / restore as
// it is the only form of restore that restores privileges.
func restoreV201ZoneconfigPrivilegeTest(exportDir string) func(t *testing.T) {
return func(t *testing.T) {
const numAccounts = 1000
_, _, tmpDir, cleanupFn := backupRestoreTestSetup(t, multiNode, numAccounts, InitManualReplication)
defer cleanupFn()

_, sqlDB, cleanup := backupRestoreTestSetupEmpty(t, singleNode, tmpDir,
InitManualReplication, base.TestClusterArgs{})
defer cleanup()
err := os.Symlink(exportDir, filepath.Join(tmpDir, "foo"))
require.NoError(t, err)
sqlDB.Exec(t, `RESTORE FROM $1`, localFoo)
testDBGrants := [][]string{
{"test", "admin", "ALL", "true"},
{"test", "root", "ALL", "true"},
{"test", "testuser", "ZONECONFIG", "false"},
}
sqlDB.CheckQueryResults(t, `show grants on database test`, testDBGrants)

testTableGrants := [][]string{
{"test", "public", "test_table", "admin", "ALL", "true"},
{"test", "public", "test_table", "root", "ALL", "true"},
{"test", "public", "test_table", "testuser", "ZONECONFIG", "false"},
}
sqlDB.CheckQueryResults(t, `show grants on test.test_table`, testTableGrants)

testTable2Grants := [][]string{
{"test", "public", "test_table2", "admin", "ALL", "true"},
{"test", "public", "test_table2", "root", "ALL", "true"},
{"test", "public", "test_table2", "testuser", "ALL", "false"},
}
sqlDB.CheckQueryResults(t, `show grants on test.test_table2`, testTable2Grants)
}
}

func deprecatedRestoreOldVersionClusterTest(exportDir string) func(t *testing.T) {
return func(t *testing.T) {
externalDir, dirCleanup := testutils.TempDir(t)
ctx := context.Background()
tc := testcluster.StartTestCluster(t, singleNode, base.TestClusterArgs{
ServerArgs: base.TestServerArgs{
// Disabling the test tenant due to test 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)

// Ensure that the restore succeeds.
sqlDB.Exec(t, `RESTORE FROM $1`, localFoo)

sqlDB.CheckQueryResults(t, "SHOW USERS", [][]string{
{"admin", "", "{}"},
{"craig", "", "{}"},
{"root", "", "{admin}"},
})
sqlDB.CheckQueryResults(t, "SELECT comment FROM system.comments ORDER BY object_id", [][]string{
{"database comment string"},
{"table comment string"},
})
// In the backup, Public schemas for non-system databases have ID 29.
// These should all be updated to explicit public schemas.
sqlDB.CheckQueryResults(t, `SELECT
if((id = 29), 'system', 'non-system') AS is_system_schema, count(*) as c
FROM
system.namespace
WHERE
"parentSchemaID" = 0 AND name = 'public'
GROUP BY
is_system_schema
ORDER BY
c ASC`, [][]string{
{"system", "1"},
{"non-system", "3"},
})
sqlDB.CheckQueryResults(t, "SELECT * FROM data.bank", [][]string{{"1"}})
}
}

func restoreOldVersionClusterTest(exportDir string) func(t *testing.T) {
return func(t *testing.T) {
externalDir, dirCleanup := testutils.TempDir(t)
Expand All @@ -412,7 +303,7 @@ func restoreOldVersionClusterTest(exportDir string) func(t *testing.T) {
require.NoError(t, err)

// Ensure that the restore succeeds.
sqlDB.Exec(t, `RESTORE FROM $1`, localFoo)
sqlDB.Exec(t, `RESTORE FROM LATEST IN $1`, localFoo)

sqlDB.CheckQueryResults(t, "SHOW DATABASES", [][]string{
{"data", "root", "NULL", "NULL", "{}", "NULL"},
Expand Down
48 changes: 48 additions & 0 deletions pkg/ccl/backupccl/testdata/backup-restore/regression-tests
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,51 @@ SELECT count(*) FROM [SHOW DATABASES] WHERE database_name = 'db1'
1

subtest end

subtest privileges-zone-config

exec-sql
CREATE DATABASE test;
SET database = test;
CREATE USER testuser;
CREATE TABLE test_table();
CREATE TABLE test_table2();
GRANT ZONECONFIG ON DATABASE test TO testuser;
GRANT ZONECONFIG ON test_table TO testuser;
GRANT ALL ON test_table2 TO testuser;
----

exec-sql
BACKUP INTO 'nodelocal://1/priv-zone-cfg'
----

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

exec-sql
RESTORE FROM LATEST IN 'nodelocal://1/priv-zone-cfg';
----

query-sql
show grants on database test;
----
test admin ALL true
test public CONNECT false
test root ALL true
test testuser ZONECONFIG false

query-sql
show grants on test.test_table
----
test public test_table admin ALL true
test public test_table root ALL true
test public test_table testuser ZONECONFIG false

query-sql
show grants on test.test_table2
----
test public test_table2 admin ALL true
test public test_table2 root ALL true
test public test_table2 testuser ALL false

subtest end
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o���
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MI=
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�<tM
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/2022/12/22-030544.02
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.

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.

This file was deleted.

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.
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.

This file was deleted.

Binary file not shown.

This file was deleted.

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.

0 comments on commit fbdcca5

Please sign in to comment.