use of com.taobao.tddl.dbsync.binlog.event.LogHeader in project canal by alibaba.
the class LogEventConvert method buildQueryEntry.
private Entry buildQueryEntry(String queryString, LogHeader logHeader) {
Header header = createHeader(binlogFileName, logHeader, "", "", EventType.QUERY);
RowChange.Builder rowChangeBuider = RowChange.newBuilder();
rowChangeBuider.setSql(queryString);
rowChangeBuider.setEventType(EventType.QUERY);
return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
use of com.taobao.tddl.dbsync.binlog.event.LogHeader in project canal by alibaba.
the class LogDecoder method decode.
/**
* Decoding an event from binary-log buffer.
*
* @return <code>UknownLogEvent</code> if event type is unknown or skipped,
* <code>null</code> if buffer is not including a full event.
*/
public LogEvent decode(LogBuffer buffer, LogContext context) throws IOException {
final int limit = buffer.limit();
if (limit >= FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN) {
LogHeader header = new LogHeader(buffer, context.getFormatDescription());
final int len = header.getEventLen();
if (limit >= len) {
LogEvent event;
/* Checking binary-log's header */
if (handleSet.get(header.getType())) {
buffer.limit(len);
try {
/* Decoding binary-log to event */
event = decode(buffer, header, context);
} catch (IOException e) {
if (logger.isWarnEnabled())
logger.warn("Decoding " + LogEvent.getTypeName(header.getType()) + " failed from: " + context.getLogPosition(), e);
throw e;
} finally {
buffer.limit(limit);
/* Restore limit */
}
} else {
/* Ignore unsupported binary-log. */
event = new UnknownLogEvent(header);
}
/* consume this binary-log. */
buffer.consume(len);
return event;
}
}
/* Rewind buffer's position to 0. */
buffer.rewind();
return null;
}
Aggregations