From 16508dad129285d12a84e7b617ee394d13bc7971 Mon Sep 17 00:00:00 2001 From: Brian Lalor Date: Sun, 28 Jun 2015 08:48:39 -0400 Subject: [PATCH] Only check for semi-sync ack request if semi-sync is enabled for this connection I think this is correct, since the docs[1] for enabling semi-sync indicate that not all slaves need to support it, even if the msater does. This does resolve the problem I sort-of-reported in #13, which appears to be two bytes missing from the beginning of the packet at the time the event is parsed. [1]: https://dev.mysql.com/doc/refman/5.5/en/replication-semisync-installation.html --- replication/binlogsyncer.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/replication/binlogsyncer.go b/replication/binlogsyncer.go index 2cbeed892..9ced64afd 100644 --- a/replication/binlogsyncer.go +++ b/replication/binlogsyncer.go @@ -39,6 +39,7 @@ type BinlogSyncer struct { nextPos Position running bool + semiSyncEnabled bool } func NewBinlogSyncer(serverID uint32, flavor string) *BinlogSyncer { @@ -52,6 +53,7 @@ func NewBinlogSyncer(serverID uint32, flavor string) *BinlogSyncer { b.parser = NewBinlogParser() b.running = false + b.semiSyncEnabled = false return b } @@ -211,6 +213,11 @@ func (b *BinlogSyncer) EnableSemiSync() error { } _, err := b.c.Execute(`SET @rpl_semi_sync_slave = 1;`) + + if err != nil { + b.semiSyncEnabled = true + } + return err } @@ -479,11 +486,11 @@ func (b *BinlogSyncer) onStream(s *BinlogStreamer) { } func (b *BinlogSyncer) parseEvent(s *BinlogStreamer, data []byte) error { - //skip 0x00 + //skip OK byte, 0x00 data = data[1:] needACK := false - if data[0] == SemiSyncIndicator { + if b.semiSyncEnabled && (data[0] == SemiSyncIndicator) { needACK = (data[1] == 0x01) //skip semi sync header data = data[2:]