- Notifications
You must be signed in to change notification settings - Fork 1k
Adding replication protocol support to mysql server implementation #759
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
Changes from 13 commits
2d8ffec
e96001b
cae8dcf
c6e73da
132c325
5fdb922
d8ec4a6
4e4b1b5
125d938
d98f42c
46a38cf
09f1f26
960c01a
5f660c9
60d5d2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -5,6 +5,7 @@ import ( | |
"fmt" | ||
| ||
. "github.com/go-mysql-org/go-mysql/mysql" | ||
"github.com/go-mysql-org/go-mysql/replication" | ||
"github.com/siddontang/go/hack" | ||
) | ||
| ||
| @@ -30,6 +31,13 @@ type Handler interface { | |
HandleOtherCommand(cmd byte, data []byte) error | ||
} | ||
| ||
type ReplicationHandler interface { | ||
// handle Replication command | ||
HandleRegisterSlave(data []byte) error | ||
HandleBinlogDump(pos *Position) (*replication.BinlogStreamer, error) | ||
HandleBinlogDumpGTID(gtidSet *MysqlGTIDSet) (*replication.BinlogStreamer, error) | ||
} | ||
| ||
func (c *Conn) HandleCommand() error { | ||
if c.Conn == nil { | ||
return fmt.Errorf("connection closed") | ||
| @@ -131,6 +139,37 @@ func (c *Conn) dispatch(data []byte) interface{} { | |
} | ||
| ||
return eofResponse{} | ||
case COM_REGISTER_SLAVE: | ||
if h, ok := c.h.(ReplicationHandler); ok { | ||
return h.HandleRegisterSlave(data) | ||
} else { | ||
return c.h.HandleOtherCommand(cmd, data) | ||
} | ||
case COM_BINLOG_DUMP: | ||
if h, ok := c.h.(ReplicationHandler); ok { | ||
pos, _ := parseBinlogDump(data) | ||
if s, err := h.HandleBinlogDump(pos); err != nil { | ||
return err | ||
} else { | ||
return s | ||
} | ||
} else { | ||
return c.h.HandleOtherCommand(cmd, data) | ||
} | ||
case COM_BINLOG_DUMP_GTID: | ||
if h, ok := c.h.(ReplicationHandler); ok { | ||
gtidSet, err := parseBinlogDumpGTID(data) | ||
if err != nil { | ||
return err | ||
} | ||
if s, err := h.HandleBinlogDumpGTID(gtidSet); err != nil { | ||
return err | ||
} else { | ||
return s | ||
} | ||
} else { | ||
return c.h.HandleOtherCommand(cmd, data) | ||
} | ||
default: | ||
return c.h.HandleOtherCommand(cmd, data) | ||
} | ||
| @@ -139,6 +178,10 @@ func (c *Conn) dispatch(data []byte) interface{} { | |
type EmptyHandler struct { | ||
} | ||
| ||
type EmptyReplicationHandler struct { | ||
lance6716 marked this conversation as resolved. Show resolved Hide resolved | ||
EmptyHandler | ||
} | ||
| ||
func (h EmptyHandler) UseDB(dbName string) error { | ||
return nil | ||
} | ||
| @@ -160,6 +203,18 @@ func (h EmptyHandler) HandleStmtClose(context interface{}) error { | |
return nil | ||
} | ||
| ||
func (h EmptyReplicationHandler) HandleRegisterSlave(data []byte) error { | ||
return fmt.Errorf("not supported now") | ||
} | ||
| ||
func (h EmptyReplicationHandler) HandleBinlogDump(pos *Position) (*replication.BinlogStreamer, error) { | ||
return nil, fmt.Errorf("not supported now") | ||
} | ||
| ||
func (h EmptyReplicationHandler) HandleBinlogDumpGTID(gtidSet *MysqlGTIDSet) (*replication.BinlogStreamer, error) { | ||
return nil, fmt.Errorf("not supported now") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest adding | ||
| ||
func (h EmptyHandler) HandleOtherCommand(cmd byte, data []byte) error { | ||
return NewError( | ||
ER_UNKNOWN_ERROR, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package server | ||
| ||
import ( | ||
"encoding/binary" | ||
| ||
"github.com/go-mysql-org/go-mysql/mysql" | ||
) | ||
| ||
func parseBinlogDump(data []byte) (*mysql.Position, error) { | ||
lance6716 marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
var p mysql.Position | ||
p.Pos = binary.LittleEndian.Uint32(data[0:4]) | ||
p.Name = string(data[10:]) | ||
| ||
return &p, nil | ||
} | ||
| ||
func parseBinlogDumpGTID(data []byte) (*mysql.MysqlGTIDSet, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you plan to support MariaDB GTID set? you can see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MariaDB doesn't implement COM_BINLOG_DUMP_GTID - so, we can assume that this message sent by MySQL. https://github.com/MariaDB/server/blob/10.9/include/mysql_com.h#L118 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I mean if there's not too much work to do we can support MariaDB by the way. But as you said MariaDB does not use COM_BINLOG_DUMP_GTID so it may not be a trivial work | ||
lenPosName := binary.LittleEndian.Uint32(data[11:15]) | ||
lance6716 marked this conversation as resolved. Show resolved Hide resolved | ||
| ||
return mysql.DecodeMysqlGTIDSet(data[22+lenPosName:]) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.