backupccl: fix crash in SHOW BACKUP when types have cross-db references#55774
backupccl: fix crash in SHOW BACKUP when types have cross-db references#55774craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
5962382 to
266c5b9
Compare
|
This is a first attempt at it. It's getting close, but I'm running into issues with hydrating the descriptors in this cross-db reference state... |
|
Try: diff --git a/pkg/sql/catalog/descs/collection.go b/pkg/sql/catalog/descs/collection.go
index 1985efab32..ac8f123602 100644
--- a/pkg/sql/catalog/descs/collection.go
+++ b/pkg/sql/catalog/descs/collection.go
@@ -1585,8 +1585,17 @@ func HydrateGivenDescriptors(ctx context.Context, descs []catalog.Descriptor) er
// we need to hydrate our types. Set up an accessor for the type hydration
// method to look into the scanned set of descriptors.
typeLookup := func(ctx context.Context, id descpb.ID) (tree.TypeName, catalog.TypeDescriptor, error) {
- typDesc := typDescs[id]
- dbDesc := dbDescs[typDesc.ParentID]
+ typDesc, ok := typDescs[id]
+ if !ok {
+ n := tree.MakeUnresolvedName(fmt.Sprintf("[%d]", id))
+ return tree.TypeName{}, nil, sqlerrors.NewUndefinedObjectError(&n,
+ tree.TypeObject)
+ }
+ dbDesc, ok := dbDescs[typDesc.ParentID]
+ if !ok {
+ n := fmt.Sprintf("[%d]", typDesc.ParentID)
+ return tree.TypeName{}, nil, sqlerrors.NewUndefinedDatabaseError(n)
+ } |
|
Maybe that is bad because it now just omits the table altogether. |
|
What's the right UX here? |
2e39da5 to
84aa9f6
Compare
|
Latest change logs and silently ignores any error we get showing the create statement. I also played around with displaying an error message in that cell rather than "NULL"... but I'm not sure that's the right way to go here. |
|
Silently ignoring the error is sort of good, right, because it leads to omitting the table, right? That seems sane because you can't restore that table. |
|
We can silently ignore it in 2 ways:
|
|
SGTM |
|
Reworking the tests since this will fail once we disallow the rename. |
84aa9f6 to
b068106
Compare
b068106 to
ac74d08
Compare
ac74d08 to
58bd663
Compare
ajwerner
left a comment
There was a problem hiding this comment.
Reviewed 2 of 7 files at r1.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @dt, @lucy-zhang, and @pbardea)
pkg/ccl/backupccl/restore_old_versions_test.go, line 89 at r1 (raw file):
CREATE TYPE t AS ENUM ('foo'); CREATE TABLE tbl (a t);
(I don't care enough for you to fix it tbh) nit: spacing
58bd663 to
fa844ac
Compare
|
Removed the map changes so that we have the minimal set of changes go in the backport. |
thoszhang
left a comment
There was a problem hiding this comment.
Reviewed 7 of 7 files at r1, 2 of 2 files at r2.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @dt and @pbardea)
pkg/ccl/backupccl/restore_old_versions_test.go, line 94 at r1 (raw file):
BACKUP DATABASE otherdb TO 'nodelocal://1/xDbRef'; This was permitted on some release candidates of v20.2.
Add an issue number?
pkg/ccl/backupccl/restore_old_versions_test.go, line 123 at r1 (raw file):
sqlDB.ExpectErr(t, `type "t" has unknown ParentID 50`, `RESTORE DATABASE otherdb FROM $1`, LocalFoo) sqlDB.CheckQueryResults(t, `
Maybe briefly comment on what we're looking for here? (i.e., no crash, and we get some NULLs)
thoszhang
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @dt and @pbardea)
pkg/ccl/backupccl/restore_old_versions_test.go, line 94 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
Add an issue number?
(#55709)
Previously, SHOW BACKUP would expect that the database and schema it references is in the backup. In the case that we had a cross-db reference, the schema or database that it references would not be included in the backup, and would crash. It now reports objects that it cannot find as NULL. Release note (bug fix): Fix crash when performing a SHOW BACKUP against a backup which contains a table that references a type in another database. This state was only reachable in 20.2 release candidates and earlier.
fa844ac to
0b6544f
Compare
pbardea
left a comment
There was a problem hiding this comment.
Thanks for the reviews!
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner, @dt, and @lucy-zhang)
pkg/ccl/backupccl/restore_old_versions_test.go, line 89 at r1 (raw file):
Previously, ajwerner wrote…
(I don't care enough for you to fix it tbh) nit: spacing
Done.
pkg/ccl/backupccl/restore_old_versions_test.go, line 94 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
(#55709)
Done.
pkg/ccl/backupccl/restore_old_versions_test.go, line 123 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
Maybe briefly comment on what we're looking for here? (i.e., no crash, and we get some NULLs)
Done.
|
bors r=lucy-zhang,ajwerner |
|
Build succeeded: |
Previously, SHOW BACKUP would expect that the database and schema it
references is in the backup. In the case that we had a cross-db
reference, the schema or database that it references would not be
included in the backup, and would crash. It now reports objects that it
cannot find as NULL.
Fixes #55772.
Release note (bug fix): Fix crash when performing a SHOW BACKUP against
a backup which contains a table that references a type in another
database. This state was only reachable in 20.2 release candidates and
earlier.