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: migrate pitr id map to the system table mysql.tidb_pitr_id_map #55871

Merged
merged 22 commits into from
Sep 13, 2024

Conversation

Leavrth
Copy link
Contributor

@Leavrth Leavrth commented Sep 5, 2024

What problem does this PR solve?

Issue Number: ref #55870

Problem Summary:
BR restore should not have the permission to write/delete the external storage.

What changed and how does it work?

migrate pitr id map to the system table mysql.tidb_pitr_id_map

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: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 5, 2024
Copy link

tiprow bot commented Sep 5, 2024

Hi @Leavrth. 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.

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 72.30769% with 18 lines in your changes missing coverage. Please review.

Project coverage is 56.8682%. Comparing base (bb3456b) to head (f78334d).
Report is 3 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #55871         +/-   ##
=================================================
- Coverage   72.9007%   56.8682%   -16.0326%     
=================================================
  Files          1604       1756        +152     
  Lines        446805     630412     +183607     
=================================================
+ Hits         325724     358504      +32780     
- Misses       101028     247249     +146221     
- Partials      20053      24659       +4606     
Flag Coverage Δ
integration 39.6444% <27.6923%> (?)
unit 72.0391% <64.6153%> (+0.0320%) ⬆️

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

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 63.1987% <74.1379%> (+17.4949%) ⬆️

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
pkg/session/bootstrap.go Outdated Show resolved Hide resolved
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 9, 2024
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
kv.WithInternalSourceType(ctx, kv.InternalTxnBR),
nil,
getPitrIDMapSQL,
restoreTS,
Copy link
Contributor

Choose a reason for hiding this comment

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

restoreTS maybe confusing, because sometimes we use start-ts to build pitr map. esspecially in L584.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current log restore's start-ts is the last log restore's restored-ts, so BR gets the pitr id map at start-ts of the current log restore is actually to get the pitr id map at restored-ts of the last log restore.

if err != nil {
return errors.Trace(err)
}
// clean the dirty id map at first
Copy link
Contributor

Choose a reason for hiding this comment

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

is it safe? if process exits abnormally after deleting finished.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have the processes to persist id map:

  1. directly get the pitr id map if checkpoint task progress mark that BR has persist pitr id map.
  2. if not, generate pitr id map, and
    a. delete the id map at restored ts
    b. write the id map at restored ts
    c. update the checkpoint task progress to mark that BR has persist pitr id map.

In the external storage, step 2.a and 2.b is replaced with uploading files with override mode. Actually, the atomic is not necessary. That's because there must be failed at the step 2.b or 2.c, which means the pitr id map is incomplete. But just do the step 2.a in the next execution to delete the incomplete pitr id map.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on id map at start-ts and the metakv to generate the new id map at restored-ts. So delete the new id map at restored-ts is safe because we still can regenerate the same one.

if BRVersion.Major > 8 || (BRVersion.Major == 8 && BRVersion.Minor >= 4) {
if tikvVersion.Major < 8 || (tikvVersion.Major == 8 && tikvVersion.Minor < 4) {
return errors.Annotatef(berrors.ErrVersionMismatch,
"TiKV node %s version %s is too old because the PITR id map is written into the cluster system table mysql.tidb_pitr_id_map, please use the tikv with version v8.4.0+",
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess TiKV isn't related to the systable...? Perhaps replace "TiKV" with "cluster".

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, there seems an assumption that each component version is the same.

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Copy link

ti-chi-bot bot commented Sep 12, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-11 07:21:27.930943161 +0000 UTC m=+427357.671367100: ☑️ agreed by YuJuncen.
  • 2024-09-12 03:34:09.829230921 +0000 UTC m=+500119.569654859: ☑️ agreed by 3pointer.

Copy link

@yudongusa yudongusa left a comment

Choose a reason for hiding this comment

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

LGTM for the bootstrap.

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

/approve

for import part

@ti-chi-bot ti-chi-bot bot added the approved label Sep 12, 2024
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
@Leavrth
Copy link
Contributor Author

Leavrth commented Sep 12, 2024

/ok-to-test

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
@ti-chi-bot ti-chi-bot bot removed the approved label Sep 12, 2024
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
@ti-chi-bot ti-chi-bot bot added the sig/planner SIG: Planner label Sep 12, 2024
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

@Leavrth
Copy link
Contributor Author

Leavrth commented Sep 13, 2024

/retest

@ti-chi-bot ti-chi-bot bot added the approved label Sep 13, 2024
Copy link

ti-chi-bot bot commented Sep 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3pointer, hawkingrei, lance6716, windtalker, winoros, yudongusa, 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 merged commit 027f01b into pingcap:master Sep 13, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants