Skip to content

Conversation

@mhamza15
Copy link
Contributor

@mhamza15 mhamza15 commented Dec 9, 2025

Description

This PR is a continuation of #18552, since I no longer have access to the old fork 😅. It's been slightly refactored to match the changes introduced in #18787.

This PR introduces a "session" tablet balancer, which will direct a session to the same tablet for the duration of the session. This protects against cases where a session reads a value from one tablet, and then gets routed to a different, higher-lag tablet and reads an older value.

The session balancer initially used consistent hashing, but was later switched to use rendezvous hashing for simplicity. The tradeoff there is that rendezvous hashing has an O(n) runtime, n being the number of tablets per target (keyspace + shard + tablet type + cell). As the number of tablets per target is expected to be small, the performance should be reasonable (I plan on benchmarking this).

Related Issue(s)

Closes #11971

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

AI Disclosure

Add `PickOpts` which allow balancers to accept options specific to their
implementation. This allows the `Pick` signature not to get overly long
as implementations and their options are added.

Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
This reverts commit bd6a1b792d69b238df90b5bf979e0911087ada16.

Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Update the signature of the wrapper func to accept a new `WrapOpts`
struct, which currently contains `ExecuteOptions`, which now contains
the session UUID so that it can be passed into `Pick` for the balancer.

Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
mhamza15 and others added 9 commits August 30, 2025 10:38
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Dec 9, 2025

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 9, 2025
@github-actions github-actions bot added this to the v24.0.0 milestone Dec 9, 2025
@FINDMEAI
Copy link

FINDMEAI commented Dec 9, 2025

nice bro

Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 81.48148% with 25 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@3dd1516). Learn more about missing BASE report.

Files with missing lines Patch % Lines
go/vt/vttablet/queryservice/wrapped.go 73.33% 16 Missing ⚠️
go/vt/vtgate/balancer/balancer.go 50.00% 4 Missing ⚠️
go/vt/vtgate/balancer/session.go 91.17% 3 Missing ⚠️
go/vt/vtgate/tabletgateway.go 92.85% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #19007   +/-   ##
=======================================
  Coverage        ?   69.82%           
=======================================
  Files           ?     1611           
  Lines           ?   215427           
  Branches        ?        0           
=======================================
  Hits            ?   150416           
  Misses          ?    65011           
  Partials        ?        0           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random Tablet Selection causes "time inconsistent" data reads

2 participants