forked from go-mysql-org/go-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.go
68 lines (49 loc) · 1013 Bytes
/
master.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package canal
import (
"sync"
"github.com/dumbmachine/go-mysql/mysql"
"github.com/siddontang/go-log/loggers"
)
type masterInfo struct {
sync.RWMutex
pos mysql.Position
gset mysql.GTIDSet
timestamp uint32
logger loggers.Advanced
}
func (m *masterInfo) Update(pos mysql.Position) {
m.logger.Debugf("update master position %s", pos)
m.Lock()
m.pos = pos
m.Unlock()
}
func (m *masterInfo) UpdateTimestamp(ts uint32) {
m.logger.Debugf("update master timestamp %d", ts)
m.Lock()
m.timestamp = ts
m.Unlock()
}
func (m *masterInfo) UpdateGTIDSet(gset mysql.GTIDSet) {
m.logger.Debugf("update master gtid set %s", gset)
m.Lock()
m.gset = gset
m.Unlock()
}
func (m *masterInfo) Position() mysql.Position {
m.RLock()
defer m.RUnlock()
return m.pos
}
func (m *masterInfo) Timestamp() uint32 {
m.RLock()
defer m.RUnlock()
return m.timestamp
}
func (m *masterInfo) GTIDSet() mysql.GTIDSet {
m.RLock()
defer m.RUnlock()
if m.gset == nil {
return nil
}
return m.gset.Clone()
}