Skip to content

Commit

Permalink
Remove the support of master backup
Browse files Browse the repository at this point in the history
Modify some spelling error
  • Loading branch information
dancebear committed Sep 16, 2014
1 parent 022bd55 commit c6c97bb
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 105 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Mixer is a MySQL proxy powered by Go which aims to supply a simple solution for
- Supports basic SQL statements (select, insert, update, replace, delete)
- Supports transactions
- Splits reads and writes (not fully tested)
- MySQL HA, switches to backup automatically if main crashes (not fully tested)
- MySQL HA
- Basic SQL Routing
- Supports prepared statement: `COM_STMT_PREPARE`, `COM_STMT_EXECUTE`, etc.

Expand Down Expand Up @@ -46,11 +46,10 @@ It acts as a MySQL server too, clients can communicate with it using the MySQL p

### node

Mixer uses nodes to represent the real remote MySQL servers. A node can have three MySQL servers:
Mixer uses nodes to represent the real remote MySQL servers. A node can have two MySQL servers:

+ master: main MySQL server, all write operations, read operations (if ```rw_split``` and slave are not set) will be executed here.
All transactions will be executed here too.
+ master backup: if the master was down, the mixer can switch over to the backup MySQL server. (can not set)
+ slave: if ```rw_split``` is set, any select operations will be executed here. (can not set)

Notice:
Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ type NodeConfig struct {
User string `yaml:"user"`
Password string `yaml:"password"`

Master string `yaml:"master"`
MasterBackup string `yaml:"master_backup"`
Slave string `yaml:"slave"`
Master string `yaml:"master"`
Slave string `yaml:"slave"`
}

type SchemaConfig struct {
Expand Down
6 changes: 2 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ nodes :
user: root
password:
master : 127.0.0.1:3306
master_backup : 127.0.0.1:3307
slave : 127.0.0.1:4306
-
name : node2
Expand Down Expand Up @@ -82,9 +81,8 @@ schemas :
User: "root",
Password: "",

Master: "127.0.0.1:3306",
MasterBackup: "127.0.0.1:3307",
Slave: "127.0.0.1:4306",
Master: "127.0.0.1:3306",
Slave: "127.0.0.1:4306",
}

if !reflect.DeepEqual(cfg.Nodes[0], testNode) {
Expand Down
3 changes: 0 additions & 3 deletions etc/mixer.conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ nodes :
# master represents a real mysql master server
master : 127.0.0.1:3306

# master backup server
master_backup : 127.0.0.1:3307

# slave represents a real mysql salve server
slave : 127.0.0.1:4306

Expand Down
1 change: 0 additions & 1 deletion etc/mixer_multi.conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ nodes :
user: root
password:
master : 127.0.0.1:3306
master_backup :
slave :
-
name : node2
Expand Down
3 changes: 0 additions & 3 deletions etc/mixer_single.conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ nodes :
# master represents a real mysql master server
master : 127.0.0.1:3306

# master backup server
master_backup :

# slave represents a real mysql salve server
slave :

Expand Down
4 changes: 0 additions & 4 deletions proxy/conn_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func (c *Conn) adminUpNodeServer(values sqlparser.ValExprs) error {
switch sType {
case Master:
return c.server.UpMaster(nodeName, addr)
case MasterBackup:
return c.server.UpMasterBackup(nodeName, addr)
case Slave:
return c.server.UpSlave(nodeName, addr)
default:
Expand All @@ -58,8 +56,6 @@ func (c *Conn) adminDownNodeServer(values sqlparser.ValExprs) error {
switch sType {
case Master:
return c.server.DownMaster(nodeName)
case MasterBackup:
return c.server.DownMasterBackup(nodeName)
case Slave:
return c.server.DownSlave(nodeName)
default:
Expand Down
3 changes: 0 additions & 3 deletions proxy/conn_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ func (c *Conn) handleShowProxyConfig() (*Resultset, error) {
if node.master != nil {
nodeRows = append(nodeRows, []string{nodeSection, "Master", node.master.String()})
}
if node.masterBackup != nil {
nodeRows = append(nodeRows, []string{nodeSection, "Master_Backup", node.masterBackup.String()})
}

if node.slave != nil {
nodeRows = append(nodeRows, []string{nodeSection, "Slave", node.slave.String()})
Expand Down
88 changes: 8 additions & 80 deletions proxy/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
)

const (
Master = "master"
MasterBackup = "master_backup"
Slave = "slave"
Master = "master"
Slave = "slave"
)

type Node struct {
Expand All @@ -25,9 +24,8 @@ type Node struct {
//running master db
db *client.DB

master *client.DB
masterBackup *client.DB
slave *client.DB
master *client.DB
slave *client.DB

downAfterNoAlive time.Duration

Expand Down Expand Up @@ -108,7 +106,7 @@ func (n *Node) checkMaster() {
if int64(n.downAfterNoAlive) > 0 && time.Now().Unix()-n.lastMasterPing > int64(n.downAfterNoAlive) {
log.Error("%s down master db %s", n, n.master.Addr())

n.downMater()
n.downMaster()
}
}

Expand Down Expand Up @@ -177,26 +175,6 @@ func (n *Node) upMaster(addr string) error {
return nil
}

func (n *Node) upMasterBackup(addr string) error {
n.Lock()
if n.masterBackup != nil {
n.Unlock()
return fmt.Errorf("%s master backup must be down first", n)
}
n.Unlock()

db, err := n.checkUpDB(addr)
if err != nil {
return err
}

n.Lock()
n.masterBackup = db
n.Unlock()

return nil
}

func (n *Node) upSlave(addr string) error {
n.Lock()
if n.slave != nil {
Expand All @@ -217,37 +195,11 @@ func (n *Node) upSlave(addr string) error {
return nil
}

func (n *Node) downMater() error {
func (n *Node) downMaster() error {
n.Lock()
db := n.master
if n.master != nil {
n.master = nil
}

//switch db if exists
n.db = n.masterBackup

n.Unlock()

if db != nil {
db.Close()
}
return nil
}

func (n *Node) downMaterBackup() error {
n.Lock()

db := n.masterBackup

n.masterBackup = nil
n.db = n.master

n.Unlock()

if db != nil {
db.Close()
}
return nil
}

Expand All @@ -264,7 +216,6 @@ func (n *Node) downSlave() error {
return nil
}

// Let node use master if using backup before
func (s *Server) UpMaster(node string, addr string) error {
n := s.getNode(node)
if n == nil {
Expand All @@ -282,29 +233,13 @@ func (s *Server) UpSlave(node string, addr string) error {

return n.upSlave(addr)
}

func (s *Server) UpMasterBackup(node string, addr string) error {
n := s.getNode(node)
if n == nil {
return fmt.Errorf("invalid node %s", node)
}
return n.upMasterBackup(addr)
}

func (s *Server) DownMaster(node string) error {
n := s.getNode(node)
if n == nil {
return fmt.Errorf("invalid node %s", node)
}
return n.downMater()
}

func (s *Server) DownMasterBackup(node string) error {
n := s.getNode(node)
if n == nil {
return fmt.Errorf("invalid node [%s].", node)
}
return n.downMaterBackup()
n.db = nil
return n.downMaster()
}

func (s *Server) DownSlave(node string) error {
Expand Down Expand Up @@ -357,13 +292,6 @@ func (s *Server) parseNode(cfg config.NodeConfig) (*Node, error) {

n.db = n.master

if len(cfg.MasterBackup) > 0 {
if n.masterBackup, err = n.openDB(cfg.MasterBackup); err != nil {
log.Error(err.Error())
n.masterBackup = nil
}
}

if len(cfg.Slave) > 0 {
if n.slave, err = n.openDB(cfg.Slave); err != nil {
log.Error(err.Error())
Expand Down
1 change: 0 additions & 1 deletion proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ nodes :
user: root
password:
master : 127.0.0.1:3306
master_backup :
slave :
-
name : node2
Expand Down

0 comments on commit c6c97bb

Please sign in to comment.