Skip to content
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

Merged
merged 1 commit into from
Jan 12, 2022

Conversation

adityamaru
Copy link
Contributor

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: #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.

@adityamaru adityamaru requested review from dt, stevendanna and a team January 9, 2022 19:50
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@adityamaru
Copy link
Contributor Author

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. master has gotten rid of the special casing of defaultdb and so this test passes. I'll forward port the test.

Copy link
Collaborator

@stevendanna stevendanna left a 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.

Comment on lines 1097 to 1100
if typ.GetParentID() == defaultDBID && typ.GetKind() == descpb.TypeDescriptor_MULTIREGION_ENUM {
backedUpDefaultDBRegionConfig.RegionEnumID = typ.GetID()
break
}
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Comment on lines 2444 to 2445
db := desc.(*dbdesc.Mutable)
db.SetRegionConfig(nil)
Copy link
Collaborator

@stevendanna stevendanna Jan 10, 2022

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)).

Copy link
Contributor Author

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.

Copy link
Collaborator

@stevendanna stevendanna left a 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.
@adityamaru
Copy link
Contributor Author

If you wanted you could probably reduce some of the duplication between the set and clear paths for the defaultdb region

good idea, done.

@adityamaru adityamaru merged commit b4a27f3 into cockroachdb:release-21.2 Jan 12, 2022
@adityamaru adityamaru deleted the mr-defaultdb-fix branch January 12, 2022 02:12
adityamaru added a commit to adityamaru/cockroach that referenced this pull request Jan 16, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants