Search in sources :

Example 1 with LogHeader

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());
}
Also used : Header(com.alibaba.otter.canal.protocol.CanalEntry.Header) LogHeader(com.taobao.tddl.dbsync.binlog.event.LogHeader) RowChange(com.alibaba.otter.canal.protocol.CanalEntry.RowChange)

Example 2 with LogHeader

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;
}
Also used : UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) ExecuteLoadLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadLogEvent) PreviousGtidsLogEvent(com.taobao.tddl.dbsync.binlog.event.PreviousGtidsLogEvent) BinlogCheckPointLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.BinlogCheckPointLogEvent) ExecuteLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.ExecuteLoadQueryLogEvent) BeginLoadQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.BeginLoadQueryLogEvent) IntvarLogEvent(com.taobao.tddl.dbsync.binlog.event.IntvarLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) RandLogEvent(com.taobao.tddl.dbsync.binlog.event.RandLogEvent) XidLogEvent(com.taobao.tddl.dbsync.binlog.event.XidLogEvent) AppendBlockLogEvent(com.taobao.tddl.dbsync.binlog.event.AppendBlockLogEvent) HeartbeatLogEvent(com.taobao.tddl.dbsync.binlog.event.HeartbeatLogEvent) TableMapLogEvent(com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent) RotateLogEvent(com.taobao.tddl.dbsync.binlog.event.RotateLogEvent) QueryLogEvent(com.taobao.tddl.dbsync.binlog.event.QueryLogEvent) MariaGtidLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidLogEvent) DeleteFileLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteFileLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) StopLogEvent(com.taobao.tddl.dbsync.binlog.event.StopLogEvent) UserVarLogEvent(com.taobao.tddl.dbsync.binlog.event.UserVarLogEvent) FormatDescriptionLogEvent(com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent) IgnorableLogEvent(com.taobao.tddl.dbsync.binlog.event.IgnorableLogEvent) MariaGtidListLogEvent(com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidListLogEvent) GtidLogEvent(com.taobao.tddl.dbsync.binlog.event.GtidLogEvent) IncidentLogEvent(com.taobao.tddl.dbsync.binlog.event.IncidentLogEvent) RowsLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsLogEvent) UnknownLogEvent(com.taobao.tddl.dbsync.binlog.event.UnknownLogEvent) CreateFileLogEvent(com.taobao.tddl.dbsync.binlog.event.CreateFileLogEvent) LoadLogEvent(com.taobao.tddl.dbsync.binlog.event.LoadLogEvent) UnknownLogEvent(com.taobao.tddl.dbsync.binlog.event.UnknownLogEvent) IOException(java.io.IOException) LogHeader(com.taobao.tddl.dbsync.binlog.event.LogHeader)

Aggregations

LogHeader (com.taobao.tddl.dbsync.binlog.event.LogHeader)2 Header (com.alibaba.otter.canal.protocol.CanalEntry.Header)1 RowChange (com.alibaba.otter.canal.protocol.CanalEntry.RowChange)1 AppendBlockLogEvent (com.taobao.tddl.dbsync.binlog.event.AppendBlockLogEvent)1 BeginLoadQueryLogEvent (com.taobao.tddl.dbsync.binlog.event.BeginLoadQueryLogEvent)1 CreateFileLogEvent (com.taobao.tddl.dbsync.binlog.event.CreateFileLogEvent)1 DeleteFileLogEvent (com.taobao.tddl.dbsync.binlog.event.DeleteFileLogEvent)1 DeleteRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent)1 ExecuteLoadLogEvent (com.taobao.tddl.dbsync.binlog.event.ExecuteLoadLogEvent)1 ExecuteLoadQueryLogEvent (com.taobao.tddl.dbsync.binlog.event.ExecuteLoadQueryLogEvent)1 FormatDescriptionLogEvent (com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent)1 GtidLogEvent (com.taobao.tddl.dbsync.binlog.event.GtidLogEvent)1 HeartbeatLogEvent (com.taobao.tddl.dbsync.binlog.event.HeartbeatLogEvent)1 IgnorableLogEvent (com.taobao.tddl.dbsync.binlog.event.IgnorableLogEvent)1 IncidentLogEvent (com.taobao.tddl.dbsync.binlog.event.IncidentLogEvent)1 IntvarLogEvent (com.taobao.tddl.dbsync.binlog.event.IntvarLogEvent)1 LoadLogEvent (com.taobao.tddl.dbsync.binlog.event.LoadLogEvent)1 PreviousGtidsLogEvent (com.taobao.tddl.dbsync.binlog.event.PreviousGtidsLogEvent)1 QueryLogEvent (com.taobao.tddl.dbsync.binlog.event.QueryLogEvent)1 RandLogEvent (com.taobao.tddl.dbsync.binlog.event.RandLogEvent)1