release-20.1: sql: in schema changer, wait for leases of referenced descriptors to update #55375
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 1/1 commits from #54434.
/cc @cockroachdb/release
In 20.1 we moved the schema changer over to utilize the jobs infrastructure.
Prior to that change, after committing a sql transaction we'd kick off the
schema changer to run for the relevant mutations and then we'd wait for all
modified descriptors to have just one version (after the schema change). In
20.1 we decided for descriptors referenced in schema changes to also create
schema change jobs that have an InvalidMutationID which leads to the job
merely waiting for one version for that descriptor. Unfortunately, that
solution doesn't generally work. In particular, it doesn't work in cases
where we are add an fk constraint that we need to mark validated at the
end and it doesn't work in cases where we want to remove a type back
reference after dropping a column or when adding a type reference.
Realistically, when the schema change job ends up touching multiple
descriptors, we need to make sure we wait for the leases to update
for all of them.
You might think that this could lead directly to eliminating the
InvalidMutationID schema change jobs, but I'm not convinced that
that always follows and so I'm leaving that for later.
It turns out that I don't think the type portions of this represent
correctness problems as the type references just used for type DDLs but
I do think for tables it might be worse. At the very least it might mean
that query plans a tad longer to reflect fk relationships.
Fixes #52539.
Fixes #40200.
Release note (bug fix): Fixed a bug which allowed statements after a
schema change to fail to observe side-effects of that change on referenced
tables.