2016-03-24 14:11:56 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 GitHub Inc.
|
2016-05-16 09:09:17 +00:00
|
|
|
See https://github.com/github/gh-ost/blob/master/LICENSE
|
2016-03-24 14:11:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package binlog
|
|
|
|
|
2016-04-06 16:44:54 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2016-05-16 09:09:17 +00:00
|
|
|
"github.com/github/gh-ost/go/mysql"
|
2016-04-06 16:44:54 +00:00
|
|
|
)
|
|
|
|
|
2016-03-24 21:27:39 +00:00
|
|
|
// BinlogEntry describes an entry in the binary log
|
2016-03-24 14:11:56 +00:00
|
|
|
type BinlogEntry struct {
|
2016-04-06 16:44:54 +00:00
|
|
|
Coordinates mysql.BinlogCoordinates
|
|
|
|
EndLogPos uint64
|
|
|
|
|
2016-04-07 13:57:12 +00:00
|
|
|
DmlEvent *BinlogDMLEvent
|
2016-03-24 21:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewBinlogEntry creates an empty, ready to go BinlogEntry object
|
2016-04-06 16:44:54 +00:00
|
|
|
func NewBinlogEntry(logFile string, logPos uint64) *BinlogEntry {
|
|
|
|
binlogEntry := &BinlogEntry{
|
|
|
|
Coordinates: mysql.BinlogCoordinates{LogFile: logFile, LogPos: int64(logPos)},
|
|
|
|
}
|
|
|
|
return binlogEntry
|
|
|
|
}
|
|
|
|
|
2018-04-27 06:58:07 +00:00
|
|
|
// NewBinlogEntryAt creates an empty, ready to go BinlogEntry object
|
2016-04-06 16:44:54 +00:00
|
|
|
func NewBinlogEntryAt(coordinates mysql.BinlogCoordinates) *BinlogEntry {
|
|
|
|
binlogEntry := &BinlogEntry{
|
|
|
|
Coordinates: coordinates,
|
|
|
|
}
|
2016-03-24 21:27:39 +00:00
|
|
|
return binlogEntry
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duplicate creates and returns a new binlog entry, with some of the attributes pre-assigned
|
|
|
|
func (this *BinlogEntry) Duplicate() *BinlogEntry {
|
2016-04-06 16:44:54 +00:00
|
|
|
binlogEntry := NewBinlogEntry(this.Coordinates.LogFile, uint64(this.Coordinates.LogPos))
|
2016-03-24 21:27:39 +00:00
|
|
|
binlogEntry.EndLogPos = this.EndLogPos
|
|
|
|
return binlogEntry
|
2016-03-24 14:11:56 +00:00
|
|
|
}
|
2016-04-06 16:44:54 +00:00
|
|
|
|
2018-04-27 06:58:07 +00:00
|
|
|
// String() returns a string representation of this binlog entry
|
2016-04-06 16:44:54 +00:00
|
|
|
func (this *BinlogEntry) String() string {
|
2016-04-07 13:57:12 +00:00
|
|
|
return fmt.Sprintf("[BinlogEntry at %+v; dml:%+v]", this.Coordinates, this.DmlEvent)
|
2016-04-06 16:44:54 +00:00
|
|
|
}
|