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: add table filter for log restore #57394

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

Conversation

Tristan1900
Copy link
Contributor

@Tristan1900 Tristan1900 commented Nov 15, 2024

What problem does this PR solve?

Issue Number: close #57613

Problem Summary:
Need table filter for PiTR

What changed and how does it work?

The following happens if a custom filter is specified during PiTR.

  1. Do a log backup meta scan at first before snapshot restore, and record all the table rename history and table mapping information during the scan, since we don't have access to genGlobalId, we use a temp id as a placeholder.
  2. During snapshot restore, adjust the tables that need to be restored according to the rename history. It needs to add tables that renamed into the filter and removes the tables that are renamed out of the filter range during log backup. And put all the tables that need to be restored into a map/filter and pass down to log restore
  3. During log restore, we use that map/filter from the above and filters out the tables/kvs that don't need to restore/rewrite, and we replace the temp id in the id map with real global ids.
  4. For actual meta kv restore, use id map to filter out the kvs that doesn't need to restore. so for tables not exist in the id map, we can simply ignore it because they are filtered out.
  5. The id map is persisted once built to work with checkpoint, so our filter naturally works with checkpoint as well.

Performance:
we are still scanning log meta kv twice, it's just we move the previously id map building step before snapshot happens.

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 15, 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 release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-tests-checked do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 15, 2024
Copy link

tiprow bot commented Nov 15, 2024

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

@Tristan1900 Tristan1900 marked this pull request as ready for review November 25, 2024 00:06
@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 25, 2024
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 66.00634% with 429 lines in your changes missing coverage. Please review.

Project coverage is 74.1069%. Comparing base (7cee190) to head (977507c).
Report is 11 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57394        +/-   ##
================================================
+ Coverage   73.1112%   74.1069%   +0.9957%     
================================================
  Files          1684       1709        +25     
  Lines        466366     479249     +12883     
================================================
+ Hits         340966     355157     +14191     
+ Misses       104467     101489      -2978     
- Partials      20933      22603      +1670     
Flag Coverage Δ
integration 41.5512% <66.0063%> (?)

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

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 61.0781% <66.0063%> (+15.7548%) ⬆️

@Tristan1900 Tristan1900 force-pushed the table-filter branch 2 times, most recently from f624281 to 6ebc531 Compare November 25, 2024 15:53
@Tristan1900 Tristan1900 force-pushed the table-filter branch 6 times, most recently from 852dcff to b5132a9 Compare December 23, 2024 18:56
@Tristan1900 Tristan1900 force-pushed the table-filter branch 7 times, most recently from d2b68b8 to d72415c Compare December 30, 2024 23:30
@Tristan1900 Tristan1900 force-pushed the table-filter branch 2 times, most recently from 021494a to 1eee968 Compare January 13, 2025 17:37
@Tristan1900
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jan 13, 2025

@Tristan1900: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

}

// write cf doesn't have short value in it
if value == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we handle the DELETE operations in the write CF? (Which doesn't have a value.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, I think it's not necessarily needed, we are only tracking the all the table ids at this step, if there is a delete there must be a create table happened before, so that should be tracked already.

ctx context.Context,
s storage.ExternalStorage,
tableFilter filter.Filter,
piTRTableFilter *utils.PiTRTableTracker,
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps name the variable piTRTableTracker or rename the PiTRTableTracker to something like TracedPiTRTableFilter? As tracker.ContainsDB(foo) -> Filtered Out looks a little bit strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, I want to avoid using filter here because I feel like the term is overloaded so can cause confusion. let me rename all to be tracker related. but actually tracker.ContainsDB(foo) -> included

Comment on lines +689 to +733
func (rc *SnapClient) GetDatabaseMap() map[int64]*metautil.Database {
dbMap := make(map[int64]*metautil.Database)
for _, db := range rc.databases {
dbMap[db.Info.ID] = db
}
return dbMap
Copy link
Contributor

Choose a reason for hiding this comment

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

How about maps.Clone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh it's indexed differently if you mean to clone rc.databases. one is indexed by db name and this one is db id

@@ -1655,3 +1823,26 @@ func afterTableRestoredCh(ctx context.Context, createdTables []*snapclient.Creat
}()
return outCh
}

func convertMapsToSlices(
Copy link
Contributor

Choose a reason for hiding this comment

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

How about make a generic function like:

func convertMapToSlice[K, V any](m map[K]V) []V {
    values := make([]T, 0, len(m))
    for v := range maps.Values(m) {
        values = append(values, v)
    }
    return values
}

And call it three times?

}
// handle case where current is not in range and original was in range, we need to remove the original from
// restoring
} else if utils.MatchTable(cfg.TableFilter, dbName, start.TableName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering whether the table will be created again by putting meta again (By the meta entry of rename). I didn't found something that filters out not matched meta keys.

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 not sure about the meaning of this one, will follow up offline

},
}

// Test case 1: Basic table tracking
Copy link
Contributor

Choose a reason for hiding this comment

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

When there are many similar cases, would you parameterize those case? like:

type Case struct {
    Filter string
    PiTRHistories struct{ tid int64, tname string, did int64 }

    ExceptsTables [][2]int
    ExceptsDBNotExist []int
    ExcpetsTableNotExist []int
}

Also you may warp each case with t.Run, so cases can be run independently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call!

// gc.ratio-threshold = "-1.0", which represents disable gc in TiKV.
func KeepGcDisabled(g glue.Glue, store kv.Storage) (RestoreFunc, string, error) {
func DisableGc(g glue.Glue, store kv.Storage) (RestoreGcFunc, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Go prefers captialize all letters in acronyms. As we are going to rename we may follow this tradition by the way.

Suggested change
func DisableGc(g glue.Glue, store kv.Storage) (RestoreGcFunc, string, error) {
func DisableGC(g glue.Glue, store kv.Storage) (RestoreGCFunc, string, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, good to know!

Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Signed-off-by: Wenqi Mou <[email protected]>
Copy link

ti-chi-bot bot commented Jan 23, 2025

@Tristan1900: 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
idc-jenkins-ci-tidb/unit-test 977507c link true /test unit-test
idc-jenkins-ci-tidb/check_dev 977507c link true /test check-dev
pull-br-integration-test 977507c link true /test pull-br-integration-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-sigs/prow 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.

br: add table filter for Pitr restore
3 participants