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

executor: sync deletable columns to binlog when remove record #53617

Merged
merged 4 commits into from
May 29, 2024

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented May 28, 2024

What problem does this PR solve?

Issue Number: close #53133

Problem Summary:

Previously, when TiDB writes delete records to binlog, column count of schema and data mismatch. This is because only public columns are selected, while data includes all deletable columns.

What changed and how does it work?

Make schema use all deletable columns.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    1. deploy two TiDB clusters, and start pump & drainer.
    2. modify upstream TiDB code:
    diff --git a/pkg/config/config.toml.example b/pkg/config/config.toml.example
    index c1438a9e85..b73828367d 100644
    --- a/pkg/config/config.toml.example
    +++ b/pkg/config/config.toml.example
    @@ -416,7 +416,7 @@ capacity-mb = 1000.0
     # enable to write binlog.
     # NOTE: If binlog is enabled with Kafka (e.g. arbiter cluster),
     # txn-total-size-limit should be less than 1073741824(1G) because this is the maximum size that can be handled by Kafka.
    -enable = false
    +enable = true
     
     # WriteTimeout specifies how long it will wait for writing binlog to pump.
     write-timeout = "15s"
    diff --git a/pkg/ddl/column.go b/pkg/ddl/column.go
    index 206b64d513..1727ba4c44 100644
    --- a/pkg/ddl/column.go
    +++ b/pkg/ddl/column.go
    @@ -173,6 +173,7 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error)
                    // reorganization -> public
                    // Adjust table column offset.
                    failpoint.InjectCall("onAddColumnStateWriteReorg")
    +               time.Sleep(20 * time.Second)
                    offset, err := LocateOffsetToMove(columnInfo.Offset, pos, tblInfo)
                    if err != nil {
                            return ver, errors.Trace(err)
    1. execute SQL at upstream:
    -- session 1
    CREATE TABLE `t` (
      `a` int(11) DEFAULT NULL,
      `b` int(11) DEFAULT NULL,
      `c` int(11) DEFAULT NULL,
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
    insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 3);
    alter table t add column d int default 3;
    
    -- session 2
    delete from t where a = 1;
    
    1. execute SQL at downstream:
    mysql> select * from t;
    +------+------+------+------+
    | a    | b    | c    | d    |
    +------+------+------+------+
    |    3 |    3 |    3 |    3 |
    |    2 |    2 |    2 |    3 |
    +------+------+------+------+
    2 rows in set (0.00 sec)
    
    Even if we synchronize a 4-columns row to binlog, drainer can handle it correctly by decoding necessary(public) columns:
    https://github.com/pingcap/tidb-binlog/blob/6fba4f883a0c6c7e0d68b3b8aef1a53d9454b273/drainer/translator/mysql.go#L88-L90
  • 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 28, 2024
Copy link

tiprow bot commented May 28, 2024

Hi @tangenta. 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 May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.6091%. Comparing base (bdb0545) to head (23ea05f).
Report is 1139 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53617        +/-   ##
================================================
+ Coverage   72.4359%   74.6091%   +2.1732%     
================================================
  Files          1506       1506                
  Lines        430579     433369      +2790     
================================================
+ Hits         311894     323333     +11439     
+ Misses        99367      90086      -9281     
- Partials      19318      19950       +632     
Flag Coverage Δ
integration 49.1612% <66.6666%> (?)
unit 71.4387% <100.0000%> (+0.0265%) ⬆️

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

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 50.4674% <ø> (+9.0192%) ⬆️

@wjhuang2016
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 28, 2024
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label May 28, 2024
deletableCols := t.DeletableCols()
for i, d := range deletableData {
dCol := deletableCols[i]
if dCol.State == model.StatePublic {
Copy link
Contributor

@D3Hunter D3Hunter May 28, 2024

Choose a reason for hiding this comment

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

suppose we are dropping/lossy-modify a column, this list won't contains the changed column while binlog think the column exist, not sure if binlog can handle it.

Copy link
Contributor Author

@tangenta tangenta May 29, 2024

Choose a reason for hiding this comment

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

For lossy modifying a column, it consists of two steps:

1. add a hidden column
2. drop the old column

Since DDL is only synced when the job state is done, the hidden column does not exists in downstream.

@tangenta tangenta changed the title executor: extract public datums before writing to binlog executor: sync deletable columns to binlog when remove record May 29, 2024
@@ -1368,7 +1368,7 @@ func (t *TableCommon) RemoveRecord(ctx table.MutateContext, h kv.Handle, r []typ
memBuffer.Release(sh)

if shouldWriteBinlog(ctx.GetSessionVars(), t.meta) {
cols := t.Cols()
cols := t.DeletableCols()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistent with

} else if b.inDeleteStmt {
// DeletableCols returns all columns of the table in deletable states.
columns = tbl.DeletableCols()

Copy link
Contributor

Choose a reason for hiding this comment

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

when add column this list will contain the new column that binlog does not know now, can binlog handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

ti-chi-bot bot commented May 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, wjhuang2016

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

ti-chi-bot bot commented May 29, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-28 13:27:07.85031357 +0000 UTC m=+2782981.607449143: ☑️ agreed by wjhuang2016.
  • 2024-05-29 07:01:13.948109721 +0000 UTC m=+2846227.705245293: ☑️ agreed by D3Hunter.

@ti-chi-bot ti-chi-bot bot merged commit 6efce0f into pingcap:master May 29, 2024
21 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #53647.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request May 29, 2024
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. label May 31, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request May 31, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #53700.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #54942.

@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. label Oct 28, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #56887.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
4 participants