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();
}
Aggregations