Skip to content

vtorc: wait for configuration before initializing forgetAliases cache#20163

Open
arthurschreiber wants to merge 1 commit into
mainfrom
arthur/vtorc-forget-aliases-wait-for-config
Open

vtorc: wait for configuration before initializing forgetAliases cache#20163
arthurschreiber wants to merge 1 commit into
mainfrom
arthur/vtorc-forget-aliases-wait-for-config

Conversation

@arthurschreiber
Copy link
Copy Markdown
Member

@arthurschreiber arthurschreiber commented May 22, 2026

Description

Follow-up to #19843. That PR replaced the busy-wait cache init with a sync.Once, but the initForgetAliasesCache body still reads config.GetInstancePollTime() without first waiting for configuration to be loaded.

If InstanceIsForgotten or ForgetInstance reaches the cache before config.MarkConfigurationLoaded() has been called, the cache is built with the default instance-poll-time and sync.Once then prevents it from ever being rebuilt with the configured value.

This moves the WaitForConfigurationToBeLoaded() call inside the forgetAliasesOnce.Do block so the cache is always created from the loaded configuration, regardless of which goroutine wins the race to initialize it.

Spotted by Copilot in #19846 (comment).

The go/vt/vtorc/logic tests call inst.InitializeForgetAliasesCache() directly, which now waits for configuration. The inst package already had a test-only init() calling config.MarkConfigurationLoaded() (instance_test.go); this PR mirrors that in logic via a new main_test.go so the affected tests don't deadlock.

Related Issue(s)

Follow-up to #19843.

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

None.

AI Disclosure

Most of this was written by Claude Code — I provided direction and review.

The lazy init in initForgetAliasesCache reads config.GetInstancePollTime()
inside forgetAliasesOnce.Do, but nothing guarantees configuration has been
loaded at that point. If InstanceIsForgotten or ForgetInstance reaches the
cache before config.MarkConfigurationLoaded() runs, the cache is built with
the default instance-poll-time and sync.Once locks that in for the lifetime
of the process.

Move the WaitForConfigurationToBeLoaded call inside the Once.Do block so
the cache is always created with the configured value, regardless of which
goroutine wins the race to initialize it.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Copilot AI review requested due to automatic review settings May 22, 2026 08:50
@arthurschreiber arthurschreiber added Type: Bug Component: VTOrc Vitess Orchestrator integration Backport to: release-23.0 Needs to be backport to release-23.0 Backport to: release-24.0 Needs to be backport to release-24.0 labels May 22, 2026
@github-actions github-actions Bot added this to the v25.0.0 milestone May 22, 2026
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work 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 May 22, 2026
@vitess-bot
Copy link
Copy Markdown
Contributor

vitess-bot Bot commented May 22, 2026

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a configuration race in VTOrc’s forgetAliases cache initialization: the cache is now guaranteed to be created using loaded configuration values, even if InstanceIsForgotten/ForgetInstance wins the race to initialize it before MarkConfigurationLoaded() runs.

Changes:

  • Moved config.WaitForConfigurationToBeLoaded() into the forgetAliasesOnce.Do(...) initialization block so the cache TTL is always derived from the configured instance-poll-time.
  • Removed the now-redundant configuration wait from initializeInstanceDao().

@arthurschreiber arthurschreiber 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 May 22, 2026
@arthurschreiber arthurschreiber marked this pull request as ready for review May 22, 2026 08:53
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.45%. Comparing base (70c7a72) to head (1186a4b).
⚠️ Report is 270 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #20163       +/-   ##
===========================================
+ Coverage   69.67%   77.45%    +7.78%     
===========================================
  Files        1614       14     -1600     
  Lines      216793     2187   -214606     
===========================================
- Hits       151044     1694   -149350     
+ Misses      65749      493    -65256     
Flag Coverage Δ
partial 77.45% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Copy Markdown
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.

I think that we should add the missing vtorc logic test configuration setup here: go/vt/vtorc/inst/instance_dao.go:78-80

Moving config.WaitForConfigurationToBeLoaded() inside forgetAliasesOnce.Do fixes the production race, but the current PR diff only changes instance_dao.go. The go/vt/vtorc/logic tests still call inst.InitializeForgetAliasesCache() directly without ever calling config.MarkConfigurationLoaded(), so the unit-test jobs are timing out in TestRefreshTabletsInKeyspaceShard while blocked in initForgetAliasesCache. The PR description mentions adding a logic/main_test.go, but that file is not present in the current diff. Please add the test-package init setup, similar to go/vt/vtorc/inst/instance_test.go, so these tests do not deadlock.

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

Labels

Backport to: release-23.0 Needs to be backport to release-23.0 Backport to: release-24.0 Needs to be backport to release-24.0 Component: VTOrc Vitess Orchestrator integration Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants