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

syncer(dm): init schemaTracker when syncer run #6052

Merged
merged 9 commits into from
Jun 30, 2022

Conversation

buchuitoudegou
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #6014

What is changed and how it works?

The validator will get the old schemaTracker because the syncer re-builds the schemaTracker every time it starts. To avoid that, I'm about to decouple the creating and initialization of the schemaTracker so that the syncer will only initialize the schemaTracker when it starts to run and the schemaTracker remains the same instance in the whole lifecycle of the task.

  1. create dump schemaTracker when initializing the syncer
  2. initialize the schemaTracker when running

Check List

Tests

  • Unit test

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

`None`

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jun 27, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • D3Hunter
  • lance6716

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 do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. labels Jun 27, 2022
@buchuitoudegou
Copy link
Contributor Author

/area dm

@ti-chi-bot ti-chi-bot added the area/dm Issues or PRs related to DM. label Jun 27, 2022
@buchuitoudegou buchuitoudegou marked this pull request as ready for review June 27, 2022 07:56
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jun 27, 2022
@buchuitoudegou
Copy link
Contributor Author

/run-dm-integration-test

@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2022
@lance6716

This comment was marked as resolved.

@buchuitoudegou
Copy link
Contributor Author

schemaTracker remains the same instance in the whole lifecycle of the task

this will cause #5344 and #4187

The schemaTracker can still be Close'd every time the task is paused, where the persistent storage is removed. Just avoid creating a new instance.

return os.RemoveAll(tr.storePath)

@buchuitoudegou
Copy link
Contributor Author

/run-dm-integration-test

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

And also can we add a test of "two tracker"?
rest lgtm

@@ -99,16 +99,25 @@ type DownstreamTableInfo struct {
WhereHandle *sqlmodel.WhereHandle
}

// NewTracker creates a new tracker. `sessionCfg` will be set as tracker's session variables if specified, or retrieve
// NewDumpTracker simply returns an empty Tracker,
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the meaning of Dump? Syncer can run without dump unit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will rename 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.

@@ -1696,7 +1698,13 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
}
}

s.schemaTracker, err = schema.NewTracker(ctx, s.cfg.Name, s.cfg.To.Session, s.downstreamTrackConn, s.tctx.L())
if s.schemaTracker == nil {
s.schemaTracker, err = schema.NewTracker(ctx, s.cfg.Name, s.cfg.To.Session, s.downstreamTrackConn, s.tctx.L())
Copy link
Contributor

Choose a reason for hiding this comment

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

this is only to make test happy? we can left a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. some tests set the schemaTracker themselves. Will leave a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@buchuitoudegou
Copy link
Contributor Author

/cc @D3Hunter

@ti-chi-bot ti-chi-bot requested a review from D3Hunter June 27, 2022 10:32
ctx context.Context,
task string,
sessionCfg map[string]string,
downstreamConn *dbconn.DBConn,
logger log.Logger,
) (*Tracker, error) {
) error {
if tr == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

when will tr be nil?

if it's for test, we can change test instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line is copied from the old version. I remember it will let the load_task IT fail if deleted (probably this test case tries to pause-task before initializing the syncer). will take a look tomorrow.

dsTracker: dsTracker,
}, nil
// NewTracker creates a new tracker. It's preserved for test.
func NewTracker(
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer to name NewDumpTracker as NewTracker, and remove this one.

for test, we change them to Init

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe leaving a function invoking NewTracker and subsequently Init is better, so as to make the test more succinct.

Copy link
Contributor

Choose a reason for hiding this comment

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

then name it explicitly as something like NewTrackerForTest. NewTracker is how we name normal ctor

Copy link
Contributor

Choose a reason for hiding this comment

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

IDE should be able to easily rename them all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@buchuitoudegou
Copy link
Contributor Author

/run-dm-integration-test

@codecov-commenter
Copy link

Codecov Report

Merging #6052 (8dceb81) into master (b1ce2c9) will decrease coverage by 3.1611%.
The diff coverage is 44.0251%.

Flag Coverage Δ
cdc ?
dm 51.9370% <43.8461%> (-0.0359%) ⬇️
engine 62.2086% <44.0922%> (-0.2319%) ⬇️

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

@@               Coverage Diff                @@
##             master      #6052        +/-   ##
================================================
- Coverage   57.2815%   54.1204%   -3.1612%     
================================================
  Files           680        399       -281     
  Lines         80230      50055     -30175     
================================================
- Hits          45957      27090     -18867     
+ Misses        30009      20302      -9707     
+ Partials       4264       2663      -1601     

Comment on lines +253 to +254
tr.Lock()
defer tr.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

now this lock is used in 3 places, please refine comments in Tracker definition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@buchuitoudegou
Copy link
Contributor Author

/run-verify
/run-leak-test
/run-dm-integration-test

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 29, 2022
@ti-chi-bot ti-chi-bot removed the status/LGT1 Indicates that a PR has LGTM 1. label Jun 29, 2022
@ti-chi-bot ti-chi-bot added the status/LGT2 Indicates that a PR has LGTM 2. label Jun 29, 2022
@lance6716
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 77cfbca

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

/run-dm-integration-test

@buchuitoudegou
Copy link
Contributor Author

/run-dm-integration-test

@buchuitoudegou
Copy link
Contributor Author

/run-dm-integration-test

@ti-chi-bot ti-chi-bot merged commit 4839e39 into pingcap:master Jun 30, 2022
asddongmen pushed a commit that referenced this pull request Jul 1, 2022
)

* syncer(dm): init schemaTracker when syncer run (#6052)

close #6014

* cdc: upgrade pebble and stabilize a case (#6116)

close #5798

* meta(engine): Resourcemeta support job level isolation (#5817)

close #5816

* owner(cdc): clean up admin jobs on async close (#6129)

close #6128

* pkg/errctx(engine): avoid creating goroutinue in errctx (#6061)

ref #6013

* cdc,pkg: accommodate systemd TimeoutStopSec and k8s terminationGracePeriodSeconds (#6097)

* cdc,pkg: accommodate systemd TimeoutStopSec and k8s terminationGracePeriodSeconds
* cdc: correct drain capture doc

Signed-off-by: Neil Shen <[email protected]>

* cdc: drain waits for owner resign and table move out

Signed-off-by: Neil Shen <[email protected]>

* tp(cdc): make drain capture scheduler aware of capture state

Signed-off-by: Neil Shen <[email protected]>

* cdc: remove verbose log and set liveness stop after resign owner

Signed-off-by: Neil Shen <[email protected]>

* cdc: skip owner resign when there is only one capture

Signed-off-by: Neil Shen <[email protected]>

* fix ut

* apply comments

* fix integration test

* fix lint

Co-authored-by: Obliviate <[email protected]>
Co-authored-by: qupeng <[email protected]>
Co-authored-by: maxshuang <[email protected]>
Co-authored-by: Neil Shen <[email protected]>
Co-authored-by: Yujie Xia <[email protected]>
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/L Denotes a PR that changes 100-499 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.

separate schemaTracker's construction and initialization
5 participants