Search in sources :

Example 6 with DirectLogFetcher

use of com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher 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)

Example 7 with DirectLogFetcher

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

the class DirectLogFetcherTest method testSimple.

@Test
public void testSimple() {
    DirectLogFetcher fetcher = new DirectLogFetcher();
    try {
        MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "canal", "canal");
        connector.connect();
        updateSettings(connector);
        loadBinlogChecksum(connector);
        sendRegisterSlave(connector, 3);
        sendBinlogDump(connector, "mysql-bin.000001", 4L, 3);
        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()) {
            LogEvent event = null;
            event = decoder.decode(fetcher, context);
            if (event == null) {
                throw new RuntimeException("parse failed");
            }
            int eventType = event.getHeader().getType();
            switch(eventType) {
                case LogEvent.ROTATE_EVENT:
                    // binlogFileName = ((RotateLogEvent)
                    // event).getFilename();
                    System.out.println(((RotateLogEvent) event).getFilename());
                    break;
                case LogEvent.TABLE_MAP_EVENT:
                    parseTableMapEvent((TableMapLogEvent) event);
                    break;
                case LogEvent.WRITE_ROWS_EVENT_V1:
                case LogEvent.WRITE_ROWS_EVENT:
                    parseRowsEvent((WriteRowsLogEvent) event);
                    break;
                case LogEvent.UPDATE_ROWS_EVENT_V1:
                case LogEvent.PARTIAL_UPDATE_ROWS_EVENT:
                case LogEvent.UPDATE_ROWS_EVENT:
                    parseRowsEvent((UpdateRowsLogEvent) event);
                    break;
                case LogEvent.DELETE_ROWS_EVENT_V1:
                case LogEvent.DELETE_ROWS_EVENT:
                    parseRowsEvent((DeleteRowsLogEvent) event);
                    break;
                case LogEvent.QUERY_EVENT:
                    parseQueryEvent((QueryLogEvent) event);
                    break;
                case LogEvent.ROWS_QUERY_LOG_EVENT:
                    parseRowsQueryEvent((RowsQueryLogEvent) event);
                    break;
                case LogEvent.ANNOTATE_ROWS_EVENT:
                    break;
                case LogEvent.XID_EVENT:
                    break;
                default:
                    break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    } finally {
        try {
            fetcher.close();
        } catch (IOException e) {
            Assert.fail(e.getMessage());
        }
    }
}
Also used : MysqlConnector(com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector) FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher) UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) LogEvent(com.taobao.tddl.dbsync.binlog.LogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) XidLogEvent(com.taobao.tddl.dbsync.binlog.event.XidLogEvent) TableMapLogEvent(com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent) RotateLogEvent(com.taobao.tddl.dbsync.binlog.event.RotateLogEvent) QueryLogEvent(com.taobao.tddl.dbsync.binlog.event.QueryLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) RowsLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsLogEvent) InetSocketAddress(java.net.InetSocketAddress) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) LogDecoder(com.taobao.tddl.dbsync.binlog.LogDecoder) IOException(java.io.IOException) CanalParseException(com.alibaba.otter.canal.parse.exception.CanalParseException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 8 with DirectLogFetcher

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

the class MysqlBinlogEventPerformanceTest 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());
        LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
        LogContext context = new LogContext();
        AtomicLong sum = new AtomicLong(0);
        long start = System.currentTimeMillis();
        long last = 0;
        long end = 0;
        while (fetcher.fetch()) {
            decoder.decode(fetcher, context);
            sum.incrementAndGet();
            long current = sum.get();
            if (current - last >= 100000) {
                end = System.currentTimeMillis();
                long tps = ((current - last) * 1000) / (end - start);
                System.out.println(" total : " + sum + " , cost : " + (end - start) + " , tps : " + tps);
                last = current;
                start = end;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MysqlConnector(com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector) AtomicLong(java.util.concurrent.atomic.AtomicLong) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher) InetSocketAddress(java.net.InetSocketAddress) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) LogDecoder(com.taobao.tddl.dbsync.binlog.LogDecoder) IOException(java.io.IOException)

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