Skip to content

Commit

Permalink
restoreccl: insert system.namespace entry for synthetic public schema…
Browse files Browse the repository at this point in the history
…s during restore

Release note (bug fix): Previously during restore we wouldn't insert a system.namespace
entry for synthetic public schemas.
  • Loading branch information
RichardJCai committed Jan 19, 2022
1 parent d1db410 commit 8f8ed99
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8348,3 +8348,26 @@ CREATE SCHEMA db.s;

sqlDB.Exec(t, `BACKUP DATABASE db TO 'nodelocal://0/test/2'`)
}

// Verify that upon restoring a database, there is a namespace entry for its
// public schema.
func TestRestoreSyntheticPublicSchemaNamespaceEntry(t *testing.T) {
const numAccounts = 100
params := base.TestClusterArgs{}

_, _, sqlDB, _, cleanup := backupRestoreTestSetupWithParams(t, singleNode, numAccounts,
InitManualReplication, params)
defer cleanup()

sqlDB.Exec(t, "CREATE DATABASE d")
sqlDB.Exec(t, "BACKUP DATABASE d TO $1", LocalFoo)
sqlDB.Exec(t, "DROP DATABASE d")

sqlDB.Exec(t, fmt.Sprintf("RESTORE DATABASE d FROM '%s'", LocalFoo))

var dbID int
row := sqlDB.QueryRow(t, `SELECT id FROM system.namespace WHERE name = 'd'`)
row.Scan(&dbID)

sqlDB.CheckQueryResults(t, fmt.Sprintf(`SELECT id FROM system.namespace WHERE name = 'public' AND "parentID"=%d`, dbID), [][]string{{"29"}})
}
3 changes: 3 additions & 0 deletions pkg/ccl/backupccl/restore_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ func WriteDescriptors(
// behavior if the cluster version is bumped DURING a restore.
dKey := catalogkv.MakeDatabaseNameKey(ctx, settings, desc.GetName())
b.CPut(dKey.Key(codec), desc.GetID(), nil)

// We also have to put a system.namespace entry for the public schema.
b.CPut(catalogkeys.NewPublicSchemaKey(desc.GetID()).Key(codec), keys.PublicSchemaID, nil)
}

// Write namespace and descriptor entries for each schema.
Expand Down

0 comments on commit 8f8ed99

Please sign in to comment.