VStreamer: recompute table plan if a new table is encountered for the same id#9978
Merged
rohit-nayak-ps merged 3 commits intovitessio:mainfrom Mar 26, 2022
Conversation
…same id Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
mattlord
approved these changes
Mar 25, 2022
Member
mattlord
left a comment
There was a problem hiding this comment.
Just a small nit about the log message (feel free to ignore).
Thank you!
| return nil, nil | ||
| } | ||
| vs.plans[id] = nil | ||
| log.Infof("table map changed: id %d for %s has changed to %s", id, plan.Table.Name, tm.Name) |
Member
There was a problem hiding this comment.
Maybe also note that we will reload and cache a new plan for the table to avoid concern and indicate corrective action being taken ~:
log.Infof("Table plan map changed in VStream: the id %d was associated with %s and now represents %s. We will reload and cache a new plan for the table.", id, plan.Table.Name, tm.Name)
Member
Author
There was a problem hiding this comment.
Good suggestion, I will update in my next PR though, rather than start another CI cycle for this ...
aliulis
pushed a commit
to vinted/vitess
that referenced
this pull request
Mar 28, 2022
… same id (vitessio#9978) * Recompute the plan for a table if a new table is encountered for the same id Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com>
tanjinx
added a commit
to slackhq/vitess
that referenced
this pull request
Aug 30, 2022
3 tasks
rohit-nayak-ps
added a commit
to planetscale/vitess
that referenced
this pull request
Aug 31, 2022
… same id (vitessio#9978) * Recompute the plan for a table if a new table is encountered for the same id Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com>
3 tasks
rohit-nayak-ps
added a commit
to planetscale/vitess
that referenced
this pull request
Aug 31, 2022
… same id (vitessio#9978) * Recompute the plan for a table if a new table is encountered for the same id Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com>
3 tasks
rohit-nayak-ps
added a commit
that referenced
this pull request
Aug 31, 2022
… same id (#9978) (#11148) * Recompute the plan for a table if a new table is encountered for the same id Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com> Signed-off-by: Rohit Nayak <rohit@planetscale.com>
rohit-nayak-ps
added a commit
that referenced
this pull request
Aug 31, 2022
… same id (#9978) (#11149) * Recompute the plan for a table if a new table is encountered for the same id Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Trigger rebuild Signed-off-by: Rohit Nayak <rohit@planetscale.com> Signed-off-by: Rohit Nayak <rohit@planetscale.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
VStreamer caches a "table plan" for each new table it encounters via the binlog TABLE_MAP_EVENT.
MySQL internally generates a unique (incrementing) id for a table as it inserts them into the binlog. The first time we see an id, we compute the table plan (essentially the list of columns with name and type information). If we get the same id again, we currently assume it is the same table and use the cached plan.
However when the mysql server restarts it starts a new numbering for table ids and depending on the DMLs encountered the table id map can be different from the earlier one.
Thus the binlog will contain the same id for different tables. While streaming from an older GTID, it can happen that we have cached a plan for table1 for id 100, say. And later we get the same id 100 for table2. Usually this will result in an error because the fields for the table will not match the row image. If a vstreamer encounters an error it just restarts after 5 seconds, when it recreates the plans and heals itself.
But in rare situations where the schemas are almost identical we can generate unrelated FieldEvents and consequently a DML for the wrong table.
This PR adds a check before using a cached plan. If the table name for the cached plan doesn't match that for the table map event, it nullifies that cache entry and recomputes the plan for this id.
Signed-off-by: Rohit Nayak rohit@planetscale.com
Related Issue(s)
#9976
Checklist