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

table: refactor options for `Table.AddRecord/Table.UpdateRecord/IndexCreate #55125

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

lcwangchao
Copy link
Collaborator

What problem does this PR solve?

Issue Number: close #55121

What changed and how does it work?

This PR does some code refactors of the input options for methods Table.AddRecord/UpdateRecord and Index.Create including:

  1. Introduce UpdateRecordOption to give some optional args for Table.UpdateRecord:

We moved argument ctx to UpdateRecordOption for method UpdateRecord

// UpdateRecordOption is defined for the UpdateRecord() method of the Table interface.
type UpdateRecordOption interface {
	ApplyUpdateRecordOpt(*UpdateRecordOpt)
}

type Table interface {
	// ...
	UpdateRecord(ctx MutateContext, h kv.Handle, currData, newData []types.Datum, touched []bool, opts ...UpdateRecordOption) error
	// ...
}

Now, the method UpdateRecord is more like AddRecord and we can extend it in the future.

  1. Use CreateIdxOption to replace CreateIdxOptFunc:

The option for Index.Create is defined as an interface now instead of an function:

// CreateIdxOption is defined for the Create() method of the Index interface.
type CreateIdxOption interface {
	ApplyCreateIdxOpt(*CreateIdxOpt)
}

type Index interface {
	// ...
	Create(ctx MutateContext, txn kv.Transaction, indexedValues []types.Datum, h kv.Handle, handleRestoreData []types.Datum, opts ...CreateIdxOption) (kv.Handle, error)
	// ...
}

After this PR, AddRecordOption / UpdateRecordOption / CreateIdxOption are all interfaces that make it easy for some options to used in all these methods. And CreateIdxOptFunc implements CreateIdxOption to add new options easily.

type CreateIdxOptFunc func(*CreateIdxOpt)

// ApplyCreateIdxOpt implements the CreateIdxOption interface.
func (f CreateIdxOptFunc) ApplyCreateIdxOpt(opt *CreateIdxOpt) {
	f(opt)
}

// WithIgnoreAssertion uses to indicate the process can ignore assertion.
var WithIgnoreAssertion CreateIdxOptFunc = func(opt *CreateIdxOpt) {
	opt.IgnoreAssertion = true
}

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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 1, 2024
Copy link

tiprow bot commented Aug 1, 2024

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

return c.create(sctx, txn, indexedValue, h, handleRestoreData, false, opt)
}

func (c *index) create(sctx table.MutateContext, txn kv.Transaction, indexedValue []types.Datum, h kv.Handle, handleRestoreData []types.Datum, untouched bool, opt *table.CreateIdxOpt) (kv.Handle, error) {
Copy link
Collaborator Author

@lcwangchao lcwangchao Aug 1, 2024

Choose a reason for hiding this comment

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

The private method of create is used for internal invokes and the caller can pass some internal options to it such as untouched which is removed from CreateIdxOpt to avoid public usage.

We also added private method of addRecord and updateRecord for the same reason.

@lcwangchao lcwangchao force-pushed the tableopt branch 2 times, most recently from 816e739 to edac28e Compare August 1, 2024 07:07
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 92.59259% with 8 lines in your changes missing coverage. Please review.

Project coverage is 75.4365%. Comparing base (b5555c3) to head (6690ee8).
Report is 21 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #55125        +/-   ##
================================================
+ Coverage   74.7109%   75.4365%   +0.7256%     
================================================
  Files          1563       1563                
  Lines        364517     440353     +75836     
================================================
+ Hits         272334     332187     +59853     
- Misses        72402      87634     +15232     
- Partials      19781      20532       +751     
Flag Coverage Δ
integration 51.1460% <85.1851%> (?)
unit 71.6998% <90.7407%> (-1.8857%) ⬇️

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

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

@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Aug 1, 2024

@lcwangchao: 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.

@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Aug 1, 2024

@lcwangchao: 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.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 5, 2024
Copy link

ti-chi-bot bot commented Aug 5, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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

ti-chi-bot bot commented Aug 5, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-05 07:25:57.464598104 +0000 UTC m=+250487.331697192: ☑️ agreed by cfzjywxk.
  • 2024-08-05 08:30:37.758940119 +0000 UTC m=+254367.626039207: ☑️ agreed by tangenta.

@ti-chi-bot ti-chi-bot bot merged commit 9a2da2d into pingcap:master Aug 5, 2024
24 checks passed
@lcwangchao lcwangchao deleted the tableopt branch August 5, 2024 09:29
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor options for Table.AddRecord/Table.UpdateRecord/Index.Create
3 participants