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

Restore: implement restorer for compacted SST/Snapshot/log files #57208

Merged
merged 31 commits into from
Nov 20, 2024

Conversation

3pointer
Copy link
Contributor

@3pointer 3pointer commented Nov 7, 2024

What problem does this PR solve?

Issue Number: close #57209

Problem Summary:

This pull request introduces a unified structure for managing compacted SST, Snapshot, and log files. Previously, these file types were handled independently, leading to redundant code and potential inconsistencies. The new common struct simplifies file management, improves code maintainability, and reduces the likelihood of errors.

What changed and how does it work?

  • Unified Struct Abstraction: A shared struct has been created to manage compacted SST, Snapshot, and log files collectively, providing a consistent interface across these file types.
// FileRestorer defines the essential methods required for restoring SST files, 
// covering different types of backups and compacted logs, including:
// 1. Raw backup SSTs
// 2. Txn backup SSTs
// 3. TiDB backup SSTs
// 4. Compacted log SSTs
// 
// Base structures for these restorations include:
// - SimpleRestorer: Handles raw, txn, and compacted log backups.
// - MultiTablesRestorer: Manages snapshot-based multi-table restorations.
type FileRestorer interface {
	// Restore imports files to TiKV.
	Restore(onProgress func(int64), files ...BatchRestoreFilesInfo) error
	// WaitUntilFinish waits for all pending restore files to complete.
	WaitUntilFinish() error
	// Close releases resources.
	Close() error
}
  • Impact: This update significantly streamlines the restoration process, reducing complexity and improving performance by adopting a unified handling approach. Components across the system have been updated to leverage the new struct, fostering consistency and reducing maintenance overhead.

  • NOTE: This PR doesn't consider the checkpoint logic for compacted log files. I'll do it in another PR.

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

Copy link

ti-chi-bot bot commented Nov 7, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 7, 2024
Copy link

tiprow bot commented Nov 7, 2024

Hi @3pointer. 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.

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.

@3pointer 3pointer marked this pull request as ready for review November 12, 2024 09:59
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 12, 2024
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 74.02597% with 280 lines in your changes missing coverage. Please review.

Project coverage is 74.8449%. Comparing base (d86a366) to head (fed41b5).
Report is 17 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57208        +/-   ##
================================================
+ Coverage   72.8440%   74.8449%   +2.0009%     
================================================
  Files          1672       1721        +49     
  Lines        462716     474632     +11916     
================================================
+ Hits         337061     355238     +18177     
+ Misses       104867      97306      -7561     
- Partials      20788      22088      +1300     
Flag Coverage Δ
integration 49.5579% <48.1447%> (?)
unit 72.4389% <47.8664%> (+0.2170%) ⬆️

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 60.9165% <74.0259%> (+15.8380%) ⬆️
---- 🚨 Try these New Features:

Copy link
Contributor

@YuJuncen YuJuncen left a comment

Choose a reason for hiding this comment

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

rest lgtm

}
if len(sstOutputs) != len(subCompaction.SstOutputs) {
log.Info("partial files in sub compaction skipped due to checkpoint")
subCompaction.SstOutputs = sstOutputs
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a little strange that a predicate function modifies its argument. Would you add some comments in the interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because the subCompaction is not a basic restore unit during restore, the restore unit is file. and subCompaction might contains multiple files. sometimes we may need to skip partial files in one subCompaction.

br/pkg/restore/log_client/log_file_manager_test.go Outdated Show resolved Hide resolved
// Skip the file by checkpoints or invalid files
ShouldSkip(T) bool
// GetAccumulations returns an iterator for the accumulated values.
GetAccumulations() *SplitHelperIterator
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a little strange that Accumulate receives T but GetAccumulations returns Valued? It seems this method actually returns the keys to be splitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I want to refactor SplitHelperIterator too, but I suggest doing this in future PR.

br/pkg/restore/split/splitter.go Outdated Show resolved Hide resolved
br/pkg/restore/split/splitter.go Outdated Show resolved Hide resolved
br/pkg/restore/restorer.go Show resolved Hide resolved
br/pkg/restore/restorer.go Outdated Show resolved Hide resolved
br/pkg/restore/restorer.go Show resolved Hide resolved
return f[:idx]
}

type PipelineRestorerWrapper[T any] struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this can be a plain function. So the type argument can be deduced, no explicit annotations like restore.PipelineRestorerWrapper[*logclient.LogDataFileInfo] needed.

br/pkg/restore/split/splitter.go Outdated Show resolved Hide resolved
@3pointer
Copy link
Contributor Author

/test unit-test

Copy link

ti-chi-bot bot commented Nov 17, 2024

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

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test pull-br-integration-test
  • /test pull-integration-ddl-test
  • /test pull-lightning-integration-test
  • /test pull-mysql-client-test
  • /test pull-unit-test-ddlv1
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-common-test
  • /test pull-e2e-test
  • /test pull-integration-common-test
  • /test pull-integration-copr-test
  • /test pull-integration-e2e-test
  • /test pull-integration-jdbc-test
  • /test pull-integration-mysql-test
  • /test pull-integration-nodejs-test
  • /test pull-integration-python-orm-test
  • /test pull-sqllogic-test
  • /test pull-tiflash-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
  • pingcap/tidb/pull_br_integration_test
  • pingcap/tidb/pull_integration_ddl_test
  • pingcap/tidb/pull_lightning_integration_test
  • pingcap/tidb/pull_mysql_client_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.

@3pointer
Copy link
Contributor Author

/test pull-lightning-integration-test

Copy link

tiprow bot commented Nov 17, 2024

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

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

Copy link

tiprow bot commented Nov 17, 2024

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

In response to this:

/test pull-lightning-integration-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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 18, 2024
Copy link

ti-chi-bot bot commented Nov 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Leavrth, YuJuncen

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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 19, 2024
Copy link

ti-chi-bot bot commented Nov 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-18 02:14:05.854802798 +0000 UTC m=+840808.045671795: ☑️ agreed by YuJuncen.
  • 2024-11-19 10:02:25.461273552 +0000 UTC m=+955307.652142544: ☑️ agreed by Leavrth.

@Leavrth
Copy link
Contributor

Leavrth commented Nov 19, 2024

/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 Nov 19, 2024
@3pointer
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 20, 2024
@3pointer
Copy link
Contributor Author

/test pull-lightning-integration-test

Copy link

tiprow bot commented Nov 20, 2024

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

In response to this:

/test pull-lightning-integration-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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot merged commit 9530fdc into pingcap:master Nov 20, 2024
29 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.

Refine restorer to support both logs and compacted sst files.
3 participants