diff --git a/pkg/ccl/backupccl/restore_old_versions_test.go b/pkg/ccl/backupccl/restore_old_versions_test.go index 2fc4bc9ae406..a5472e88bbf2 100644 --- a/pkg/ccl/backupccl/restore_old_versions_test.go +++ b/pkg/ccl/backupccl/restore_old_versions_test.go @@ -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" @@ -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)) } }) @@ -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) @@ -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) @@ -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"}, diff --git a/pkg/ccl/backupccl/testdata/backup-restore/regression-tests b/pkg/ccl/backupccl/testdata/backup-restore/regression-tests index 6f085c0ad295..01eccecef9d5 100644 --- a/pkg/ccl/backupccl/testdata/backup-restore/regression-tests +++ b/pkg/ccl/backupccl/testdata/backup-restore/regression-tests @@ -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 diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/v22.1.3/BACKUP-LOCK-780220986219692033 b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP-LOCK-824468910992424961 similarity index 100% rename from pkg/ccl/backupccl/testdata/restore_old_versions/cluster/v22.1.3/BACKUP-LOCK-780220986219692033 rename to pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP-LOCK-824468910992424961 diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP-STATISTICS b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP-STATISTICS new file mode 100644 index 000000000000..635cd4a79bf3 Binary files /dev/null and b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP-STATISTICS differ diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP_MANIFEST b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP_MANIFEST new file mode 100644 index 000000000000..ae64d79bed7e Binary files /dev/null and b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP_MANIFEST differ diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP_MANIFEST-CHECKSUM b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP_MANIFEST-CHECKSUM new file mode 100644 index 000000000000..969a281a3d32 --- /dev/null +++ b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/BACKUP_MANIFEST-CHECKSUM @@ -0,0 +1 @@ +oÇðÏ \ No newline at end of file diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/data/824468911158099969.sst b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/data/824468911158099969.sst new file mode 100644 index 000000000000..a3518f0b8f2a Binary files /dev/null and b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/data/824468911158099969.sst differ diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc7cdc9cec8c6ccc8dfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcacfc6cac6ccc8c6fffe b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc7cdc9cec8c6ccc8dfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcacfc6cac6ccc8c6fffe new file mode 100644 index 000000000000..f661934d7a92 Binary files /dev/null and b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc7cdc9cec8c6ccc8dfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcacfc6cac6ccc8c6fffe differ diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc7cdc9cec8c6ccc8dfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcacfc6cac6ccc8c6fffe-CHECKSUM b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc7cdc9cec8c6ccc8dfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcacfc6cac6ccc8c6fffe-CHECKSUM new file mode 100644 index 000000000000..3cc9130265a1 --- /dev/null +++ b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc7cdc9cec8c6ccc8dfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcacfc6cac6ccc8c6fffe-CHECKSUM @@ -0,0 +1 @@ +MI= \ No newline at end of file diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc9cacdcdcbcac7cadfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcccccac9c9cfcdc8fffe b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc9cacdcdcbcac7cadfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcccccac9c9cfcdc8fffe new file mode 100644 index 000000000000..a67d6611b690 Binary files /dev/null and b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc9cacdcdcbcac7cadfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcccccac9c9cfcdc8fffe differ diff --git a/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc9cacdcdcbcac7cadfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcccccac9c9cfcdc8fffe-CHECKSUM b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc9cacdcdcbcac7cadfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcccccac9c9cfcdc8fffe-CHECKSUM new file mode 100644 index 000000000000..3d5ce0df0e2b --- /dev/null +++ b/pkg/ccl/backupccl/testdata/restore_old_versions/cluster/22.2.0/2022/12/22-030544.02/progress/BACKUP-CHECKPOINT-13cdcfcdcdd2cecdd2cdcddfcfccc5cfcac5cbcbd1cfc9cacdcdcbcac7cadfd4cfcfcfcfdfaaabbcdf92c2d4cecdcad1cfcccccac9c9cfcdc8fffe-CHECKSUM @@ -0,0 +1 @@ +›