Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Pipelined restore. #266

Merged
merged 69 commits into from
Jun 15, 2020
Merged

Pipelined restore. #266

merged 69 commits into from
Jun 15, 2020

Conversation

YuJuncen
Copy link
Collaborator

@YuJuncen YuJuncen commented May 8, 2020

What problem does this PR solve?

Currently, the full restore workflow is:

  1. Firstly, create all tables, collect their new table IDs, and make rewrite rules by it.
  2. Then, use those metadata to split regions, and ingest SST files.

That would be good if there are few tables, but when the number of table grows, the time we waste on create table will also be greatly incremented. F1 DDL is slow, even TiDB make great effort on optimize it, create a table will spend about 2 secs, and cannot be paralleled.

What is changed and how it works?

I pipelined the workflow, that is, we won't wait until all tables created. (e.g. we can do restore and create tables at the same time).

Check List

Tests

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

We tested this on a 3-TiKV cluster, in the 500+ table, per table 2000k records workload:

Test Object Time Spent
Original 46 mins (27 mins restore + 19 mins DDL)
Pipelined 32 mins
Pipelined + send batch periodicity 25 mins

And there is a internal test report.

Side effects

  • Increased code complexity
  • Breaking backward compatibility(don't support restore TiFlash nodes when failed restore yet.)

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release Note

  • Boost the restore speed by pipelining the restore process.

@YuJuncen YuJuncen added the WIP label May 8, 2020
@codecov
Copy link

codecov bot commented May 9, 2020

Codecov Report

Merging #266 into master will decrease coverage by 1.99%.
The diff coverage is 71.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #266      +/-   ##
==========================================
- Coverage   74.18%   72.18%   -2.00%     
==========================================
  Files          50       50              
  Lines        6007     5616     -391     
==========================================
- Hits         4456     4054     -402     
- Misses       1044     1078      +34     
+ Partials      507      484      -23     
Impacted Files Coverage Δ
pkg/restore/client.go 66.78% <48.83%> (-10.94%) ⬇️
pkg/restore/pipeline_items.go 62.66% <62.66%> (ø)
pkg/task/restore.go 58.78% <73.33%> (-7.35%) ⬇️
pkg/restore/util.go 78.20% <82.41%> (-3.41%) ⬇️
pkg/restore/batcher.go 88.82% <88.82%> (ø)
pkg/restore/range.go 82.60% <100.00%> (ø)
pkg/backup/push.go 64.51% <0.00%> (-4.84%) ⬇️
pkg/restore/split_client.go 56.60% <0.00%> (-4.16%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49448c8...0ecbcd6. Read the comment docs.

@5kbpers
Copy link
Contributor

5kbpers commented May 9, 2020

Do region splitting and scattering can be pipelined?

@YuJuncen YuJuncen linked an issue May 11, 2020 that may be closed by this pull request
3 tasks
@YuJuncen
Copy link
Collaborator Author

Do region splitting and scattering can be pipelined?

That would be OK by small change probably, let me check it.

@kennytm
Copy link
Collaborator

kennytm commented May 11, 2020

perhaps let's defer the pipelined scattering into the next PR, and get this PR merged first.

@YuJuncen
Copy link
Collaborator Author

perhaps let's defer the pipelined scattering into the next PR, and get this PR merged first.

OK, to pipeline scattering seems just need change restore/pipeline_items.go, and would be a small PR.

Copy link
Collaborator

@kennytm kennytm 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

pkg/restore/batcher.go Outdated Show resolved Hide resolved
pkg/restore/batcher.go Outdated Show resolved Hide resolved
pkg/restore/batcher.go Outdated Show resolved Hide resolved
pkg/restore/batcher.go Outdated Show resolved Hide resolved
pkg/restore/batcher.go Outdated Show resolved Hide resolved
pkg/restore/batcher.go Outdated Show resolved Hide resolved
pkg/restore/pipeline_items.go Outdated Show resolved Hide resolved
pkg/restore/pipeline_items.go Outdated Show resolved Hide resolved
pkg/restore/client.go Outdated Show resolved Hide resolved
pkg/restore/client.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@kennytm kennytm 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

Comment on lines +280 to +287
if err := b.manager.Leave(ctx, drainResult.BlankTablesAfterSend); err != nil {
log.Error("encountering error when leaving recover mode, we can go on but some regions may stick on restore mode",
append(
ZapRanges(ranges),
ZapTables(tbs),
zap.Error(err))...,
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

move this defer after Enter() is called

@YuJuncen
Copy link
Collaborator Author

/run-all-tests

3 similar comments
@YuJuncen
Copy link
Collaborator Author

/run-all-tests

@3pointer
Copy link
Collaborator

/run-all-tests

@YuJuncen
Copy link
Collaborator Author

/run-all-tests

@YuJuncen YuJuncen merged commit d7a3060 into pingcap:master Jun 15, 2020
@ti-srebot
Copy link
Contributor

cherry pick to release-3.1 failed

@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 failed

YuJuncen added a commit to YuJuncen/br that referenced this pull request Jun 16, 2020
* restore: add pipelined CreateTable.

* restore: add pipelined ValidateFileRanges.

* restore: pipelining restore process.

* restore, task: use batching when pipelining.

* restore: batcher split by range(instead of table).

* restore,task: new way to for polling errCh.

We use select instead of for range, so we can send error when context cancelled.

* restore, task: pipelining checksum.

* restore, task: cancel parallel DDL request.

* restore: restore will now send batch periodly.

* restore: refactor batcher.

* restore: add tests on batcher.

* restore, task: make linter happy.

* *: add dep to multierr.

* task: adjust to new function sig.

* task, restore: close updateCh until all task finish.

* task, restore: pipelined restore supports parition.

* backup: always wait worker to finish.

* backup, task: skip checksum when needed.

* *: make linter happy.

* restore: move batcher test to restore_test package.

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore, task: remove context on struct types.

* restore: batcher auto commit can be disabled now.

* restore, task: fix typos.

* recover: fix a bug about removing tiflash.

* restore: MapTableToFiles issues Error log when key range not match.

* *: merge master.

* restore: fix test to match new change of master.

* Apply suggestions from code review

* restore: merge two progresses.

* restore: fix a bug.

that is, when table is too big or batch size is too low,
we will fail to restore the head part of this table.

* restore: extract batcher to another file

* task: don't return imediately when files is empty.

* restore,task: do some refactor

We move `splitPrepareWork` into a struct named `ContextManager`,
so that we can batchly set placement rules on online restore.

* restore: fix a shaming bug... :|

* task,restore: panic on file broken

* restore: record tiflash count to disk when removed

* restore,task: simplify some code,

* task,restore: fix a bug.

The bug causes,
when a singal table is splt into multi part of batches,
it sometimes fail to checksum.

* restore: some factory and fix

1. make the batcher worker has two send style
2. make functions for debuging tables and ranges
3. rewrite a test case to adapt the new batcher

* tests: try to fix CI

* tests: try to fix CI, again

* Apply suggestions from code review

Co-authored-by: 3pointer <qdlc2010@gmail.com>

* restore: change some log levels

* restore: merge joiner of sendWorker into messagebox

... and, some small changes:
- don't send sending request if here is one.
- the method of how a batcher is send move to log level debug

* restore,task: run RemoveRestoreLabels at restore post work

* task: adapt the remove-tiflash flag

* restore,task: fetch new placement rules each time

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore,task: run Leave always, and modify some log level

* restore: fix a bug that may cause checksum time incorrect

* restore: don't Leave if never Enter

Co-authored-by: kennytm <kennytm@gmail.com>
Co-authored-by: 3pointer <qdlc2010@gmail.com>
Co-authored-by: 3pointer <luancheng@pingcap.com>
YuJuncen added a commit to YuJuncen/br that referenced this pull request Jun 16, 2020
* restore: add pipelined CreateTable.

* restore: add pipelined ValidateFileRanges.

* restore: pipelining restore process.

* restore, task: use batching when pipelining.

* restore: batcher split by range(instead of table).

* restore,task: new way to for polling errCh.

We use select instead of for range, so we can send error when context cancelled.

* restore, task: pipelining checksum.

* restore, task: cancel parallel DDL request.

* restore: restore will now send batch periodly.

* restore: refactor batcher.

* restore: add tests on batcher.

* restore, task: make linter happy.

* *: add dep to multierr.

* task: adjust to new function sig.

* task, restore: close updateCh until all task finish.

* task, restore: pipelined restore supports parition.

* backup: always wait worker to finish.

* backup, task: skip checksum when needed.

* *: make linter happy.

* restore: move batcher test to restore_test package.

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore, task: remove context on struct types.

* restore: batcher auto commit can be disabled now.

* restore, task: fix typos.

* recover: fix a bug about removing tiflash.

* restore: MapTableToFiles issues Error log when key range not match.

* *: merge master.

* restore: fix test to match new change of master.

* Apply suggestions from code review

* restore: merge two progresses.

* restore: fix a bug.

that is, when table is too big or batch size is too low,
we will fail to restore the head part of this table.

* restore: extract batcher to another file

* task: don't return imediately when files is empty.

* restore,task: do some refactor

We move `splitPrepareWork` into a struct named `ContextManager`,
so that we can batchly set placement rules on online restore.

* restore: fix a shaming bug... :|

* task,restore: panic on file broken

* restore: record tiflash count to disk when removed

* restore,task: simplify some code,

* task,restore: fix a bug.

The bug causes,
when a singal table is splt into multi part of batches,
it sometimes fail to checksum.

* restore: some factory and fix

1. make the batcher worker has two send style
2. make functions for debuging tables and ranges
3. rewrite a test case to adapt the new batcher

* tests: try to fix CI

* tests: try to fix CI, again

* Apply suggestions from code review

Co-authored-by: 3pointer <qdlc2010@gmail.com>

* restore: change some log levels

* restore: merge joiner of sendWorker into messagebox

... and, some small changes:
- don't send sending request if here is one.
- the method of how a batcher is send move to log level debug

* restore,task: run RemoveRestoreLabels at restore post work

* task: adapt the remove-tiflash flag

* restore,task: fetch new placement rules each time

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore,task: run Leave always, and modify some log level

* restore: fix a bug that may cause checksum time incorrect

* restore: don't Leave if never Enter

Co-authored-by: kennytm <kennytm@gmail.com>
Co-authored-by: 3pointer <qdlc2010@gmail.com>
Co-authored-by: 3pointer <luancheng@pingcap.com>
kennytm added a commit that referenced this pull request Jun 16, 2020
* restore: add pipelined CreateTable.

* restore: add pipelined ValidateFileRanges.

* restore: pipelining restore process.

* restore, task: use batching when pipelining.

* restore: batcher split by range(instead of table).

* restore,task: new way to for polling errCh.

We use select instead of for range, so we can send error when context cancelled.

* restore, task: pipelining checksum.

* restore, task: cancel parallel DDL request.

* restore: restore will now send batch periodly.

* restore: refactor batcher.

* restore: add tests on batcher.

* restore, task: make linter happy.

* *: add dep to multierr.

* task: adjust to new function sig.

* task, restore: close updateCh until all task finish.

* task, restore: pipelined restore supports parition.

* backup: always wait worker to finish.

* backup, task: skip checksum when needed.

* *: make linter happy.

* restore: move batcher test to restore_test package.

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore, task: remove context on struct types.

* restore: batcher auto commit can be disabled now.

* restore, task: fix typos.

* recover: fix a bug about removing tiflash.

* restore: MapTableToFiles issues Error log when key range not match.

* *: merge master.

* restore: fix test to match new change of master.

* Apply suggestions from code review

* restore: merge two progresses.

* restore: fix a bug.

that is, when table is too big or batch size is too low,
we will fail to restore the head part of this table.

* restore: extract batcher to another file

* task: don't return imediately when files is empty.

* restore,task: do some refactor

We move `splitPrepareWork` into a struct named `ContextManager`,
so that we can batchly set placement rules on online restore.

* restore: fix a shaming bug... :|

* task,restore: panic on file broken

* restore: record tiflash count to disk when removed

* restore,task: simplify some code,

* task,restore: fix a bug.

The bug causes,
when a singal table is splt into multi part of batches,
it sometimes fail to checksum.

* restore: some factory and fix

1. make the batcher worker has two send style
2. make functions for debuging tables and ranges
3. rewrite a test case to adapt the new batcher

* tests: try to fix CI

* tests: try to fix CI, again

* Apply suggestions from code review

Co-authored-by: 3pointer <qdlc2010@gmail.com>

* restore: change some log levels

* restore: merge joiner of sendWorker into messagebox

... and, some small changes:
- don't send sending request if here is one.
- the method of how a batcher is send move to log level debug

* restore,task: run RemoveRestoreLabels at restore post work

* task: adapt the remove-tiflash flag

* restore,task: fetch new placement rules each time

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore,task: run Leave always, and modify some log level

* restore: fix a bug that may cause checksum time incorrect

* restore: don't Leave if never Enter

Co-authored-by: kennytm <kennytm@gmail.com>
Co-authored-by: 3pointer <qdlc2010@gmail.com>
Co-authored-by: 3pointer <luancheng@pingcap.com>

Co-authored-by: kennytm <kennytm@gmail.com>
Co-authored-by: 3pointer <qdlc2010@gmail.com>
Co-authored-by: 3pointer <luancheng@pingcap.com>
kennytm added a commit that referenced this pull request Jun 17, 2020
* Pipelined restore. (#266)

* restore: add pipelined CreateTable.

* restore: add pipelined ValidateFileRanges.

* restore: pipelining restore process.

* restore, task: use batching when pipelining.

* restore: batcher split by range(instead of table).

* restore,task: new way to for polling errCh.

We use select instead of for range, so we can send error when context cancelled.

* restore, task: pipelining checksum.

* restore, task: cancel parallel DDL request.

* restore: restore will now send batch periodly.

* restore: refactor batcher.

* restore: add tests on batcher.

* restore, task: make linter happy.

* *: add dep to multierr.

* task: adjust to new function sig.

* task, restore: close updateCh until all task finish.

* task, restore: pipelined restore supports parition.

* backup: always wait worker to finish.

* backup, task: skip checksum when needed.

* *: make linter happy.

* restore: move batcher test to restore_test package.

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore, task: remove context on struct types.

* restore: batcher auto commit can be disabled now.

* restore, task: fix typos.

* recover: fix a bug about removing tiflash.

* restore: MapTableToFiles issues Error log when key range not match.

* *: merge master.

* restore: fix test to match new change of master.

* Apply suggestions from code review

* restore: merge two progresses.

* restore: fix a bug.

that is, when table is too big or batch size is too low,
we will fail to restore the head part of this table.

* restore: extract batcher to another file

* task: don't return imediately when files is empty.

* restore,task: do some refactor

We move `splitPrepareWork` into a struct named `ContextManager`,
so that we can batchly set placement rules on online restore.

* restore: fix a shaming bug... :|

* task,restore: panic on file broken

* restore: record tiflash count to disk when removed

* restore,task: simplify some code,

* task,restore: fix a bug.

The bug causes,
when a singal table is splt into multi part of batches,
it sometimes fail to checksum.

* restore: some factory and fix

1. make the batcher worker has two send style
2. make functions for debuging tables and ranges
3. rewrite a test case to adapt the new batcher

* tests: try to fix CI

* tests: try to fix CI, again

* Apply suggestions from code review

Co-authored-by: 3pointer <qdlc2010@gmail.com>

* restore: change some log levels

* restore: merge joiner of sendWorker into messagebox

... and, some small changes:
- don't send sending request if here is one.
- the method of how a batcher is send move to log level debug

* restore,task: run RemoveRestoreLabels at restore post work

* task: adapt the remove-tiflash flag

* restore,task: fetch new placement rules each time

* Apply suggestions from code review

Co-authored-by: kennytm <kennytm@gmail.com>

* restore,task: run Leave always, and modify some log level

* restore: fix a bug that may cause checksum time incorrect

* restore: don't Leave if never Enter

Co-authored-by: kennytm <kennytm@gmail.com>
Co-authored-by: 3pointer <qdlc2010@gmail.com>
Co-authored-by: 3pointer <luancheng@pingcap.com>

* restore: fix a package name error

seems the rename package PR isn't cherry-picked to release-3.0.
So I move batcher_test to restore(from restore_test)

Co-authored-by: kennytm <kennytm@gmail.com>
Co-authored-by: 3pointer <qdlc2010@gmail.com>
Co-authored-by: 3pointer <luancheng@pingcap.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BR restore performance optimize
6 participants