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

br: support PiTR feature #34409

Merged
merged 40 commits into from
May 12, 2022
Merged

br: support PiTR feature #34409

merged 40 commits into from
May 12, 2022

Conversation

joccau
Copy link
Member

@joccau joccau commented May 6, 2022

What problem does this PR solve?

Issue Number: ref #29501

Problem Summary:

What is changed and how it works?

The new feature: PiTR

  • Take a backup of key-value recored in TiKV If you run br log start ...
  • Restore table and record from snapshot-ts to restore-ts if you run br restore point ...

Relative design/tests

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.

Support the new feature of PiTR.

YuJuncen and others added 30 commits March 21, 2022 17:48
* stream: initial commit of stream backup

* br/stream: basic logic of stream backup metadata

* br/stream: add prefix scanner

* br/stream: use types from kv package

* br/stream: unexport prefix scanner(remove it to utils package and export it in need)

* br/stream: move kvproto to br-stream branch, added a playground

* br/stream: added some new functions for playground

* br/stream: added a builder for task

* br/stream: remove playground, use math.MaxUInt64

* br: replace kvproto with br-stream

* br/stream: update error code

* br/stream: fix tests

* br/stream: added copyright
* Add stream start/pause/resume/stop command

Signed-off-by: joccau <zak.zhao@pingcap.com>
* Add stream start/pause/resume/stop command

Signed-off-by: joccau <zak.zhao@pingcap.com>

* Add build observe ranges

Signed-off-by: joccau <zak.zhao@pingcap.com>

* Compare startTS and endTS

Signed-off-by: joccau <zak.zhao@pingcap.com>

* test for stream task

Signed-off-by: joccau <zak.zhao@pingcap.com>

* test for stream task

Signed-off-by: joccau <zak.zhao@pingcap.com>

* Deal comments in pr

Signed-off-by: joccau <zak.zhao@pingcap.com>

* Add comment for function

Signed-off-by: joccau <zak.zhao@pingcap.com>

* modify comments

Signed-off-by: joccau <zak.zhao@pingcap.com>

* update building of key-range for tableID

Signed-off-by: joccau <zak.zhao@pingcap.com>

* resolve the check issue

Signed-off-by: joccau <zak.zhao@pingcap.com>

* Deal comments in pr

Signed-off-by: joccau <zak.zhao@pingcap.com>

* Debug stream log to test flow

Signed-off-by: joccau <zak.zhao@pingcap.com>

* Deal comments in PR

Signed-off-by: joccau <zak.zhao@pingcap.com>

* use + / rather join

Signed-off-by: joccau <zak.zhao@pingcap.com>

* maintain test case for backup stream

Signed-off-by: joccau <zak.zhao@pingcap.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
* Add stream start/pause/resume/stop command

Signed-off-by: joccau <zak.zhao@pingcap.com>
* add restore command

* coarse implement restore
* add restore_ts for apply

* update kvproto
* fix file rewrite end key

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* run go fmt

Signed-off-by: Yu Juncen <yu745514916@live.com>

* run go mod tidy

Signed-off-by: Yu Juncen <yu745514916@live.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
* br-stream: add region context in applyRequest
* add ObjPrefix to speed up walkDir in br-stream

* add start/end key to filter unnecessay key
* Add code for stream restore metaKV

Signed-off-by: joccau <zak.zhao@pingcap.com>
* add switch check before stream starts
* added truncate log

Signed-off-by: Yu Juncen <yu745514916@live.com>
* observer all data in stream task

Signed-off-by: joccau <zak.zhao@pingcap.com>
* support checkSum during restore dml kv-events.

Signed-off-by: joccau <zak.zhao@pingcap.com>

* update usage API

Signed-off-by: joccau <zak.zhao@pingcap.com>

* fix bug in stream start

Signed-off-by: joccau <zak.zhao@pingcap.com>

* maintain testcase

Signed-off-by: joccau <zak.zhao@pingcap.com>
* restore full and stream by command "br stream restore"

Signed-off-by: joccau <zak.zhao@pingcap.com>
* support task info

Signed-off-by: Yu Juncen <yu745514916@live.com>

* added QPS

Signed-off-by: Yu Juncen <yu745514916@live.com>

address comments

Signed-off-by: Yu Juncen <yu745514916@live.com>

* set the start ts as the default global checkpoint

Signed-off-by: Yu Juncen <yu745514916@live.com>
commit 981c9c39f9b7fe4cbe6e6f3cbf2a0c57838c1224
Author: Yu Juncen <yu745514916@live.com>
Date:   Thu Mar 17 17:22:53 2022 +0800

    fix tests

    Signed-off-by: Yu Juncen <yu745514916@live.com>

