Search in sources :

Example 1 with LogBuffer

use of com.taobao.tddl.dbsync.binlog.LogBuffer 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 LogBuffer

use of com.taobao.tddl.dbsync.binlog.LogBuffer 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 3 with LogBuffer

use of com.taobao.tddl.dbsync.binlog.LogBuffer in project canal by alibaba.

the class MysqlBinlogParsePerformanceTest method main.

public static void main(String[] args) {
    try (DirectLogFetcher fetcher = new DirectLogFetcher()) {
        MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "root", "hello");
        connector.connect();
        updateSettings(connector);
        sendBinlogDump(connector, "mysql-bin.000006", 120L, 3);
        fetcher.start(connector.getChannel());
        final BlockingQueue<LogBuffer> buffer = new ArrayBlockingQueue<>(1024);
        Thread thread = new Thread(() -> {
            try {
                consumer(buffer);
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();
        while (fetcher.fetch()) {
            buffer.put(fetcher.duplicate());
            fetcher.consume(fetcher.limit());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MysqlConnector(com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector) LogBuffer(com.taobao.tddl.dbsync.binlog.LogBuffer) RowsLogBuffer(com.taobao.tddl.dbsync.binlog.event.RowsLogBuffer) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

DirectLogFetcher (com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher)3 LogBuffer (com.taobao.tddl.dbsync.binlog.LogBuffer)3 MysqlConnector (com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector)1 RowsLogBuffer (com.taobao.tddl.dbsync.binlog.event.RowsLogBuffer)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1