gh-ost/vendor/github.com/siddontang/go-mysql/canal/master.go

67 lines
967 B
Go
Raw Normal View History

2017-02-12 11:13:54 +00:00
package canal
import (
"sync"
"github.com/siddontang/go-log/log"
2017-02-12 11:13:54 +00:00
"github.com/siddontang/go-mysql/mysql"
)
type masterInfo struct {
sync.RWMutex
2017-02-12 11:13:54 +00:00
pos mysql.Position
2017-02-12 11:13:54 +00:00
gset mysql.GTIDSet
2017-02-12 11:13:54 +00:00
timestamp uint32
2017-02-12 11:13:54 +00:00
}
func (m *masterInfo) Update(pos mysql.Position) {
log.Debugf("update master position %s", pos)
2017-02-12 11:13:54 +00:00
m.Lock()
m.pos = pos
m.Unlock()
2017-02-12 11:13:54 +00:00
}
func (m *masterInfo) UpdateTimestamp(ts uint32) {
log.Debugf("update master timestamp %s", ts)
2017-02-12 11:13:54 +00:00
m.Lock()
m.timestamp = ts
m.Unlock()
}
2017-02-12 11:13:54 +00:00
func (m *masterInfo) UpdateGTIDSet(gset mysql.GTIDSet) {
log.Debugf("update master gtid set %s", gset)
2017-02-12 11:13:54 +00:00
m.Lock()
m.gset = gset
m.Unlock()
2017-02-12 11:13:54 +00:00
}
func (m *masterInfo) Position() mysql.Position {
m.RLock()
defer m.RUnlock()
return m.pos
2017-02-12 11:13:54 +00:00
}
func (m *masterInfo) Timestamp() uint32 {
m.RLock()
defer m.RUnlock()
2017-02-12 11:13:54 +00:00
return m.timestamp
2017-02-12 11:13:54 +00:00
}
func (m *masterInfo) GTIDSet() mysql.GTIDSet {
m.RLock()
defer m.RUnlock()
if m.gset == nil {
return nil
}
return m.gset.Clone()
2017-02-12 11:13:54 +00:00
}