Java Code Examples for com.taobao.tddl.dbsync.binlog.LogEvent#ROTATE_EVENT

The following examples show how to use com.taobao.tddl.dbsync.binlog.LogEvent#ROTATE_EVENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogHeader.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public LogHeader(LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
    when = buffer.getUint32();
    type = buffer.getUint8(); // LogEvent.EVENT_TYPE_OFFSET;
    serverId = buffer.getUint32(); // LogEvent.SERVER_ID_OFFSET;
    eventLen = (int) buffer.getUint32(); // LogEvent.EVENT_LEN_OFFSET;

    if (descriptionEvent.binlogVersion == 1) {
        logPos = 0;
        flags = 0;
        return;
    }

    /* 4.0 or newer */
    logPos = buffer.getUint32(); // LogEvent.LOG_POS_OFFSET
    /*
     * If the log is 4.0 (so here it can only be a 4.0 relay log read by the
     * SQL thread or a 4.0 master binlog read by the I/O thread), log_pos is
     * the beginning of the event: we transform it into the end of the
     * event, which is more useful. But how do you know that the log is 4.0:
     * you know it if description_event is version 3 *and* you are not
     * reading a Format_desc (remember that mysqlbinlog starts by assuming
     * that 5.0 logs are in 4.0 format, until it finds a Format_desc).
     */
    if (descriptionEvent.binlogVersion == 3 && type < LogEvent.FORMAT_DESCRIPTION_EVENT && logPos != 0) {
        /*
         * If log_pos=0, don't change it. log_pos==0 is a marker to mean
         * "don't change rli->group_master_log_pos" (see
         * inc_group_relay_log_pos()). As it is unreal log_pos, adding the
         * event len's is nonsense. For example, a fake Rotate event should
         * not have its log_pos (which is 0) changed or it will modify
         * Exec_master_log_pos in SHOW SLAVE STATUS, displaying a nonsense
         * value of (a non-zero offset which does not exist in the master's
         * binlog, so which will cause problems if the user uses this value
         * in CHANGE MASTER).
         */
        logPos += eventLen; /* purecov: inspected */
    }

    flags = buffer.getUint16(); // LogEvent.FLAGS_OFFSET
    if ((type == LogEvent.FORMAT_DESCRIPTION_EVENT) || (type == LogEvent.ROTATE_EVENT)) {
        /*
         * These events always have a header which stops here (i.e. their
         * header is FROZEN).
         */
        /*
         * Initialization to zero of all other Log_event members as they're
         * not specified. Currently there are no such members; in the future
         * there will be an event UID (but Format_description and Rotate
         * don't need this UID, as they are not propagated through
         * --log-slave-updates (remember the UID is used to not play a query
         * twice when you have two masters which are slaves of a 3rd
         * master). Then we are done.
         */

        if (type == LogEvent.FORMAT_DESCRIPTION_EVENT) {
            int commonHeaderLen = buffer.getUint8(FormatDescriptionLogEvent.LOG_EVENT_MINIMAL_HEADER_LEN
                                                  + FormatDescriptionLogEvent.ST_COMMON_HEADER_LEN_OFFSET);
            buffer.position(commonHeaderLen + FormatDescriptionLogEvent.ST_SERVER_VER_OFFSET);
            String serverVersion = buffer.getFixString(FormatDescriptionLogEvent.ST_SERVER_VER_LEN); // ST_SERVER_VER_OFFSET
            int versionSplit[] = new int[] { 0, 0, 0 };
            FormatDescriptionLogEvent.doServerVersionSplit(serverVersion, versionSplit);
            checksumAlg = LogEvent.BINLOG_CHECKSUM_ALG_UNDEF;
            if (FormatDescriptionLogEvent.versionProduct(versionSplit) >= FormatDescriptionLogEvent.checksumVersionProduct) {
                buffer.position(eventLen - LogEvent.BINLOG_CHECKSUM_LEN - LogEvent.BINLOG_CHECKSUM_ALG_DESC_LEN);
                checksumAlg = buffer.getUint8();
            }

            processCheckSum(buffer);
        }
        return;
    }

    /*
     * CRC verification by SQL and Show-Binlog-Events master side. The
     * caller has to provide @description_event->checksum_alg to be the last
     * seen FD's (A) descriptor. If event is FD the descriptor is in it.
     * Notice, FD of the binlog can be only in one instance and therefore
     * Show-Binlog-Events executing master side thread needs just to know
     * the only FD's (A) value - whereas RL can contain more. In the RL
     * case, the alg is kept in FD_e (@description_event) which is reset to
     * the newer read-out event after its execution with possibly new alg
     * descriptor. Therefore in a typical sequence of RL: {FD_s^0, FD_m,
     * E_m^1} E_m^1 will be verified with (A) of FD_m. See legends
     * definition on MYSQL_BIN_LOG::relay_log_checksum_alg docs lines
     * (log.h). Notice, a pre-checksum FD version forces alg :=
     * BINLOG_CHECKSUM_ALG_UNDEF.
     */
    checksumAlg = descriptionEvent.getHeader().checksumAlg; // fetch
                                                            // checksum alg
    processCheckSum(buffer);
    /* otherwise, go on with reading the header from buf (nothing now) */
}
 
