Skip to content

Conversation

@timvaillancourt
Copy link
Contributor

@timvaillancourt timvaillancourt commented Dec 10, 2025

Description

This PR causes the grpctmclient library to validate the tablet record before trying to connect to a tablet. This to address this error (connecting to ":0" 🫤) when Hostname and the grpc port mapping are empty values ("" and 0 respectively):

[component.go:39] [core] [Channel #33 SubChannel #34]grpc: addrConn.createTransport failed to connect to {Addr: ":0", ServerName: "localhost:0", }. Err: connection error: desc = "transport: Error while dialing: dial tcp :0: connect: connection refused"

Also, a new TabletShutdownTime field was added to topodatapb.Tablet. This field indicates to topo clients that a tablet cleanly shut itself down (and "when") - which is something hard to reliably match today because tablet shutdown nil/zero's many record values. This field is best-effort, and used to avoid useless connections and log noise when we know a connection will be unsuccessful. If a tablet is stopped uncleanly, this will remain nil in the topo and the current, <= v23 behaviour will be seen (a log error + useless connection to the downed tablet)

For vttablet to start, it must succeed in updating this value to nil, so there should be no risk of a running tablet having ShutdownTime set to a non-nil value - it wouldn't be able to start

Testing: before tablet shutdown

tim@Tims-PS-MacBook local % vtctldclient GetTablet zone1-0000000102
{
  "alias": {
    "cell": "zone1",
    "uid": 102
  },
  "hostname": "",
  "port_map": {},
  "keyspace": "commerce",
  "shard": "0",
  "key_range": null,
  "type": "RDONLY",
  "db_name_override": "",
  "tags": {},
  "mysql_hostname": "",
  "mysql_port": 17102,
  "primary_term_start_time": null,
  "default_conn_collation": 255,
  "tablet_shutdown_time": null
  }

Testing: after shutdown

tim@Tims-PS-MacBook local % ps ux | grep zone1-0000000102
tim  68601   0.1  0.1 412090272  66416 s002  S    12:41PM   0:00.26 vttablet --config-file-not-found-handling=ignore --topo-implementation etcd2 --topo-global-server-address localhost:2379 --topo-global-root /vitess/global --log_dir /Users/tim/github/timvaillancourt/vitess/vtdataroot/tmp --log-queries-to-file /Users/tim/github/timvaillancourt/vitess/vtdataroot/tmp/vttablet_0000000102_querylog.txt --tablet-path zone1-0000000102 --tablet-hostname  --init-keyspace commerce --init-shard 0 --init-tablet-type rdonly --health-check-interval 5s --backup-storage-implementation file --file-backup-storage-root /Users/tim/github/timvaillancourt/vitess/vtdataroot/backups --restore-from-backup --port 15102 --grpc-port 16102 --service-map grpc-queryservice,grpc-tabletmanager,grpc-updatestream --pid-file /Users/tim/github/timvaillancourt/vitess/vtdataroot/vt_0000000102/vttablet.pid --heartbeat-on-demand-duration=5s --pprof-http
tim  69244   0.0  0.0 410059408    160 s002  R+   12:41PM   0:00.00 grep zone1-0000000102
tim@Tims-PS-MacBook local % kill 68601
tim@Tims-PS-MacBook local % ps ux|grep zone1-0000000102
tim  69273   0.0  0.0 410059408    144 s002  R+   12:42PM   0:00.00 grep zone1-0000000102
tim@Tims-PS-MacBook local % vtctldclient GetTablet zone1-0000000102
{
  "alias": {
    "cell": "zone1",
    "uid": 102
  },
  "hostname": "",
  "port_map": {},
  "keyspace": "commerce",
  "shard": "0",
  "key_range": null,
  "type": "RDONLY",
  "db_name_override": "",
  "tags": {},
  "mysql_hostname": "",
  "mysql_port": 17102,
  "primary_term_start_time": null,
  "default_conn_collation": 255,
  "tablet_shutdown_time": {
    "seconds": "1765539714",
    "nanoseconds": 843177000
  }
}

Related Issue(s)

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

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Dec 10, 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 10, 2025
@github-actions github-actions bot added this to the v24.0.0 milestone Dec 10, 2025
@timvaillancourt timvaillancourt changed the title Tmc full status validate tablet grpctmclient: validate tablet record on dial Dec 10, 2025
@timvaillancourt timvaillancourt 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 10, 2025
@timvaillancourt timvaillancourt marked this pull request as ready for review December 10, 2025 15:26
@promptless
Copy link
Contributor

promptless bot commented Dec 10, 2025

📝 Documentation updates detected!

New suggestion: Add changelog entry for grpctmclient tablet validation

@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 84.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.82%. Comparing base (9461e71) to head (d0d65aa).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtorc/inst/instance_dao.go 0.00% 2 Missing ⚠️
go/vt/vttablet/grpctmclient/client.go 90.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #19009   +/-   ##
=======================================
  Coverage   69.81%   69.82%           
=======================================
  Files        1610     1610           
  Lines      215362   215392   +30     
=======================================
+ Hits       150358   150399   +41     
+ Misses      65004    64993   -11     

☔ 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.

@timvaillancourt
Copy link
Contributor Author

In hindsight, it appears it is valid for a tablet record to be in the topo with zero'd out values: https://github.com/vitessio/vitess/blob/main/go/vt/vttablet/tabletmanager/tm_init.go#L508-L510

So as it stands, this PR will just create invalid tablet ... noise for tablets that have cleanly shutdown. Therefore, some changes are needed

Moving this back to draft 🤔

@timvaillancourt timvaillancourt marked this pull request as draft December 10, 2025 17:01
@timvaillancourt timvaillancourt marked this pull request as ready for review December 10, 2025 17:40
DbNameOverride: initDbNameOverride,
Tags: mergeTags(buildTags, initTags),
DefaultConnCollation: uint32(charset),
IsShutdown: false,
Copy link
Contributor Author

@timvaillancourt timvaillancourt Dec 10, 2025

Choose a reason for hiding this comment

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

vttablet must write this record to the topo to be able to successfully start (that's not new), so we will always set IsShutdown: false if vttablet starts 👍

The opposite is not guaranteed, because processes can crash, OOM, be-killed, etc. This is documented in comments

tablet.Hostname = ""
tablet.MysqlHostname = ""
tablet.PortMap = nil
tablet.IsShutdown = true
Copy link
Contributor Author

@timvaillancourt timvaillancourt Dec 10, 2025

Choose a reason for hiding this comment

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

This is not guaranteed to run, and callers need to expect this (this is also not new)

If a tablet stops uncleanly, the existing/pre-v24 behaviour is seen: log noise and a fruitless connection to "":0

@mattlord
Copy link
Member

Please let me know when the tests are passing. FWIW, I would recommend keeping something in draft until the tests are passing and you're sure that you're happy with it (done self review, etc). It makes it much easier on everyone that way. ❤️

@timvaillancourt timvaillancourt marked this pull request as draft December 10, 2025 23:54
@timvaillancourt
Copy link
Contributor Author

Please let me know when the tests are passing. FWIW, I would recommend keeping something in draft until the tests are passing and you're sure that you're happy with it (done self review, etc). It makes it much easier on everyone that way. ❤️

Good point, I was a bit too confident in this one. It seems the downgrade tests don't align 👀

@timvaillancourt timvaillancourt force-pushed the tmc-FullStatus-validate-tablet branch from ec07715 to fa81a31 Compare December 12, 2025 16:04
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt timvaillancourt force-pushed the tmc-FullStatus-validate-tablet branch from fa81a31 to 4397174 Compare December 12, 2025 16:04
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
…te-tablet

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt timvaillancourt marked this pull request as ready for review December 12, 2025 19:46
@promptless
Copy link
Contributor

promptless bot commented Dec 12, 2025

📝 Documentation updates detected!

New suggestion: Add changelog entry for tablet shutdown tracking and validation

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants