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

streamer: refactor and add test cases #140

Merged
merged 58 commits into from
Jun 10, 2019

Conversation

csuzhangxc
Copy link
Member

@csuzhangxc csuzhangxc commented May 8, 2019

What problem does this PR solve?

  • tiny refactor to make relay reader (streamer) clearer
  • improve test coverage for pkg/streamer, 31.4% --> 92.9%
  • ignore io.EOF returned from BinlogParser.ParseFile

What is changed and how it works?

  • refactor some code
  • add test cases for streamer pkg

Check List

Tests

  • Unit test
  • Integration test

@csuzhangxc csuzhangxc added priority/normal Minor change, requires approval from ≥1 primary reviewer status/WIP This PR is still work in progress type/enhancement Performance improvement or refactoring type/qa relate to quality assurance labels May 8, 2019
pkg/streamer/reader_test.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #140 into master will increase coverage by 2.4499%.
The diff coverage is 89.2857%.

@@               Coverage Diff                @@
##             master       #140        +/-   ##
================================================
+ Coverage   50.8692%   53.3191%   +2.4499%     
================================================
  Files           121        121                
  Lines         13633      13648        +15     
================================================
+ Hits           6935       7277       +342     
+ Misses         5977       5644       -333     
- Partials        721        727         +6

@csuzhangxc
Copy link
Member Author

/run-all-tests

@csuzhangxc
Copy link
Member Author

/run-all-tests

@amyangfei
Copy link
Contributor

/run-all-tests

pkg/streamer/file.go Show resolved Hide resolved
pkg/streamer/file.go Show resolved Hide resolved
pkg/streamer/file.go Show resolved Hide resolved
pkg/streamer/hub_test.go Show resolved Hide resolved
pkg/binlog/filename.go Outdated Show resolved Hide resolved
pkg/streamer/reader_test.go Outdated Show resolved Hide resolved
pkg/streamer/reader_test.go Outdated Show resolved Hide resolved
pkg/streamer/reader_test.go Outdated Show resolved Hide resolved
pkg/streamer/reader_test.go Outdated Show resolved Hide resolved
@csuzhangxc
Copy link
Member Author

/run-all-tests

@csuzhangxc
Copy link
Member Author

/run-all-tests

1 similar comment
@csuzhangxc
Copy link
Member Author

/run-all-tests

// Filename represents a binlog filename.
type Filename struct {
BaseName string
Seq string
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not float64?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we want to keep the number format like 000001,
we can add one more float64 or int filed to keep the number value, something like space-time tradeoff?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added another int64 field in d7f60d5

@amyangfei
Copy link
Contributor

/run-all-tests

}

// GetFilenameIndex returns a float64 index value (seq number) of the filename.
func GetFilenameIndex(filename string) (float64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why float64, not int64?

Copy link
Member Author

Choose a reason for hiding this comment

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

changed to int64 in d7f60d5.

Copy link
Contributor

@WangXiangUSTC WangXiangUSTC left a comment

Choose a reason for hiding this comment

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

rest LGTM


// VerifyFilename verifies whether is a valid MySQL/MariaDB binlog filename.
// valid format is `base + '.' + seq`.
func VerifyFilename(filename string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems this function return bool type is better

Copy link
Member Author

Choose a reason for hiding this comment

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

done in d7f60d5.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in d7f60d5.

c.Assert(errors.Cause(err), Equals, ErrReaderRunning)
c.Assert(s, IsNil)

c.Assert(ev, IsNil)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about move this line after L626?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 done in d7f60d5.

@csuzhangxc
Copy link
Member Author

@amyangfei @WangXiangUSTC PTAL again

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 Jun 10, 2019
@WangXiangUSTC
Copy link
Contributor

LGTM

@WangXiangUSTC WangXiangUSTC added status/LGT2 Two reviewers already commented LGTM, ready for merge and removed status/LGT1 One reviewer already commented LGTM labels Jun 10, 2019
@csuzhangxc csuzhangxc merged commit 7d427b9 into pingcap:master Jun 10, 2019
@csuzhangxc csuzhangxc deleted the relay-reader branch June 10, 2019 09:51
lichunzhu pushed a commit to lichunzhu/dm that referenced this pull request Apr 6, 2020
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/enhancement Performance improvement or refactoring type/qa relate to quality assurance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants