Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

dm-worker: refine conn #266

Merged
merged 61 commits into from
Oct 18, 2019
Merged

dm-worker: refine conn #266

merged 61 commits into from
Oct 18, 2019

Conversation

3pointer
Copy link
Contributor

@3pointer 3pointer commented Sep 2, 2019

What problem does this PR solve?

Optimize Database connections in dm-worker units, after unify DB operations

What is changed and how it works?

  1. one worker use one individual connection
  2. same functional connection comes from one DB object
  3. define some package for DB object and connections, all DB object generate in conn.DBProvider.Apply
  4. split upstream DB connection and downstream(worker) DB connection, because they have totally different DB operations, it's better use *sql.DB in upstream, and use individual connection for each worker in downstream.
  5. define two basic object, BaseDB and BaseConn,
    BaseDB generates BaseConn, BaseConn wraps sql.Conn with own retry policy
    BaseDB -> BaseConn correspond to sql.DB -> sql.Conn
    In our scenario, there are two main reasons why we need BaseConn
    1. we often need one fixed DB connection to execute sql
    2. we need own retry policy during execute failed
      So we split a fixed sql.Conn out of sql.DB, and wraps it to BaseConn
      And Similar with sql.Conn, all BaseConn generated from one BaseDB shares this BaseDB to reset

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has interface methods change
  • Has persistent data change

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation
  • Need to update the dm/dm-ansible
  • Need to be included in the release note

@3pointer 3pointer added priority/normal Minor change, requires approval from ≥1 primary reviewer status/PTAL This PR is ready for review. Add this label back after committing new changes type/enhancement Performance improvement or refactoring labels Sep 2, 2019
@codecov
Copy link

codecov bot commented Sep 2, 2019

Codecov Report

Merging #266 into master will decrease coverage by 0.1888%.
The diff coverage is 21.8487%.

@@              Coverage Diff               @@
##             master     #266        +/-   ##
==============================================
- Coverage   60.1288%   59.94%   -0.1889%     
==============================================
  Files           136      135         -1     
  Lines         16448    15010      -1438     
==============================================
- Hits           9890     8997       -893     
+ Misses         5625     5141       -484     
+ Partials        933      872        -61

@csuzhangxc
Copy link
Member

@amyangfei @WangXiangUSTC PTAL

syncer/checkpoint.go Outdated Show resolved Hide resolved
dm/config/subtask.go Outdated Show resolved Hide resolved
loader/checkpoint.go Outdated Show resolved Hide resolved
loader/db.go Outdated Show resolved Hide resolved
loader/db.go Outdated Show resolved Hide resolved
loader/db.go Outdated Show resolved Hide resolved
loader/loader.go Outdated Show resolved Hide resolved
@3pointer 3pointer force-pushed the refine_conn branch 2 times, most recently from d31cf58 to 22d5987 Compare September 4, 2019 12:51
loader/db.go Outdated Show resolved Hide resolved
pkg/conn/basedb.go Outdated Show resolved Hide resolved
pkg/conn/basedb.go Outdated Show resolved Hide resolved
syncer/db.go Outdated Show resolved Hide resolved
syncer/syncer.go Outdated Show resolved Hide resolved
@WangXiangUSTC
Copy link
Contributor

loader has struct Conn, syncer has struct WorkerConn, and they both have function createConn, can we unify them as a pkg?

@3pointer
Copy link
Contributor Author

3pointer commented Sep 9, 2019

loader has struct Conn, syncer has struct WorkerConn, and they both have function createConn, can we unify them as a pkg?

loader and syncer although have similar conn struct, but they also have different log content and stats content, so they are not same struct, if we unify their createConn into one pkg, we should return either same struct or same interface, then how to deal with different log and stats?

@3pointer 3pointer added the needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated label Sep 9, 2019
split workerConn and upstreamConn in syncer
split conn and db
unify conn in syncer and loader
@3pointer 3pointer added needs-cherry-pick-release-1.0 This PR should be cherry-picked to release-1.0. Remove this label after cherry-picked to release-1.0 and removed needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated labels Sep 16, 2019
syncer/syncer.go Outdated
@@ -920,11 +916,6 @@ func (s *Syncer) sync(ctx *tcontext.Context, queueBucket string, db *Conn, jobCh
idx++

if sqlJob.tp == ddl {
err = executeSQLs()
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 block of code is useless, so I removed it, @amyangfei please check it

loader/checkpoint.go Outdated Show resolved Hide resolved
loader/checkpoint.go Outdated Show resolved Hide resolved
loader/checkpoint.go Outdated Show resolved Hide resolved
loader/loader.go Outdated Show resolved Hide resolved
syncer/db.go Outdated Show resolved Hide resolved
syncer/db.go Outdated Show resolved Hide resolved
syncer/db.go Outdated Show resolved Hide resolved
@csuzhangxc csuzhangxc added the status/LGT1 One reviewer already commented LGTM label Oct 16, 2019
@csuzhangxc
Copy link
Member

@WangXiangUSTC @amyangfei PTAL

@csuzhangxc csuzhangxc added the priority/release-blocker This PR blocks a release. Please review it ASAP. label Oct 16, 2019
@amyangfei
Copy link
Contributor

please resolve the conflicts

@3pointer
Copy link
Contributor Author

/run-all-tests

syncer/syncer.go Outdated Show resolved Hide resolved
loader/loader.go Outdated Show resolved Hide resolved
pkg/conn/baseconn.go Outdated Show resolved Hide resolved
Copy link
Contributor

@amyangfei amyangfei left a comment

Choose a reason for hiding this comment

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

LGTM

@amyangfei amyangfei added status/LGT2 Two reviewers already commented LGTM, ready for merge and removed status/LGT1 One reviewer already commented LGTM labels Oct 18, 2019
@3pointer 3pointer merged commit 26b90b3 into pingcap:master Oct 18, 2019
@csuzhangxc csuzhangxc added status/LGT3 Three reviewers already commented LGTM, ready for merge and removed status/LGT2 Two reviewers already commented LGTM, ready for merge labels Oct 18, 2019
@3pointer 3pointer deleted the refine_conn branch October 18, 2019 07:31
@sre-bot
Copy link

sre-bot commented Oct 18, 2019

cherry pick to release-1.0 failed

3pointer added a commit to 3pointer/dm that referenced this pull request Oct 18, 2019
* define conn
split workerConn and upstreamConn in syncer
split conn and db
unify conn in syncer and loader
* change upstream DB to BaseDB
* update raw db config
IANTHEREAL pushed a commit that referenced this pull request Oct 19, 2019
@csuzhangxc csuzhangxc added already-cherry-pick-1.0 The related PR is already cherry-picked to release-1.0. Add this label once the PR is cherry-picked and removed needs-cherry-pick-release-1.0 This PR should be cherry-picked to release-1.0. Remove this label after cherry-picked to release-1.0 labels Mar 13, 2020
lichunzhu pushed a commit to lichunzhu/dm that referenced this pull request Apr 6, 2020
* define conn
split workerConn and upstreamConn in syncer
split conn and db
unify conn in syncer and loader
* change upstream DB to BaseDB
* update raw db config
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
already-cherry-pick-1.0 The related PR is already cherry-picked to release-1.0. Add this label once the PR is cherry-picked priority/normal Minor change, requires approval from ≥1 primary reviewer priority/release-blocker This PR blocks a release. Please review it ASAP. status/LGT3 Three reviewers already commented LGTM, ready for merge type/enhancement Performance improvement or refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants