-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql,backupccl: set system.role_members ID columns to NOT NULL #93301
Conversation
d29b1db
to
0bcd48a
Compare
a728aa8
to
c4ef9af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @andyyang890 and @rhu713)
pkg/ccl/backupccl/restore_job.go
line 2858 at r1 (raw file):
} userIDMap := make(map[tree.DString]oid.Oid)
nit: can you make this use tree.DOid
instead of oid.Oid
? i think it's better to treat these all as datums
pkg/ccl/backupccl/system_schema.go
line 252 at r1 (raw file):
txn *kv.Txn, systemTableName, tempTableName string, ) error {
can you make this a named return parameter, retErr
? (see below comment)
pkg/ccl/backupccl/system_schema.go
line 283 at r1 (raw file):
if err != nil { return err }
there should be a call like this here:
defer func() { retErr = errors.CombineErrors(retErr, it.Close()) }()
actually, we'd want the same fix to be in roleOptionsRestoreFunc
. the reason is that some errors are only returned when the iterator is closed, and this is important for correct error handling.
pkg/ccl/backupccl/system_schema.go
line 318 at r1 (raw file):
} restoreQuery := fmt.Sprintf(`INSERT INTO system.%s ("role", "member", "isAdmin", role_id, member_id) VALUES ($1, $2, $3, $4, $5)`, systemTableName)
i think you can avoid the need for the ids
map, if you use an update ... from
statement: https://www.cockroachlabs.com/docs/stable/update.html#update-using-values-from-a-different-table
also, it feels like it would be cleaner if the INSERT was done in a different loop after the one that scans through it
. i don't think we are allowed to execute other statements while the internal executor still has an iterator open.
cf68983
to
747025a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another test for restoring from a backup that did not have the ID columns!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss and @rhu713)
pkg/ccl/backupccl/restore_job.go
line 2858 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
nit: can you make this use
tree.DOid
instead ofoid.Oid
? i think it's better to treat these all as datums
Done.
pkg/ccl/backupccl/system_schema.go
line 252 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
can you make this a named return parameter,
retErr
? (see below comment)
Done.
pkg/ccl/backupccl/system_schema.go
line 283 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
there should be a call like this here:
defer func() { retErr = errors.CombineErrors(retErr, it.Close()) }()
actually, we'd want the same fix to be in
roleOptionsRestoreFunc
. the reason is that some errors are only returned when the iterator is closed, and this is important for correct error handling.
Done.
pkg/ccl/backupccl/system_schema.go
line 318 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
i think you can avoid the need for the
ids
map, if you use anupdate ... from
statement: https://www.cockroachlabs.com/docs/stable/update.html#update-using-values-from-a-different-tablealso, it feels like it would be cleaner if the INSERT was done in a different loop after the one that scans through
it
. i don't think we are allowed to execute other statements while the internal executor still has an iterator open.
I've moved it into a separate loop after the iterator loop. I think you can't actually use UPDATE ... FROM
here because the new table starts empty and we are inserting rows into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this up and adding the cross-version tests. I left a couple of questions.
bf6431b
to
8b7d0fa
Compare
938f4e3
to
c06835e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed comments and ready for another review!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss, @rhu713, and @stevendanna)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the backup/restore tests. Overall the backup/restore parts look reasonable to me.
This patch sets the newly added `role_id` and `member_id` columns in `system.role_members` to be NOT NULL. It also changes the `RESTORE` logic to be able to handle the case when restoring from a backup where the `system.role_members` table did not have the columns. Release note: None
c06835e
to
db94d07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rhu713 and @stevendanna)
TFTR! bors r=stevendanna,rafiss |
Build succeeded: |
This patch sets the newly added
role_id
andmember_id
columns insystem.role_members
to be NOT NULL. It also changes theRESTORE
logic to be able to handle the case when restoring from a backup where
the
system.role_members
table did not have the columns.Part of #87079
Release note: None