Search in sources :

Example 1 with DeleteRowsEventV2

use of com.google.code.or.binlog.impl.event.DeleteRowsEventV2 in project databus by linkedin.

the class ORListener method run.

@Override
public void run() {
    List<BinlogEventV4> eventList = new ArrayList<BinlogEventV4>();
    BinlogEventV4 event;
    while (!isShutdownRequested()) {
        if (isPauseRequested()) {
            LOG.info("Pause requested for ORListener. Pausing !!");
            signalPause();
            LOG.info("Pausing. Waiting for resume command");
            try {
                awaitUnPauseRequest();
            } catch (InterruptedException e) {
                _log.info("Interrupted !!");
            }
            LOG.info("Resuming ORListener !!");
            signalResumed();
            LOG.info("ORListener resumed !!");
        }
        eventList.clear();
        int eventNumber = _binlogEventQueue.drainTo(eventList);
        if (eventNumber == 0) {
            try {
                event = _binlogEventQueue.poll(_queueTimeoutMs, TimeUnit.MILLISECONDS);
                if (event != null) {
                    eventList.add(event);
                    eventNumber = eventList.size();
                }
            } catch (InterruptedException e) {
                _log.info("Interrupted when poll from _binlogEventQueue!!");
            }
        }
        for (int i = 0; i < eventNumber; i++) {
            event = eventList.get(i);
            if (event == null) {
                _log.error("Received null event");
                continue;
            }
            try {
                // Beginning of Txn
                if (event instanceof QueryEvent) {
                    QueryEvent qe = (QueryEvent) event;
                    String sql = qe.getSql().toString();
                    if ("BEGIN".equalsIgnoreCase(sql)) {
                        _isBeginTxnSeen = true;
                        _log.info("BEGIN sql: " + sql);
                        _currTxnSizeInBytes = event.getHeader().getEventLength();
                        startXtion(qe);
                        continue;
                    }
                } else if (event instanceof RotateEvent) {
                    RotateEvent re = (RotateEvent) event;
                    String fileName = re.getBinlogFileName().toString();
                    _log.info("File Rotated : FileName :" + fileName + ", _binlogFilePrefix :" + _binlogFilePrefix);
                    String fileNumStr = fileName.substring(fileName.lastIndexOf(_binlogFilePrefix) + _binlogFilePrefix.length() + 1);
                    _currFileNum = Integer.parseInt(fileNumStr);
                    _tableMapEvents.clear();
                    continue;
                }
                if (!_isBeginTxnSeen) {
                    if (_log.isDebugEnabled()) {
                        _log.debug("Skipping event (" + event + ") as this is before the start of first transaction");
                    }
                    continue;
                }
                _currTxnSizeInBytes += event.getHeader().getEventLength();
                if (event instanceof QueryEvent) {
                    QueryEvent qe = (QueryEvent) event;
                    String sql = qe.getSql().toString();
                    if ("COMMIT".equalsIgnoreCase(sql)) {
                        _log.debug("COMMIT sql: " + sql);
                        endXtion(qe);
                        continue;
                    } else if ("ROLLBACK".equalsIgnoreCase(sql)) {
                        _log.debug("ROLLBACK sql: " + sql);
                        rollbackXtion(qe);
                        continue;
                    } else {
                        // Ignore DDL statements for now
                        _log.debug("Likely DDL statement sql: " + sql);
                        continue;
                    }
                } else if (event instanceof XidEvent) {
                    XidEvent xe = (XidEvent) event;
                    long xid = xe.getXid();
                    _log.debug("Treating XID event with xid = " + xid + " as commit for the transaction");
                    endXtion(xe);
                    continue;
                } else if (event instanceof FormatDescriptionEvent) {
                    // we don't need process this event
                    _log.info("received FormatDescriptionEvent event");
                    continue;
                } else if (event instanceof WriteRowsEvent) {
                    WriteRowsEvent wre = (WriteRowsEvent) event;
                    insertRows(wre);
                } else if (event instanceof WriteRowsEventV2) {
                    WriteRowsEventV2 wre = (WriteRowsEventV2) event;
                    insertRows(wre);
                } else if (event instanceof UpdateRowsEvent) {
                    UpdateRowsEvent ure = (UpdateRowsEvent) event;
                    updateRows(ure);
                } else if (event instanceof UpdateRowsEventV2) {
                    UpdateRowsEventV2 ure = (UpdateRowsEventV2) event;
                    updateRows(ure);
                } else if (event instanceof DeleteRowsEventV2) {
                    DeleteRowsEventV2 dre = (DeleteRowsEventV2) event;
                    deleteRows(dre);
                } else if (event instanceof DeleteRowsEvent) {
                    DeleteRowsEvent dre = (DeleteRowsEvent) event;
                    deleteRows(dre);
                } else if (event instanceof TableMapEvent) {
                    TableMapEvent tme = (TableMapEvent) event;
                    processTableMapEvent(tme);
                } else {
                    _log.warn("Skipping !! Unknown OR event e: " + event);
                    continue;
                }
                if (_log.isDebugEnabled()) {
                    _log.debug("e: " + event);
                }
            } catch (Exception e) {
                _log.error("failed to process binlog event, event: " + event, e);
            }
        }
    }
    _log.info("ORListener Thread done");
    doShutdownNotify();
}
Also used : RotateEvent(com.google.code.or.binlog.impl.event.RotateEvent) DeleteRowsEvent(com.google.code.or.binlog.impl.event.DeleteRowsEvent) TableMapEvent(com.google.code.or.binlog.impl.event.TableMapEvent) FormatDescriptionEvent(com.google.code.or.binlog.impl.event.FormatDescriptionEvent) WriteRowsEvent(com.google.code.or.binlog.impl.event.WriteRowsEvent) ArrayList(java.util.ArrayList) BinlogEventV4(com.google.code.or.binlog.BinlogEventV4) AbstractBinlogEventV4(com.google.code.or.binlog.impl.event.AbstractBinlogEventV4) QueryEvent(com.google.code.or.binlog.impl.event.QueryEvent) NoSuchSchemaException(com.linkedin.databus2.schemas.NoSuchSchemaException) DatabusException(com.linkedin.databus2.core.DatabusException) DatabusRuntimeException(com.linkedin.databus.core.DatabusRuntimeException) WriteRowsEventV2(com.google.code.or.binlog.impl.event.WriteRowsEventV2) UpdateRowsEvent(com.google.code.or.binlog.impl.event.UpdateRowsEvent) XidEvent(com.google.code.or.binlog.impl.event.XidEvent) UpdateRowsEventV2(com.google.code.or.binlog.impl.event.UpdateRowsEventV2) DeleteRowsEventV2(com.google.code.or.binlog.impl.event.DeleteRowsEventV2)