Example 2
Source File: MysqlBinlogParsePerformanceTest.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public static void consumer(BlockingQueue<LogBuffer> buffer) throws IOException, InterruptedException {
    LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
    LogContext context = new LogContext();

    AtomicLong sum = new AtomicLong(0);
    long start = System.currentTimeMillis();
    long last = 0;
    long end = 0;
    while (true) {
        LogEvent event = null;
        event = decoder.decode(buffer.take(), context);
        int eventType = event.getHeader().getType();
        switch (eventType) {
            case LogEvent.ROTATE_EVENT:
                break;
            case LogEvent.WRITE_ROWS_EVENT_V1:
            case LogEvent.WRITE_ROWS_EVENT:
                parseRowsEvent((WriteRowsLogEvent) event, sum);
                break;
            case LogEvent.UPDATE_ROWS_EVENT_V1:
            case LogEvent.PARTIAL_UPDATE_ROWS_EVENT:
            case LogEvent.UPDATE_ROWS_EVENT:
                parseRowsEvent((UpdateRowsLogEvent) event, sum);
                break;
            case LogEvent.DELETE_ROWS_EVENT_V1:
            case LogEvent.DELETE_ROWS_EVENT:
                parseRowsEvent((DeleteRowsLogEvent) event, sum);
                break;
            case LogEvent.XID_EVENT:
                sum.incrementAndGet();
                break;
            case LogEvent.QUERY_EVENT:
                sum.incrementAndGet();
                break;
            default:
                break;
        }

        long current = sum.get();
        if (current - last >= 100000) {
            end = System.currentTimeMillis();
            long tps = ((current - last) * 1000) / (end - start);
            System.out.println(" total : " + sum + " , cost : " + (end - start) + " , tps : " + tps);
            last = current;
            start = end;
        }
    }
}
 
Example 3
Source File: LogEventConvert.java    From DBus with Apache License 2.0 4 votes vote down vote up
public Entry parse(LogEvent logEvent) throws CanalParseException {
    if (logEvent == null || logEvent instanceof UnknownLogEvent) {
        return null;
    }

    int eventType = logEvent.getHeader().getType();
    switch (eventType) {
        case LogEvent.ROTATE_EVENT:
            binlogFileName = ((RotateLogEvent) logEvent).getFilename();
            break;
        case LogEvent.QUERY_EVENT:
            return parseQueryEvent((QueryLogEvent) logEvent);
        case LogEvent.XID_EVENT:
            return parseXidEvent((XidLogEvent) logEvent);
        case LogEvent.TABLE_MAP_EVENT:
            break;
        case LogEvent.WRITE_ROWS_EVENT_V1:
        case LogEvent.WRITE_ROWS_EVENT:
            return parseRowsEvent((WriteRowsLogEvent) logEvent);
        case LogEvent.UPDATE_ROWS_EVENT_V1:
        case LogEvent.UPDATE_ROWS_EVENT:
            return parseRowsEvent((UpdateRowsLogEvent) logEvent);
        case LogEvent.DELETE_ROWS_EVENT_V1:
        case LogEvent.DELETE_ROWS_EVENT:
            return parseRowsEvent((DeleteRowsLogEvent) logEvent);
        case LogEvent.ROWS_QUERY_LOG_EVENT:
            return parseRowsQueryEvent((RowsQueryLogEvent) logEvent);
        case LogEvent.ANNOTATE_ROWS_EVENT:
            return parseAnnotateRowsEvent((AnnotateRowsEvent) logEvent);
        case LogEvent.USER_VAR_EVENT:
            return parseUserVarLogEvent((UserVarLogEvent) logEvent);
        case LogEvent.INTVAR_EVENT:
            return parseIntrvarLogEvent((IntvarLogEvent) logEvent);
        case LogEvent.RAND_EVENT:
            return parseRandLogEvent((RandLogEvent) logEvent);
        default:
            break;
    }

    return null;
}
 
