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

partition: reorganized the execution order of partition table update operators #52442

Merged
merged 4 commits into from Apr 10, 2024

Conversation

Defined2014
Copy link
Contributor

@Defined2014 Defined2014 commented Apr 9, 2024

What problem does this PR solve?

Issue Number: close #52380, close #49998

Problem Summary: As updateRecord, we should remove record first and use memBuffer.Staging() to restore it when we meet errors in add records.

Ref code link

tidb/pkg/executor/write.go

Lines 165 to 195 in 510f44f

if handleChanged {
// For `UPDATE IGNORE`/`INSERT IGNORE ON DUPLICATE KEY UPDATE`
// we use the staging buffer so that we don't need to precheck the existence of handle or unique keys by sending
// extra kv requests, and the remove action will not take effect if there are conflicts.
if updated, err := func() (bool, error) {
txn, err := sctx.Txn(true)
if err != nil {
return false, err
}
memBuffer := txn.GetMemBuffer()
sh := memBuffer.Staging()
defer memBuffer.Cleanup(sh)
if err = t.RemoveRecord(sctx.GetTableCtx(), h, oldData); err != nil {
return false, err
}
_, err = t.AddRecord(sctx.GetTableCtx(), newData, table.IsUpdate, table.WithCtx(ctx))
if err != nil {
return false, err
}
memBuffer.Release(sh)
return true, nil
}(); err != nil {
if terr, ok := errors.Cause(err).(*terror.Error); ok && (terr.Code() == errno.ErrNoPartitionForGivenValue || terr.Code() == errno.ErrRowDoesNotMatchGivenPartitionSet) {
ec := sctx.GetSessionVars().StmtCtx.ErrCtx()
return false, ec.HandleError(err)
}
return updated, err
}
} else {

What changed and how does it work?

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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 9, 2024
Copy link

tiprow bot commented Apr 9, 2024

Hi @Defined2014. 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/test-infra repository.

@@ -355,15 +354,6 @@ func (c *index) Create(sctx table.MutateContext, txn kv.Transaction, indexedValu
}
continue
}
if c.idxInfo.Global && len(value) != 0 && !bytes.Equal(value, idxVal) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added by #42311. After change the update operators, no need this code anymore.

@Defined2014
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Apr 9, 2024

@Defined2014: 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/test-infra repository.

memBuffer.Cleanup(sh)
}
}()

err = t.GetPartition(from).RemoveRecord(ctx, h, currData)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As updateRecord, remove record first.

@mjonss
Copy link
Contributor

mjonss commented Apr 9, 2024

@Defined2014 I assume this will also close #49998 ?

Copy link

codecov bot commented Apr 10, 2024

Codecov Report

Merging #52442 (152a13b) into master (035f5a3) will increase coverage by 2.5465%.
Report is 30 commits behind head on master.
The diff coverage is 73.6842%.

❗ Current head 152a13b differs from pull request most recent head b886ec1. Consider uploading reports for the commit b886ec1 to get more accurate results

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #52442        +/-   ##
================================================
+ Coverage   72.2286%   74.7752%   +2.5465%     
================================================
  Files          1467       1467                
  Lines        426789     431049      +4260     
================================================
+ Hits         308264     322318     +14054     
+ Misses        99427      88735     -10692     
- Partials      19098      19996       +898     
Flag Coverage Δ
integration 49.2246% <73.6842%> (?)
unit 71.0151% <42.1052%> (-0.1027%) ⬇️

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

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

Copy link

ti-chi-bot bot commented Apr 10, 2024

@Defined2014: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-br-integration-test 152a13b 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/test-infra repository. I understand the commands that are listed here.

@Defined2014
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Apr 10, 2024

@Defined2014: 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/test-infra repository.

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

@Defined2014
Copy link
Contributor Author

@Defined2014 I assume this will also close #49998 ?

Yes, linked.

// The old and new data locate in different partitions.
// Remove record from old partition and add record to new partition.
if from != to {
_, err = t.GetPartition(to).AddRecord(ctx, newData)
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 old code does not get duplicate key error in this AddRecord operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ti-chi-bot ti-chi-bot bot added the lgtm label Apr 10, 2024
Copy link

ti-chi-bot bot commented Apr 10, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-04-10 02:50:16.458669975 +0000 UTC m=+1017077.986210521: ☑️ agreed by zimulala.
  • 2024-04-10 06:46:19.949320696 +0000 UTC m=+1031241.476861244: ☑️ agreed by tiancaiamao.

Copy link
Contributor

@mjonss mjonss 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

ti-chi-bot bot commented Apr 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mjonss, tiancaiamao, zimulala

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 merged commit e540f0f into pingcap:master Apr 10, 2024
23 of 24 checks passed
@Defined2014 Defined2014 deleted the fix-52380 branch April 10, 2024 07:37
3AceShowHand pushed a commit to 3AceShowHand/tidb that referenced this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
4 participants