Fix errant GTID detection in VTOrc to also work with a replica not connected to any primary #17267
+229
−29
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.
Description
As pointed out in #17254, there is a case where VTOrc is unable to detect errant GTIDs on a tablet that got demoted.
The underlying cause of the problem was that VTOrc was not running errant GTID detection for tablets that weren't connected to any primary. Previously it would fix the replication on the tablet first and then run errant GTID detection eventually to figure out if it had errant GTIDs. However, ever since we made the vttablets also run errant GTID detection on reparent (#16833), VTOrc is unsuccessful in reparenting the tablet with errant GTIDs since the vttablets fail with an error.
The fix is to augment VTOrc to run errant GTID detection with the primary tablet that it would reparent the replica to. There is only one special case that we need to handle which is that of the new primary's information not being advanced enough. Since VTOrc gathers information in a polling fashion, it is possible that the shard record in its data store points to the new primary, but the data collected from the new primary is older than when the promotion happened. If we use this information for errant GTID detection, we will end up marking the wrong GTIDs as errant. This situation is, however, easy to detect. We do so by checking if the primary's record has a source of its own or not. If it doesn't then the information has to have been gathered after it was promoted.
Related Issue(s)
Checklist
Deployment Notes