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 StalledDiskPrimary analysis and recovery by vtorc #16050

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

Conversation

joekelley
Copy link

@joekelley joekelley commented Jun 4, 2024

Description

At HubSpot we have had a handful of incidents where a primary becomes impaired due to disk issues. When this happens, we observe that vtorc assigns an UnreachablePrimary analysis and does nothing because the FullStatus
call it makes to the tablet times out. We monitor for these cases outside of Vitess and resolve them by running ERS, but it would be ideal if vtorc could detect and address these cases itself.

This change adds support for a StalledDiskPrimary analysis and recovery by vtorc. To detect when a tablet has a stalled disk we add a FileSystemManager that attempts to write a file to vt data root every five seconds and expose a method that the tablet manager invokes in FullStatus to report whether the disk is stalled. Vtorc is modified to check for the stalled disk error from FullStatus and record the result in the Cleanup block.

We are in the process of testing a change to this effect in lower environments at HubSpot. We aren't running the latest version of Vitess, so our internal patch is a bit different than what is presented here and this exact implementation hasn't been tested. This is my first Vitess PR. Any and all feedback is greatly appreciated 🙂

Related Issue(s)

Slack discussion from this time last year: https://vitess.slack.com/archives/C02GSRZ8XAN/p1685456224040299
PR that came from that discussion but didn't get merged: #13207

Note that this implementation is heavily inspired by the comments on #13207.

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 Jun 4, 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 Jun 4, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Jun 4, 2024
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 68.53933% with 28 lines in your changes missing coverage. Please review.

Project coverage is 68.59%. Comparing base (f4591fb) to head (ca654ab).
Report is 65 commits behind head on main.

Files Patch % Lines
go/vt/vttablet/tabletmanager/filesystemmanager.go 73.33% 16 Missing ⚠️
go/vt/vtorc/inst/instance_dao.go 54.54% 5 Missing ⚠️
go/vt/vttablet/tabletmanager/tm_init.go 25.00% 3 Missing ⚠️
go/vt/vttablet/tabletmanager/rpc_replication.go 0.00% 2 Missing ⚠️
go/vt/vtorc/config/config.go 66.66% 1 Missing ⚠️
go/vt/vtorc/logic/topology_recovery.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16050      +/-   ##
==========================================
+ Coverage   68.23%   68.59%   +0.36%     
==========================================
  Files        1541     1545       +4     
  Lines      197254   198060     +806     
==========================================
+ Hits       134597   135864    +1267     
+ Misses      62657    62196     -461     

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

@GuptaManan100 GuptaManan100 added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VTorc Vitess Orchestrator integration and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jun 19, 2024
Comment on lines +59 to +63
// Return error if the disk is stalled or rejecting writes.
// Noop by default, must be enabled with the flag "enable_stalled_disk_check".
if tm.fsManager.IsDiskStalled() {
return nil, errors.New("stalled disk")
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to have a boolean field or an error field here. Even if the disk is stalled, we do get all the other field information back in FullStatus that can be used. Also, an error in full status indicates to vtorc that it couldn't reach the vttablet.

Copy link
Author

Choose a reason for hiding this comment

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

I developed this change by using fsfreeze -f /vt on the primary instance in a test keyspace. In my testing before making any code changes, I found that vtorc's invocation of FullStatus would timeout and return a context deadline exceeded error. Simple queries like select @@global.server_id; would hang until the filesystem was unfrozen.

We could add a boolean or error field to model this, but I think we'd want to return here either way if the check fails, and it seems a bit cleaner to me to return an error rather than a response message with mostly nil/zero values.

Comment on lines 203 to 207
if err != nil {
if config.Config.EnableStalledDiskPrimaryAnalysis && strings.Contains(err.Error(), "stalled disk") {
stalledDisk = true
}
goto Cleanup
Copy link
Member

Choose a reason for hiding this comment

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

If we don't send the stalled disk as an error back as suggested ☝️, we can set the value in the normal flow below and it would be written as part of mkInsertOdkuInstances, and we won't need to change UpdateInstanceLastChecked.

type writeFunction func() error

func attemptFileWrite() error {
file, err := os.Create(path.Join(env.VtDataRoot(), ".stalled_disk_check"))
Copy link
Contributor

@timvaillancourt timvaillancourt Jun 21, 2024

Choose a reason for hiding this comment

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

Are there any cases where VTDATAROOT isn't the same disk as MySQL datadir? For our deployment it IS the same disk - our datadir is one level below VTDATAROOT. But theoretically datadir could be on it's own disk 🤔

It might be more flexible to have a flag like --stalled_disk_check_dir / stalled_disk_check_root enable this feature vs a boolean "enable" flag

@@ -105,6 +108,9 @@ func registerInitFlags(fs *pflag.FlagSet) {
fs.Var(&initTags, "init_tags", "(init parameter) comma separated list of key:value pairs used to tag the tablet")
fs.DurationVar(&initTimeout, "init_timeout", initTimeout, "(init parameter) timeout to use for the init phase.")
fs.DurationVar(&mysqlShutdownTimeout, "mysql-shutdown-timeout", mysqlShutdownTimeout, "timeout to use when MySQL is being shut down.")
fs.BoolVar(&enableStalledDiskCheck, "enable_stalled_disk_check", enableStalledDiskCheck, "if true, tablet will check if disk is stalled or rejecting writes")
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe new flags need to use - instead of _. Correct @deepthi?

@timvaillancourt
Copy link
Contributor

@joekelley this is awesome, thanks a lot for moving this forward!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VTorc Vitess Orchestrator integration NeedsIssue A linked issue is missing for this Pull Request Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants