Skip to content

Commit 639eccd

Browse files
authored
replication: add IsEmpty method to GTIDSet interface & implementations (#1019)
1 parent f8d108d commit 639eccd

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

mysql/gtid.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type GTIDSet interface {
1717
Update(GTIDStr string) error
1818

1919
Clone() GTIDSet
20+
21+
// IsEmpty returns true if the given set is empty and false otherwise.
22+
IsEmpty() bool
2023
}
2124

2225
func ParseGTIDSet(flavor string, s string) (GTIDSet, error) {

mysql/mariadb_gtid.go

+4
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,7 @@ func (s *MariadbGTIDSet) Contain(o GTIDSet) bool {
256256

257257
return true
258258
}
259+
260+
func (s *MariadbGTIDSet) IsEmpty() bool {
261+
return len(s.Sets) == 0
262+
}

mysql/mariadb_gtid_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,13 @@ func TestMariaDBGTIDSetSortedString(t *testing.T) {
243243
require.Equal(t, strs[1], gtidSet.String())
244244
}
245245
}
246+
247+
func TestMariadbGTIDSetIsEmpty(t *testing.T) {
248+
emptyGTIDSet := new(MariadbGTIDSet)
249+
emptyGTIDSet.Sets = make(map[uint32]map[uint32]*MariadbGTID)
250+
require.True(t, emptyGTIDSet.IsEmpty())
251+
252+
nonEmptyGTIDSet, err := ParseMariadbGTIDSet("0-1-2")
253+
require.NoError(t, err)
254+
require.False(t, nonEmptyGTIDSet.IsEmpty())
255+
}

mysql/mysql_gtid.go

+4
Original file line numberDiff line numberDiff line change
@@ -596,3 +596,7 @@ func (gtid *MysqlGTIDSet) Clone() GTIDSet {
596596

597597
return clone
598598
}
599+
600+
func (s *MysqlGTIDSet) IsEmpty() bool {
601+
return len(s.Sets) == 0
602+
}

mysql/mysql_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,12 @@ func TestValidateFlavor(t *testing.T) {
360360
}
361361
}
362362
}
363+
364+
func TestMysqlGTIDSetIsEmpty(t *testing.T) {
365+
emptyGTIDSet := new(MysqlGTIDSet)
366+
emptyGTIDSet.Sets = make(map[string]*UUIDSet)
367+
require.True(t, emptyGTIDSet.IsEmpty())
368+
369+
nonEmptyGTIDSet := mysqlGTIDfromString(t, "de278ad0-2106-11e4-9f8e-6edd0ca20947:1-2")
370+
require.False(t, nonEmptyGTIDSet.IsEmpty())
371+
}

0 commit comments

Comments
 (0)