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

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

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. labels Nov 7, 2024
Copy link

ti-chi-bot bot commented Nov 7, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from 3pointer, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label 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 48.05195% with 560 lines in your changes missing coverage. Please review.

Project coverage is 74.6477%. Comparing base (4a6bf46) to head (1f1b636).

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57208        +/-   ##
================================================
+ Coverage   72.8367%   74.6477%   +1.8110%     
================================================
  Files          1672       1721        +49     
  Lines        462640     471130      +8490     
================================================
+ Hits         336972     351688     +14716     
+ Misses       104878      97343      -7535     
- Partials      20790      22099      +1309     
Flag Coverage Δ
integration 49.0657% <48.0519%> (?)

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 59.8005% <48.0519%> (+14.6963%) ⬆️

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
Close() error
}

type FileImporter interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems FileImporter is almost the same as SstRestorer. Would you merge them or add some comments that explains why we need two?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, add some comments, PTAL

br/pkg/restore/restorer.go Outdated Show resolved Hide resolved
onProgress(int64(len(filesReplica)))
}
}()
if importErr := m.fileImporter.Import(m.ectx, filesReplica...); importErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we already managed the concurrenct execution. Why we still need ConcurrentlFileImporter here? Would you replace it with a normal one or add some comment here to explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ConcurrentFileImporter only used in MultiTablesRestorer, which has a condition wait during restore. this make a better control of concurrency to make download balanced.

If we make this a default behavior for raw/txn ssts. Then it can be removed. but in this PR, I want to make the behavior keeps same as before.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering that given there is internal concurrency in the ConcurrentFileImporter, is the outer workerPool still needed?

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.

Copy link

ti-chi-bot bot commented Nov 17, 2024

@3pointer: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-br-integration-test fafb0d2 link true /test pull-br-integration-test
idc-jenkins-ci-tidb/unit-test 1f1b636 link true /test unit-test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
2 participants