Search in sources :

Example 1 with DirectLogFetcher

use of com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher in project canal by alibaba.

the class MysqlConnection method dump.

@Override
public void dump(String binlogfilename, Long binlogPosition, MultiStageCoprocessor coprocessor) throws IOException {
    updateSettings();
    loadBinlogChecksum();
    sendRegisterSlave();
    sendBinlogDump(binlogfilename, binlogPosition);
    ((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
    ((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
    try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
        fetcher.start(connector.getChannel());
        while (fetcher.fetch()) {
            accumulateReceivedBytes(fetcher.limit());
            LogBuffer buffer = fetcher.duplicate();
            fetcher.consume(fetcher.limit());
            if (!coprocessor.publish(buffer)) {
                break;
            }
        }
    }
}
Also used : LogBuffer(com.taobao.tddl.dbsync.binlog.LogBuffer) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher)

Example 2 with DirectLogFetcher

use of com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher in project canal by alibaba.

the class MysqlConnection method dump.

@Override
public void dump(GTIDSet gtidSet, SinkFunction func) throws IOException {
    updateSettings();
    loadBinlogChecksum();
    sendBinlogDumpGTID(gtidSet);
    try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
        fetcher.start(connector.getChannel());
        LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
        LogContext context = new LogContext();
        context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
        // fix bug: #890 将gtid传输至context中,供decode使用
        context.setGtidSet(gtidSet);
        while (fetcher.fetch()) {
            accumulateReceivedBytes(fetcher.limit());
            LogEvent event = null;
            event = decoder.decode(fetcher, context);
            if (event == null) {
                throw new CanalParseException("parse failed");
            }
            if (!func.sink(event)) {
                break;
            }
        }
    }
}
Also used : FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher) LogEvent(com.taobao.tddl.dbsync.binlog.LogEvent) FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) LogDecoder(com.taobao.tddl.dbsync.binlog.LogDecoder) CanalParseException(com.alibaba.otter.canal.parse.exception.CanalParseException)

Example 3 with DirectLogFetcher

use of com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher in project canal by alibaba.

the class MysqlConnection method seek.

/**
 * 加速主备切换时的查找速度,做一些特殊优化,比如只解析事务头或者尾
 */
public void seek(String binlogfilename, Long binlogPosition, String gtid, SinkFunction func) throws IOException {
    updateSettings();
    loadBinlogChecksum();
    sendBinlogDump(binlogfilename, binlogPosition);
    DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
    fetcher.start(connector.getChannel());
    LogDecoder decoder = new LogDecoder();
    decoder.handle(LogEvent.ROTATE_EVENT);
    decoder.handle(LogEvent.FORMAT_DESCRIPTION_EVENT);
    decoder.handle(LogEvent.QUERY_EVENT);
    decoder.handle(LogEvent.XID_EVENT);
    LogContext context = new LogContext();
    // using CHANGE MASTER TO MASTER_AUTO_POSITION = 1 ...
    if (StringUtils.isNotEmpty(gtid)) {
        GTIDSet gtidSet = parseGtidSet(gtid, isMariaDB());
        if (isMariaDB()) {
            decoder.handle(LogEvent.GTID_EVENT);
            decoder.handle(LogEvent.GTID_LIST_EVENT);
        } else {
            decoder.handle(LogEvent.GTID_LOG_EVENT);
        }
        context.setGtidSet(gtidSet);
    }
    context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
    while (fetcher.fetch()) {
        accumulateReceivedBytes(fetcher.limit());
        LogEvent event = null;
        event = decoder.decode(fetcher, context);
        if (event == null) {
            throw new CanalParseException("parse failed");
        }
        if (!func.sink(event)) {
            break;
        }
    }
}
Also used : FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher) LogEvent(com.taobao.tddl.dbsync.binlog.LogEvent) FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) LogDecoder(com.taobao.tddl.dbsync.binlog.LogDecoder) GTIDSet(com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet) CanalParseException(com.alibaba.otter.canal.parse.exception.CanalParseException)

Example 4 with DirectLogFetcher

use of com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher in project canal by alibaba.

the class MysqlConnection method dump.

@Override
public void dump(GTIDSet gtidSet, MultiStageCoprocessor coprocessor) throws IOException {
    updateSettings();
    loadBinlogChecksum();
    sendBinlogDumpGTID(gtidSet);
    ((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
    ((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
    try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
        fetcher.start(connector.getChannel());
        while (fetcher.fetch()) {
            accumulateReceivedBytes(fetcher.limit());
            LogBuffer buffer = fetcher.duplicate();
            fetcher.consume(fetcher.limit());
            if (!coprocessor.publish(buffer)) {
                break;
            }
        }
    }
}
Also used : LogBuffer(com.taobao.tddl.dbsync.binlog.LogBuffer) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher)

Example 5 with DirectLogFetcher

use of com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher in project canal by alibaba.

the class MysqlConnection method dump.

public void dump(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException {
    updateSettings();
    loadBinlogChecksum();
    sendRegisterSlave();
    sendBinlogDump(binlogfilename, binlogPosition);
    DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
    fetcher.start(connector.getChannel());
    LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
    LogContext context = new LogContext();
    context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
    while (fetcher.fetch()) {
        accumulateReceivedBytes(fetcher.limit());
        LogEvent event = null;
        event = decoder.decode(fetcher, context);
        if (event == null) {
            throw new CanalParseException("parse failed");
        }
        if (!func.sink(event)) {
            break;
        }
        if (event.getSemival() == 1) {
            sendSemiAck(context.getLogPosition().getFileName(), context.getLogPosition().getPosition());
        }
    }
}
Also used : FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher) LogEvent(com.taobao.tddl.dbsync.binlog.LogEvent) FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) LogDecoder(com.taobao.tddl.dbsync.binlog.LogDecoder) CanalParseException(com.alibaba.otter.canal.parse.exception.CanalParseException)

Aggregations

DirectLogFetcher (com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher)8 LogContext (com.taobao.tddl.dbsync.binlog.LogContext)5 LogDecoder (com.taobao.tddl.dbsync.binlog.LogDecoder)5 CanalParseException (com.alibaba.otter.canal.parse.exception.CanalParseException)4 LogEvent (com.taobao.tddl.dbsync.binlog.LogEvent)4 FormatDescriptionLogEvent (com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent)4 MysqlConnector (com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector)3 LogBuffer (com.taobao.tddl.dbsync.binlog.LogBuffer)3 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 GTIDSet (com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet)1 DeleteRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent)1 QueryLogEvent (com.taobao.tddl.dbsync.binlog.event.QueryLogEvent)1 RotateLogEvent (com.taobao.tddl.dbsync.binlog.event.RotateLogEvent)1 RowsLogBuffer (com.taobao.tddl.dbsync.binlog.event.RowsLogBuffer)1 RowsLogEvent (com.taobao.tddl.dbsync.binlog.event.RowsLogEvent)1 RowsQueryLogEvent (com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent)1 TableMapLogEvent (com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent)1 UpdateRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent)1