Allow zero (in) date when setting up internal _vt schema#12262
Allow zero (in) date when setting up internal _vt schema#12262shlomi-noach merged 11 commits intovitessio:mainfrom
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
If a new flag is being introduced:
If a workflow is added or modified:
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
rohit-nayak-ps
left a comment
There was a problem hiding this comment.
Thanks for catching and fixing this!
lgtm
rohit-nayak-ps
left a comment
There was a problem hiding this comment.
A few unit tests need fixing to handle the new queries to get/set sql_mode.
|
v15 "backport": #12263 ; it's not a real backport because of how schema management has diverged, so it's its own fix. |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
|
@rohit-nayak-ps what am I doing wrong with the tests here? My fix does not seem to produce the correct result. I'm getting a |
cbef86e to
1da859b
Compare
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
|
Thank you @rohit-nayak-ps for fixing the tests! |
mattlord
left a comment
There was a problem hiding this comment.
LGTM! However, I think this should be address the more general issue of SQL_MODE in the context of what this package is supposed to achieve.
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
mattlord
left a comment
There was a problem hiding this comment.
LGTM. Thank you! ❤️
I had a couple of minor comments that you can address as you see best.
go/vt/sidecardb/sidecardb.go
Outdated
| // We need to allow zero dates for existing sidecar database tables which may happen to | ||
| // actually have zero (in) date values. setPermissiveSQLMode gets the current sql_mode, change it to a more relaxed value, | ||
| // defer restoring it to the original value. |
There was a problem hiding this comment.
Suggestion:
// setPermissiveSQLMode gets the current sql_mode for the session, removes any
// restrictions, and returns a function to restore it back to the original session value.
// We need to allow for the recreation of any data that currently exists in the table, such
// as e.g. allowing any zero dates that may already exist in a preexisting sidecar table.
| sqlMode := sqltypes.MakeTestResult(sqltypes.MakeTestFields( | ||
| "sql_mode", | ||
| "varchar"), | ||
| "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION", | ||
| ) | ||
| db.AddQuery("select @@session.sql_mode as sql_mode", sqlMode) | ||
| db.AddQueryPattern("set @@session.sql_mode=.*", &sqltypes.Result{}) |
There was a problem hiding this comment.
We shouldn't need this as it's done above in AddSchemaInitQueries().
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
|
unit tests still fail with "query not found" |
251ef77 to
e7986ee
Compare
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Fixed |
|
|
|
I was unable to backport this Pull Request to the following branches: |
) * Allow zero (in) date when setting up internal _vt schema Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> * modify test sto include @@sql_mod query support Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> * Allow zero (in) date when setting up internal _vt schema Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> * modify test sto include @@sql_mod query support Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> * Fix test failures Signed-off-by: Rohit Nayak <rohit@planetscale.com> * Fix failing tests. Minor refactor Signed-off-by: Rohit Nayak <rohit@planetscale.com> * change sql_mode t omost permissive (empty) Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> * setPermissiveSQLMode Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> * fixes per review Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> * Add missing mock query Signed-off-by: Rohit Nayak <rohit@planetscale.com> --------- Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Signed-off-by: Rohit Nayak <rohit@planetscale.com> Co-authored-by: Rohit Nayak <rohit@planetscale.com>
…2406) * Allow zero (in) date when setting up internal _vt schema * modify test sto include @@sql_mod query support * Allow zero (in) date when setting up internal _vt schema * modify test sto include @@sql_mod query support * Fix test failures * Fix failing tests. Minor refactor * change sql_mode t omost permissive (empty) * setPermissiveSQLMode * fixes per review * Add missing mock query --------- Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Signed-off-by: Rohit Nayak <rohit@planetscale.com> Co-authored-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Co-authored-by: Rohit Nayak <rohit@planetscale.com>
Description
Fixes #12261
Historically, there have been zero values in
_vt.schema_migrations.requested_timestampcolumn; this was due to a bug, fixed in 3012060#diff-d7427b60825b46773b837642e539fd8f00382fc230b717043f3aa76d3ee7ae14R103Unfortunately, those values violate the default
sql_mode, which includesno_zero_dateandno_zero_in_date.If we make changes to
_vt.schema_migrationstable, via theschemadiffmechanism, and if zero values are found inrequested_timestampcolumn, then those schema changes will fail, and the tablet will not be able to initialize properly.In this PR, we take a general approach allowing zero in date and zero date in the session running the schema changes. This isn't specific to
_vt.schema_migrationsor to any specific column. It ensures we can preserve an already existing situation.Related Issue(s)
requested_timestamp#12261Checklist
Deployment Notes