Search in sources :

Example 1 with DeleteRowsLogEvent

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

the class MysqlBinlogParsePerformanceTest method consumer.

public static void consumer(BlockingQueue<LogBuffer> buffer) throws IOException, InterruptedException {
    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 (true) {
        LogEvent event = null;
        event = decoder.decode(buffer.take(), context);
        int eventType = event.getHeader().getType();
        switch(eventType) {
            case LogEvent.ROTATE_EVENT:
                break;
            case LogEvent.WRITE_ROWS_EVENT_V1:
            case LogEvent.WRITE_ROWS_EVENT:
                parseRowsEvent((WriteRowsLogEvent) event, sum);
                break;
            case LogEvent.UPDATE_ROWS_EVENT_V1:
            case LogEvent.PARTIAL_UPDATE_ROWS_EVENT:
            case LogEvent.UPDATE_ROWS_EVENT:
                parseRowsEvent((UpdateRowsLogEvent) event, sum);
                break;
            case LogEvent.DELETE_ROWS_EVENT_V1:
            case LogEvent.DELETE_ROWS_EVENT:
                parseRowsEvent((DeleteRowsLogEvent) event, sum);
                break;
            case LogEvent.XID_EVENT:
                sum.incrementAndGet();
                break;
            case LogEvent.QUERY_EVENT:
                sum.incrementAndGet();
                break;
            default:
                break;
        }
        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;
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) LogEvent(com.taobao.tddl.dbsync.binlog.LogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) TableMapLogEvent(com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) RowsLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsLogEvent) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) LogDecoder(com.taobao.tddl.dbsync.binlog.LogDecoder)

Example 2 with DeleteRowsLogEvent

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

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

the class FileLogFetcherTest method testSimple.

@Test
public void testSimple() {
    FileLogFetcher fetcher = new FileLogFetcher(1024 * 16);
    try {
        LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
        LogContext context = new LogContext();
        File current = new File(directory, "mysql-bin.000001");
        fetcher.open(current, 2051L);
        context.setLogPosition(new LogPosition(current.getName()));
        while (fetcher.fetch()) {
            LogEvent event = null;
            event = decoder.decode(fetcher, context);
            if (event != null) {
                int eventType = event.getHeader().getType();
                switch(eventType) {
                    case LogEvent.ROTATE_EVENT:
                        binlogFileName = ((RotateLogEvent) event).getFilename();
                        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:
                        parseAnnotateRowsEvent((AnnotateRowsEvent) event);
                        break;
                    case LogEvent.XID_EVENT:
                        parseXidEvent((XidLogEvent) event);
                        break;
                    default:
                        break;
                }
            }
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    } finally {
        try {
            fetcher.close();
        } catch (IOException e) {
            Assert.fail(e.getMessage());
        }
    }
}
Also used : UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) XidLogEvent(com.taobao.tddl.dbsync.binlog.event.XidLogEvent) RotateLogEvent(com.taobao.tddl.dbsync.binlog.event.RotateLogEvent) QueryLogEvent(com.taobao.tddl.dbsync.binlog.event.QueryLogEvent) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with DeleteRowsLogEvent

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

the class LogDecoder method decode.

/**
 * Deserialize an event from buffer.
 *
 * @return <code>UknownLogEvent</code> if event type is unknown or skipped.
 */
public static LogEvent decode(LogBuffer buffer, LogHeader header, LogContext context) throws IOException {
    FormatDescriptionLogEvent descriptionEvent = context.getFormatDescription();
    LogPosition logPosition = context.getLogPosition();
    int checksumAlg = LogEvent.BINLOG_CHECKSUM_ALG_UNDEF;
    if (header.getType() != LogEvent.FORMAT_DESCRIPTION_EVENT) {
        checksumAlg = descriptionEvent.header.getChecksumAlg();
    } else {
        // 如果是format事件自己,也需要处理checksum
        checksumAlg = header.getChecksumAlg();
    }
    if (checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_OFF && checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_UNDEF) {
        // remove checksum bytes
        buffer.limit(header.getEventLen() - LogEvent.BINLOG_CHECKSUM_LEN);
    }
    GTIDSet gtidSet = context.getGtidSet();
    LogEvent gtidLogEvent = context.getGtidLogEvent();
    switch(header.getType()) {
        case LogEvent.QUERY_EVENT:
            {
                QueryLogEvent event = new QueryLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.XID_EVENT:
            {
                XidLogEvent event = new XidLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.TABLE_MAP_EVENT:
            {
                TableMapLogEvent mapEvent = new TableMapLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                context.putTable(mapEvent);
                return mapEvent;
            }
        case LogEvent.WRITE_ROWS_EVENT_V1:
        case LogEvent.WRITE_ROWS_EVENT:
            {
                RowsLogEvent event = new WriteRowsLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                event.fillTable(context);
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.UPDATE_ROWS_EVENT_V1:
        case LogEvent.UPDATE_ROWS_EVENT:
            {
                RowsLogEvent event = new UpdateRowsLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                event.fillTable(context);
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.DELETE_ROWS_EVENT_V1:
        case LogEvent.DELETE_ROWS_EVENT:
            {
                RowsLogEvent event = new DeleteRowsLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                event.fillTable(context);
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.ROTATE_EVENT:
            {
                RotateLogEvent event = new RotateLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition = new LogPosition(event.getFilename(), event.getPosition());
                context.setLogPosition(logPosition);
                return event;
            }
        case LogEvent.LOAD_EVENT:
        case LogEvent.NEW_LOAD_EVENT:
            {
                LoadLogEvent event = new LoadLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.SLAVE_EVENT:
            /* can never happen (unused event) */
            {
                if (logger.isWarnEnabled())
                    logger.warn("Skipping unsupported SLAVE_EVENT from: " + context.getLogPosition());
                break;
            }
        case LogEvent.CREATE_FILE_EVENT:
            {
                CreateFileLogEvent event = new CreateFileLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.APPEND_BLOCK_EVENT:
            {
                AppendBlockLogEvent event = new AppendBlockLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.DELETE_FILE_EVENT:
            {
                DeleteFileLogEvent event = new DeleteFileLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.EXEC_LOAD_EVENT:
            {
                ExecuteLoadLogEvent event = new ExecuteLoadLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.START_EVENT_V3:
            {
                /* This is sent only by MySQL <=4.x */
                StartLogEventV3 event = new StartLogEventV3(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.STOP_EVENT:
            {
                StopLogEvent event = new StopLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.INTVAR_EVENT:
            {
                IntvarLogEvent event = new IntvarLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.RAND_EVENT:
            {
                RandLogEvent event = new RandLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.USER_VAR_EVENT:
            {
                UserVarLogEvent event = new UserVarLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.FORMAT_DESCRIPTION_EVENT:
            {
                descriptionEvent = new FormatDescriptionLogEvent(header, buffer, descriptionEvent);
                context.setFormatDescription(descriptionEvent);
                return descriptionEvent;
            }
        case LogEvent.PRE_GA_WRITE_ROWS_EVENT:
            {
                if (logger.isWarnEnabled())
                    logger.warn("Skipping unsupported PRE_GA_WRITE_ROWS_EVENT from: " + context.getLogPosition());
                // description_event);
                break;
            }
        case LogEvent.PRE_GA_UPDATE_ROWS_EVENT:
            {
                if (logger.isWarnEnabled())
                    logger.warn("Skipping unsupported PRE_GA_UPDATE_ROWS_EVENT from: " + context.getLogPosition());
                // description_event);
                break;
            }
        case LogEvent.PRE_GA_DELETE_ROWS_EVENT:
            {
                if (logger.isWarnEnabled())
                    logger.warn("Skipping unsupported PRE_GA_DELETE_ROWS_EVENT from: " + context.getLogPosition());
                // description_event);
                break;
            }
        case LogEvent.BEGIN_LOAD_QUERY_EVENT:
            {
                BeginLoadQueryLogEvent event = new BeginLoadQueryLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.EXECUTE_LOAD_QUERY_EVENT:
            {
                ExecuteLoadQueryLogEvent event = new ExecuteLoadQueryLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.INCIDENT_EVENT:
            {
                IncidentLogEvent event = new IncidentLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.HEARTBEAT_LOG_EVENT:
            {
                HeartbeatLogEvent event = new HeartbeatLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.IGNORABLE_LOG_EVENT:
            {
                IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.ROWS_QUERY_LOG_EVENT:
            {
                RowsQueryLogEvent event = new RowsQueryLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.PARTIAL_UPDATE_ROWS_EVENT:
            {
                RowsLogEvent event = new UpdateRowsLogEvent(header, buffer, descriptionEvent, true);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                event.fillTable(context);
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.GTID_LOG_EVENT:
        case LogEvent.ANONYMOUS_GTID_LOG_EVENT:
            {
                GtidLogEvent event = new GtidLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                if (gtidSet != null) {
                    gtidSet.update(event.getGtidStr());
                    // update latest gtid
                    header.putGtid(gtidSet, event);
                }
                // update current gtid event to context
                context.setGtidLogEvent(event);
                return event;
            }
        case LogEvent.PREVIOUS_GTIDS_LOG_EVENT:
            {
                PreviousGtidsLogEvent event = new PreviousGtidsLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.TRANSACTION_CONTEXT_EVENT:
            {
                TransactionContextLogEvent event = new TransactionContextLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.VIEW_CHANGE_EVENT:
            {
                ViewChangeEvent event = new ViewChangeEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.XA_PREPARE_LOG_EVENT:
            {
                XaPrepareLogEvent event = new XaPrepareLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.ANNOTATE_ROWS_EVENT:
            {
                AnnotateRowsEvent event = new AnnotateRowsEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                header.putGtid(context.getGtidSet(), gtidLogEvent);
                return event;
            }
        case LogEvent.BINLOG_CHECKPOINT_EVENT:
            {
                BinlogCheckPointLogEvent event = new BinlogCheckPointLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        case LogEvent.GTID_EVENT:
            {
                MariaGtidLogEvent event = new MariaGtidLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                if (gtidSet != null) {
                    gtidSet.update(event.getGtidStr());
                    // update latest gtid
                    header.putGtid(gtidSet, event);
                }
                // update current gtid event to context
                context.setGtidLogEvent(event);
                return event;
            }
        case LogEvent.GTID_LIST_EVENT:
            {
                MariaGtidListLogEvent event = new MariaGtidListLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                if (gtidSet != null) {
                    gtidSet.update(event.getGtidStr());
                    // update latest gtid
                    header.putGtid(gtidSet, event);
                }
                // update current gtid event to context
                context.setGtidLogEvent(event);
                return event;
            }
        case LogEvent.START_ENCRYPTION_EVENT:
            {
                StartEncryptionLogEvent event = new StartEncryptionLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            }
        default:
            /*
                 * Create an object of Ignorable_log_event for unrecognized
                 * sub-class. So that SLAVE SQL THREAD will only update the
                 * position and continue.
                 */
            if ((buffer.getUint16(LogEvent.FLAGS_OFFSET) & LogEvent.LOG_EVENT_IGNORABLE_F) > 0) {
                IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
                /* updating position in context */
                logPosition.position = header.getLogPos();
                return event;
            } else {
                if (logger.isWarnEnabled()) {
                    logger.warn("Skipping unrecognized binlog event " + LogEvent.getTypeName(header.getType()) + " from: " + context.getLogPosition());
                }
            }
    }
    /* updating position in context */
    logPosition.position = header.getLogPos();
    /* Unknown or unsupported log event */
    return new UnknownLogEvent(header);
}
Also used : FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) PreviousGtidsLogEvent(com.taobao.tddl.dbsync.binlog.event.PreviousGtidsLogEvent) StartEncryptionLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.StartEncryptionLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) MariaGtidLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidLogEvent) GtidLogEvent(com.taobao.tddl.dbsync.binlog.event.GtidLogEvent) UserVarLogEvent(com.taobao.tddl.dbsync.binlog.event.UserVarLogEvent) UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) CreateFileLogEvent(com.taobao.tddl.dbsync.binlog.event.CreateFileLogEvent) StopLogEvent(com.taobao.tddl.dbsync.binlog.event.StopLogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) IncidentLogEvent(com.taobao.tddl.dbsync.binlog.event.IncidentLogEvent) BinlogCheckPointLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.BinlogCheckPointLogEvent) TransactionContextLogEvent(com.taobao.tddl.dbsync.binlog.event.TransactionContextLogEvent) ViewChangeEvent(com.taobao.tddl.dbsync.binlog.event.ViewChangeEvent) RandLogEvent(com.taobao.tddl.dbsync.binlog.event.RandLogEvent) BeginLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.BeginLoadQueryLogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) ExecuteLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadQueryLogEvent) BeginLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.BeginLoadQueryLogEvent) QueryLogEvent(com.taobao.tddl.dbsync.binlog.event.QueryLogEvent) ExecuteLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadQueryLogEvent) XidLogEvent(com.taobao.tddl.dbsync.binlog.event.XidLogEvent) TableMapLogEvent(com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent) DeleteFileLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteFileLogEvent) XaPrepareLogEvent(com.taobao.tddl.dbsync.binlog.event.XaPrepareLogEvent) UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) ExecuteLoadLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadLogEvent) PreviousGtidsLogEvent(com.taobao.tddl.dbsync.binlog.event.PreviousGtidsLogEvent) TransactionContextLogEvent(com.taobao.tddl.dbsync.binlog.event.TransactionContextLogEvent) BinlogCheckPointLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.BinlogCheckPointLogEvent) ExecuteLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadQueryLogEvent) BeginLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.BeginLoadQueryLogEvent) IntvarLogEvent(com.taobao.tddl.dbsync.binlog.event.IntvarLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) RandLogEvent(com.taobao.tddl.dbsync.binlog.event.RandLogEvent) XidLogEvent(com.taobao.tddl.dbsync.binlog.event.XidLogEvent) AppendBlockLogEvent(com.taobao.tddl.dbsync.binlog.event.AppendBlockLogEvent) HeartbeatLogEvent(com.taobao.tddl.dbsync.binlog.event.HeartbeatLogEvent) TableMapLogEvent(com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent) RotateLogEvent(com.taobao.tddl.dbsync.binlog.event.RotateLogEvent) QueryLogEvent(com.taobao.tddl.dbsync.binlog.event.QueryLogEvent) XaPrepareLogEvent(com.taobao.tddl.dbsync.binlog.event.XaPrepareLogEvent) MariaGtidLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidLogEvent) StartEncryptionLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.StartEncryptionLogEvent) DeleteFileLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteFileLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) StopLogEvent(com.taobao.tddl.dbsync.binlog.event.StopLogEvent) UserVarLogEvent(com.taobao.tddl.dbsync.binlog.event.UserVarLogEvent) FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) IgnorableLogEvent(com.taobao.tddl.dbsync.binlog.event.IgnorableLogEvent) MariaGtidListLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidListLogEvent) GtidLogEvent(com.taobao.tddl.dbsync.binlog.event.GtidLogEvent) IncidentLogEvent(com.taobao.tddl.dbsync.binlog.event.IncidentLogEvent) RowsLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsLogEvent) UnknownLogEvent(com.taobao.tddl.dbsync.binlog.event.UnknownLogEvent) CreateFileLogEvent(com.taobao.tddl.dbsync.binlog.event.CreateFileLogEvent) LoadLogEvent(com.taobao.tddl.dbsync.binlog.event.LoadLogEvent) UnknownLogEvent(com.taobao.tddl.dbsync.binlog.event.UnknownLogEvent) UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) RowsLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsLogEvent) RotateLogEvent(com.taobao.tddl.dbsync.binlog.event.RotateLogEvent) AnnotateRowsEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.AnnotateRowsEvent) GTIDSet(com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet) ExecuteLoadLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadLogEvent) HeartbeatLogEvent(com.taobao.tddl.dbsync.binlog.event.HeartbeatLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) StartLogEventV3(com.taobao.tddl.dbsync.binlog.event.StartLogEventV3) ExecuteLoadLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadLogEvent) LoadLogEvent(com.taobao.tddl.dbsync.binlog.event.LoadLogEvent) IgnorableLogEvent(com.taobao.tddl.dbsync.binlog.event.IgnorableLogEvent) MariaGtidLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidLogEvent) MariaGtidListLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidListLogEvent) IntvarLogEvent(com.taobao.tddl.dbsync.binlog.event.IntvarLogEvent) AppendBlockLogEvent(com.taobao.tddl.dbsync.binlog.event.AppendBlockLogEvent)

Example 5 with DeleteRowsLogEvent

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

the class DirectLogFetcherTest method testSimple.

@Test
public void testSimple() {
    DirectLogFetcher fecther = new DirectLogFetcher();
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306", "root", "hello");
        Statement statement = connection.createStatement();
        statement.execute("SET @master_binlog_checksum='@@global.binlog_checksum'");
        statement.execute("SET @mariadb_slave_capability='" + LogEvent.MARIA_SLAVE_CAPABILITY_MINE + "'");
        fecther.open(connection, "mysql-bin.000007", 89797036L, 2);
        LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
        LogContext context = new LogContext();
        while (fecther.fetch()) {
            LogEvent event = decoder.decode(fecther, context);
            int eventType = event.getHeader().getType();
            switch(eventType) {
                case LogEvent.ROTATE_EVENT:
                    binlogFileName = ((RotateLogEvent) event).getFilename();
                    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:
                    parseAnnotateRowsEvent((AnnotateRowsEvent) event);
                    break;
                case LogEvent.XID_EVENT:
                    parseXidEvent((XidLogEvent) event);
                    break;
                default:
                    break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    } finally {
        try {
            fecther.close();
        } catch (IOException e) {
            Assert.fail(e.getMessage());
        }
    }
}
Also used : UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) XidLogEvent(com.taobao.tddl.dbsync.binlog.event.XidLogEvent) RotateLogEvent(com.taobao.tddl.dbsync.binlog.event.RotateLogEvent) QueryLogEvent(com.taobao.tddl.dbsync.binlog.event.QueryLogEvent) Statement(java.sql.Statement) Connection(java.sql.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

DeleteRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent)5 UpdateRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent)5 WriteRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent)5 QueryLogEvent (com.taobao.tddl.dbsync.binlog.event.QueryLogEvent)4 RotateLogEvent (com.taobao.tddl.dbsync.binlog.event.RotateLogEvent)4 RowsQueryLogEvent (com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent)4 XidLogEvent (com.taobao.tddl.dbsync.binlog.event.XidLogEvent)4 RowsLogEvent (com.taobao.tddl.dbsync.binlog.event.RowsLogEvent)3 TableMapLogEvent (com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 LogContext (com.taobao.tddl.dbsync.binlog.LogContext)2 LogDecoder (com.taobao.tddl.dbsync.binlog.LogDecoder)2 LogEvent (com.taobao.tddl.dbsync.binlog.LogEvent)2 FormatDescriptionLogEvent (com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent)2 MysqlConnector (com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector)1 GTIDSet (com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet)1 CanalParseException (com.alibaba.otter.canal.parse.exception.CanalParseException)1 DirectLogFetcher (com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher)1 AppendBlockLogEvent (com.taobao.tddl.dbsync.binlog.event.AppendBlockLogEvent)1