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

TableGC: speed up GC process via RequestChecks(). Utilized by Online DDL for artifact cleanup #14431

Merged
merged 8 commits into from
Dec 4, 2023

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Nov 2, 2023

Description

Normally, the TableGC mechanism checks for GC table statuses once per hour. It will transition tables to their next state, potentially dealing with that new state yet only one hour later. There's incentive to speed up the process. But instead of reducing the interval (causing more load on the PRIMARY), we choose to intelligently kick new check routines whenever there's a plausible reason -- or an explicit request.

Any time a table changes state, calls for a new cycle that takes place within seconds. A public function, RequestChecks(), makes it possible to "inform" the GC mechanism of recent changes that can benefit from GC.
To combat load, the check function is non-reentrant, and discards recurring or flooding calls made within a period of 10 seconds (ie. the function only agrees to run once per 10 seconds at most).

This is in turn used by Online DDL's state machine: right after a ALTER VITESS_MIGRATION ... CLEANUP (or similar command) is invoked, and assuming an actual artifact is affected, Online DDL calls GC's RequestChecks() to speed up the destruction and cleanup of said artifact tables.

Related Issue(s)

Fixes #14427

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

Deployment Notes

@shlomi-noach shlomi-noach added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: TabletManager Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) labels Nov 2, 2023
Copy link
Contributor

vitess-bot bot commented Nov 2, 2023

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 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 Nov 2, 2023
@shlomi-noach shlomi-noach requested a review from a team November 2, 2023 12:37
@github-actions github-actions bot added this to the v19.0.0 milestone Nov 2, 2023
@shlomi-noach
Copy link
Contributor Author

shlomi-noach commented Nov 6, 2023

tabletmanager_tablegc failure is definitely related, and is due to how the timings have changed. It's a race which we'll need to fix in the test.

@shlomi-noach shlomi-noach 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 labels Nov 6, 2023
@shlomi-noach
Copy link
Contributor Author

endtoend test fixed.

@shlomi-noach
Copy link
Contributor Author

Request for additional review 🙏

Copy link
Contributor

@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 only had minor comments so will let you resolve as you feel best.

I like this! I think it will make the behavior more intuitive for users based on related interactions I've had. Thanks!

Comment on lines 363 to 377
// ctx, cancel := context.WithTimeout(ctx, tableTransitionExpiration+gc.CheckTablesReentryMinInterval)
// defer cancel()

// ticker := time.NewTicker(time.Second)
// defer ticker.Stop()

// for {
// select {

// case <-ctx.Done():
// case <-ticker.C:
// }
// }
// time.Sleep(tableTransitionExpiration + gc.CheckTablesReentryMinInterval)
// We're now both beyond table's timestamp as well as a tableGC interval
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to keep this commented code around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

@@ -0,0 +1,140 @@
/*
Copyright 2020 The Vitess Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use 2023 here.

func TestSuspendableTicker(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ticker := NewSuspendableTicker(10*time.Millisecond, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it would be nicer to make this a variable and then we can use that as the base for later sleeps and asserts (*3 e.g.).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

Choose a reason for hiding this comment

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

The logic seems correct but I suspect we'll see some flakes in CI. Have we re-run this several times in a row to be sure it's at least mostly reliable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have.

collector.removePurgingTable(tableName)
// Chances are, there's more tables waiting to be purged. Let's speed things by
// requesting another purge, instead of waiting a full purgeReentranceInterval cycle
purgeReentranceTicker.TickAfter(time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should time.Second be a variable? I'm unsure why we're using that specific value here. I think it's a minimum we may use in various places over time, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now a variable. And you're right, it's a minimum; first and foremost because it ensures the table name signature, which is partly composed of a timestamp, gets a unique value over time.

To be fair, the purge logic is going to eventually disappear. It's relevant to 5.7, and to old 8.0 versions. Eventually we'll retire this.

Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
@shlomi-noach shlomi-noach merged commit 17a7e59 into vitessio:main Dec 4, 2023
116 checks passed
@shlomi-noach shlomi-noach deleted the onlineddl-cleanup-faster branch December 4, 2023 12:04
ejortegau pushed a commit to slackhq/vitess that referenced this pull request Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) Component: TabletManager Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: ALTER VITESS_MIGRATION ... CLEANUP should cause cleanup sooner
3 participants