Skip to content

Commit

Permalink
restoreccl: allow restoring system users without user ids
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
RichardJCai committed May 24, 2022
1 parent 391a6f7 commit ab42799
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9395,7 +9395,6 @@ func TestExcludeDataFromBackupDoesNotHoldupGC(t *testing.T) {
func TestBackupRestoreSystemUsers(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
skip.WithIssue(t, 78963)

sqlDB, tempDir, cleanupFn := createEmptyCluster(t, singleNode)
_, sqlDBRestore, cleanupEmptyCluster := backupRestoreTestSetupEmpty(t, singleNode, tempDir, InitManualReplication, base.TestClusterArgs{})
Expand Down Expand Up @@ -9454,16 +9453,20 @@ func TestBackupRestoreSystemUsers(t *testing.T) {

_, sqlDBRestore1, cleanupEmptyCluster1 := backupRestoreTestSetupEmpty(t, singleNode, tempDir, InitManualReplication, base.TestClusterArgs{})
defer cleanupEmptyCluster1()
t.Run("restore-from-backup-with-no-system-role-members", func(t *testing.T) {
t.Run("restore-from-backup-with-system-role-members", func(t *testing.T) {
// testuser should take ID 101. The restored users originally have no ID
// but should be updated to have IDs 102 and so on.
sqlDBRestore1.Exec(t, `CREATE USER testuser`)
sqlDBRestore1.Exec(t, "RESTORE SYSTEM USERS FROM $1", localFoo+"/3")

sqlDBRestore1.CheckQueryResults(t, "SELECT username, \"hashedPassword\", \"isRole\" FROM system.users", [][]string{
{"admin", "", "true"},
{"app", "NULL", "false"},
{"app_role", "NULL", "true"},
{"root", "", "false"},
{"test", "NULL", "false"},
{"test_role", "NULL", "true"},
sqlDBRestore1.CheckQueryResults(t, "SELECT username, \"hashedPassword\", \"isRole\", \"user_id\" FROM system.users", [][]string{
{"admin", "", "true", "2"},
{"app", "NULL", "false", "102"},
{"app_role", "NULL", "true", "103"},
{"root", "", "false", "1"},
{"test", "NULL", "false", "104"},
{"test_role", "NULL", "true", "105"},
{"testuser", "NULL", "false", "101"},
})
sqlDBRestore1.CheckQueryResults(t, "SELECT \"role\", \"member\", \"isAdmin\" FROM system.role_members", [][]string{
{"admin", "root", "true"},
Expand All @@ -9475,6 +9478,7 @@ func TestBackupRestoreSystemUsers(t *testing.T) {
{"root", "", "{admin}"},
{"test", "", "{}"},
{"test_role", "", "{}"},
{"testuser", "", "{}"},
})
})
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/ccl/backupccl/restore_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func allocateDescriptorRewrites(
}
for _, seqID := range col.UsesSequenceIds {
if _, ok := tablesByID[seqID]; !ok {
if seqID == keys.RoleIDSequenceID {
// We don't have to restore the RoleIDSequence, the sequence should
// already exist in the system database.
continue
}
if !opts.SkipMissingSequences {
return nil, errors.Errorf(
"cannot restore table %q without referenced sequence %d (or %q option)",
Expand Down

0 comments on commit ab42799

Please sign in to comment.