Skip to content

Allow zero (in) date when setting up internal _vt schema#12262

Merged
shlomi-noach merged 11 commits intovitessio:mainfrom
planetscale:internal-schemadiff-allow-zero-date
Feb 13, 2023
Merged

Allow zero (in) date when setting up internal _vt schema#12262
shlomi-noach merged 11 commits intovitessio:mainfrom
planetscale:internal-schemadiff-allow-zero-date

Conversation

@shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Feb 7, 2023

Description

Fixes #12261

Historically, there have been zero values in _vt.schema_migrations.requested_timestamp column; this was due to a bug, fixed in 3012060#diff-d7427b60825b46773b837642e539fd8f00382fc230b717043f3aa76d3ee7ae14R103

Unfortunately, those values violate the default sql_mode, which includes no_zero_date and no_zero_in_date.

If we make changes to _vt.schema_migrations table, via the schemadiff mechanism, and if zero values are found in requested_timestamp column, 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_migrations or to any specific column. It ensures we can preserve an already existing situation.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Feb 7, 2023
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Feb 7, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.
  • If a test is added or modified, there should be a documentation on top of the test to explain what the expected behavior is what the test does.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow should be required, the maintainer team should be notified.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from VTop, if used there.

@shlomi-noach shlomi-noach added Type: Bug Component: VReplication Component: General Changes throughout the code base Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Feb 7, 2023
Copy link
Member

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching and fixing this!

lgtm

@rohit-nayak-ps rohit-nayak-ps self-requested a review February 7, 2023 11:55
Copy link
Member

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few unit tests need fixing to handle the new queries to get/set sql_mode.

@shlomi-noach
Copy link
Contributor Author

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>
@shlomi-noach
Copy link
Contributor Author

@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 No such field in RowNamedValues

@rohit-nayak-ps rohit-nayak-ps marked this pull request as draft February 7, 2023 13:50
@rohit-nayak-ps rohit-nayak-ps self-assigned this Feb 7, 2023
@rohit-nayak-ps rohit-nayak-ps force-pushed the internal-schemadiff-allow-zero-date branch from cbef86e to 1da859b Compare February 7, 2023 22:11
shlomi-noach and others added 4 commits February 7, 2023 23:12
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>
@rohit-nayak-ps rohit-nayak-ps removed their assignment Feb 8, 2023
@rohit-nayak-ps rohit-nayak-ps marked this pull request as ready for review February 8, 2023 09:26
@shlomi-noach
Copy link
Contributor Author

Thank you @rohit-nayak-ps for fixing the tests!

Copy link
Member

@mattlord mattlord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

@mattlord mattlord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you! ❤️

I had a couple of minor comments that you can address as you see best.

Comment on lines +211 to +213
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +35 to +41
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{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need this as it's done above in AddSchemaInitQueries().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

unit tests still fail with "query not found"

@rohit-nayak-ps rohit-nayak-ps force-pushed the internal-schemadiff-allow-zero-date branch from 251ef77 to e7986ee Compare February 12, 2023 21:11
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@rohit-nayak-ps
Copy link
Member

unit tests still fail with "query not found"

Fixed

@shlomi-noach
Copy link
Contributor Author

Upgrade Downgrade Testing Query Serving (Schema) is flaky. Merging while it's failing.

@shlomi-noach shlomi-noach merged commit 32d77db into vitessio:main Feb 13, 2023
@shlomi-noach shlomi-noach deleted the internal-schemadiff-allow-zero-date branch February 13, 2023 11:34
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Feb 13, 2023

I was unable to backport this Pull Request to the following branches: release-16.0.

frouioui pushed a commit to planetscale/vitess that referenced this pull request Feb 21, 2023
)

* 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>
frouioui added a commit that referenced this pull request Feb 22, 2023
…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>
@hmaurer hmaurer mentioned this pull request Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: General Changes throughout the code base Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) Component: VReplication Type: Bug

Projects

None yet

3 participants