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

Combine syncer localReader into one interface #215

Merged
merged 6 commits into from
Jul 29, 2019

Conversation

3pointer
Copy link
Contributor

What problem does this PR solve?

Combine two Syncer members (Syncer.syncer and Syncer.localReader) into one variable (streamerProducer), base on two reasons:

  1. Obviously Syncer.syncer and Syncer.localReader has same ability to generate stream which can generate events, And Syncer only need one not two at any time
  2. And after put them in one interface, it's easy for any implementations who implement StreamerProducer and Stream interfaces to take place of Syncer.streamerProducer, such as a mock test

What is changed and how it works?

Combine two Syncer members into one streamerProducer

Check List

Tests

  • Unit test
  • Integration test

@@ -383,12 +383,11 @@ func (r *BinlogReader) updateUUIDs() error {
}

// Close closes BinlogReader.
func (r *BinlogReader) Close() error {
func (r *BinlogReader) Close() {
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 implementation aligned with *BinlogSyncer Close() in go-mysql

@3pointer 3pointer changed the title extract syncer localReader to one interface Combine syncer localReader into one interface Jul 25, 2019
@3pointer 3pointer added type/feature-request This issue is a feature request 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/feature New feature labels Jul 25, 2019
@codecov
Copy link

codecov bot commented Jul 25, 2019

Codecov Report

Merging #215 into master will decrease coverage by 0.5883%.
The diff coverage is 53.125%.

@@               Coverage Diff                @@
##             master       #215        +/-   ##
================================================
- Coverage   59.4612%   58.8729%   -0.5884%     
================================================
  Files           123        123                
  Lines         14887      14054       -833     
================================================
- Hits           8852       8274       -578     
+ Misses         5150       4953       -197     
+ Partials        885        827        -58

syncer/syncer.go Outdated
if s.localReader != nil {
s.localReader.Close()
if s.streamerProducer != nil {
rr, ok := s.streamerProducer.(*remoteBinlogReader)
Copy link
Contributor

Choose a reason for hiding this comment

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

switch r := s.streamerProducer.(type) {
case *remoteBinlogReader:
    // process remote binlog reader
case *localBinlogReader:
    // process local binlog reader
}

use type-switch is more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

} else if s.binlogType == LocalBinlog {
s.streamer, err = s.getBinlogStreamer(s.localReader, pos)
}
s.streamer, err = s.streamerProducer.generateStreamer(pos)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove getBinlogStreamer, getLocalBinlogStreamer and getRemoteBinlogStreamer after we extract the interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

syncer/syncer.go Outdated
@@ -79,6 +79,46 @@ const (
LocalBinlog
)

// StreamerProducer provide the ability to generate binlog streamer by StartSync()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// StreamerProducer provide the ability to generate binlog streamer by StartSync()
// StreamerProducer provides the ability to generate binlog streamer by StartSync()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

syncer/syncer.go Outdated
@@ -79,6 +79,46 @@ const (
LocalBinlog
)

// StreamerProducer provide the ability to generate binlog streamer by StartSync()
// but go-mysql StartSync() return (struct, err) rather than (interface, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// but go-mysql StartSync() return (struct, err) rather than (interface, err)
// but go-mysql StartSync() returns (struct, err) rather than (interface, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

syncer/syncer.go Outdated
}()
if r.EnableGTID {
// NOTE: our (per-table based) checkpoint does not support GTID yet
return nil, errors.New("[syncer] now support GTID mode yet")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.New("[syncer] now support GTID mode yet")
return nil, errors.New("[syncer] not support GTID mode yet")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -589,7 +589,6 @@ func (t *testReaderSuite) TestStartSync(c *C) {
// NOTE: load new UUIDs dynamically not supported yet

// close the reader
err = r.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Although Close doesn't return error anymore, we'd better reserve it to form a complete usage flow.

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, I forgot to use it, it's been fixed already in the latest commit

@@ -589,8 +589,8 @@ func (t *testReaderSuite) TestStartSync(c *C) {
// NOTE: load new UUIDs dynamically not supported yet

// close the reader
err = r.Close()
c.Assert(err, IsNil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove 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.

already added back

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/LGT1 One reviewer already commented LGTM and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Jul 29, 2019
if s.syncer != nil {
err := s.closeBinlogSyncer(s.syncer)
s.syncer = nil
if s.streamerProducer != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we check whether it's remote binlog reader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only remote binlog reader call this function currently, but adding a check is better

@IANTHEREAL
Copy link
Collaborator

Rest LGTM

syncer/syncer.go Outdated
return nil, errors.Trace(err)
}
case *localBinlogReader:
return nil, errors.New("[syncer] not support local relay reader reopen currently")
Copy link
Collaborator

@IANTHEREAL IANTHEREAL Jul 29, 2019

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.New("[syncer] not support local relay reader reopen currently")
return nil, errors.New("don't support reopen %T currently", r)

syncer/syncer.go Outdated
}()
if r.EnableGTID {
// NOTE: our (per-table based) checkpoint does not support GTID yet
return nil, errors.New("[syncer] not support GTID mode yet")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.New("[syncer] not support GTID mode yet")
return nil, errors.New("don't support open streamer with GTID mode")

syncer/syncer.go Outdated
if err != nil {
return nil, errors.Trace(err)
if s.streamerProducer != nil {
switch s.streamerProducer.(type) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
switch s.streamerProducer.(type) {
switch r := s.streamerProducer.(type) {

syncer/syncer.go Outdated
if s.streamerProducer != nil {
switch s.streamerProducer.(type) {
case *remoteBinlogReader:
err := s.closeBinlogSyncer(s.streamerProducer.(*remoteBinlogReader).reader)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
err := s.closeBinlogSyncer(s.streamerProducer.(*remoteBinlogReader).reader)
err := s.closeBinlogSyncer(r.reader)

syncer/syncer.go Outdated
if err != nil {
return nil, errors.Trace(err)
}
case *localBinlogReader:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
case *localBinlogReader:
default:

@IANTHEREAL
Copy link
Collaborator

/run-all-tests

1 similar comment
@3pointer
Copy link
Contributor Author

/run-all-tests

Copy link
Collaborator

@IANTHEREAL IANTHEREAL left a comment

Choose a reason for hiding this comment

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

Good Job! LGTM

@IANTHEREAL IANTHEREAL added status/LGT2 Two reviewers already commented LGTM, ready for merge and removed status/LGT1 One reviewer already commented LGTM labels Jul 29, 2019
@3pointer 3pointer merged commit 4abf188 into pingcap:master Jul 29, 2019
lichunzhu pushed a commit to lichunzhu/dm that referenced this pull request Apr 6, 2020
* extract syncer localReader to one interface

* use generateStreamer wrap function

* update some implementations and remove useless code

* remove useless err check

* update check syncer reopen

* update error message
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority/normal Minor change, requires approval from ≥1 primary reviewer status/LGT2 Two reviewers already commented LGTM, ready for merge type/feature New feature type/feature-request This issue is a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants