forked from signal18/replication-manager
/
crash.go
80 lines (70 loc) · 1.95 KB
/
crash.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
69
70
71
72
73
74
75
76
77
78
79
80
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
// Copyright 2017 Signal 18 SARL
// Authors: Guillaume Lefranc <guillaume@signal18.io>
// Stephane Varoqui <svaroqui@gmail.com>
// This source code is licensed under the GNU General Public License, version 3.
// Redistribution/Reuse of this code is permitted under the GNU v3 license, as
// an additional term, ALL code must carry the original Author(s) credit in comment form.
// See LICENSE in this directory for the integral text.
package cluster
import (
"encoding/json"
"io/ioutil"
"github.com/signal18/replication-manager/gtid"
)
// Crash will store informations on a crash based on the replication stream
type Crash struct {
URL string
FailoverMasterLogFile string
FailoverMasterLogPos string
NewMasterLogFile string
NewMasterLogPos string
FailoverSemiSyncSlaveStatus bool
FailoverIOGtid *gtid.List
ElectedMasterURL string
}
type crashList []*Crash
func (cluster *Cluster) newCrash(*Crash) (*Crash, error) {
crash := new(Crash)
return crash, nil
}
func (cluster *Cluster) getCrashFromJoiner(URL string) *Crash {
for _, cr := range cluster.crashes {
if cr.URL == URL {
return cr
}
}
return nil
}
func (cluster *Cluster) getCrashFromMaster(URL string) *Crash {
for _, cr := range cluster.crashes {
if cr.ElectedMasterURL == URL {
return cr
}
}
return nil
}
// GetCrashes return crashes
func (cluster *Cluster) GetCrashes() crashList {
return cluster.crashes
}
func (crash *Crash) delete(cl *crashList) {
lsm := *cl
for k, s := range lsm {
if crash.URL == s.URL {
lsm[k] = lsm[len(lsm)-1]
lsm[len(lsm)-1] = nil
lsm = lsm[:len(lsm)-1]
break
}
}
*cl = lsm
}
func (crash *Crash) Save(path string) error {
saveJson, _ := json.MarshalIndent(crash, "", "\t")
err := ioutil.WriteFile(path, saveJson, 0644)
if err != nil {
return err
}
return nil
}