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

domain: support GC runaway record #44784

Merged
merged 11 commits into from
Jun 21, 2023

Conversation

CabinfeverB
Copy link
Contributor

@CabinfeverB CabinfeverB commented Jun 19, 2023

What problem does this PR solve?

Issue Number: ref #43691 close #44804
As RFC shown, tidb_runaway_quarantined_watch only keeps active quarantined queries. So we should support gc.

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB CabinfeverB requested a review from a team as a code owner June 19, 2023 07:50
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 19, 2023
domain/domain.go Outdated
}
}
gcRunawayRecords := func() {
sql := "DELETE FROM mysql.tidb_runaway_queries WHERE time < CONVERT_TZ(%?, '+00:00', @@TIME_ZONE)"
Copy link
Contributor

@glorv glorv Jun 19, 2023

Choose a reason for hiding this comment

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

I think the runaway records should be kept for a period of time. And, btw, it is possible that there are too many outdated records, then delete all of them in a single txn can exceed tidb's txn max size, so I suggest manually select and delete the records in batch.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 19, 2023
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB
Copy link
Contributor Author

cc @nolouch
@lcwangchao Could u take a lock at the modification about ttl/cache/table.go

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB
Copy link
Contributor Author

/retest

domain/domain.go Outdated
func (do *Domain) runawayRecordFlushLoop() {
defer util.Recover(metrics.LabelDomain, "runawayRecordFlushLoop", nil, false)

quarantineRecordGCInterval := time.Second * 15 //time.Minute * 15
Copy link
Member

Choose a reason for hiding this comment

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

use const?

Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

And don't forget to update doc as well

Copy link
Contributor

@glorv glorv left a comment

Choose a reason for hiding this comment

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

Please add necessary test cases to cover the new logic

domain/domain.go Outdated
var leftRows [][]types.Datum
for {
sql := ""
limit := int(variable.TTLScanBatchSize.Load())
Copy link
Contributor

Choose a reason for hiding this comment

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

Better not depend on variable of other feature, you can define a const instead

domain/domain.go Outdated
tbCIStr := model.NewCIStr(tableName)
tbl, err := do.InfoSchema().TableByName(systemSchemaCIStr, tbCIStr)
if err != nil {
logutil.BgLogger().Info("delete system table failed", zap.String("table", tableName), zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logutil.BgLogger().Info("delete system table failed", zap.String("table", tableName), zap.Error(err))
logutil.BgLogger().Error("delete system table failed", zap.String("table", tableName), zap.Error(err))

domain/domain.go Outdated
func (do *Domain) runawayRecordFlushLoop() {
defer util.Recover(metrics.LabelDomain, "runawayRecordFlushLoop", nil, false)

quarantineRecordGCInterval := time.Second * 15 //time.Minute * 15
runawayRecordGCInterval := time.Second * 15 //time.Hour * 24
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this small duration?

domain/domain.go Outdated
@@ -1294,6 +1389,10 @@ func (do *Domain) runawayRecordFlushLoop() {
// flush as soon as possible.
if len(quarantineRecordCh) == 0 || len(quarantineRecords) >= flushThrehold {
flushQuarantineRecords()
if owner.IsOwner() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why need gc here, don't get the point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because when the watch is updated, it may be a new identify, at this time, I think I can delete the old one immediately.

domain/domain.go Outdated
runawayRecordFluashTimer.Reset(time.Second)
}
case <-runawayRecordGCTicker.C:
if owner.IsOwner() {
Copy link
Contributor

Choose a reason for hiding this comment

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

better to move this check into gcSystemTable to avoid this check everywhere

domain/domain.go Outdated
}
case <-runawayRecordGCTicker.C:
if owner.IsOwner() {
do.gcSystemTable("tidb_runaway_queries", "time", runawayRecordExpiredDuration)
Copy link
Contributor

Choose a reason for hiding this comment

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

As gcSystemTable can be very slow, to avoid blocking handling other events, better spawn a new routine to do this job.

domain/domain.go Outdated
}

for len(leftRows) > 0 {
maxBatch := 100
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the previous select is already paged, why do paging again here?

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
domain/domain.go Outdated Show resolved Hide resolved
domain/domain.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 20, 2023
@glorv
Copy link
Contributor

glorv commented Jun 20, 2023

/retest

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB
Copy link
Contributor Author

/test build

@CabinfeverB
Copy link
Contributor Author

/test unit-test

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 20, 2023

@CabinfeverB: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test canary-scan-security
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-integration-br-test
  • /test pull-integration-mysql-test
  • /test unit-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/ghpr_build
  • pingcap/tidb/ghpr_check
  • pingcap/tidb/ghpr_check2
  • pingcap/tidb/ghpr_mysql_test
  • pingcap/tidb/ghpr_unit_test

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@CabinfeverB
Copy link
Contributor Author

/test unit-test

@glorv
Copy link
Contributor

glorv commented Jun 20, 2023

/retest

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 20, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 20, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-06-20 09:59:36.107444779 +0000 UTC m=+96941.508695226: ☑️ agreed by glorv.
  • 2023-06-20 13:36:56.52654347 +0000 UTC m=+109981.927793919: ☑️ agreed by nolouch.

@@ -1248,11 +1251,116 @@ func (do *Domain) SetOnClose(onClose func()) {
do.onClose = onClose
}

const (
Copy link
Member

Choose a reason for hiding this comment

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

move it to resource group package?

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 21, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: glorv, nolouch, qw4990

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot merged commit 47101e8 into pingcap:master Jun 21, 2023
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.2: #44860.

ti-chi-bot bot pushed a commit that referenced this pull request Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.2 release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mysql.tidb_runaway_quarantined_watch includes unactivated watches
6 participants