-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Change healthcheck to only reload specific keyspace shard tablets #17872
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
Merged
GuptaManan100
merged 10 commits into
vitessio:main
from
planetscale:healthcheck-tablet-refresh-reduce-topo
Mar 5, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
278bd13
feat: change healthcheck to only reload specific keyspace shard tablets
GuptaManan100 5fc13aa
feat: fix clearing out of the channel
GuptaManan100 416cb0a
feat: fix the get tablet map call to respect the passed in options
GuptaManan100 2003483
feat: fix the topo functions and add unit test
GuptaManan100 5379795
test: add a healthcheck test
GuptaManan100 14ea6db
tests: add tests for the load tablets function
GuptaManan100 75be025
feat: use the prev target keyspace shard
GuptaManan100 7314f48
feat: split load tablets into 2 separate functions
GuptaManan100 642a19b
feat: have a single go routine
GuptaManan100 36bc2b6
feat: use the correct reference to topology watcher
GuptaManan100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,20 +110,39 @@ func (tw *TopologyWatcher) getTablets() ([]*topo.TabletInfo, error) { | |
| return tw.topoServer.GetTabletsByCell(tw.ctx, tw.cell, nil) | ||
| } | ||
|
|
||
| func (tw *TopologyWatcher) getTabletsByShard(keyspace string, shard string) ([]*topo.TabletInfo, error) { | ||
| return tw.topoServer.GetTabletsByShardCell(tw.ctx, keyspace, shard, []string{tw.cell}) | ||
| } | ||
|
|
||
| // Start starts the topology watcher. | ||
| func (tw *TopologyWatcher) Start() { | ||
| tw.wg.Add(1) | ||
| // Goroutine to refresh the tablets list periodically. | ||
| go func(t *TopologyWatcher) { | ||
| defer t.wg.Done() | ||
| ticker := time.NewTicker(t.refreshInterval) | ||
| defer ticker.Stop() | ||
| t.loadTablets() | ||
| for { | ||
| t.loadTablets() | ||
| select { | ||
| case <-t.ctx.Done(): | ||
| return | ||
| case <-tw.healthcheck.GetLoadTabletsTrigger(): | ||
| case kss := <-t.healthcheck.GetLoadTabletsTrigger(): | ||
| t.loadTabletsForKeyspaceShard(kss.Keyspace, kss.Shard) | ||
| case <-ticker.C: | ||
| // Since we are going to load all the tablets, | ||
| // we can clear out the entire list for reloading | ||
| // specific keyspace shards. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the review! 💕 |
||
| func() { | ||
| for { | ||
| select { | ||
| case <-t.healthcheck.GetLoadTabletsTrigger(): | ||
| default: | ||
| return | ||
| } | ||
| } | ||
| }() | ||
| t.loadTablets() | ||
| } | ||
| } | ||
| }(tw) | ||
|
|
@@ -136,10 +155,23 @@ func (tw *TopologyWatcher) Stop() { | |
| tw.wg.Wait() | ||
| } | ||
|
|
||
| func (tw *TopologyWatcher) loadTabletsForKeyspaceShard(keyspace string, shard string) { | ||
| if keyspace == "" || shard == "" { | ||
| log.Errorf("topologyWatcher: loadTabletsForKeyspaceShard: keyspace and shard are required") | ||
| return | ||
| } | ||
| tabletInfos, err := tw.getTabletsByShard(keyspace, shard) | ||
| if err != nil { | ||
| log.Errorf("error getting tablets for keyspace-shard: %v:%v: %v", keyspace, shard, err) | ||
| return | ||
| } | ||
| // Since we are only reading tablets for a keyspace shard, | ||
| // this is by default a partial result. | ||
| tw.storeTabletInfos(tabletInfos /* partialResults */, true) | ||
| } | ||
|
|
||
| func (tw *TopologyWatcher) loadTablets() { | ||
| newTablets := make(map[string]*tabletInfo) | ||
| var partialResult bool | ||
|
|
||
| // First get the list of all tablets. | ||
| tabletInfos, err := tw.getTablets() | ||
| topologyWatcherOperations.Add(topologyWatcherOpListTablets, 1) | ||
|
|
@@ -155,6 +187,11 @@ func (tw *TopologyWatcher) loadTablets() { | |
| } | ||
| } | ||
|
|
||
| tw.storeTabletInfos(tabletInfos, partialResult) | ||
| } | ||
|
|
||
| func (tw *TopologyWatcher) storeTabletInfos(tabletInfos []*topo.TabletInfo, partialResult bool) { | ||
| newTablets := make(map[string]*tabletInfo) | ||
| // Accumulate a list of all known alias strings to use later | ||
| // when sorting. | ||
| tabletAliasStrs := make([]string, 0, len(tabletInfos)) | ||
|
|
@@ -243,7 +280,6 @@ func (tw *TopologyWatcher) loadTablets() { | |
| } | ||
| tw.topoChecksum = crc32.ChecksumIEEE(buf.Bytes()) | ||
| tw.lastRefresh = time.Now() | ||
|
|
||
| } | ||
|
|
||
| // RefreshLag returns the time since the last refresh. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.