зеркало из https://github.com/github/vitess-gh.git
Moving code around so it makes more sense.
We don't STOP SLAVE, RESET SLAVE in InitSlave any more. We don't use BreakSlaves on new master in InitMaster any more, we just use a couple SQL statements to init binlogs.
This commit is contained in:
Родитель
f865f43e97
Коммит
b4c2b12135
|
@ -31,7 +31,6 @@ type MysqlDaemon interface {
|
|||
|
||||
// reparenting related methods
|
||||
ResetReplicationCommands() ([]string, error)
|
||||
BreakSlaves() error
|
||||
MasterPosition() (proto.ReplicationPosition, error)
|
||||
SetReadOnly(on bool) error
|
||||
StartReplicationCommands(status *proto.ReplicationStatus) ([]string, error)
|
||||
|
@ -72,9 +71,6 @@ type FakeMysqlDaemon struct {
|
|||
// ResetReplicationError is returned by ResetReplication
|
||||
ResetReplicationError error
|
||||
|
||||
// BreakSlavesError is returned by BreakSlaves
|
||||
BreakSlavesError error
|
||||
|
||||
// CurrentMasterPosition is returned by MasterPosition
|
||||
CurrentMasterPosition proto.ReplicationPosition
|
||||
|
||||
|
@ -166,11 +162,6 @@ func (fmd *FakeMysqlDaemon) ResetReplicationCommands() ([]string, error) {
|
|||
return fmd.ResetReplicationResult, fmd.ResetReplicationError
|
||||
}
|
||||
|
||||
// BreakSlaves is part of the MysqlDaemon interface
|
||||
func (fmd *FakeMysqlDaemon) BreakSlaves() error {
|
||||
return fmd.BreakSlavesError
|
||||
}
|
||||
|
||||
// MasterPosition is part of the MysqlDaemon interface
|
||||
func (fmd *FakeMysqlDaemon) MasterPosition() (proto.ReplicationPosition, error) {
|
||||
return fmd.CurrentMasterPosition, nil
|
||||
|
@ -219,7 +210,9 @@ func (fmd *FakeMysqlDaemon) ExecuteSuperQueryList(queryList []string) error {
|
|||
// remove the SUB from the expected,
|
||||
// and truncate the query to length(expected)
|
||||
expected = expected[3:]
|
||||
query = query[:len(expected)]
|
||||
if len(query) > len(expected) {
|
||||
query = query[:len(expected)]
|
||||
}
|
||||
}
|
||||
if expected != query {
|
||||
return fmt.Errorf("wrong query for ExecuteSuperQueryList: expected %v got %v", expected, query)
|
||||
|
|
|
@ -111,8 +111,6 @@ func (*mariaDB10) StartReplicationCommands(params *sqldb.ConnParams, status *pro
|
|||
changeMasterTo := "CHANGE MASTER TO\n " + strings.Join(args, ",\n ")
|
||||
|
||||
return []string{
|
||||
"STOP SLAVE",
|
||||
"RESET SLAVE",
|
||||
setSlavePos,
|
||||
changeMasterTo,
|
||||
"START SLAVE",
|
||||
|
|
|
@ -187,8 +187,6 @@ func TestMariadbStartReplicationCommands(t *testing.T) {
|
|||
MasterConnectRetry: 1234,
|
||||
}
|
||||
want := []string{
|
||||
"STOP SLAVE",
|
||||
"RESET SLAVE",
|
||||
"SET GLOBAL gtid_slave_pos = '1-41983-12345'",
|
||||
`CHANGE MASTER TO
|
||||
MASTER_HOST = 'localhost',
|
||||
|
@ -227,8 +225,6 @@ func TestMariadbStartReplicationCommandsSSL(t *testing.T) {
|
|||
MasterConnectRetry: 1234,
|
||||
}
|
||||
want := []string{
|
||||
"STOP SLAVE",
|
||||
"RESET SLAVE",
|
||||
"SET GLOBAL gtid_slave_pos = '1-41983-12345'",
|
||||
`CHANGE MASTER TO
|
||||
MASTER_HOST = 'localhost',
|
||||
|
|
|
@ -210,7 +210,9 @@ func (mysqld *Mysqld) RestartSlave(replicationStatus *proto.ReplicationStatus, w
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mysqld.ExecuteSuperQueryList(cmds); err != nil {
|
||||
allCmds := []string{"STOP SLAVE", "RESET SLAVE"}
|
||||
allCmds = append(allCmds, cmds...)
|
||||
if err := mysqld.ExecuteSuperQueryList(allCmds); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -431,9 +431,10 @@ func (agent *ActionAgent) ResetReplication(ctx context.Context) error {
|
|||
// position, insert a row in the reparent_journal table, and returns
|
||||
// the replication position
|
||||
func (agent *ActionAgent) InitMaster(ctx context.Context) (myproto.ReplicationPosition, error) {
|
||||
// first break the slaves, so anyone who may have been replicating
|
||||
// before will stop. This is meant to catch misconfigured hosts.
|
||||
if err := agent.MysqlDaemon.BreakSlaves(); err != nil {
|
||||
// we need to insert something in the binlogs, so we can get the
|
||||
// current position. Let's just use the mysqlctl.CreateReparentJournal commands.
|
||||
cmds := mysqlctl.CreateReparentJournal()
|
||||
if err := agent.MysqlDaemon.ExecuteSuperQueryList(cmds); err != nil {
|
||||
return myproto.ReplicationPosition{}, err
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package testlib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -48,6 +47,8 @@ func TestInitMasterShard(t *testing.T) {
|
|||
"reset rep 1",
|
||||
"CREATE DATABASE IF NOT EXISTS _vt",
|
||||
"SUBCREATE TABLE IF NOT EXISTS _vt.reparent_journal",
|
||||
"CREATE DATABASE IF NOT EXISTS _vt",
|
||||
"SUBCREATE TABLE IF NOT EXISTS _vt.reparent_journal",
|
||||
"SUBINSERT INTO _vt.reparent_journal (time_created_ns, action_name, master_alias, replication_position) VALUES",
|
||||
}
|
||||
master.StartActionLoop(t, wr)
|
||||
|
@ -140,13 +141,13 @@ func TestInitMasterShardChecks(t *testing.T) {
|
|||
}
|
||||
|
||||
// InitShardMaster where the new master fails (use force flag
|
||||
// as we have 2 masters)
|
||||
master.FakeMysqlDaemon.BreakSlavesError = fmt.Errorf("forced test error")
|
||||
// as we have 2 masters). We force the failure by making the
|
||||
// SQL commands executed on the master unexpected by the test fixture
|
||||
master.StartActionLoop(t, wr)
|
||||
defer master.StopActionLoop(t)
|
||||
master2.StartActionLoop(t, wr)
|
||||
defer master2.StopActionLoop(t)
|
||||
if err := wr.InitShardMaster(ctx, master.Tablet.Keyspace, master.Tablet.Shard, master.Tablet.Alias, true /*force*/, 10*time.Second); err == nil || !strings.Contains(err.Error(), "forced test error") {
|
||||
if err := wr.InitShardMaster(ctx, master.Tablet.Keyspace, master.Tablet.Shard, master.Tablet.Alias, true /*force*/, 10*time.Second); err == nil || !strings.Contains(err.Error(), "unexpected extra query") {
|
||||
t.Errorf("InitShardMaster with new master failing BreakSlaves returned wrong error: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +175,8 @@ func TestInitMasterShardOneSlaveFails(t *testing.T) {
|
|||
}
|
||||
master.FakeMysqlDaemon.ReadOnly = true
|
||||
master.FakeMysqlDaemon.ExpectedExecuteSuperQueryList = []string{
|
||||
"CREATE DATABASE IF NOT EXISTS _vt",
|
||||
"SUBCREATE TABLE IF NOT EXISTS _vt.reparent_journal",
|
||||
"CREATE DATABASE IF NOT EXISTS _vt",
|
||||
"SUBCREATE TABLE IF NOT EXISTS _vt.reparent_journal",
|
||||
"SUBINSERT INTO _vt.reparent_journal (time_created_ns, action_name, master_alias, replication_position) VALUES",
|
||||
|
|
Загрузка…
Ссылка в новой задаче