Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability create consistent transactions #4533

Merged
merged 1 commit into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions go/mysql/flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type flavor interface {
// startSlave returns the command to start the slave.
startSlaveCommand() string

// startSlaveUntilAfter will restart replication, but only allow it
// to run until `pos` is reached. After reaching pos, replication will be stopped again
startSlaveUntilAfter(pos Position) string

// stopSlave returns the command to stop the slave.
stopSlaveCommand() string

Expand Down Expand Up @@ -146,6 +150,11 @@ func (c *Conn) StartSlaveCommand() string {
return c.flavor.startSlaveCommand()
}

// StartSlaveUntilAfterCommand returns the command to start the slave.
func (c *Conn) StartSlaveUntilAfterCommand(pos Position) string {
return c.flavor.startSlaveUntilAfter(pos)
}

// StopSlaveCommand returns the command to stop the slave.
func (c *Conn) StopSlaveCommand() string {
return c.flavor.stopSlaveCommand()
Expand Down
4 changes: 4 additions & 0 deletions go/mysql/flavor_mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (mariadbFlavor) masterGTIDSet(c *Conn) (GTIDSet, error) {
return parseMariadbGTIDSet(qr.Rows[0][0].ToString())
}

func (mariadbFlavor) startSlaveUntilAfter(pos Position) string {
return fmt.Sprintf("START SLAVE UNTIL master_gtid_pos = \"%s\"", pos)
}

func (mariadbFlavor) startSlaveCommand() string {
return "START SLAVE"
}
Expand Down
4 changes: 4 additions & 0 deletions go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (mysqlFlavor) startSlaveCommand() string {
return "START SLAVE"
}

func (mysqlFlavor) startSlaveUntilAfter(pos Position) string {
return fmt.Sprintf("START SLAVE UNTIL SQL_AFTER_GTIDS = '%s'", pos)
}

func (mysqlFlavor) stopSlaveCommand() string {
return "STOP SLAVE"
}
Expand Down
14 changes: 14 additions & 0 deletions go/vt/mysqlctl/fakemysqldaemon/fakemysqldaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type FakeMysqlDaemon struct {
// If it doesn't match, SetSlavePosition will return an error.
SetSlavePositionPos mysql.Position

// StartSlaveUntilAfterPos is matched against the input
StartSlaveUntilAfterPos mysql.Position

// SetMasterInput is matched against the input of SetMaster
// (as "%v:%v"). If it doesn't match, SetMaster will return an error.
SetMasterInput string
Expand Down Expand Up @@ -240,6 +243,17 @@ func (fmd *FakeMysqlDaemon) StartSlave(hookExtraEnv map[string]string) error {
})
}

// StartSlaveUntilAfter is part of the MysqlDaemon interface.
func (fmd *FakeMysqlDaemon) StartSlaveUntilAfter(ctx context.Context, pos mysql.Position) error {
if !reflect.DeepEqual(fmd.StartSlaveUntilAfterPos, pos) {
return fmt.Errorf("wrong pos for StartSlaveUntilAfter: expected %v got %v", fmd.SetSlavePositionPos, pos)
}

return fmd.ExecuteSuperQueryList(context.Background(), []string{
"START SLAVE UNTIL AFTER",
})
}

// StopSlave is part of the MysqlDaemon interface.
func (fmd *FakeMysqlDaemon) StopSlave(hookExtraEnv map[string]string) error {
return fmd.ExecuteSuperQueryList(context.Background(), []string{
Expand Down
1 change: 1 addition & 0 deletions go/vt/mysqlctl/mysql_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type MysqlDaemon interface {

// replication related methods
StartSlave(hookExtraEnv map[string]string) error
StartSlaveUntilAfter(ctx context.Context, pos mysql.Position) error
StopSlave(hookExtraEnv map[string]string) error
SlaveStatus() (mysql.SlaveStatus, error)
SetSemiSyncEnabled(master, slave bool) error
Expand Down
13 changes: 13 additions & 0 deletions go/vt/mysqlctl/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ func (mysqld *Mysqld) StartSlave(hookExtraEnv map[string]string) error {
return h.ExecuteOptional()
}

// StartSlaveUntilAfter starts a slave until replication has come to `targetPos`, then it stops replication
func (mysqld *Mysqld) StartSlaveUntilAfter(ctx context.Context, targetPos mysql.Position) error {
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()

queries := []string{conn.StartSlaveUntilAfterCommand(targetPos)}

return mysqld.executeSuperQueryListConn(ctx, conn, queries)
}

// StopSlave stops a slave.
func (mysqld *Mysqld) StopSlave(hookExtraEnv map[string]string) error {
h := hook.NewSimpleHook("preflight_stop_slave")
Expand Down
Loading