зеркало из https://github.com/github/vitess-gh.git
Export GTID fields so MysqlFlavor can access the internals.
This commit is contained in:
Родитель
0fcd9fcb3d
Коммит
ecc55cd992
|
@ -18,35 +18,35 @@ func parseGoogleGTID(s string) (GTID, error) {
|
|||
return nil, fmt.Errorf("invalid Google MySQL group_id (%v): %v", s, err)
|
||||
}
|
||||
|
||||
return googleGTID{groupID: id}, nil
|
||||
return GoogleGTID{GroupID: id}, nil
|
||||
}
|
||||
|
||||
type googleGTID struct {
|
||||
groupID uint64
|
||||
type GoogleGTID struct {
|
||||
GroupID uint64
|
||||
}
|
||||
|
||||
// String implements GTID.String().
|
||||
func (gtid googleGTID) String() string {
|
||||
return fmt.Sprintf("%d", gtid.groupID)
|
||||
func (gtid GoogleGTID) String() string {
|
||||
return fmt.Sprintf("%d", gtid.GroupID)
|
||||
}
|
||||
|
||||
// Flavor implements GTID.Flavor().
|
||||
func (gtid googleGTID) Flavor() string {
|
||||
func (gtid GoogleGTID) Flavor() string {
|
||||
return googleMysqlFlavorID
|
||||
}
|
||||
|
||||
// TryCompare implements GTID.TryCompare().
|
||||
func (gtid googleGTID) TryCompare(cmp GTID) (int, error) {
|
||||
other, ok := cmp.(googleGTID)
|
||||
func (gtid GoogleGTID) TryCompare(cmp GTID) (int, error) {
|
||||
other, ok := cmp.(GoogleGTID)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("can't compare GTID, wrong type: %#v.TryCompare(%#v)",
|
||||
gtid, cmp)
|
||||
}
|
||||
|
||||
switch true {
|
||||
case gtid.groupID < other.groupID:
|
||||
case gtid.GroupID < other.GroupID:
|
||||
return -1, nil
|
||||
case gtid.groupID > other.groupID:
|
||||
case gtid.GroupID > other.GroupID:
|
||||
return 1, nil
|
||||
default:
|
||||
return 0, nil
|
||||
|
|
|
@ -11,13 +11,13 @@ import (
|
|||
|
||||
func TestParseGoogleGTID(t *testing.T) {
|
||||
input := "1758283"
|
||||
want := googleGTID{groupID: 1758283}
|
||||
want := GoogleGTID{GroupID: 1758283}
|
||||
|
||||
got, err := parseGoogleGTID(input)
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if got.(googleGTID) != want {
|
||||
if got.(GoogleGTID) != want {
|
||||
t.Errorf("ParseGTID(%v) = %v, want %v", input, got, want)
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func TestParseInvalidGoogleGTID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDString(t *testing.T) {
|
||||
input := googleGTID{groupID: 1857273}
|
||||
input := GoogleGTID{GroupID: 1857273}
|
||||
want := "1857273"
|
||||
|
||||
got := input.String()
|
||||
|
@ -46,7 +46,7 @@ func TestGoogleGTIDString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDFlavor(t *testing.T) {
|
||||
input := googleGTID{groupID: 123}
|
||||
input := GoogleGTID{GroupID: 123}
|
||||
want := "GoogleMysql"
|
||||
|
||||
got := input.Flavor()
|
||||
|
@ -56,8 +56,8 @@ func TestGoogleGTIDFlavor(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDCompareLess(t *testing.T) {
|
||||
input1 := googleGTID{groupID: 12345}
|
||||
input2 := googleGTID{groupID: 54321}
|
||||
input1 := GoogleGTID{GroupID: 12345}
|
||||
input2 := GoogleGTID{GroupID: 54321}
|
||||
|
||||
cmp, err := input1.TryCompare(input2)
|
||||
if err != nil {
|
||||
|
@ -69,8 +69,8 @@ func TestGoogleGTIDCompareLess(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDCompareGreater(t *testing.T) {
|
||||
input1 := googleGTID{groupID: 98765}
|
||||
input2 := googleGTID{groupID: 56789}
|
||||
input1 := GoogleGTID{GroupID: 98765}
|
||||
input2 := GoogleGTID{GroupID: 56789}
|
||||
|
||||
cmp, err := input1.TryCompare(input2)
|
||||
if err != nil {
|
||||
|
@ -82,8 +82,8 @@ func TestGoogleGTIDCompareGreater(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDCompareEqual(t *testing.T) {
|
||||
input1 := googleGTID{groupID: 41234}
|
||||
input2 := googleGTID{groupID: 41234}
|
||||
input1 := GoogleGTID{GroupID: 41234}
|
||||
input2 := GoogleGTID{GroupID: 41234}
|
||||
|
||||
cmp, err := input1.TryCompare(input2)
|
||||
if err != nil {
|
||||
|
@ -95,7 +95,7 @@ func TestGoogleGTIDCompareEqual(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDCompareWrongType(t *testing.T) {
|
||||
input1 := googleGTID{groupID: 123}
|
||||
input1 := GoogleGTID{GroupID: 123}
|
||||
input2 := fakeGTID{}
|
||||
want := "can't compare GTID, wrong type"
|
||||
|
||||
|
@ -109,7 +109,7 @@ func TestGoogleGTIDCompareWrongType(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDCompareNil(t *testing.T) {
|
||||
input1 := googleGTID{groupID: 123}
|
||||
input1 := GoogleGTID{GroupID: 123}
|
||||
input2 := GTID(nil)
|
||||
want := "can't compare GTID"
|
||||
|
||||
|
@ -123,8 +123,8 @@ func TestGoogleGTIDCompareNil(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDEqual(t *testing.T) {
|
||||
input1 := GTID(googleGTID{groupID: 41234})
|
||||
input2 := GTID(googleGTID{groupID: 41234})
|
||||
input1 := GTID(GoogleGTID{GroupID: 41234})
|
||||
input2 := GTID(GoogleGTID{GroupID: 41234})
|
||||
want := true
|
||||
|
||||
cmp := input1 == input2
|
||||
|
@ -134,8 +134,8 @@ func TestGoogleGTIDEqual(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoogleGTIDNotEqual(t *testing.T) {
|
||||
input1 := GTID(googleGTID{groupID: 41234})
|
||||
input2 := GTID(googleGTID{groupID: 51234})
|
||||
input1 := GTID(GoogleGTID{GroupID: 41234})
|
||||
input2 := GTID(GoogleGTID{GroupID: 51234})
|
||||
want := false
|
||||
|
||||
cmp := input1 == input2
|
||||
|
|
|
@ -17,69 +17,69 @@ func parseMariadbGTID(s string) (GTID, error) {
|
|||
// Split into parts.
|
||||
parts := strings.Split(s, "-")
|
||||
if len(parts) != 3 {
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID (%v): expecting domain-server-sequence", s)
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID (%v): expecting Domain-Server-Sequence", s)
|
||||
}
|
||||
|
||||
// Parse domain ID.
|
||||
domain, err := strconv.ParseUint(parts[0], 10, 32)
|
||||
// Parse Domain ID.
|
||||
Domain, err := strconv.ParseUint(parts[0], 10, 32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID domain ID (%v): %v", parts[0], err)
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID Domain ID (%v): %v", parts[0], err)
|
||||
}
|
||||
|
||||
// Parse server ID.
|
||||
server, err := strconv.ParseUint(parts[1], 10, 32)
|
||||
// Parse Server ID.
|
||||
Server, err := strconv.ParseUint(parts[1], 10, 32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID server ID (%v): %v", parts[1], err)
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID Server ID (%v): %v", parts[1], err)
|
||||
}
|
||||
|
||||
// Parse sequence number.
|
||||
sequence, err := strconv.ParseUint(parts[2], 10, 64)
|
||||
// Parse Sequence number.
|
||||
Sequence, err := strconv.ParseUint(parts[2], 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID sequence number (%v): %v", parts[2], err)
|
||||
return nil, fmt.Errorf("invalid MariaDB GTID Sequence number (%v): %v", parts[2], err)
|
||||
}
|
||||
|
||||
return mariadbGTID{
|
||||
domain: uint32(domain),
|
||||
server: uint32(server),
|
||||
sequence: sequence,
|
||||
return MariadbGTID{
|
||||
Domain: uint32(Domain),
|
||||
Server: uint32(Server),
|
||||
Sequence: Sequence,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type mariadbGTID struct {
|
||||
domain uint32
|
||||
server uint32
|
||||
sequence uint64
|
||||
type MariadbGTID struct {
|
||||
Domain uint32
|
||||
Server uint32
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
// String implements GTID.String().
|
||||
func (gtid mariadbGTID) String() string {
|
||||
return fmt.Sprintf("%d-%d-%d", gtid.domain, gtid.server, gtid.sequence)
|
||||
func (gtid MariadbGTID) String() string {
|
||||
return fmt.Sprintf("%d-%d-%d", gtid.Domain, gtid.Server, gtid.Sequence)
|
||||
}
|
||||
|
||||
// Flavor implements GTID.Flavor().
|
||||
func (gtid mariadbGTID) Flavor() string {
|
||||
func (gtid MariadbGTID) Flavor() string {
|
||||
return mariadbFlavorID
|
||||
}
|
||||
|
||||
// TryCompare implements GTID.TryCompare().
|
||||
func (gtid mariadbGTID) TryCompare(cmp GTID) (int, error) {
|
||||
other, ok := cmp.(mariadbGTID)
|
||||
func (gtid MariadbGTID) TryCompare(cmp GTID) (int, error) {
|
||||
other, ok := cmp.(MariadbGTID)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("can't compare GTID, wrong type: %#v.TryCompare(%#v)",
|
||||
gtid, cmp)
|
||||
}
|
||||
|
||||
if gtid.domain != other.domain {
|
||||
return 0, fmt.Errorf("can't compare GTID, MariaDB domain doesn't match: %v != %v", gtid.domain, other.domain)
|
||||
if gtid.Domain != other.Domain {
|
||||
return 0, fmt.Errorf("can't compare GTID, MariaDB Domain doesn't match: %v != %v", gtid.Domain, other.Domain)
|
||||
}
|
||||
if gtid.server != other.server {
|
||||
return 0, fmt.Errorf("can't compare GTID, MariaDB server doesn't match: %v != %v", gtid.server, other.server)
|
||||
if gtid.Server != other.Server {
|
||||
return 0, fmt.Errorf("can't compare GTID, MariaDB Server doesn't match: %v != %v", gtid.Server, other.Server)
|
||||
}
|
||||
|
||||
switch true {
|
||||
case gtid.sequence < other.sequence:
|
||||
case gtid.Sequence < other.Sequence:
|
||||
return -1, nil
|
||||
case gtid.sequence > other.sequence:
|
||||
case gtid.Sequence > other.Sequence:
|
||||
return 1, nil
|
||||
default:
|
||||
return 0, nil
|
||||
|
|
|
@ -11,13 +11,13 @@ import (
|
|||
|
||||
func TestParseMariaGTID(t *testing.T) {
|
||||
input := "12-345-6789"
|
||||
want := mariadbGTID{domain: 12, server: 345, sequence: 6789}
|
||||
want := MariadbGTID{Domain: 12, Server: 345, Sequence: 6789}
|
||||
|
||||
got, err := parseMariadbGTID(input)
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if got.(mariadbGTID) != want {
|
||||
if got.(MariadbGTID) != want {
|
||||
t.Errorf("ParseGTID(%v) = %v, want %v", input, got, want)
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func TestParseInvalidMariaGTID(t *testing.T) {
|
|||
|
||||
func TestParseMariaGTIDInvalidDomain(t *testing.T) {
|
||||
input := "1x-33-142"
|
||||
want := "invalid MariaDB GTID domain ID"
|
||||
want := "invalid MariaDB GTID Domain ID"
|
||||
|
||||
_, err := parseMariadbGTID(input)
|
||||
if err == nil {
|
||||
|
@ -50,7 +50,7 @@ func TestParseMariaGTIDInvalidDomain(t *testing.T) {
|
|||
|
||||
func TestParseMariaGTIDInvalidServer(t *testing.T) {
|
||||
input := "1-2c3-142"
|
||||
want := "invalid MariaDB GTID server ID"
|
||||
want := "invalid MariaDB GTID Server ID"
|
||||
|
||||
_, err := parseMariadbGTID(input)
|
||||
if err == nil {
|
||||
|
@ -63,7 +63,7 @@ func TestParseMariaGTIDInvalidServer(t *testing.T) {
|
|||
|
||||
func TestParseMariaGTIDInvalidSequence(t *testing.T) {
|
||||
input := "1-33-a142"
|
||||
want := "invalid MariaDB GTID sequence number"
|
||||
want := "invalid MariaDB GTID Sequence number"
|
||||
|
||||
_, err := parseMariadbGTID(input)
|
||||
if err == nil {
|
||||
|
@ -75,7 +75,7 @@ func TestParseMariaGTIDInvalidSequence(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDString(t *testing.T) {
|
||||
input := mariadbGTID{domain: 5, server: 4727, sequence: 1737373}
|
||||
input := MariadbGTID{Domain: 5, Server: 4727, Sequence: 1737373}
|
||||
want := "5-4727-1737373"
|
||||
|
||||
got := input.String()
|
||||
|
@ -85,7 +85,7 @@ func TestMariaGTIDString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDFlavor(t *testing.T) {
|
||||
input := mariadbGTID{domain: 1, server: 2, sequence: 123}
|
||||
input := MariadbGTID{Domain: 1, Server: 2, Sequence: 123}
|
||||
want := "MariaDB"
|
||||
|
||||
got := input.Flavor()
|
||||
|
@ -95,8 +95,8 @@ func TestMariaGTIDFlavor(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDCompareLess(t *testing.T) {
|
||||
input1 := mariadbGTID{domain: 5, server: 4727, sequence: 300}
|
||||
input2 := mariadbGTID{domain: 5, server: 4727, sequence: 700}
|
||||
input1 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 300}
|
||||
input2 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 700}
|
||||
|
||||
cmp, err := input1.TryCompare(input2)
|
||||
if err != nil {
|
||||
|
@ -108,8 +108,8 @@ func TestMariaGTIDCompareLess(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDCompareGreater(t *testing.T) {
|
||||
input1 := mariadbGTID{domain: 5, server: 4727, sequence: 9000}
|
||||
input2 := mariadbGTID{domain: 5, server: 4727, sequence: 100}
|
||||
input1 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 9000}
|
||||
input2 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 100}
|
||||
|
||||
cmp, err := input1.TryCompare(input2)
|
||||
if err != nil {
|
||||
|
@ -121,8 +121,8 @@ func TestMariaGTIDCompareGreater(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDCompareEqual(t *testing.T) {
|
||||
input1 := mariadbGTID{domain: 5, server: 4727, sequence: 1234}
|
||||
input2 := mariadbGTID{domain: 5, server: 4727, sequence: 1234}
|
||||
input1 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 1234}
|
||||
input2 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 1234}
|
||||
|
||||
cmp, err := input1.TryCompare(input2)
|
||||
if err != nil {
|
||||
|
@ -134,7 +134,7 @@ func TestMariaGTIDCompareEqual(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDCompareNil(t *testing.T) {
|
||||
input1 := mariadbGTID{domain: 1, server: 2, sequence: 123}
|
||||
input1 := MariadbGTID{Domain: 1, Server: 2, Sequence: 123}
|
||||
input2 := GTID(nil)
|
||||
want := "can't compare GTID"
|
||||
|
||||
|
@ -148,7 +148,7 @@ func TestMariaGTIDCompareNil(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDCompareWrongType(t *testing.T) {
|
||||
input1 := mariadbGTID{domain: 5, server: 4727, sequence: 1234}
|
||||
input1 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 1234}
|
||||
input2 := fakeGTID{}
|
||||
want := "can't compare GTID, wrong type"
|
||||
|
||||
|
@ -162,9 +162,9 @@ func TestMariaGTIDCompareWrongType(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDCompareWrongDomain(t *testing.T) {
|
||||
input1 := mariadbGTID{domain: 3, server: 4727, sequence: 1234}
|
||||
input2 := mariadbGTID{domain: 5, server: 4727, sequence: 1234}
|
||||
want := "can't compare GTID, MariaDB domain doesn't match"
|
||||
input1 := MariadbGTID{Domain: 3, Server: 4727, Sequence: 1234}
|
||||
input2 := MariadbGTID{Domain: 5, Server: 4727, Sequence: 1234}
|
||||
want := "can't compare GTID, MariaDB Domain doesn't match"
|
||||
|
||||
_, err := input1.TryCompare(input2)
|
||||
if err == nil {
|
||||
|
@ -176,9 +176,9 @@ func TestMariaGTIDCompareWrongDomain(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDCompareWrongServer(t *testing.T) {
|
||||
input1 := mariadbGTID{domain: 3, server: 4727, sequence: 1234}
|
||||
input2 := mariadbGTID{domain: 3, server: 5555, sequence: 1234}
|
||||
want := "can't compare GTID, MariaDB server doesn't match"
|
||||
input1 := MariadbGTID{Domain: 3, Server: 4727, Sequence: 1234}
|
||||
input2 := MariadbGTID{Domain: 3, Server: 5555, Sequence: 1234}
|
||||
want := "can't compare GTID, MariaDB Server doesn't match"
|
||||
|
||||
_, err := input1.TryCompare(input2)
|
||||
if err == nil {
|
||||
|
@ -190,8 +190,8 @@ func TestMariaGTIDCompareWrongServer(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDEqual(t *testing.T) {
|
||||
input1 := GTID(mariadbGTID{domain: 3, server: 5555, sequence: 1234})
|
||||
input2 := GTID(mariadbGTID{domain: 3, server: 5555, sequence: 1234})
|
||||
input1 := GTID(MariadbGTID{Domain: 3, Server: 5555, Sequence: 1234})
|
||||
input2 := GTID(MariadbGTID{Domain: 3, Server: 5555, Sequence: 1234})
|
||||
want := true
|
||||
|
||||
cmp := input1 == input2
|
||||
|
@ -201,8 +201,8 @@ func TestMariaGTIDEqual(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMariaGTIDNotEqual(t *testing.T) {
|
||||
input1 := GTID(mariadbGTID{domain: 3, server: 5555, sequence: 1234})
|
||||
input2 := GTID(mariadbGTID{domain: 3, server: 4555, sequence: 1234})
|
||||
input1 := GTID(MariadbGTID{Domain: 3, Server: 5555, Sequence: 1234})
|
||||
input2 := GTID(MariadbGTID{Domain: 3, Server: 4555, Sequence: 1234})
|
||||
want := false
|
||||
|
||||
cmp := input1 == input2
|
||||
|
|
Загрузка…
Ссылка в новой задаче