Example 4
Source File: LogEventConvert_old.java    From DBus with Apache License 2.0 4 votes vote down vote up
public Entry parse(LogEvent logEvent) throws CanalParseException {
    if (logEvent == null || logEvent instanceof UnknownLogEvent) {
        return null;
    }

    int eventType = logEvent.getHeader().getType();
    switch (eventType) {
        case LogEvent.ROTATE_EVENT:
            binlogFileName = ((RotateLogEvent) logEvent).getFilename();
            break;
        case LogEvent.QUERY_EVENT:
            return parseQueryEvent((QueryLogEvent) logEvent);
        case LogEvent.XID_EVENT:
            return parseXidEvent((XidLogEvent) logEvent);
        case LogEvent.TABLE_MAP_EVENT:
            break;
        case LogEvent.WRITE_ROWS_EVENT_V1:
        case LogEvent.WRITE_ROWS_EVENT:
            return parseRowsEvent((WriteRowsLogEvent) logEvent);
        case LogEvent.UPDATE_ROWS_EVENT_V1:
        case LogEvent.UPDATE_ROWS_EVENT:
            return parseRowsEvent((UpdateRowsLogEvent) logEvent);
        case LogEvent.DELETE_ROWS_EVENT_V1:
        case LogEvent.DELETE_ROWS_EVENT:
            return parseRowsEvent((DeleteRowsLogEvent) logEvent);
        case LogEvent.ROWS_QUERY_LOG_EVENT:
            return parseRowsQueryEvent((RowsQueryLogEvent) logEvent);
        case LogEvent.ANNOTATE_ROWS_EVENT:
            return parseAnnotateRowsEvent((AnnotateRowsEvent) logEvent);
        case LogEvent.USER_VAR_EVENT:
            return parseUserVarLogEvent((UserVarLogEvent) logEvent);
        case LogEvent.INTVAR_EVENT:
            return parseIntrvarLogEvent((IntvarLogEvent) logEvent);
        case LogEvent.RAND_EVENT:
            return parseRandLogEvent((RandLogEvent) logEvent);
        default:
            break;
    }

    return null;
}
 
