Skip to content

disttask: collect metering data to subtask's real time summary#63431

Merged
ti-chi-bot[bot] merged 17 commits into
pingcap:masterfrom
tangenta:next-gen-collect-metering
Sep 15, 2025
Merged

disttask: collect metering data to subtask's real time summary#63431
ti-chi-bot[bot] merged 17 commits into
pingcap:masterfrom
tangenta:next-gen-collect-metering

Conversation

@tangenta

@tangenta tangenta commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #61702

Problem Summary:

What changed and how does it work?

Since DXF subtasks are executed by system keyspace TiDB instances that scaled out automatically, we need to meter the resource usage for billing. This PR collects four metrics for adding index using DXF :

  • Table scan data network traffic.
  • Actual index data size.
  • S3 put request count.
  • S3 get request count.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 9, 2025
@tiprow

tiprow Bot commented Sep 9, 2025

Copy link
Copy Markdown

Hi @tangenta. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

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-sigs/prow repository.

@tangenta tangenta changed the title disttask: collect metering data to realtime summary disttask: collect metering data to subtask's real time summary Sep 9, 2025
Comment thread Makefile
Comment on lines +514 to +515
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/lightning/backend Backend,EngineWriter,TargetInfoGetter > br/pkg/mock/backend.go
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/lightning/common ChunkFlushStatus > br/pkg/mock/common.go

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ChunkFlushStatus is moved from package backend to common to avoid package circular dependency between external and backend.

This PR adds the dependency backend --(depends on)-> external because I added OnReaderClose to the external engine configuration, which is used to collect reading related information.

Comment thread go.mod
github.com/stretchr/testify v1.10.0
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/client-go/v2 v2.0.8-0.20250828075934-b794d681774f
github.com/tikv/client-go/v2 v2.0.8-0.20250905073636-469a7adf7ae8

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Update client-go for bug-fix tikv/client-go#1752

Signed-off-by: tangenta <tangenta@126.com>
@codecov

codecov Bot commented Sep 9, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.31884% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.8373%. Comparing base (68d18d6) to head (64b75f4).
⚠️ Report is 34 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #63431        +/-   ##
================================================
+ Coverage   72.7588%   74.8373%   +2.0784%     
================================================
  Files          1835       1886        +51     
  Lines        496690     512660     +15970     
================================================
+ Hits         361386     383661     +22275     
+ Misses       113324     105409      -7915     
- Partials      21980      23590      +1610     
Flag Coverage Δ
integration 48.5177% <2.4154%> (?)
unit 72.3531% <62.0689%> (+0.0657%) ⬆️

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

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 63.3236% <56.2500%> (+16.8500%) ⬆️
🚀 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.

@D3Hunter

Copy link
Copy Markdown
Contributor

/retest

@tiprow

tiprow Bot commented Sep 10, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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-sigs/prow repository.

Signed-off-by: tangenta <tangenta@126.com>
if err != nil {
return "", "", "", err
}
w.putReqCnt++

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does the write count equals to "S3 put request count", since we use a buffered writer.

tidb/br/pkg/storage/s3.go

Lines 1232 to 1237 in d022959

bufSize := WriteBufferSize
if option != nil && option.PartSize > 0 {
bufSize = int(option.PartSize)
}
uploaderWriter := newBufferedWriter(uploader, bufSize, NoCompression)
return uploaderWriter, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and we are using multi part upload, does this counted as 1 PUT, or each part is one PUT?

Comment thread pkg/lightning/backend/external/byte_reader.go Outdated
Comment thread pkg/disttask/framework/taskexecutor/execute/interface.go Outdated
@tangenta

Copy link
Copy Markdown
Contributor Author

/hold

@ti-chi-bot ti-chi-bot Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 10, 2025
Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>

@D3Hunter D3Hunter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

29/65

Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>
@D3Hunter

Copy link
Copy Markdown
Contributor

/retest

@tiprow

tiprow Bot commented Sep 11, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 11, 2025

@D3Hunter D3Hunter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

34/65

Comment thread br/pkg/storage/s3.go
if option != nil {
onFlush = option.OnUpload
if onFlush != nil {
onFlush() // Initiate: PUT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you also paste the link to how AWS cal API count of the multi part upload in the comment?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

check whether we are using multi-part-upload?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

check whether we are using multi-part-upload?

Do you mean the case option.Concurrency <= 1? Both of the ways use s3.CreateMultipartUploadInput.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need to care about these 2 requests? If so, what if we meet an error and don't call complete?

Comment thread br/pkg/storage/writer.go
m.mu.Unlock()
}
onReaderClose := func(summary *external.ReaderSummary) {
m.summary.GetReqCnt.Add(summary.GetRequestCount)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about PUT req count?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. Let me add an integration test for the merge-sort step.

Signed-off-by: tangenta <tangenta@126.com>
Comment thread pkg/ddl/backfilling_operators.go Outdated
Comment thread pkg/ddl/backfilling_operators.go Outdated
Comment thread pkg/ddl/backfilling_operators.go Outdated
Comment thread pkg/disttask/framework/taskexecutor/execute/interface.go Outdated
Comment thread pkg/ddl/index.go Outdated
return errors.Trace(err)
return totalKVBytes, errors.Trace(err)
}
totalKVBytes += len(key) + len(idxVal)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

external writer will calculate the written file size, can we directly use that?

TotalSize: w.totalSize,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This size is only updated when the writer is flushed or closed. But we collect them during the write.

Let me change to this way in the next PR?

Comment thread pkg/lightning/backend/external/kv_reader.go Outdated
Comment thread pkg/lightning/backend/external/stat_reader.go Outdated
Comment thread pkg/lightning/backend/external/testutil.go Outdated
Comment thread pkg/lightning/backend/external/writer.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please also add some tests for import into

Comment thread tests/realtikvtest/addindextest2/global_sort_test.go Outdated
Comment thread tests/realtikvtest/addindextest2/global_sort_test.go Outdated
Comment thread tests/realtikvtest/addindextest2/global_sort_test.go Outdated
Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 15, 2025
@ti-chi-bot

ti-chi-bot Bot commented Sep 15, 2025

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2025-09-11 06:10:26.056385229 +0000 UTC m=+514492.616266726: ☑️ agreed by joechenrh.
  • 2025-09-15 03:06:54.921713061 +0000 UTC m=+849081.481594558: ☑️ agreed by D3Hunter.

@tangenta tangenta removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 15, 2025

@bb7133 bb7133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot Bot added the approved label Sep 15, 2025

@bb7133 bb7133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@cfzjywxk cfzjywxk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the client-go update

@ti-chi-bot

ti-chi-bot Bot commented Sep 15, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, cfzjywxk, D3Hunter, joechenrh, Leavrth

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

The pull request process is described here

Details 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

Signed-off-by: tangenta <tangenta@126.com>
@wjhuang2016

Copy link
Copy Markdown
Member

/hold

@ti-chi-bot ti-chi-bot Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 15, 2025
Signed-off-by: tangenta <tangenta@126.com>
@tangenta tangenta removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 15, 2025
Signed-off-by: tangenta <tangenta@126.com>
@wjhuang2016

Copy link
Copy Markdown
Member

The test is insufficient.
Consider that another component requests this PR to test, it's ok to merge now. But we need to add more tests to ensure it meets our expectations.

@tangenta

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented Sep 15, 2025

Copy link
Copy Markdown

@tangenta: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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-sigs/prow repository.

@tangenta

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented Sep 15, 2025

Copy link
Copy Markdown

@tangenta: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot merged commit eb25197 into pingcap:master Sep 15, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants