Search in sources :

Example 1 with UpdateRowsEventData

use of com.github.shyiko.mysql.binlog.event.UpdateRowsEventData in project debezium by debezium.

the class BinlogReader method handleUpdate.

/**
 * Generate source records for the supplied event with an {@link UpdateRowsEventData}.
 *
 * @param event the database change data event to be processed; may not be null
 * @throws InterruptedException if this thread is interrupted while blocking
 */
protected void handleUpdate(Event event) throws InterruptedException {
    if (skipEvent) {
        // We can skip this because we should already be at least this far ...
        logger.debug("Skipping previously processed row event: {}", event);
        return;
    }
    if (ignoreDmlEventByGtidSource) {
        logger.debug("Skipping DML event because this GTID source is filtered: {}", event);
        return;
    }
    UpdateRowsEventData update = unwrapData(event);
    long tableNumber = update.getTableId();
    BitSet includedColumns = update.getIncludedColumns();
    // BitSet includedColumnsBefore = update.getIncludedColumnsBeforeUpdate();
    RecordsForTable recordMaker = recordMakers.forTable(tableNumber, includedColumns, super::enqueueRecord);
    if (recordMaker != null) {
        List<Entry<Serializable[], Serializable[]>> rows = update.getRows();
        Long ts = context.getClock().currentTimeInMillis();
        int count = 0;
        int numRows = rows.size();
        if (startingRowNumber < numRows) {
            for (int row = startingRowNumber; row != numRows; ++row) {
                Map.Entry<Serializable[], Serializable[]> changes = rows.get(row);
                Serializable[] before = changes.getKey();
                Serializable[] after = changes.getValue();
                count += recordMaker.update(before, after, ts, row, numRows);
            }
            if (logger.isDebugEnabled()) {
                if (startingRowNumber != 0) {
                    logger.debug("Recorded {} update record(s) for last {} row(s) in event: {}", count, numRows - startingRowNumber, event);
                } else {
                    logger.debug("Recorded {} update record(s) for event: {}", count, event);
                }
            }
        } else {
            // All rows were previously processed ...
            logger.debug("Skipping previously processed update event: {}", event);
        }
    } else {
        informAboutUnknownTableIfRequired(event, recordMakers.getTableIdFromTableNumber(tableNumber), "update row");
    }
    startingRowNumber = 0;
}
Also used : Entry(java.util.Map.Entry) Serializable(java.io.Serializable) UpdateRowsEventData(com.github.shyiko.mysql.binlog.event.UpdateRowsEventData) BitSet(java.util.BitSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordsForTable(io.debezium.connector.mysql.RecordMakers.RecordsForTable) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 2 with UpdateRowsEventData

use of com.github.shyiko.mysql.binlog.event.UpdateRowsEventData in project SpinalTap by airbnb.

the class MysqlSource method toBinlogEvent.

public static BinlogEvent toBinlogEvent(Event event, BinlogFilePos filePos) {
    EventHeaderV4 header = event.getHeader();
    EventType eventType = header.getEventType();
    long serverId = header.getServerId();
    long timestamp = header.getTimestamp();
    if (EventType.isWrite(eventType)) {
        WriteRowsEventData data = event.getData();
        return new WriteEvent(data.getTableId(), serverId, timestamp, filePos, data.getRows());
    } else if (EventType.isUpdate(eventType)) {
        UpdateRowsEventData data = event.getData();
        return new UpdateEvent(data.getTableId(), serverId, timestamp, filePos, data.getRows());
    } else if (EventType.isDelete(eventType)) {
        DeleteRowsEventData data = event.getData();
        return new DeleteEvent(data.getTableId(), serverId, timestamp, filePos, data.getRows());
    } else {
        switch(eventType) {
            case TABLE_MAP:
                TableMapEventData tableMapData = event.getData();
                return new TableMapEvent(tableMapData.getTableId(), serverId, timestamp, filePos, tableMapData.getDatabase(), tableMapData.getTable(), tableMapData.getColumnTypes());
            case XID:
                XidEventData xidData = event.getData();
                return new XidEvent(serverId, timestamp, filePos, xidData.getXid());
            case QUERY:
                QueryEventData queryData = event.getData();
                return new QueryEvent(serverId, timestamp, filePos, queryData.getDatabase(), queryData.getSql());
            case FORMAT_DESCRIPTION:
                return new StartEvent(serverId, timestamp, filePos);
            default:
                return null;
        }
    }
}
Also used : WriteEvent(com.airbnb.spinaltap.mysql.event.WriteEvent) QueryEventData(com.github.shyiko.mysql.binlog.event.QueryEventData) TableMapEvent(com.airbnb.spinaltap.mysql.event.TableMapEvent) WriteRowsEventData(com.github.shyiko.mysql.binlog.event.WriteRowsEventData) EventType(com.github.shyiko.mysql.binlog.event.EventType) UpdateRowsEventData(com.github.shyiko.mysql.binlog.event.UpdateRowsEventData) DeleteRowsEventData(com.github.shyiko.mysql.binlog.event.DeleteRowsEventData) XidEventData(com.github.shyiko.mysql.binlog.event.XidEventData) QueryEvent(com.airbnb.spinaltap.mysql.event.QueryEvent) DeleteEvent(com.airbnb.spinaltap.mysql.event.DeleteEvent) TableMapEventData(com.github.shyiko.mysql.binlog.event.TableMapEventData) StartEvent(com.airbnb.spinaltap.mysql.event.StartEvent) EventHeaderV4(com.github.shyiko.mysql.binlog.event.EventHeaderV4) XidEvent(com.airbnb.spinaltap.mysql.event.XidEvent) UpdateEvent(com.airbnb.spinaltap.mysql.event.UpdateEvent)

Example 3 with UpdateRowsEventData

use of com.github.shyiko.mysql.binlog.event.UpdateRowsEventData in project rocketmq-externals by apache.

the class EventProcessor method processUpdateEvent.

private void processUpdateEvent(Event event) {
    UpdateRowsEventData data = event.getData();
    Long tableId = data.getTableId();
    List<Map.Entry<Serializable[], Serializable[]>> list = data.getRows();
    for (Map.Entry<Serializable[], Serializable[]> entry : list) {
        addRow("UPDATE", tableId, entry.getValue());
    }
}
Also used : Serializable(java.io.Serializable) UpdateRowsEventData(com.github.shyiko.mysql.binlog.event.UpdateRowsEventData) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

UpdateRowsEventData (com.github.shyiko.mysql.binlog.event.UpdateRowsEventData)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DeleteEvent (com.airbnb.spinaltap.mysql.event.DeleteEvent)1 QueryEvent (com.airbnb.spinaltap.mysql.event.QueryEvent)1 StartEvent (com.airbnb.spinaltap.mysql.event.StartEvent)1 TableMapEvent (com.airbnb.spinaltap.mysql.event.TableMapEvent)1 UpdateEvent (com.airbnb.spinaltap.mysql.event.UpdateEvent)1 WriteEvent (com.airbnb.spinaltap.mysql.event.WriteEvent)1 XidEvent (com.airbnb.spinaltap.mysql.event.XidEvent)1 DeleteRowsEventData (com.github.shyiko.mysql.binlog.event.DeleteRowsEventData)1 EventHeaderV4 (com.github.shyiko.mysql.binlog.event.EventHeaderV4)1 EventType (com.github.shyiko.mysql.binlog.event.EventType)1 QueryEventData (com.github.shyiko.mysql.binlog.event.QueryEventData)1 TableMapEventData (com.github.shyiko.mysql.binlog.event.TableMapEventData)1 WriteRowsEventData (com.github.shyiko.mysql.binlog.event.WriteRowsEventData)1 XidEventData (com.github.shyiko.mysql.binlog.event.XidEventData)1 RecordsForTable (io.debezium.connector.mysql.RecordMakers.RecordsForTable)1 BitSet (java.util.BitSet)1