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: update the reorg range after delay for async txn #38195

Merged
merged 2 commits into from Oct 8, 2022

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Sep 27, 2022

What problem does this PR solve?

Issue Number: close #38165

Problem Summary:

Previously, reorgInfo is initialized in getReorgInfo(), which happens before delayForAsyncCommit(). However, the reorg range may change after the delay(for example, an async commit transaction inserts a record). As a result, the backfill transaction does not add the corresponding index record.

What is changed and how it works?

This PR moves the reorg info range initialization after delayForAsyncCommit. It makes sure no async transactions are active.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    It is not easy to write the unit test because client-go is involved. I follow the steps described in issue, the problem does not occur anymore.
    ["[ddl] split table range from PD"] [physicalTableID=169] [startHandle=1] [endHandle=1]
    
    -- session 1
    mysql> alter table t add index idx(a);
    Query OK, 0 rows affected (3.86 sec)
    mysql> admin check table t;
    Query OK, 0 rows affected (0.00 sec)
    -- session 2
    mysql> insert into t values (1);
    Query OK, 1 row affected (2.01 sec)
    
  • No code

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.

Fix the data inconsistent issue after creating index.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 27, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • xiongjiwei
  • zimulala

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 release-note do-not-merge/needs-triage-completed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Type: Need cherry pick to release-5.4 needs-cherry-pick-release-6.1 needs-cherry-pick-6.3 and removed do-not-merge/needs-triage-completed labels Sep 27, 2022
ddl/reorg.go Outdated Show resolved Hide resolved
ddl/reorg.go Outdated
if reorgInfo.mergingTmpIdx {
start, end = tablecodec.GetTableIndexKeyRange(pid, tablecodec.TempIndexPrefix|elem.ID)
} else {
currentVer, err := getValidCurrentVersion(dCtx.store)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the currentVer value is changed. Before this PR, the version is got when region.first is true. Maybe we can use job.SnapshotVer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use job.SnapshotVer, we cannot get the latest data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, it went back.
But if not, does it feel like whether it is "first" doesn't make much of a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think the reorgInfo.first is necessary right from the start... Let me refactor these code later.

Copy link
Contributor

@zimulala zimulala Sep 28, 2022

Choose a reason for hiding this comment

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

OK~, I mean that if it isn't necessary, we can do #38195 (comment) .

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 28, 2022
ddl/stat_test.go Outdated
@@ -89,7 +89,7 @@ func TestDDLStatsInfo(t *testing.T) {
varMap, err := d.Stats(nil)
wg.Done()
require.NoError(t, err)
require.Equal(t, "1", varMap[ddlJobReorgHandle])
require.Equal(t, "", varMap[ddlJobReorgHandle])
Copy link
Contributor

Choose a reason for hiding this comment

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

why the test is changed

Copy link
Contributor Author

@tangenta tangenta Sep 29, 2022

Choose a reason for hiding this comment

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

Because the channel ddl.TestCheckWorkerNumCh sends, the transaction that updating ddl_job_reorg_handle is not committed.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 29, 2022
@xiongjiwei
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 333e389c93b956ef54f0344c23dd9c64aa26b091

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 29, 2022
@tangenta
Copy link
Contributor Author

/hold because add index test is timed out.

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 29, 2022
@hawkingrei
Copy link
Member

In the Cloud CI,check_2 only have 8 core cpu to run this test case. it maybe an reason。

@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed status/can-merge Indicates a PR has been approved by a committer. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 30, 2022
@xiongjiwei
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: b4fadfd

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 8, 2022
// get the current version for reorganization if we don't have
if d.lease > 0 { // Only delay when it's not in test.
delayForAsyncCommit()
}
ver, err := getValidCurrentVersion(d.store)
Copy link
Member

Choose a reason for hiding this comment

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

There are the same codes. I think it can be merged into a single function.

info.first = true
...
ver, err := getValidCurrentVersion(d.store)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Frankly speaking, getReorgInfoFromPartitions should reuse getReorgInfo since they are quite similar. Please note that getReorgInfoFromPartitions is only used by the global index feature, which is experimental, unstable, and lacks maintenance.

We need to discuss how to handle this piece of code properly.

Copy link
Member

Choose a reason for hiding this comment

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

OK, it may be improved after GA the global index feature.

@tangenta
Copy link
Contributor Author

tangenta commented Oct 8, 2022

/unhold
/merge

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 8, 2022
@ti-chi-bot ti-chi-bot merged commit 543417b into pingcap:master Oct 8, 2022
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: cannot checkout 5.3: error checking out 5.3: exit status 1. output: error: pathspec '5.3' did not match any file(s) known to git

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: cannot checkout 5.4: error checking out 5.4: exit status 1. output: error: pathspec '5.4' did not match any file(s) known to git

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: cannot checkout 6.1: error checking out 6.1: exit status 1. output: error: pathspec '6.1' did not match any file(s) known to git

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: cannot checkout 6.3: error checking out 6.3: exit status 1. output: error: pathspec '6.3' did not match any file(s) known to git

@sre-bot
Copy link
Contributor

sre-bot commented Oct 8, 2022

TiDB MergeCI notify

🔴 Bad News! New failing [1] after this pr merged.
These new failed integration tests seem to be caused by the current PR, please try to fix these new failed integration tests, thanks!

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-ddl-test 🟥 failed 1, success 5, total 6 30 min New failing
idc-jenkins-ci-tidb/common-test 🔴 failed 1, success 10, total 11 9 min 22 sec Existing failure
idc-jenkins-ci/integration-cdc-test 🟢 all 37 tests passed 25 min Existing passed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 17 tests passed 11 min Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 5 min 23 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 4 min 42 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 4 min 12 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 3 min 10 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 2 min 52 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Type: Need cherry pick to release-5.4 needs-cherry-pick-release-6.1 release-note size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Admin check failed after creating index
6 participants