-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
backupccl: defaultdb
is not restored as MR in cluster restore
#74607
backupccl: defaultdb
is not restored as MR in cluster restore
#74607
Conversation
I don't love it, but I've tried to fix it in the most explicit way since it's to a prior release branch and I didn't want to introduce any subtle bugs. |
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.
defaultdb
strikes again.
Thanks for the detailed comments.
pkg/ccl/backupccl/restore_job.go
Outdated
if typ.GetParentID() == defaultDBID && typ.GetKind() == descpb.TypeDescriptor_MULTIREGION_ENUM { | ||
backedUpDefaultDBRegionConfig.RegionEnumID = typ.GetID() | ||
break | ||
} |
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.
Is it worth an assertion failure for the (believed impossible?) case of not finding the multi region enum?
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.
fortunately, we validate that the region enum ID we are pointing to actually refers to a type in the database - https://github.com/adityamaru/cockroach/blob/4a3ad27613d88c02ddfe8d4726c25b5d8411186f/pkg/sql/catalog/dbdesc/database_desc.go#L260-L260. So if this is set to something non-sensical it will error out when we go to write the database descriptor below.
Your comment got me thinking though that we don't really need this mapping since in a cluster restore, a type will have the same ID as when it was backed up. Removed the for loop entirely.
pkg/ccl/backupccl/restore_job.go
Outdated
db := desc.(*dbdesc.Mutable) | ||
db.SetRegionConfig(nil) |
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.
Do we need to do anything else to write this out or does DescsTxn somehow handle that for us? Typically, I see us creating a batch (b := txn.NewBatch()
), writing the new descriptor to the batch with descCol.WriteToBatch
and then running that batch (txn.Run(ctx, b)
).
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.
ahhh good catch, fixing this.
4a3ad27
to
1baaff9
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.
If you wanted you could probably reduce some of the duplication between the set and clear paths for the defaultdb region configuration, but that is just pushing the peas around our plate a bit I suppose.
This change fixes a bug where a backed up `defaultdb` with a MR LocalityConfig, is not restored as an MR database on cluster restore. In a cluster restore, we do not restore the database `defaultdb` from the BACKUP, but instead re-parent all backed up schema objects that were in `defaultdb` to point to the restoring cluster's `defaultdb`. This special handling is to account for the fact that every new cluster has a `defaultdb` at a static ID created on startup. As a result of this, we must set the RegionConfig of `defaultdb` on the restoring cluster, to match the config set on the backed up `defaultdb` descriptor. Fixes: cockroachdb#74586 Release note (bug fix): Fixes a bug where a backed up `defaultdb` that is configured to be MR, is not restored as a MR database on cluster restore. Release justification: bug fix.
1baaff9
to
25d4398
Compare
good idea, done. |
This is a forward port of the test from cockroachdb#74607. In 22.1 onwards defalutdb is treated like any other database in the backup and so it should be restored with the correct RegionConfig without any intervention. Release note: None
This change fixes a bug where a backed up
defaultdb
with aMR LocalityConfig, is not restored as an MR database on cluster
restore.
In a cluster restore, we do not restore the database
defaultdb
fromthe BACKUP, but instead re-parent all backed up schema objects that
were in
defaultdb
to point to the restoring cluster'sdefaultdb
.This special handling is to account for the fact that every new cluster
has a
defaultdb
at a static ID created on startup.As a result of this, we must set the RegionConfig of
defaultdb
onthe restoring cluster, to match the config set on the backed up
defaultdb
descriptor.Fixes: #74586
Release note (bug fix): Fixes a bug where a backed up
defaultdb
that is configured to be MR, is not restored as a MR database on
cluster restore.
Release justification: bug fix.