Aggregations

BinlogEventV4 (com.google.code.or.binlog.BinlogEventV4)1 AbstractBinlogEventV4 (com.google.code.or.binlog.impl.event.AbstractBinlogEventV4)1 DeleteRowsEvent (com.google.code.or.binlog.impl.event.DeleteRowsEvent)1 DeleteRowsEventV2 (com.google.code.or.binlog.impl.event.DeleteRowsEventV2)1 FormatDescriptionEvent (com.google.code.or.binlog.impl.event.FormatDescriptionEvent)1 QueryEvent (com.google.code.or.binlog.impl.event.QueryEvent)1 RotateEvent (com.google.code.or.binlog.impl.event.RotateEvent)1 TableMapEvent (com.google.code.or.binlog.impl.event.TableMapEvent)1 UpdateRowsEvent (com.google.code.or.binlog.impl.event.UpdateRowsEvent)1 UpdateRowsEventV2 (com.google.code.or.binlog.impl.event.UpdateRowsEventV2)1 WriteRowsEvent (com.google.code.or.binlog.impl.event.WriteRowsEvent)1 WriteRowsEventV2 (com.google.code.or.binlog.impl.event.WriteRowsEventV2)1 XidEvent (com.google.code.or.binlog.impl.event.XidEvent)1 DatabusRuntimeException (com.linkedin.databus.core.DatabusRuntimeException)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 NoSuchSchemaException (com.linkedin.databus2.schemas.NoSuchSchemaException)1 ArrayList (java.util.ArrayList)1