position.go 528 B

123456789101112131415161718192021222324252627282930313233
  1. package mysql
  2. import (
  3. "fmt"
  4. )
  5. // For binlog filename + position based replication
  6. type Position struct {
  7. Name string
  8. Pos uint32
  9. }
  10. func (p Position) Compare(o Position) int {
  11. // First compare binlog name
  12. if p.Name > o.Name {
  13. return 1
  14. } else if p.Name < o.Name {
  15. return -1
  16. } else {
  17. // Same binlog file, compare position
  18. if p.Pos > o.Pos {
  19. return 1
  20. } else if p.Pos < o.Pos {
  21. return -1
  22. } else {
  23. return 0
  24. }
  25. }
  26. }
  27. func (p Position) String() string {
  28. return fmt.Sprintf("(%s, %d)", p.Name, p.Pos)
  29. }