Skip to content

Commit

Permalink
Feature 2-node xenon turn on semisync(radondb#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Easontai committed Dec 27, 2018
1 parent a94108b commit 3922116
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/mysql/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ func (m *Mysql) DisableSemiSyncMaster() error {
return m.replHandler.DisableSemiSyncMaster(db)
}

// SetSemiSyncMasterDefault useed to set semi-sync master timeout = default.
func (m *Mysql) SetSemiSyncMasterDefault() error {
db, err := m.getDB()
if err != nil {
return err
}
return m.replHandler.SetSemiSyncMasterDefault(db)
}

// CheckUserExists used to check the user exists or not.
func (m *Mysql) CheckUserExists(user string) (bool, error) {
db, err := m.getDB()
Expand Down
51 changes: 32 additions & 19 deletions src/mysql/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,26 @@ import (

// MockGTID tuple.
type MockGTID struct {
PingFn func(*sql.DB) (*PingEntry, error)
SetReadOnlyFn func(*sql.DB, bool) error
GetMasterGTIDFn func(*sql.DB) (*model.GTID, error)
GetSlaveGTIDFn func(*sql.DB) (*model.GTID, error)
StartSlaveIOThreadFn func(*sql.DB) error
StopSlaveIOThreadFn func(*sql.DB) error
StartSlaveFn func(*sql.DB) error
StopSlaveFn func(*sql.DB) error
ChangeMasterToFn func(*sql.DB, *model.Repl) error
ChangeToMasterFn func(*sql.DB) error
WaitUntilAfterGTIDFn func(*sql.DB, string) error
SetGlobalSysVarFn func(*sql.DB, string) error
ResetMasterFn func(*sql.DB) error
ResetSlaveAllFn func(*sql.DB) error
PurgeBinlogsToFn func(*sql.DB, string) error
EnableSemiSyncMasterFn func(*sql.DB) error
DisableSemiSyncMasterFn func(*sql.DB) error
SelectSysVarFn func(*sql.DB, string) (string, error)
SetSemiWaitSlaveCountFn func(*sql.DB, int) error
PingFn func(*sql.DB) (*PingEntry, error)
SetReadOnlyFn func(*sql.DB, bool) error
GetMasterGTIDFn func(*sql.DB) (*model.GTID, error)
GetSlaveGTIDFn func(*sql.DB) (*model.GTID, error)
StartSlaveIOThreadFn func(*sql.DB) error
StopSlaveIOThreadFn func(*sql.DB) error
StartSlaveFn func(*sql.DB) error
StopSlaveFn func(*sql.DB) error
ChangeMasterToFn func(*sql.DB, *model.Repl) error
ChangeToMasterFn func(*sql.DB) error
WaitUntilAfterGTIDFn func(*sql.DB, string) error
SetGlobalSysVarFn func(*sql.DB, string) error
ResetMasterFn func(*sql.DB) error
ResetSlaveAllFn func(*sql.DB) error
PurgeBinlogsToFn func(*sql.DB, string) error
EnableSemiSyncMasterFn func(*sql.DB) error
DisableSemiSyncMasterFn func(*sql.DB) error
SelectSysVarFn func(*sql.DB, string) (string, error)
SetSemiWaitSlaveCountFn func(*sql.DB, int) error
SetSemiSyncMasterDefaultFn func(*sql.DB) error
}

// DefaultGetSlaveGTID returns the default slave gtid.
Expand Down Expand Up @@ -216,6 +217,11 @@ func (mogtid *MockGTID) DisableSemiSyncMaster(db *sql.DB) error {
return mogtid.DisableSemiSyncMasterFn(db)
}

// SetSemiSyncMasterDefault mock.
func (mogtid *MockGTID) SetSemiSyncMasterDefault(db *sql.DB) error {
return mogtid.SetSemiSyncMasterDefaultFn(db)
}

// DefaultSelectSysVar mock.
func DefaultSelectSysVar(db *sql.DB, query string) (string, error) {
return "", nil
Expand All @@ -231,11 +237,17 @@ func DefaultSetSemiWaitSlaveCount(db *sql.DB, count int) error {
return nil
}


// SetSemiWaitSlaveCount mock
func (mogtid *MockGTID) SetSemiWaitSlaveCount(db *sql.DB, count int) error {
return mogtid.SetSemiWaitSlaveCountFn(db, count)
}

// SetSemiSyncMasterDefault mock
func SetSemiSyncMasterDefault(db *sql.DB) error {
return nil
}

func defaultMockGTID() *MockGTID {
mock := &MockGTID{}
mock.PingFn = DefaultPing
Expand All @@ -257,6 +269,7 @@ func defaultMockGTID() *MockGTID {
mock.DisableSemiSyncMasterFn = DefaultDisableSemiSyncMaster
mock.SelectSysVarFn = DefaultSelectSysVar
mock.SetSemiWaitSlaveCountFn = DefaultSetSemiWaitSlaveCount
mock.SetSemiSyncMasterDefaultFn = SetSemiSyncMasterDefault

return mock
}
Expand Down
6 changes: 6 additions & 0 deletions src/mysql/mysql57.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,9 @@ func (my *Mysql57) DisableSemiSyncMaster(db *sql.DB) error {
cmds := "SET GLOBAL rpl_semi_sync_master_enabled=OFF"
return ExecuteWithTimeout(db, reqTimeout, cmds)
}

// SetSemiSyncMasterDefault useed to set semi-sync master timeout = default
func (my *Mysql57) SetSemiSyncMasterDefault(db *sql.DB) error {
cmds := "SET GLOBAL rpl_semi_sync_master_timeout=default"
return ExecuteWithTimeout(db, reqTimeout, cmds)
}
14 changes: 14 additions & 0 deletions src/mysql/mysql57_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,17 @@ func TestMysql57SemiMaster(t *testing.T) {
err = mysql57.DisableSemiSyncMaster(db)
assert.Nil(t, err)
}

func TestMysql57SemiMasterDefault(t *testing.T) {
db, mock, err := sqlmock.New()
assert.Nil(t, err)
defer db.Close()

queryList := []string{
"SET GLOBAL rpl_semi_sync_master_timeout=default",
}

mock.ExpectExec(queryList[0]).WillReturnResult(sqlmock.NewResult(1, 1))
err = mysql57.SetSemiSyncMasterDefault(db)
assert.Nil(t, err)
}
3 changes: 3 additions & 0 deletions src/mysql/repl_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type ReplHandler interface {
// disable master semi sync: don't wait slave ack
DisableSemiSyncMaster(db *sql.DB) error

// set semi-sync master-timeout = default
SetSemiSyncMasterDefault(db *sql.DB) error

//set rpl_semi_master_wait_for_slave_count
SetSemiWaitSlaveCount(db *sql.DB, count int) error
}
4 changes: 2 additions & 2 deletions src/raft/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ func (r *Leader) checkSemiSync() {
min := 3
cur := r.getMembers()
if cur < min {
if err := r.mysql.DisableSemiSyncMaster(); err != nil {
r.ERROR("mysql.disable.semi-sync.error[%v]", err)
if err := r.mysql.SetSemiSyncMasterDefault(); err != nil {
r.ERROR("mysql.set.semi-sync.master.timeout.error[%v]", err)
}
} else {
if err := r.mysql.EnableSemiSyncMaster(); err != nil {
Expand Down

0 comments on commit 3922116

Please sign in to comment.