diff --git a/README.md b/README.md index 5ab8bb8..5c4c32b 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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: diff --git a/config/config.go b/config/config.go index 14bcc8b..23e762f 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/config/config_test.go b/config/config_test.go index ebf8765..4aa3c2c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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 @@ -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) { diff --git a/etc/mixer.conf.yaml b/etc/mixer.conf.yaml index 228da2e..df045f0 100644 --- a/etc/mixer.conf.yaml +++ b/etc/mixer.conf.yaml @@ -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 diff --git a/etc/mixer_multi.conf.yaml b/etc/mixer_multi.conf.yaml index 91adb56..294d719 100644 --- a/etc/mixer_multi.conf.yaml +++ b/etc/mixer_multi.conf.yaml @@ -12,7 +12,6 @@ nodes : user: root password: master : 127.0.0.1:3306 - master_backup : slave : - name : node2 diff --git a/etc/mixer_single.conf.yaml b/etc/mixer_single.conf.yaml index 59f667b..57e052b 100644 --- a/etc/mixer_single.conf.yaml +++ b/etc/mixer_single.conf.yaml @@ -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 : diff --git a/proxy/conn_admin.go b/proxy/conn_admin.go index 6e3be2b..4218d20 100644 --- a/proxy/conn_admin.go +++ b/proxy/conn_admin.go @@ -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: @@ -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: diff --git a/proxy/conn_show.go b/proxy/conn_show.go index 06d95d4..217917b 100644 --- a/proxy/conn_show.go +++ b/proxy/conn_show.go @@ -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()}) diff --git a/proxy/node.go b/proxy/node.go index b7be47d..8a3cec6 100644 --- a/proxy/node.go +++ b/proxy/node.go @@ -10,9 +10,8 @@ import ( ) const ( - Master = "master" - MasterBackup = "master_backup" - Slave = "slave" + Master = "master" + Slave = "slave" ) type Node struct { @@ -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 @@ -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() } } @@ -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 { @@ -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 } @@ -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 { @@ -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 { @@ -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()) diff --git a/proxy/server_test.go b/proxy/server_test.go index 59e1728..87f9675 100644 --- a/proxy/server_test.go +++ b/proxy/server_test.go @@ -27,7 +27,6 @@ nodes : user: root password: master : 127.0.0.1:3306 - master_backup : slave : - name : node2