This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Changed the parsing logic of the seqno field in the Galera state file - Added a struct to serialize/deserialize the GTID tied to the sequence number - Updated the unit tests
- Loading branch information
Matthieu`
committed
Nov 8, 2023
1 parent
be7d5cc
commit 3997fea
Showing
8 changed files
with
241 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package galera | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// GTID represents a MariaDB global transaction identifier. | ||
// See: https://mariadb.com/kb/en/gtid/ | ||
type GTID struct { | ||
DomainID uint32 `json:"domainId"` | ||
ServerID uint32 `json:"serverId"` | ||
SequenceNumber uint64 `json:"sequenceNumber"` | ||
} | ||
|
||
func (gtid *GTID) String() string { | ||
return fmt.Sprintf("%d-%d-%d", gtid.DomainID, gtid.ServerID, gtid.SequenceNumber) | ||
} | ||
|
||
func (gtid *GTID) MarshalText() ([]byte, error) { | ||
return []byte(gtid.String()), nil | ||
} | ||
|
||
func (gtid *GTID) UnmarshalText(text []byte) error { | ||
parts := strings.Split(string(text), "-") | ||
if len(parts) != 3 { | ||
return fmt.Errorf("invalid gtid: %s", text) | ||
} | ||
domainID, err := strconv.ParseUint(parts[0], 10, 32) | ||
if err != nil { | ||
return fmt.Errorf("invalid domain id: %v", err) | ||
} | ||
serverID, err := strconv.ParseUint(parts[1], 10, 32) | ||
if err != nil { | ||
return fmt.Errorf("invalid server id: %v", err) | ||
} | ||
seqno, err := strconv.ParseUint(parts[2], 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("invalid seqno: %v", err) | ||
} | ||
gtid.DomainID = uint32(domainID) | ||
gtid.ServerID = uint32(serverID) | ||
gtid.SequenceNumber = seqno | ||
return nil | ||
} |
Oops, something went wrong.