sql: fix dropping offline objects#84189
Conversation
81b6983 to
3b19cd9
Compare
fqazi
left a comment
There was a problem hiding this comment.
Looks good, a lot of the comments are superficial/nitty.
Reviewed 4 of 4 files at r1, 4 of 4 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @dt and @postamar)
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 60 at r2 (raw file):
} func undroppedElements(b BuildCtx, id catid.DescID) ElementResultSet {
Nit: Might be a bit cleaner to have a comment on this one its a shared helper function. Though we aren't good with that convention.
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 98 at r2 (raw file):
}) if name == "" { return fmt.Sprintf("%s #%d", typ, id)
It feels like there should be something stricter, but I don't think there is a nice solution here. i.e. For any new element types that are missing logic in here.
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 117 at r2 (raw file):
// CASCADE. func dropCascadeDescriptor(b BuildCtx, id catid.DescID) { undropped := undroppedElements(b, id)
Nice, much cleaner than the old pattern!
pkg/ccl/backupccl/backup_test.go line 7851 at r1 (raw file):
{ const re = `type .* is offline|relation .* is offline|cannot drop a database or a schema with OFFLINE` sqlDB.ExpectErr(t, re, `DROP TYPE newdb.sc.typ`)
Nit: Might be just cleaner to embed the individual for the first two, there is no real commonality except for the last one.
ajwerner
left a comment
There was a problem hiding this comment.
Reviewed 4 of 4 files at r1, 4 of 4 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @dt and @postamar)
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 74 at r2 (raw file):
} func errMsgPrefix(b BuildCtx, id catid.DescID) string {
Can you comment the intention of this function, it's not obvious
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 92 at r2 (raw file):
typ = "type" case *scpb.Namespace: if name == "" || target != scpb.ToPublic {
this != scpb.ToPublic deserves commentary
pkg/sql/importer/import_stmt_test.go line 1231 at r1 (raw file):
defer func() { _, _ = db.Exec(fmt.Sprintf("DROP DATABASE %s", dbName)) }()
This change doesn't leave me feeling great. I understand why you're doing it: sometimes the drop is going to fail due to offline descriptors, but I have to assume that it was here for a reason. Perhaps some of it was to validate the state of the database. Maybe augment this test with a scan of crdb_internal.invalid_objects?
Code quote:
defer sqlDB.Exec(t, fmt.Sprintf(`DROP DATABASE %s`, dbName))
chengxiong-ruan
left a comment
There was a problem hiding this comment.
thanks for fixing this.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @dt and @postamar)
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 50 at r3 (raw file):
func dropRestrictDescriptor(b BuildCtx, id catid.DescID) (hasChanged bool) { undroppedElements(b, id).ForEachElementStatus(func(_ scpb.Status, target scpb.TargetStatus, e scpb.Element) { if target == scpb.ToAbsent || target == scpb.Transient {
nit, looks like we don't need this check since everything is from undroppedElements?
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go line 62 at r3 (raw file):
func undroppedElements(b BuildCtx, id catid.DescID) ElementResultSet { return b.QueryByID(id).Filter(func(current scpb.Status, target scpb.TargetStatus, e scpb.Element) bool { if target == scpb.InvalidTarget {
could you add a comment that why target ==scpb.InvalidTarget indicate a non-public element?
Partially fixes cockroachdb#84137. Release note (bug fix): DROP SCHEMA ... CASCADE in the legacy schema changer now correctly fails when a backup restore or an import of an underlying table or type is concurrently underway.
Partially fixes cockroachdb#84137. Release note (bug fix): DROP ... CASCADE of a database or a schema in the declarative schema changer now correctly fails when a backup restore or an import is concurrently underway.
This commit does not change any functionality. These changes are separate from the previous commit to facilitate backporting. Release note: None
|
Thanks for the reviews! I've addressed most comments. I added a bunch of commentary. Thank you all for suggesting it, it needed it, and I didn't notice from the tunnel vision of hammering this change through the tests all day. I'll wait for a green CI light and bors. |
|
bors r+ |
|
Build succeeded: |
Fixes #84137.
I intend to base #83915 on this PR, backport the first two commits to 22.1, and backport only the first commit to 21.2.