Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions go/mysql/binlog_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ func (this *FileBinlogCoordinates) SmallerThan(other BinlogCoordinates) bool {
if !ok || other == nil {
return false
}
if this.LogFile < coord.LogFile {
return true
}
if this.LogFile == coord.LogFile && this.LogPos < coord.LogPos {
return true

fileNumberDist := this.FileNumberDistance(coord)
if fileNumberDist == 0 {
return this.LogPos < coord.LogPos
}
return false
return fileNumberDist > 0
}

// SmallerThanOrEquals returns true if this coordinate is the same or equal to the other one.
Expand All @@ -100,15 +99,6 @@ func (this *FileBinlogCoordinates) SmallerThanOrEquals(other BinlogCoordinates)
return this.LogFile == coord.LogFile && this.LogPos == coord.LogPos // No Type comparison
}

// FileSmallerThan returns true if this coordinate's file is strictly smaller than the other's.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Was this not used anymore? Looks like the same comment still exists in a different/wrong place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup, FileSmallerThan as well as FileNumberDistance were both unused. The latter I used here, too bad I didn't catch the comment before the PR got merge, I'll open another one! #quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's more unused stuff there, I'll change the PR base once the build is green. #20

func (this *FileBinlogCoordinates) FileSmallerThan(other BinlogCoordinates) bool {
coord, ok := other.(*FileBinlogCoordinates)
if !ok || other == nil {
return false
}
return this.LogFile < coord.LogFile
}

// FileNumberDistance returns the numeric distance between this coordinate's file number and the other's.
// Effectively it means "how many rotates/FLUSHes would make these coordinates's file reach the other's"
func (this *FileBinlogCoordinates) FileNumberDistance(other *FileBinlogCoordinates) int {
Expand Down
16 changes: 16 additions & 0 deletions go/mysql/binlog_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,19 @@ func TestIsLogPosOverflowBeyond4Bytes(t *testing.T) {
require.True(t, curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates))
}
}

func TestBinlogCoordinates_LogFileZeroPaddedTransition(t *testing.T) {
c1 := FileBinlogCoordinates{LogFile: "mysql-bin.999999", LogPos: 100}
c2 := FileBinlogCoordinates{LogFile: "mysql-bin.1000000", LogPos: 100}

require.True(t, c1.SmallerThan(&c2))
}

func TestBinlogCoordinates_SameLogFileDifferentPosition(t *testing.T) {
c1 := FileBinlogCoordinates{LogFile: "binlog.000001", LogPos: 100}
c2 := FileBinlogCoordinates{LogFile: "binlog.000001", LogPos: 200}

require.True(t, c1.SmallerThan(&c2))
require.False(t, c2.SmallerThan(&c1))
require.False(t, c1.SmallerThan(&c1))
}
Loading