Skip to content

Commit

Permalink
*: remove gates for V22_2AddSystemUserIDColumn
Browse files Browse the repository at this point in the history
This makes the next commit for mixed-version testing easier.

Release note: None
  • Loading branch information
rafiss committed Nov 23, 2022
1 parent 1d04cec commit 0390d01
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 295 deletions.
16 changes: 5 additions & 11 deletions pkg/ccl/backupccl/restore_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/ccl/backupccl/backuppb"
"github.com/cockroachdb/cockroach/pkg/cloud"
"github.com/cockroachdb/cockroach/pkg/cloud/cloudpb"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/jobs"
"github.com/cockroachdb/cockroach/pkg/jobs/joberror"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
Expand Down Expand Up @@ -2741,24 +2740,19 @@ func (r *restoreResumer) restoreSystemUsers(
return err
}

insertUser := `INSERT INTO system.users ("username", "hashedPassword", "isRole") VALUES ($1, $2, $3)`
if r.execCfg.Settings.Version.IsActive(ctx, clusterversion.V22_2AddSystemUserIDColumn) {
insertUser = `INSERT INTO system.users ("username", "hashedPassword", "isRole", "user_id") VALUES ($1, $2, $3, $4)`
}
insertUser := `INSERT INTO system.users ("username", "hashedPassword", "isRole", "user_id") VALUES ($1, $2, $3, $4)`
newUsernames := make(map[string]bool)
args := make([]interface{}, 4)
for _, user := range users {
newUsernames[user[0].String()] = true
args[0] = user[0]
args[1] = user[1]
args[2] = user[2]
if r.execCfg.Settings.Version.IsActive(ctx, clusterversion.V22_2AddSystemUserIDColumn) {
id, err := descidgen.GenerateUniqueRoleID(ctx, r.execCfg.DB, r.execCfg.Codec)
if err != nil {
return err
}
args[3] = id
id, err := descidgen.GenerateUniqueRoleID(ctx, r.execCfg.DB, r.execCfg.Codec)
if err != nil {
return err
}
args[3] = id
if _, err = executor.Exec(ctx, "insert-non-existent-users", txn, insertUser,
args...); err != nil {
return err
Expand Down
28 changes: 9 additions & 19 deletions pkg/ccl/backupccl/system_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,6 @@ func roleOptionsRestoreFunc(
txn *kv.Txn,
systemTableName, tempTableName string,
) error {
if !execCfg.Settings.Version.IsActive(ctx, clusterversion.V22_2AddSystemUserIDColumn) {
return defaultSystemTableRestoreFunc(
ctx, execCfg, txn, systemTableName, tempTableName,
)
}

executor := execCfg.InternalExecutor
hasIDColumnQuery := fmt.Sprintf(
`SELECT EXISTS (SELECT 1 FROM [SHOW COLUMNS FROM %s] WHERE column_name = 'user_id')`, tempTableName)
Expand Down Expand Up @@ -357,20 +351,16 @@ func roleIDSeqRestoreFunc(
txn *kv.Txn,
systemTableName, tempTableName string,
) error {
if execCfg.Settings.Version.IsActive(ctx, clusterversion.V22_2AddSystemUserIDColumn) {
datums, err := execCfg.InternalExecutor.QueryRowEx(
ctx, "role-id-seq-custom-restore", txn,
sessiondata.NodeUserSessionDataOverride,
`SELECT max(user_id) FROM system.users`,
)
if err != nil {
return err
}
max := tree.MustBeDOid(datums[0])
return execCfg.DB.Put(ctx, execCfg.Codec.SequenceKey(keys.RoleIDSequenceID), max.Oid+1)
datums, err := execCfg.InternalExecutor.QueryRowEx(
ctx, "role-id-seq-custom-restore", txn,
sessiondata.NodeUserSessionDataOverride,
`SELECT max(user_id) FROM system.users`,
)
if err != nil {
return err
}
// Nothing to be done since no user ids have been assigned.
return nil
max := tree.MustBeDOid(datums[0])
return execCfg.DB.Put(ctx, execCfg.Codec.SequenceKey(keys.RoleIDSequenceID), max.Oid+1)
}

// systemTableBackupConfiguration is a map from every systemTable present in the
Expand Down
21 changes: 6 additions & 15 deletions pkg/sql/create_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,15 @@ func (n *CreateRoleNode) startExec(params runParams) error {
}

// TODO(richardjcai): move hashedPassword column to system.role_options.
stmt := fmt.Sprintf("INSERT INTO %s VALUES ($1, $2, $3)", sessioninit.UsersTableName)
args := append(make([]interface{}, 0, 4), n.roleName, hashedPassword, n.isRole)
if params.ExecCfg().Settings.Version.IsActive(params.ctx, clusterversion.V22_2AddSystemUserIDColumn) {
stmt = fmt.Sprintf("INSERT INTO %s VALUES ($1, $2, $3, $4)", sessioninit.UsersTableName)
roleID, err := descidgen.GenerateUniqueRoleID(params.ctx, params.ExecCfg().DB, params.ExecCfg().Codec)
if err != nil {
return err
}
args = append(args, roleID)
stmt := fmt.Sprintf("INSERT INTO %s VALUES ($1, $2, $3, $4)", sessioninit.UsersTableName)
roleID, err := descidgen.GenerateUniqueRoleID(params.ctx, params.ExecCfg().DB, params.ExecCfg().Codec)
if err != nil {
return err
}
rowsAffected, err := params.extendedEvalCtx.ExecCfg.InternalExecutor.Exec(
params.ctx,
opName,
params.p.txn,
stmt,
args...,
params.ctx, opName, params.p.txn, stmt,
n.roleName, hashedPassword, n.isRole, roleID,
)

if err != nil {
return err
} else if rowsAffected != 1 {
Expand Down
2 changes: 0 additions & 2 deletions pkg/upgrade/upgrades/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ go_test(
"helpers_test.go",
"main_test.go",
"precondition_before_starting_an_upgrade_external_test.go",
"role_id_migration_test.go",
"role_options_migration_test.go",
"sampled_stmt_diagnostics_requests_test.go",
"schema_changes_external_test.go",
Expand Down Expand Up @@ -118,7 +117,6 @@ go_test(
"//pkg/settings/cluster",
"//pkg/sql",
"//pkg/sql/catalog",
"//pkg/sql/catalog/catalogkeys",
"//pkg/sql/catalog/catpb",
"//pkg/sql/catalog/descbuilder",
"//pkg/sql/catalog/descpb",
Expand Down
248 changes: 0 additions & 248 deletions pkg/upgrade/upgrades/role_id_migration_test.go

This file was deleted.

0 comments on commit 0390d01

Please sign in to comment.