Example 5
Source File: LogEventConvert.java    From DBus with Apache License 2.0 4 votes vote down vote up
public Entry parse(LogEvent logEvent) throws CanalParseException {
    if (logEvent == null || logEvent instanceof UnknownLogEvent) {
        return null;
    }

    int eventType = logEvent.getHeader().getType();
    switch (eventType) {
        case LogEvent.ROTATE_EVENT:
            binlogFileName = ((RotateLogEvent) logEvent).getFilename();
            break;
        case LogEvent.QUERY_EVENT:
            return parseQueryEvent((QueryLogEvent) logEvent);
        case LogEvent.XID_EVENT:
            return parseXidEvent((XidLogEvent) logEvent);
        case LogEvent.TABLE_MAP_EVENT:
            break;
        case LogEvent.WRITE_ROWS_EVENT_V1:
        case LogEvent.WRITE_ROWS_EVENT:
            return parseRowsEvent((WriteRowsLogEvent) logEvent);
        case LogEvent.UPDATE_ROWS_EVENT_V1:
        case LogEvent.UPDATE_ROWS_EVENT:
            return parseRowsEvent((UpdateRowsLogEvent) logEvent);
        case LogEvent.DELETE_ROWS_EVENT_V1:
        case LogEvent.DELETE_ROWS_EVENT:
            return parseRowsEvent((DeleteRowsLogEvent) logEvent);
        case LogEvent.ROWS_QUERY_LOG_EVENT:
            return parseRowsQueryEvent((RowsQueryLogEvent) logEvent);
        case LogEvent.ANNOTATE_ROWS_EVENT:
            return parseAnnotateRowsEvent((AnnotateRowsEvent) logEvent);
        case LogEvent.USER_VAR_EVENT:
            return parseUserVarLogEvent((UserVarLogEvent) logEvent);
        case LogEvent.INTVAR_EVENT:
            return parseIntrvarLogEvent((IntvarLogEvent) logEvent);
        case LogEvent.RAND_EVENT:
            return parseRandLogEvent((RandLogEvent) logEvent);
        default:
            break;
    }

    return null;
}
 
Example 6
Source File: LogHeader.java    From canal with Apache License 2.0 4 votes vote down vote up
public LogHeader(LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
    when = buffer.getUint32();
    type = buffer.getUint8(); // LogEvent.EVENT_TYPE_OFFSET;
    serverId = buffer.getUint32(); // LogEvent.SERVER_ID_OFFSET;
    eventLen = (int) buffer.getUint32(); // LogEvent.EVENT_LEN_OFFSET;

    if (descriptionEvent.binlogVersion == 1) {
        logPos = 0;
        flags = 0;
        return;
    }

    /* 4.0 or newer */
    logPos = buffer.getUint32(); // LogEvent.LOG_POS_OFFSET
    /*
     * If the log is 4.0 (so here it can only be a 4.0 relay log read by the
     * SQL thread or a 4.0 master binlog read by the I/O thread), log_pos is
     * the beginning of the event: we transform it into the end of the
     * event, which is more useful. But how do you know that the log is 4.0:
     * you know it if description_event is version 3 *and* you are not
     * reading a Format_desc (remember that mysqlbinlog starts by assuming
     * that 5.0 logs are in 4.0 format, until it finds a Format_desc).
     */
    if (descriptionEvent.binlogVersion == 3 && type < LogEvent.FORMAT_DESCRIPTION_EVENT && logPos != 0) {
        /*
         * If log_pos=0, don't change it. log_pos==0 is a marker to mean
         * "don't change rli->group_master_log_pos" (see
         * inc_group_relay_log_pos()). As it is unreal log_pos, adding the
         * event len's is nonsense. For example, a fake Rotate event should
         * not have its log_pos (which is 0) changed or it will modify
         * Exec_master_log_pos in SHOW SLAVE STATUS, displaying a nonsense
         * value of (a non-zero offset which does not exist in the master's
         * binlog, so which will cause problems if the user uses this value
         * in CHANGE MASTER).
         */
        logPos += eventLen; /* purecov: inspected */
    }

    flags = buffer.getUint16(); // LogEvent.FLAGS_OFFSET
    if ((type == LogEvent.FORMAT_DESCRIPTION_EVENT) || (type == LogEvent.ROTATE_EVENT)) {
        /*
         * These events always have a header which stops here (i.e. their
         * header is FROZEN).
         */
        /*
         * Initialization to zero of all other Log_event members as they're
         * not specified. Currently there are no such members; in the future
         * there will be an event UID (but Format_description and Rotate
         * don't need this UID, as they are not propagated through
         * --log-slave-updates (remember the UID is used to not play a query
         * twice when you have two masters which are slaves of a 3rd
         * master). Then we are done.
         */

        if (type == LogEvent.FORMAT_DESCRIPTION_EVENT) {
            int commonHeaderLen = buffer.getUint8(FormatDescriptionLogEvent.LOG_EVENT_MINIMAL_HEADER_LEN
                                                  + FormatDescriptionLogEvent.ST_COMMON_HEADER_LEN_OFFSET);
            buffer.position(commonHeaderLen + FormatDescriptionLogEvent.ST_SERVER_VER_OFFSET);
            String serverVersion = buffer.getFixString(FormatDescriptionLogEvent.ST_SERVER_VER_LEN); // ST_SERVER_VER_OFFSET
            int versionSplit[] = new int[] { 0, 0, 0 };
            FormatDescriptionLogEvent.doServerVersionSplit(serverVersion, versionSplit);
            checksumAlg = LogEvent.BINLOG_CHECKSUM_ALG_UNDEF;
            if (FormatDescriptionLogEvent.versionProduct(versionSplit) >= FormatDescriptionLogEvent.checksumVersionProduct) {
                buffer.position(eventLen - LogEvent.BINLOG_CHECKSUM_LEN - LogEvent.BINLOG_CHECKSUM_ALG_DESC_LEN);
                checksumAlg = buffer.getUint8();
            }

            processCheckSum(buffer);
        }
        return;
    }

    /*
     * CRC verification by SQL and Show-Binlog-Events master side. The
     * caller has to provide @description_event->checksum_alg to be the last
     * seen FD's (A) descriptor. If event is FD the descriptor is in it.
     * Notice, FD of the binlog can be only in one instance and therefore
     * Show-Binlog-Events executing master side thread needs just to know
     * the only FD's (A) value - whereas RL can contain more. In the RL
     * case, the alg is kept in FD_e (@description_event) which is reset to
     * the newer read-out event after its execution with possibly new alg
     * descriptor. Therefore in a typical sequence of RL: {FD_s^0, FD_m,
     * E_m^1} E_m^1 will be verified with (A) of FD_m. See legends
     * definition on MYSQL_BIN_LOG::relay_log_checksum_alg docs lines
     * (log.h). Notice, a pre-checksum FD version forces alg :=
     * BINLOG_CHECKSUM_ALG_UNDEF.
     */
    checksumAlg = descriptionEvent.getHeader().checksumAlg; // fetch
                                                            // checksum alg
    processCheckSum(buffer);
    /* otherwise, go on with reading the header from buf (nothing now) */
}
 
