Add a retry when getting ts from PD for validating read ts #1600
+156
−35
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.
This PR adds a retry to
ValidateReadTS
to avoid a false-positive when the checked ts comes from a different source other than the current pdOracle. This can happen in some non-TiDB caller (e.g. BR, lightning).The
ValidateReadTS
function may usegetCurrentTSForValidation
to get a ts, which internally uses a singleflight. So it's possible that a later call toValidateReadTS
reuses an older on-the-way single flight and returns an older ts. If the ts to be checked comes from outside the currentpdOralce
(so that it's not cached by the low resolution ts), it may cause false positive.The solution is to add a retry: when
ValidateReadTS
check failed with a ts returned bygetCurrentTSForValidation
, try it one more time. So when the second call togetCurrentTSForValidation
must uses a later-started singleflight, inwhich theGetTS
RPC to PD is strictly later than the call. If the given ts is valid, it can be guaranteed by PD's TSO's monotonicity that the second ts returned bygetCurrentTSForValidation
must be greater than the given ts.Ref: pingcap/tidb#59758 , this PR can avoid this problem in master branch where the validation to read ts takes effect to all read.