commit b3bafa8f0f8fd1f243c990179cbbfe8ecf2fed7e
Author: Yu Juncen <yu745514916@live.com>
Date:   Thu Mar 17 11:14:07 2022 +0800

    retry if epoch not match during finding leader

    Signed-off-by: Yu Juncen <yu745514916@live.com>

commit cf0bf4b0d61e163eb527db032dd880dbbabed809
Author: Yu Juncen <yu745514916@live.com>
Date:   Wed Mar 16 16:34:27 2022 +0800

    fix import error ignored

    Signed-off-by: Yu Juncen <yu745514916@live.com>

commit 0ae287d65465856b013680bc2183d60a08c6b37f
Author: Yu Juncen <yu745514916@live.com>
Date:   Fri Mar 11 14:48:06 2022 +0800

    fix typo

    Signed-off-by: Yu Juncen <yu745514916@live.com>

commit 4eba96e5cc6110734233376b39216fbb66a88d8d
Author: Yu Juncen <yu745514916@live.com>
Date:   Fri Mar 11 14:09:31 2022 +0800

    run tests sequential

    Signed-off-by: Yu Juncen <yu745514916@live.com>

commit 4b659359963c141ab405dca52f3607f10f2be6a2
Author: Yu Juncen <yu745514916@live.com>
Date:   Fri Mar 11 12:10:48 2022 +0800

    update go.mod

    Signed-off-by: Yu Juncen <yu745514916@live.com>

commit fc2d9290cd8d5782455565175c78edbfb43aac60
Author: Yu Juncen <yu745514916@live.com>
Date:   Fri Mar 11 11:53:43 2022 +0800

    update kvproto

    Signed-off-by: Yu Juncen <yu745514916@live.com>

commit 365975b6ef2341f4307ac39b43af9bdd037b74b4
Author: Yu Juncen <yujuncen@pingcap.com>
Date:   Thu Mar 10 20:33:10 2022 +0800

    added test cases

    Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

commit 08502b5c0670989474b6de5239235dede72f581f
Author: Yu Juncen <yujuncen@pingcap.com>
Date:   Wed Mar 9 18:23:58 2022 +0800

    added some tools for retry

    Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

commit b8d518b69dd827680f074ec1899cadf1b00647d3
Merge: 5c329e46f ce0b12c
Author: Yu Juncen <yujuncen@pingcap.com>
Date:   Wed Mar 9 16:06:36 2022 +0800

    Merge branch 'br-stream' of https://github.com/pingcap/tidb into retry-apply

    Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

commit 5c329e46f70424c27df3862a407d4a9751af1824
Author: Yu Juncen <yujuncen@pingcap.com>
Date:   Wed Mar 9 15:55:09 2022 +0800

    added retry

    Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

commit 044d804
Merge: 0451199 ebd27f8
Author: 3pointer <luancheng@pingcap.com>
Date:   Tue Mar 8 16:59:22 2022 +0800

    Merge branch 'br-stream' into key_not_found

commit 0451199
Author: 3pointer <luancheng@pingcap.com>
Date:   Tue Mar 8 16:47:47 2022 +0800

    address comment

commit b5470a9
Author: 3pointer <luancheng@pingcap.com>
Date:   Mon Mar 7 19:30:23 2022 +0800

    fix check

commit 00d49d8
Author: 3pointer <luancheng@pingcap.com>
Date:   Mon Mar 7 18:57:58 2022 +0800

    format

commit 232a646
Author: 3pointer <luancheng@pingcap.com>
Date:   Mon Mar 7 18:49:32 2022 +0800

    update kvproto

commit d46105e
Author: 3pointer <luancheng@pingcap.com>
Date:   Fri Mar 4 12:28:58 2022 +0800

    add start/end key to filter unnecessay key

commit d61a01f
Author: 3pointer <luancheng@pingcap.com>
Date:   Fri Mar 4 12:26:17 2022 +0800

    add ObjPrefix to speed up walkDir in br-stream

Signed-off-by: Yu Juncen <yu745514916@live.com>
…k here (#33725)

* refactor the status command && print "no task" when no task here

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* added some test cases

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* added the status of backup task

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* fix typo

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* make write success always

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* apply suggestions from comment

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>
* br: refine cmd stream restore to restore log
* support pause/resume stream task

Signed-off-by: joccau <zak.zhao@pingcap.com>
Signed-off-by: Yu Juncen <yujuncen@pingcap.com>
* show errors

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* fix remove last error

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* ignore tiflash when getting status

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

* Update br/pkg/stream/stream_status.go

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

* fix build

Signed-off-by: Yu Juncen <yujuncen@pingcap.com>

Co-authored-by: 3pointer <qdlc2010@gmail.com>
* remove checkpointTs in pd when stop stream task

Signed-off-by: joccau <zak.zhao@pingcap.com>
* br-stream: split put file and delete file in restore

* br-stream: implement cleanup files
)

