Skip to content

Commit 659c7ce

Browse files
author
Guillaume Lefranc
committed
Fix NPE and add debugging
1 parent 4a9ddb9 commit 659c7ce

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

mariadb-repmgr/repmgr.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ func main() {
146146
servers[k].refresh()
147147
if servers[k].UsingGtid != "" {
148148
if *verbose {
149-
log.Printf("INFO : Server %s is configured as a slave", servers[k].URL)
149+
log.Printf("DEBUG: Server %s is configured as a slave", servers[k].URL)
150150
}
151151
servers[k].State = STATE_SLAVE
152152
slaves = append(slaves, servers[k])
153153
slaveCount++
154154
} else {
155155
if *verbose {
156-
log.Printf("INFO : Server %s is not a slave. Setting aside", servers[k].URL)
156+
log.Printf("DEBUG: Server %s is not a slave. Setting aside", servers[k].URL)
157157
}
158158
}
159159
}
@@ -167,14 +167,17 @@ func main() {
167167

168168
// Depending if we are doing a failover or a switchover, we will find the master in the list of
169169
// dead hosts or unconnected hosts.
170-
if *switchover != "" {
170+
if *switchover != "" || *failover == "monitor" {
171171
// First of all, get a server id from the slaves slice, they should be all the same
172172
sid := slaves[0].MasterServerId
173173
for k, s := range servers {
174174
if s.State == STATE_UNCONN {
175175
if s.ServerId == sid {
176176
master = servers[k]
177177
master.State = STATE_MASTER
178+
if *verbose {
179+
log.Printf("DEBUG: Server %s was autodetected as a master", s.URL)
180+
}
178181
break
179182
}
180183
}
@@ -187,13 +190,16 @@ func main() {
187190
if s.Host == smh || s.IP == smh {
188191
master = servers[k]
189192
master.State = STATE_MASTER
193+
if *verbose {
194+
log.Printf("DEBUG: Server %s was autodetected as a master", s.URL)
195+
}
190196
break
191197
}
192198
}
193199
}
194200
}
195201
// Final check if master has been found
196-
if master.State == "" {
202+
if master == nil {
197203
log.Fatalln("ERROR: Could not autodetect a master!")
198204
}
199205

0 commit comments

Comments
 (0)