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

lightning: support restore data into tables that contains data #784

Merged
merged 46 commits into from
Jun 4, 2021

Conversation

glorv
Copy link
Collaborator

@glorv glorv commented Mar 3, 2021

What problem does this PR solve?

  • Support use lightning local/importer backend to load data into tables that already contain data.
  • Support running multiple lightning in parallel to load data into tables that already contain data.

What is changed and how it works?

  • Add a new metatable mysql.brie_sub_tasks in TiDB to store the meta data for each table restore task.
  • Use show table next_row_id for the auto_id allocator base value. This can avoid auto_id conflict with the existing data. If there are other task record for the same table in brie_sub_tasks, the rowid rang will be calculated based on the recored info.
  • Prefetch the checksum value and store it in the table checkpoint. Also add this value into local checksum when compares local vs remote checksum.
  • Only do checksum and analyze after the last parallel task is finished, other tasks only put their local checksum info into the metatable, so the last only actually do the checksum can sum all the local checksum to get the right result.

Alternatives:

  • It's not necessary to put the metatable into mysql db. We can create a temporary table like the checkpoints db on-demand and drop it after all lightning tasks are finished.
    • Pros: avoid ask the admin permisssion.
  • Store the metadata at pd instead of in TiDB.
    • pro: maybe easier to manage.
    • Drawback: this will only support newer cluster.

Check List

Tests

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

Code changes

  • Has persistent data change

Side effects

  • Possible performance regression
  • Increased code complexity

Related changes

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

Release Note

  • Support load data into tables that contain data.

@glorv
Copy link
Collaborator Author

glorv commented Mar 3, 2021

Need to update the Glue interface to support scan or transaction to better support the show table next_row_id result.

@glorv glorv force-pushed the incremental-restore branch 4 times, most recently from 8c03754 to b2c981c Compare March 10, 2021 07:16
@glorv glorv force-pushed the incremental-restore branch 4 times, most recently from 9dcb8a6 to c500ab5 Compare March 10, 2021 09:30
@glorv
Copy link
Collaborator Author

glorv commented May 27, 2021

/run-all-tests

Copy link
Collaborator

@Little-Wallace Little-Wallace left a comment

Choose a reason for hiding this comment

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

LGTM

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

for backend in importer local; do
if [ "$backend" = 'local' ]; then
check_cluster_version 4 0 0 'local backend' || continue
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

this check is useless

Logger: log.L(),
HideQueryLog: redact.NeedRedact(),
}
metaDBSQL := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`", b.schema)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the b.schema here and the two below should be identifier-escaped (foo`bar`foo``bar`)

}

// avoid override existing metadata if the meta is already inserted.
stmt := fmt.Sprintf("DROP DATABASE %s;", m.schemaName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

(ditto)

@@ -2733,3 +2933,789 @@ func (cr *chunkRestore) restore(
return ctx.Err()
}
}

type metaMgrBuilder interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's move these meta-manager stuff into its own .go file to avoid further bloating the restore.go file (it's over 3700 lines after this PR 😅)

@glorv
Copy link
Collaborator Author

glorv commented Jun 4, 2021

/run-all-tests

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Little-Wallace
  • kennytm

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added status/LGT2 LGTM2 and removed status/LGT1 LGTM1 labels Jun 4, 2021
@glorv
Copy link
Collaborator Author

glorv commented Jun 4, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: a352c3a

@ti-chi-bot ti-chi-bot merged commit 05beea0 into pingcap:master Jun 4, 2021
@glorv glorv deleted the incremental-restore branch June 4, 2021 08:12
3pointer added a commit to 3pointer/br that referenced this pull request Jun 4, 2021
backup/checksum: add cluster index support for ranges (pingcap#1120)

lightning/restore: support ingset multi ssts for same range (pingcap#1089)

* ingest ssts for the same range in a batch

* make ingest compatible with old tikv

tests: add row count check for br clustered index tests (pingcap#1151)

storage: mkdirAll for local storage even when SkipCheckPath is true (pingcap#1156)

tests/br: fix bug in issue pingcap#1158 (pingcap#1160)

tests/br/compatibility: fix failed for manifest unknown (pingcap#1161)

*: upgrade go version from 1.13/1.15 to 1.16 (pingcap#1159)

action trigger: fix compatibility trigger bug on push (pingcap#1170)

address comment

fix test

address comment

address comment

fix build

add ut for ignore columns

go.mod: update tidb to the new version (pingcap#1153)

lightning: support restore data into tables that contains data (pingcap#784)

fix conflict after merge master
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.

5 participants