Search in sources :

Example 1 with XidEventData

use of com.github.shyiko.mysql.binlog.event.XidEventData 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 2 with XidEventData

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

the class EventProcessor method processXidEvent.

private void processXidEvent(Event event) {
    EventHeaderV4 header = event.getHeader();
    XidEventData data = event.getData();
    String binlogFilename = binaryLogClient.getBinlogFilename();
    Long position = header.getNextPosition();
    Long xid = data.getXid();
    BinlogPosition binlogPosition = new BinlogPosition(binlogFilename, position);
    transaction.setNextBinlogPosition(binlogPosition);
    transaction.setXid(xid);
    replicator.commit(transaction, true);
    transaction = new Transaction(config);
}
Also used : XidEventData(com.github.shyiko.mysql.binlog.event.XidEventData) EventHeaderV4(com.github.shyiko.mysql.binlog.event.EventHeaderV4) BinlogPosition(org.apache.rocketmq.mysql.position.BinlogPosition)

Aggregations

EventHeaderV4 (com.github.shyiko.mysql.binlog.event.EventHeaderV4)2 XidEventData (com.github.shyiko.mysql.binlog.event.XidEventData)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 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 UpdateRowsEventData (com.github.shyiko.mysql.binlog.event.UpdateRowsEventData)1 WriteRowsEventData (com.github.shyiko.mysql.binlog.event.WriteRowsEventData)1 BinlogPosition (org.apache.rocketmq.mysql.position.BinlogPosition)1