Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tables to globally routed list in schema tracker only if they are not already present in a VSchema #17371

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

rohit-nayak-ps
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps commented Dec 11, 2024

Description

Follows up on the idea in #16517 by not considering tables already present in the globally routable list of tables.

See RFC for design and implementation details.

Related Issue(s)

#16516

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Dec 11, 2024

Review Checklist

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

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

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

Backward compatibility

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

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Dec 11, 2024
@rohit-nayak-ps rohit-nayak-ps added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Dec 11, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 97.29730% with 1 line in your changes missing coverage. Please review.

Project coverage is 67.67%. Comparing base (9383943) to head (bc53f51).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/vtgate.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17371   +/-   ##
=======================================
  Coverage   67.67%   67.67%           
=======================================
  Files        1583     1584    +1     
  Lines      254363   254391   +28     
=======================================
+ Hits       172140   172163   +23     
- Misses      82223    82228    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

Just a nomenclature nit, otherwise looks good to me!

go/vt/vtgate/vindexes/vschema.go Outdated Show resolved Hide resolved
@rohit-nayak-ps rohit-nayak-ps marked this pull request as ready for review December 12, 2024 18:10
Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

The issue with this approach arises when there are multiple unsharded keyspaces. This makes adding the table to global routing non-deterministic, failing to fully achieve the intended purpose of this PR.

@rohit-nayak-ps
Copy link
Contributor Author

The issue with this approach arises when there are multiple unsharded keyspaces. This makes adding the table to global routing non-deterministic, failing to fully achieve the intended purpose of this PR.

You mean if there are tables of the same name in multiple unsharded keyspaces (and which are not in the VSchemas).

We could collect all tables names which will be added like this (not in VSchema, but found by schema tracking) first and validate that there are no duplicates, marking ones with duplicates as ambiguous, while others get globally routed.

@rohit-nayak-ps
Copy link
Contributor Author

rohit-nayak-ps commented Dec 13, 2024

Discussed with @harshit-gangal . His point is that:

  1. We start with a sharded keyspace Sharded1 and one unsharded keyspace Unsharded1. Unsharded1 has no vschema defined yet.
  2. After this PR, schema tracking finds a table ut1 in Unsharded1 that is not in the current VSchema. It then adds it to the global tables list. User starts depending on select * from ut1.
  3. Later user adds another unsharded keyspace Unsharded2 which also has table named ut1.
  4. Now we will mark ut1 as ambiguous (this logic is not yet part of this PR, but is the enhancement I referred to in Add missing tables to globally routed list in schema tracker only if they are not already present in a VSchema #17371 (comment))
  5. Suddenly the user's select * from ut1 query will start erroring out. User won't have visibility as to why this has happened since they have not done anything obvious in Vitess like modifying/adding a VSchema and will have downtime until they drop the other table, which could be difficult to diagnose/fix.

Options here are:

  1. Close this PR and not do anything
  2. Merge this PR (with enhanced logic to detect ambiguous tables outside of current VSchemas), which will solve the problem for X% of customers who currently have downtime because we don't do this

I guess the question is what is X. Is it high enough to merge this. Or even if X is high, do we want to do this from a principled viewpoint.

@rohit-nayak-ps rohit-nayak-ps marked this pull request as draft December 16, 2024 16:23
…they are not already present in a VSchema

Signed-off-by: Rohit Nayak <[email protected]>
…e variable name had changed from positive to negative intent ...

Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
…ut vschemas to the global routing. Create more comprehensive unit test.

Signed-off-by: Rohit Nayak <[email protected]>
…h no vschema as global. Enhance e2e test to handle both flag states with and without vschema

Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
@rohit-nayak-ps rohit-nayak-ps force-pushed the rohit/global-routing-tables-not-in-vschema branch from f5d5a62 to a3032db Compare December 28, 2024 18:49
@rohit-nayak-ps
Copy link
Contributor Author

After discussions we decided to go ahead with the implementation as detailed in the RFC

@rohit-nayak-ps rohit-nayak-ps changed the title Experimental: Add missing tables to globally routed list in schema tracker only if they are not already present in a VSchema Add missing tables to globally routed list in schema tracker only if they are not already present in a VSchema Dec 30, 2024
@rohit-nayak-ps
Copy link
Contributor Author

I have added a vtgate flag, --mark_unique_unsharded_tables_as_global (default true) to allow us the ability to disable the logic added in the PR in case some breaking changes have been introduced. I can remove it if reviewers feel it is not needed.

@rohit-nayak-ps rohit-nayak-ps marked this pull request as ready for review December 30, 2024 11:42
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

Rest LGTM!

@@ -200,6 +202,7 @@ func registerFlags(fs *pflag.FlagSet) {
fs.IntVar(&warmingReadsConcurrency, "warming-reads-concurrency", 500, "Number of concurrent warming reads allowed")
fs.DurationVar(&warmingReadsQueryTimeout, "warming-reads-query-timeout", 5*time.Second, "Timeout of warming read queries")

fs.BoolVar(&MarkUniqueUnshardedTablesAsGlobal, "mark_unique_unsharded_tables_as_global", MarkUniqueUnshardedTablesAsGlobal, "Mark unique unsharded tables as global tables")
Copy link
Member

Choose a reason for hiding this comment

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

As discussed, I don't think we need the flag

@@ -473,6 +473,46 @@ func buildGlobalTables(source *vschemapb.SrvVSchema, vschema *VSchema) {
}
}

// AddAdditionalGlobalTables adds unique tables from unsharded keyspaces to the global tables.
// It is expected to be called from the schema tracking code.
func AddAdditionalGlobalTables(source *vschemapb.SrvVSchema, vschema *VSchema) {
Copy link
Member

Choose a reason for hiding this comment

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

The code logic looks 💯 correct!

go/vt/vtgate/vindexes/vschema_routing_test.go Outdated Show resolved Hide resolved
go/vt/vtgate/vindexes/vschema_routing_test.go Outdated Show resolved Hide resolved
go/vt/vtgate/vindexes/vschema_routing_test.go Outdated Show resolved Hide resolved
Tables: map[string]*vschemapb.Table{
"table6": {}, // unique
"scommon2": {}, // common with sharded2, but has RequireExplicitRouting
"scommon3": {}, // common with sharded2
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect comment. scommon3 is not common with anything. It is unique.

go/test/endtoend/vreplication/r Outdated Show resolved Hide resolved
go/test/endtoend/vreplication/r2 Outdated Show resolved Hide resolved
go/test/endtoend/vreplication/global_routing_test.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants