Skip to content

Commit

Permalink
Handle upgrade/downgrade for vtorc
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Jan 7, 2025
1 parent 6731e1e commit 01e056b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion go/vt/vtorc/inst/binlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type BinlogCoordinates struct {
Type BinlogType
}

// ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306
// ParseBinlogCoordinates will parse a string representation such as "mysql-bin.000001:12345"
// into a BinlogCoordinates struct.
func ParseBinlogCoordinates(logFileLogPos string) (*BinlogCoordinates, error) {
tokens := strings.SplitN(logFileLogPos, ":", 2)
if len(tokens) != 2 {
Expand Down
18 changes: 16 additions & 2 deletions go/vt/vtorc/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ func ReadTopologyInstanceBufferable(tabletAlias string, latency *stopwatch.Named
errorChan <- err
instance.IsDetached, _ = instance.ExecBinlogCoordinates.ExtractDetachedCoordinates()

tbp, err := ParseBinlogCoordinates(fs.ReplicationStatus.RelayLogFilePosition)
binlogPos = *tbp
binlogPos, err = getBinlogCoordinatesFromString(fs.ReplicationStatus.FilePosition)
instance.RelaylogCoordinates = binlogPos
instance.RelaylogCoordinates.Type = RelayLog
errorChan <- err
Expand Down Expand Up @@ -451,6 +450,21 @@ func getKeyspaceShardName(keyspace, shard string) string {
return fmt.Sprintf("%v:%v", keyspace, shard)
}

// getBinlogCoordinatesFromString is a bridge function to support upgrades and
// downgrades when a given string may be in one of two formats depending on
// the component versions:
// 1. GTID position, e.g. FilePos/relay-bin.000001:12345
// 2. A simple binlog file position, e.g. relay-bin.000001:12345
func getBinlogCoordinatesFromString(s string) (BinlogCoordinates, error) {
if strings.Contains(s, "/") {
// We have a GTID position which includes the flavor.
return getBinlogCoordinatesFromPositionString(s)
}
// We have a simple binlog file position.
binLogCoordinates, err := ParseBinlogCoordinates(s)
return *binLogCoordinates, err
}

func getBinlogCoordinatesFromPositionString(position string) (BinlogCoordinates, error) {
pos, err := replication.DecodePosition(position)
if err != nil || pos.GTIDSet == nil {
Expand Down

0 comments on commit 01e056b

Please sign in to comment.