backport-19.1: sql: ensure lease expiration is monotonically increasing #36631
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 #36531.
/cc @cockroachdb/release
This is a fix for both a correctness issue and a performance problem.
expiration time from a lease to a transaction T, and if the
node reacquired a lease for the table at an expiration less than
the existing lease's expiration it could release the existing
lease (with a greater expiration) before the transaction T committed,
thereby invalidating T's deadline.
time of the new lease was less than the existing lease, it would replace
the table in the cache with the new lease and release the older
lease. But unfortunately it would also not update the table in the
table name cache (the table name cache always uses the lease with
the highest expiration). The table in the table name cache would have
it's lease released rendering the name entry invalid. Therefore until
the node acquired another lease for the same table, the node would be
in a state where there was a table cached but it's name -> table cache
entry invalid, resulting in it making name resolution requests for
every query (but not lease renewals).
It is likely this bug started happening with the addition of more
aggressive lease acquisitions through #28725. I've reduced the value
of DefaultTableDescriptorLeaseJitterFraction to make the logic
ensuring the monotonicity of the lease expiration fire infrequently.
fixes #36044
Release note: None