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

*(dm): move downstream table info logic into sqlmodel #4885

Merged
merged 7 commits into from
Mar 23, 2022

Conversation

lance6716
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #4287

What is changed and how it works?

  • mainly move the logic of DM's different source table info and target table info.
  • check index state to fit CDC usage
  • rename a variable

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change
  • Has exported variable/fields change

Release note


 `None`.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 14, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • D3Hunter
  • Ehco1996

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 the release-note-none Denotes a PR that doesn't merit a release note. label Mar 14, 2022
@lance6716 lance6716 added the area/dm Issues or PRs related to DM. label Mar 14, 2022
@ti-chi-bot ti-chi-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 14, 2022
@lance6716
Copy link
Contributor Author

/cc @WizardXiao @GMHDBJD @Ehco1996

Signed-off-by: lance6716 <[email protected]>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2022
Copy link
Contributor

@Ehco1996 Ehco1996 left a comment

Choose a reason for hiding this comment

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

no big problems, nice job to megre pkg of cdc and dm 🤙🤙🤙

LGTM

AbsoluteUKIndexInfo *model.IndexInfo // absolute uk index is a pk/uk(not null)
AvailableUKIndexList []*model.IndexInfo // index list which is all uks
TableInfo *model.TableInfo // tableInfo which comes from parse create statement syntaxtree
WhereHandleCache *sqlmodel.WhereHandle
Copy link
Contributor

Choose a reason for hiding this comment

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

why call this cache ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's computed once for many row changes

Copy link
Contributor

Choose a reason for hiding this comment

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

the whole struct is cached in tr.dsTracker.tableInfos which should be called xxxCache.

prefer remove this suffix here.

pkg/sqlmodel/where_handle.go Show resolved Hide resolved
dti = GetDownStreamTI(downstreamTI, originTi)
dti = &DownstreamTableInfo{
TableInfo: downstreamTI,
WhereHandleCache: sqlmodel.GetWhereHandle(originTi, downstreamTI),
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe can rename downstreamTI to downstreamTi 😂

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 = TableInfo

Copy link
Contributor

Choose a reason for hiding this comment

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

but another one called originTi 😂

// - an UNIQUE index and the data is all NOT NULL.
// For the last case, last used index is swapped to front.
func (h *WhereHandle) getWhereIdxByData(data []interface{}) *model.IndexInfo {
if h == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems h never equal to nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to improve robustness because WhereHandle is public

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe log something, should be a bug in most usage.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 15, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 15, 2022
@lance6716
Copy link
Contributor Author

[](https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/#step-49-log-111)[](https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/#step-49-log-112)[](https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/#step-49-log-113)[](https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/#step-49-log-114)[](https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/#step-49-log-115)[](https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/#step-49-log-116)[](https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/#step-49-log-117)[2022-03-15T02:46:22.488Z] FAIL: optimist_test.go:224: testOptimist.TestOptimist

[2022-03-15T02:46:22.488Z] 

[2022-03-15T02:46:22.488Z] optimist_test.go:225:

[2022-03-15T02:46:22.488Z]     t.testOptimist(c, t.etcdTestCli, noRestart)

[2022-03-15T02:46:22.488Z] optimist_test.go:406:

[2022-03-15T02:46:22.488Z]     c.Assert(opm, HasLen, 0)

[2022-03-15T02:46:22.488Z] ... obtained map[string]map[string]map[string]map[string]optimism.Operation = map[string]map[string]map[string]map[string]optimism.Operation{"task-lock-with-init-schema":map[string]map[string]map[string]optimism.Operation{"mysql-replica-1":map[string]map[string]optimism.Operation{"foo":map[string]optimism.Operation{"bar-1":optimism.Operation{ID:"task-lock-with-init-schema-`db`.`tbl`", Task:"task-lock-with-init-schema", Source:"mysql-replica-1", UpSchema:"foo", UpTable:"bar-1", DDLs:[]string{}, ConflictStage:"none", ConflictMsg:"", Done:false, Cols:[]string{"c"}, Revision:14}}}}}

[2022-03-15T02:46:22.488Z] ... n int = 0

https://ci.pingcap.net/blue/organizations/jenkins/ut-check/detail/ut-check/5428/pipeline/

@GMHDBJD seems didn't fix the unstable case

@lance6716
Copy link
Contributor Author

ping @GMHDBJD

}
// use downstream columns to check NOT NULL constraint
if ret.UniqueNotNullIdx == nil && allColsNotNull(idx, target.Columns) {
// TODO: considering cardinality
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this todo mean?

// - an UNIQUE index and the data is all NOT NULL.
// For the last case, last used index is swapped to front.
func (h *WhereHandle) getWhereIdxByData(data []interface{}) *model.IndexInfo {
if h == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe log something, should be a bug in most usage.

AbsoluteUKIndexInfo *model.IndexInfo // absolute uk index is a pk/uk(not null)
AvailableUKIndexList []*model.IndexInfo // index list which is all uks
TableInfo *model.TableInfo // tableInfo which comes from parse create statement syntaxtree
WhereHandleCache *sqlmodel.WhereHandle
Copy link
Contributor

Choose a reason for hiding this comment

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

the whole struct is cached in tr.dsTracker.tableInfos which should be called xxxCache.

prefer remove this suffix here.

Signed-off-by: lance6716 <[email protected]>
@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 Mar 23, 2022
@lance6716
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 3a7a66e

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

/run-leak-test

@ti-chi-bot ti-chi-bot merged commit 14d01a8 into pingcap:master Mar 23, 2022
@lance6716 lance6716 deleted the refine-downstream-ti branch October 13, 2022 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dm Issues or PRs related to DM. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ 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.

refine code
4 participants