コード例 #1
0
// Stream implements BinlogStreamer.Stream().
func (bls *binlogConnStreamer) Stream(ctx *sync2.ServiceContext) (err error) {
	var stopPos myproto.ReplicationPosition
	defer func() {
		if err != nil {
			binlogStreamerErrors.Add("Stream", 1)
			err = fmt.Errorf("stream error @ %v, error: %v", stopPos, err)
			log.Error(err.Error())
		}
		log.Infof("Stream ended @ %v", stopPos)
	}()

	if bls.conn, err = mysqlctl.NewSlaveConnection(bls.mysqld); err != nil {
		return
	}
	defer bls.conn.Close()

	var events <-chan proto.BinlogEvent
	events, err = bls.conn.StartBinlogDump(bls.startPos)
	if err != nil {
		return
	}
	// parseEvents will loop until the events channel is closed, the
	// service enters the SHUTTING_DOWN state, or an error occurs.
	stopPos, err = bls.parseEvents(ctx, events)
	return
}
コード例 #2
0
ファイル: binlog_streamer.go プロジェクト: nangong92t/go_src
// Stream starts streaming binlog events using the settings from NewBinlogStreamer().
func (bls *BinlogStreamer) Stream(ctx *sync2.ServiceContext) (err error) {
	stopPos := bls.startPos
	defer func() {
		if err != nil {
			err = fmt.Errorf("stream error @ %v: %v", stopPos, err)
		}
		log.Infof("stream ended @ %v, err = %v", stopPos, err)
	}()

	if bls.conn, err = mysqlctl.NewSlaveConnection(bls.mysqld); err != nil {
		return err
	}
	defer bls.conn.Close()

	// Check that the default charsets match, if the client specified one.
	// Note that BinlogStreamer uses the settings for the 'dba' user, while
	// BinlogPlayer uses the 'filtered' user, so those are the ones whose charset
	// must match. Filtered replication should still succeed even with a default
	// mismatch, since we pass per-statement charset info. However, Vitess in
	// general doesn't support servers with different default charsets, so we
	// treat it as a configuration error.
	if bls.clientCharset != nil {
		cs, err := bls.conn.GetCharset()
		if err != nil {
			return fmt.Errorf("can't get charset to check binlog stream: %v", err)
		}
		log.Infof("binlog stream client charset = %v, server charset = %v", *bls.clientCharset, cs)
		if cs != *bls.clientCharset {
			return fmt.Errorf("binlog stream client charset (%v) doesn't match server (%v)", *bls.clientCharset, cs)
		}
	}

	var events <-chan proto.BinlogEvent
	events, err = bls.conn.StartBinlogDump(bls.startPos)
	if err != nil {
		return err
	}
	// parseEvents will loop until the events channel is closed, the
	// service enters the SHUTTING_DOWN state, or an error occurs.
	stopPos, err = bls.parseEvents(ctx, events)
	return err
}