* update command name

Signed-off-by: joccau <zak.zhao@pingcap.com>

* support restoring autoTable

Signed-off-by: joccau <zak.zhao@pingcap.com>

* report other tidb after update global schema version

Signed-off-by: joccau <zak.zhao@pingcap.com>

* support restoring sequence id

Signed-off-by: joccau <zak.zhao@pingcap.com>

* make fmt
@sre-bot
Copy link
Contributor

sre-bot commented May 6, 2022

@joccau
Copy link
Member Author

joccau commented May 7, 2022

/component br

@ti-chi-bot ti-chi-bot added the component/br This issue is related to BR of TiDB. label May 7, 2022
br/pkg/utils/schema.go Outdated Show resolved Hide resolved
Signed-off-by: joccau <zak.zhao@pingcap.com>
br/cmd/br/stream.go Outdated Show resolved Hide resolved
br/pkg/gluetidb/glue.go Show resolved Hide resolved
br/pkg/restore/client.go Outdated Show resolved Hide resolved
br/pkg/restore/client.go Outdated Show resolved Hide resolved
br/pkg/restore/client.go Outdated Show resolved Hide resolved
}

// UpdateSchemaVersion updates schema version by transaction way.
func (rc *Client) UpdateSchemaVersion(ctx context.Context) error {
Copy link
Member

Choose a reason for hiding this comment

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

It's not compatible with the concurrent DDL, we need to take care of it.

Copy link
Member Author

@joccau joccau May 10, 2022

Choose a reason for hiding this comment

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

Because PiTR is used in an empty cluster, the concurrent scenarios does not happen.
The PiTR is contains 2 parts:

  1. restore snapshot
  2. restore log

br/pkg/restore/import_retry.go Outdated Show resolved Hide resolved
br/pkg/restore/util.go Outdated Show resolved Hide resolved
* rewrite db

Signed-off-by: joccau <zak.zhao@pingcap.com>

* rewrite table

Signed-off-by: joccau <zak.zhao@pingcap.com>

* restore log from start-ts to restore-ts

Signed-off-by: joccau <zak.zhao@pingcap.com>

* safe old schemas after restore log

Signed-off-by: joccau <zak.zhao@pingcap.com>

* batch put raw kv

Signed-off-by: joccau <zak.zhao@pingcap.com>

* remove useless function and set 64 to rawkv put batch count

Signed-off-by: joccau <zak.zhao@pingcap.com>

* rename backup-stream to log-backup

Signed-off-by: joccau <zak.zhao@pingcap.com>

* deal comments in PR

Signed-off-by: joccau <zak.zhao@pingcap.com>
@3pointer
Copy link
Contributor

/run-integration-br-tests

3pointer and others added 2 commits May 10, 2022 20:46
@joccau
Copy link
Member Author

joccau commented May 11, 2022

/run-integration-br-test

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.

Given all commits LGTM, trivially(?) this PR LGTM.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 11, 2022
Copy link
Contributor

@3pointer 3pointer left a comment

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 added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 11, 2022
3pointer and others added 3 commits May 11, 2022 21:14
@joccau
Copy link
Member Author

joccau commented May 12, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 952ea7c

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 12, 2022
@joccau
Copy link
Member Author

joccau commented May 12, 2022

/run-all-tests

1 similar comment
@joccau
Copy link
Member Author

joccau commented May 12, 2022

/run-all-tests

@joccau
Copy link
Member Author

joccau commented May 12, 2022

/run-all-tests

@ti-chi-bot ti-chi-bot merged commit c6fe032 into master May 12, 2022
@ti-chi-bot ti-chi-bot deleted the br-stream branch May 12, 2022 09:08
@sre-bot
Copy link
Contributor

sre-bot commented May 12, 2022

TiDB MergeCI notify

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci/integration-cdc-test 🟢 all 34 tests passed 26 min Existing passed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 11 tests passed 13 min Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 7 min 5 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 6 min 55 sec Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 12 tests passed 6 min 54 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 6 min 40 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 6 min 30 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 3 min 27 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 3 min 2 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/br This issue is related to BR of TiDB. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants