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

ddl: clone table meta for recover table #55443

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

joechenrh
Copy link
Contributor

@joechenrh joechenrh commented Aug 15, 2024

What problem does this PR solve?

Issue Number: close #55442

Problem Summary:

As described in #55442, the infoschema checker has found inconsistent with v1 and v2 in TestRecoverTableByJobID, thus throw a panic.

This is because the tableinfo used by recovery is shallow copied from infocache and modified by subsequent process.

tidb/pkg/ddl/executor.go

Lines 1429 to 1444 in c74a233

tbInfo.State = model.StateNone
job := &model.Job{
SchemaID: schemaID,
TableID: tbInfo.ID,
SchemaName: schema.Name.L,
TableName: tbInfo.Name.L,
Type: model.ActionRecoverTable,
BinlogInfo: &model.HistoryInfo{},
Args: []any{recoverInfo, recoverCheckFlagNone},
InvolvingSchemaInfo: involvedSchemas,
CDCWriteSource: ctx.GetSessionVars().CDCWriteSource,
SQLMode: ctx.GetSessionVars().SQLMode,
}
err = e.DoDDLJob(ctx, job)
return errors.Trace(err)

What changed and how does it work?

Make a clone for table meta. This can fix TestRecoverTableByJobID failure.

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

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 15, 2024
Copy link

tiprow bot commented Aug 15, 2024

Hi @joechenrh. 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 Aug 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.2201%. Comparing base (c74a233) to head (309014c).
Report is 12 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #55443        +/-   ##
================================================
+ Coverage   74.9176%   75.2201%   +0.3025%     
================================================
  Files          1576       1576                
  Lines        365707     443461     +77754     
================================================
+ Hits         273979     333572     +59593     
- Misses        71965      89769     +17804     
- Partials      19763      20120       +357     
Flag Coverage Δ
integration 49.6556% <0.0000%> (?)
unit 72.3540% <100.0000%> (-1.5541%) ⬇️

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

Components Coverage Δ
dumpling 52.9567% <ø> (-2.2327%) ⬇️
parser ∅ <ø> (∅)
br 52.5429% <ø> (+4.7246%) ⬆️

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 16, 2024
Copy link

ti-chi-bot bot commented Aug 16, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tangenta, tiancaiamao

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:
  • OWNERS [tangenta,tiancaiamao]

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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 16, 2024
Copy link

ti-chi-bot bot commented Aug 16, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-16 01:13:58.486782426 +0000 UTC m=+489723.190252069: ☑️ agreed by tiancaiamao.
  • 2024-08-16 01:47:46.198352098 +0000 UTC m=+491750.901821742: ☑️ agreed by tangenta.

Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

why it causes "[schema:1050]Table 't_recover' already exists" if not clone?

@joechenrh
Copy link
Contributor Author

joechenrh commented Aug 16, 2024

why it causes "[schema:1050]Table 't_recover' already exists" if not clone?

Because recover table will check if it exists table with same name.

tidb/pkg/ddl/executor.go

Lines 1455 to 1458 in 2045418

// Check not exist table with same name.
if ok := is.TableExists(schema.Name, tbInfo.Name); ok {
return infoschema.ErrTableExists.GenWithStackByArgs(tbInfo.Name)
}

I have to mention that, on master branch, this test can always pass no matter whether this patch is applied or not. The key problem is that meta data retrieved from infoschema cache will be modified by recover table process, but it seems like recover table doesn't check table state. So this problem is not exposed without infoschema checker.

Besides, do you think we should check table state before executing RecoverTable?

@hawkingrei
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot merged commit f73e3e3 into pingcap:master Aug 16, 2024
23 checks passed
@joechenrh joechenrh deleted the clone-meta branch October 12, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ddl: recover table shouldn't change table info in cache
5 participants