Example 7
Source File: MysqlBinlogParsePerformanceTest.java    From canal with Apache License 2.0 4 votes vote down vote up
public static void consumer(BlockingQueue<LogBuffer> buffer) throws IOException, InterruptedException {
    LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
    LogContext context = new LogContext();

    AtomicLong sum = new AtomicLong(0);
    long start = System.currentTimeMillis();
    long last = 0;
    long end = 0;
    while (true) {
        LogEvent event = null;
        event = decoder.decode(buffer.take(), context);
        int eventType = event.getHeader().getType();
        switch (eventType) {
            case LogEvent.ROTATE_EVENT:
                break;
            case LogEvent.WRITE_ROWS_EVENT_V1:
            case LogEvent.WRITE_ROWS_EVENT:
                parseRowsEvent((WriteRowsLogEvent) event, sum);
                break;
            case LogEvent.UPDATE_ROWS_EVENT_V1:
            case LogEvent.PARTIAL_UPDATE_ROWS_EVENT:
            case LogEvent.UPDATE_ROWS_EVENT:
                parseRowsEvent((UpdateRowsLogEvent) event, sum);
                break;
            case LogEvent.DELETE_ROWS_EVENT_V1:
            case LogEvent.DELETE_ROWS_EVENT:
                parseRowsEvent((DeleteRowsLogEvent) event, sum);
                break;
            case LogEvent.XID_EVENT:
                sum.incrementAndGet();
                break;
            case LogEvent.QUERY_EVENT:
                sum.incrementAndGet();
                break;
            default:
                break;
        }

        long current = sum.get();
        if (current - last >= 100000) {
            end = System.currentTimeMillis();
            long tps = ((current - last) * 1000) / (end - start);
            System.out.println(" total : " + sum + " , cost : " + (end - start) + " , tps : " + tps);
            last = current;
            start = end;
        }
    }
}