Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions pkg/galera/galera.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type GaleraState struct {
Version string `json:"version"`
UUID string `json:"uuid"`
Seqno int `json:"seqno"`
GTID *GTID `json:"gtid"`
SafeToBootstrap bool `json:"safeToBootstrap"`
}

Expand Down Expand Up @@ -69,19 +68,17 @@ func (g *GaleraState) MarshalText() ([]byte, error) {
Version string
UUID string
Seqno int
GTID *GTID
SafeToBootstrap int
}
tpl := createTpl("grastate.dat", `version: {{ .Version }}
uuid: {{ .UUID }}
seqno: {{ .Seqno }}{{ if .GTID }},{{ .GTID }}{{ end }}
seqno: {{ .Seqno }}
safe_to_bootstrap: {{ .SafeToBootstrap }}`)
buf := new(bytes.Buffer)
err := tpl.Execute(buf, tplOpts{
Version: g.Version,
UUID: g.UUID,
Seqno: g.Seqno,
GTID: g.GTID,
SafeToBootstrap: func() int {
if g.SafeToBootstrap {
return 1
Expand Down Expand Up @@ -125,15 +122,17 @@ func (g *GaleraState) UnmarshalText(text []byte) error {
uuid = &value
case "seqno":
// When the `wsrep_gtid_mode` is set to `ON`, the `seqno` is
// actually a string of the form `seqno,gtid`.
// actually a string of the form `<seqno>,<gtid>`.
//
// For the moment we only care about the `seqno` part as we're
// still not sure about what to do with the `gtid`.
seqnoStr, gtidStr, found := strings.Cut(value, ",")
if found {
gtid = &GTID{}
err := gtid.UnmarshalText([]byte(gtidStr))
if err != nil {
return fmt.Errorf("error parsing gtid: %v", err)
}

}
i, err := strconv.Atoi(seqnoStr)
if err != nil {
Expand All @@ -158,10 +157,6 @@ func (g *GaleraState) UnmarshalText(text []byte) error {
g.Version = *version
g.UUID = *uuid
g.Seqno = *seqno
// Only set the GTID if it was found in the file.
if gtid != nil {
g.GTID = gtid
}
g.SafeToBootstrap = *safeToBootstrap
return nil
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/galera/galera_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ safe_to_bootstrap: 0`,
Version: "2.1",
UUID: "05f061bd-02a3-11ee-857c-aa370ff6666b",
Seqno: 1,
GTID: &GTID{DomainID: 0, ServerID: 1, SequenceNumber: 2},
SafeToBootstrap: true,
},
want: `version: 2.1
uuid: 05f061bd-02a3-11ee-857c-aa370ff6666b
seqno: 1,0-1-2
seqno: 1
safe_to_bootstrap: 1`,
wantErr: false,
},
Expand Down Expand Up @@ -242,7 +241,6 @@ safe_to_bootstrap: 1`),
Version: "2.1",
UUID: "05f061bd-02a3-11ee-857c-aa370ff6666b",
Seqno: 1,
GTID: &GTID{DomainID: 0, ServerID: 1, SequenceNumber: 2},
SafeToBootstrap: true,
},
},
Expand Down