Java Code Examples for com.taobao.tddl.dbsync.binlog.LogBuffer#getUint8()

The following examples show how to use com.taobao.tddl.dbsync.binlog.LogBuffer#getUint8() . 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: TableMapLogEvent.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
private void parse_signedness(LogBuffer buffer, int length) {
    // stores the signedness flags extracted from field
    List<Boolean> datas = new ArrayList<Boolean>();
    for (int i = 0; i < length; i++) {
        int ut = buffer.getUint8();
        for (int c = 0x80; c != 0; c >>= 1) {
            datas.add((ut & c) > 0);
        }
    }

    int index = 0;
    for (int i = 0; i < columnCnt; i++) {
        if (is_numeric_type(columnInfo[i].type)) {
            columnInfo[i].unsigned = datas.get(index);
            index++;
        }
    }
}
 
Example 2
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 6 votes vote down vote up
private void parse_signedness(LogBuffer buffer, int length) {
    // stores the signedness flags extracted from field
    List<Boolean> datas = new ArrayList<Boolean>();
    for (int i = 0; i < length; i++) {
        int ut = buffer.getUint8();
        for (int c = 0x80; c != 0; c >>= 1) {
            datas.add((ut & c) > 0);
        }
    }

    int index = 0;
    for (int i = 0; i < columnCnt; i++) {
        if (is_numeric_type(columnInfo[i].type)) {
            columnInfo[i].unsigned = datas.get(index);
            index++;
        }
    }
}
 
Example 3
Source File: GtidLogEvent.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public GtidLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
    super(header);

    final int commonHeaderLen = descriptionEvent.commonHeaderLen;
    // final int postHeaderLen = descriptionEvent.postHeaderLen[header.type
    // - 1];

    buffer.position(commonHeaderLen);
    commitFlag = (buffer.getUint8() != 0); // ENCODED_FLAG_LENGTH

    byte[] bs = buffer.getData(ENCODED_SID_LENGTH);
    ByteBuffer bb = ByteBuffer.wrap(bs);
    long high = bb.getLong();
    long low = bb.getLong();
    sid = new UUID(high, low);

    gno = buffer.getLong64();

    // support gtid lastCommitted and sequenceNumber
    // fix bug #776
    if (buffer.hasRemaining() && buffer.remaining() > 16 && buffer.getUint8() == LOGICAL_TIMESTAMP_TYPE_CODE) {
        lastCommitted = buffer.getLong64();
        sequenceNumber = buffer.getLong64();
    }

    // ignore gtid info read
    // sid.copy_from((uchar *)ptr_buffer);
    // ptr_buffer+= ENCODED_SID_LENGTH;
    //
    // // SIDNO is only generated if needed, in get_sidno().
    // spec.gtid.sidno= -1;
    //
    // spec.gtid.gno= uint8korr(ptr_buffer);
    // ptr_buffer+= ENCODED_GNO_LENGTH;
}
 
Example 4
Source File: FormatDescriptionLogEvent.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public FormatDescriptionLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
                                                                                                                throws IOException{
    /* Start_log_event_v3 */
    super(header, buffer, descriptionEvent);

    buffer.position(LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET);
    commonHeaderLen = buffer.getUint8();
    if (commonHeaderLen < OLD_HEADER_LEN) /* sanity check */
    {
        throw new IOException("Format Description event header length is too short");
    }

    numberOfEventTypes = buffer.limit() - (LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET + 1);

    // buffer.position(LOG_EVENT_MINIMAL_HEADER_LEN
    // + ST_COMMON_HEADER_LEN_OFFSET + 1);
    postHeaderLen = new short[numberOfEventTypes];
    for (int i = 0; i < numberOfEventTypes; i++) {
        postHeaderLen[i] = (short) buffer.getUint8();
    }

    calcServerVersionSplit();
    long calc = getVersionProduct();
    if (calc >= checksumVersionProduct) {
        /*
         * the last bytes are the checksum alg desc and value (or value's
         * room)
         */
        numberOfEventTypes -= BINLOG_CHECKSUM_ALG_DESC_LEN;
    }

    if (logger.isInfoEnabled()) logger.info("common_header_len= " + commonHeaderLen + ", number_of_event_types= "
                                            + numberOfEventTypes);
}
 
Example 5
Source File: GtidLogEvent.java    From canal with Apache License 2.0 5 votes vote down vote up
public GtidLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
    super(header);

    final int commonHeaderLen = descriptionEvent.commonHeaderLen;
    // final int postHeaderLen = descriptionEvent.postHeaderLen[header.type
    // - 1];

    buffer.position(commonHeaderLen);
    commitFlag = (buffer.getUint8() != 0); // ENCODED_FLAG_LENGTH

    byte[] bs = buffer.getData(ENCODED_SID_LENGTH);
    ByteBuffer bb = ByteBuffer.wrap(bs);
    long high = bb.getLong();
    long low = bb.getLong();
    sid = new UUID(high, low);

    gno = buffer.getLong64();

    // support gtid lastCommitted and sequenceNumber
    // fix bug #776
    if (buffer.hasRemaining() && buffer.remaining() > 16 && buffer.getUint8() == LOGICAL_TIMESTAMP_TYPE_CODE) {
        lastCommitted = buffer.getLong64();
        sequenceNumber = buffer.getLong64();
    }

    // ignore gtid info read
    // sid.copy_from((uchar *)ptr_buffer);
    // ptr_buffer+= ENCODED_SID_LENGTH;
    //
    // // SIDNO is only generated if needed, in get_sidno().
    // spec.gtid.sidno= -1;
    //
    // spec.gtid.gno= uint8korr(ptr_buffer);
    // ptr_buffer+= ENCODED_GNO_LENGTH;
}
 
Example 6
Source File: FormatDescriptionLogEvent.java    From canal with Apache License 2.0 5 votes vote down vote up
public FormatDescriptionLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
                                                                                                                throws IOException{
    /* Start_log_event_v3 */
    super(header, buffer, descriptionEvent);

    buffer.position(LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET);
    commonHeaderLen = buffer.getUint8();
    if (commonHeaderLen < OLD_HEADER_LEN) /* sanity check */
    {
        throw new IOException("Format Description event header length is too short");
    }

    numberOfEventTypes = buffer.limit() - (LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET + 1);

    // buffer.position(LOG_EVENT_MINIMAL_HEADER_LEN
    // + ST_COMMON_HEADER_LEN_OFFSET + 1);
    postHeaderLen = new short[numberOfEventTypes];
    for (int i = 0; i < numberOfEventTypes; i++) {
        postHeaderLen[i] = (short) buffer.getUint8();
    }

    calcServerVersionSplit();
    long calc = getVersionProduct();
    if (calc >= checksumVersionProduct) {
        /*
         * the last bytes are the checksum alg desc and value (or value's
         * room)
         */
        numberOfEventTypes -= BINLOG_CHECKSUM_ALG_DESC_LEN;
    }

    if (logger.isInfoEnabled()) logger.info("common_header_len= " + commonHeaderLen + ", number_of_event_types= "
                                            + numberOfEventTypes);
}
 
Example 7
Source File: LoadLogEvent.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
/**
 * @see mysql-5.1.60/sql/log_event.cc - Load_log_event::copy_log_event
 */
protected final void copyLogEvent(LogBuffer buffer, final int bodyOffset, FormatDescriptionLogEvent descriptionEvent) {
    /* this is the beginning of the post-header */
    buffer.position(descriptionEvent.commonHeaderLen + L_EXEC_TIME_OFFSET);

    execTime = buffer.getUint32(); // L_EXEC_TIME_OFFSET
    skipLines = (int) buffer.getUint32(); // L_SKIP_LINES_OFFSET
    final int tableNameLen = buffer.getUint8(); // L_TBL_LEN_OFFSET
    final int dbLen = buffer.getUint8(); // L_DB_LEN_OFFSET
    numFields = (int) buffer.getUint32(); // L_NUM_FIELDS_OFFSET

    buffer.position(bodyOffset);
    /*
     * Sql_ex.init() on success returns the pointer to the first byte after
     * the sql_ex structure, which is the start of field lengths array.
     */
    if (header.type != LOAD_EVENT /* use_new_format */) {
        /*
         * The code below assumes that buf will not disappear from under our
         * feet during the lifetime of the event. This assumption holds true
         * in the slave thread if the log is in new format, but is not the
         * case when we have old format because we will be reusing net
         * buffer to read the actual file before we write out the
         * Create_file event.
         */
        fieldTerm = buffer.getString();
        enclosed = buffer.getString();
        lineTerm = buffer.getString();
        lineStart = buffer.getString();
        escaped = buffer.getString();
        optFlags = buffer.getInt8();
        emptyFlags = 0;
    } else {
        fieldTerm = buffer.getFixString(1);
        enclosed = buffer.getFixString(1);
        lineTerm = buffer.getFixString(1);
        lineStart = buffer.getFixString(1);
        escaped = buffer.getFixString(1);
        optFlags = buffer.getUint8();
        emptyFlags = buffer.getUint8();

        if ((emptyFlags & FIELD_TERM_EMPTY) != 0) fieldTerm = null;
        if ((emptyFlags & ENCLOSED_EMPTY) != 0) enclosed = null;
        if ((emptyFlags & LINE_TERM_EMPTY) != 0) lineTerm = null;
        if ((emptyFlags & LINE_START_EMPTY) != 0) lineStart = null;
        if ((emptyFlags & ESCAPED_EMPTY) != 0) escaped = null;
    }

    final int fieldLenPos = buffer.position();
    buffer.forward(numFields);
    fields = new String[numFields];
    for (int i = 0; i < numFields; i++) {
        final int fieldLen = buffer.getUint8(fieldLenPos + i);
        fields[i] = buffer.getFixString(fieldLen + 1);
    }

    table = buffer.getFixString(tableNameLen + 1);
    db = buffer.getFixString(dbLen + 1);

    // null termination is accomplished by the caller
    final int from = buffer.position();
    final int end = from + buffer.limit();
    int found = from;
    for (; (found < end) && buffer.getInt8(found) != '\0'; found++)
        /* empty loop */;
    fname = buffer.getString(found);
    buffer.forward(1); // The + 1 is for \0 terminating fname
}
 
Example 8
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 9
Source File: RowsLogEvent.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public RowsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent, boolean partial){
    super(header);

    final int commonHeaderLen = descriptionEvent.commonHeaderLen;
    final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];
    int headerLen = 0;
    buffer.position(commonHeaderLen + RW_MAPID_OFFSET);
    if (postHeaderLen == 6) {
        /*
         * Master is of an intermediate source tree before 5.1.4. Id is 4
         * bytes
         */
        tableId = buffer.getUint32();
    } else {
        tableId = buffer.getUlong48(); // RW_FLAGS_OFFSET
    }
    flags = buffer.getUint16();

    if (postHeaderLen == FormatDescriptionLogEvent.ROWS_HEADER_LEN_V2) {
        headerLen = buffer.getUint16();
        headerLen -= 2;
        int start = buffer.position();
        int end = start + headerLen;
        for (int i = start; i < end;) {
            switch (buffer.getUint8(i++)) {
                case RW_V_EXTRAINFO_TAG:
                    // int infoLen = buffer.getUint8();
                    buffer.position(i + EXTRA_ROW_INFO_LEN_OFFSET);
                    int checkLen = buffer.getUint8(); // EXTRA_ROW_INFO_LEN_OFFSET
                    int val = checkLen - EXTRA_ROW_INFO_HDR_BYTES;
                    assert (buffer.getUint8() == val); // EXTRA_ROW_INFO_FORMAT_OFFSET
                    for (int j = 0; j < val; j++) {
                        assert (buffer.getUint8() == val); // EXTRA_ROW_INFO_HDR_BYTES
                                                           // + i
                    }
                    break;
                default:
                    i = end;
                    break;
            }
        }
    }

    buffer.position(commonHeaderLen + postHeaderLen + headerLen);
    columnLen = (int) buffer.getPackedLong();
    this.partial = partial;
    columns = buffer.getBitmap(columnLen);

    if (header.type == UPDATE_ROWS_EVENT_V1 || header.type == UPDATE_ROWS_EVENT
        || header.type == PARTIAL_UPDATE_ROWS_EVENT) {
        changeColumns = buffer.getBitmap(columnLen);
    } else {
        changeColumns = columns;
    }

    // XXX: Don't handle buffer in another thread.
    int dataSize = buffer.limit() - buffer.position();
    rowsBuf = buffer.duplicate(dataSize);
}
 
Example 10
Source File: LoadLogEvent.java    From canal with Apache License 2.0 4 votes vote down vote up
/**
 * @see mysql-5.1.60/sql/log_event.cc - Load_log_event::copy_log_event
 */
protected final void copyLogEvent(LogBuffer buffer, final int bodyOffset, FormatDescriptionLogEvent descriptionEvent) {
    /* this is the beginning of the post-header */
    buffer.position(descriptionEvent.commonHeaderLen + L_EXEC_TIME_OFFSET);

    execTime = buffer.getUint32(); // L_EXEC_TIME_OFFSET
    skipLines = (int) buffer.getUint32(); // L_SKIP_LINES_OFFSET
    final int tableNameLen = buffer.getUint8(); // L_TBL_LEN_OFFSET
    final int dbLen = buffer.getUint8(); // L_DB_LEN_OFFSET
    numFields = (int) buffer.getUint32(); // L_NUM_FIELDS_OFFSET

    buffer.position(bodyOffset);
    /*
     * Sql_ex.init() on success returns the pointer to the first byte after
     * the sql_ex structure, which is the start of field lengths array.
     */
    if (header.type != LOAD_EVENT /* use_new_format */) {
        /*
         * The code below assumes that buf will not disappear from under our
         * feet during the lifetime of the event. This assumption holds true
         * in the slave thread if the log is in new format, but is not the
         * case when we have old format because we will be reusing net
         * buffer to read the actual file before we write out the
         * Create_file event.
         */
        fieldTerm = buffer.getString();
        enclosed = buffer.getString();
        lineTerm = buffer.getString();
        lineStart = buffer.getString();
        escaped = buffer.getString();
        optFlags = buffer.getInt8();
        emptyFlags = 0;
    } else {
        fieldTerm = buffer.getFixString(1);
        enclosed = buffer.getFixString(1);
        lineTerm = buffer.getFixString(1);
        lineStart = buffer.getFixString(1);
        escaped = buffer.getFixString(1);
        optFlags = buffer.getUint8();
        emptyFlags = buffer.getUint8();

        if ((emptyFlags & FIELD_TERM_EMPTY) != 0) fieldTerm = null;
        if ((emptyFlags & ENCLOSED_EMPTY) != 0) enclosed = null;
        if ((emptyFlags & LINE_TERM_EMPTY) != 0) lineTerm = null;
        if ((emptyFlags & LINE_START_EMPTY) != 0) lineStart = null;
        if ((emptyFlags & ESCAPED_EMPTY) != 0) escaped = null;
    }

    final int fieldLenPos = buffer.position();
    buffer.forward(numFields);
    fields = new String[numFields];
    for (int i = 0; i < numFields; i++) {
        final int fieldLen = buffer.getUint8(fieldLenPos + i);
        fields[i] = buffer.getFixString(fieldLen + 1);
    }

    table = buffer.getFixString(tableNameLen + 1);
    db = buffer.getFixString(dbLen + 1);

    // null termination is accomplished by the caller
    final int from = buffer.position();
    final int end = from + buffer.limit();
    int found = from;
    for (; (found < end) && buffer.getInt8(found) != '\0'; found++)
        /* empty loop */;
    fname = buffer.getString(found);
    buffer.forward(1); // The + 1 is for \0 terminating fname
}
 
Example 11
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 12
Source File: RowsLogEvent.java    From canal with Apache License 2.0 4 votes vote down vote up
public RowsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent, boolean partial){
    super(header);

    final int commonHeaderLen = descriptionEvent.commonHeaderLen;
    final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];
    int headerLen = 0;
    buffer.position(commonHeaderLen + RW_MAPID_OFFSET);
    if (postHeaderLen == 6) {
        /*
         * Master is of an intermediate source tree before 5.1.4. Id is 4
         * bytes
         */
        tableId = buffer.getUint32();
    } else {
        tableId = buffer.getUlong48(); // RW_FLAGS_OFFSET
    }
    flags = buffer.getUint16();

    if (postHeaderLen == FormatDescriptionLogEvent.ROWS_HEADER_LEN_V2) {
        headerLen = buffer.getUint16();
        headerLen -= 2;
        int start = buffer.position();
        int end = start + headerLen;
        for (int i = start; i < end;) {
            switch (buffer.getUint8(i++)) {
                case RW_V_EXTRAINFO_TAG:
                    // int infoLen = buffer.getUint8();
                    buffer.position(i + EXTRA_ROW_INFO_LEN_OFFSET);
                    int checkLen = buffer.getUint8(); // EXTRA_ROW_INFO_LEN_OFFSET
                    int val = checkLen - EXTRA_ROW_INFO_HDR_BYTES;
                    assert (buffer.getUint8() == val); // EXTRA_ROW_INFO_FORMAT_OFFSET
                    for (int j = 0; j < val; j++) {
                        assert (buffer.getUint8() == val); // EXTRA_ROW_INFO_HDR_BYTES
                                                           // + i
                    }
                    break;
                default:
                    i = end;
                    break;
            }
        }
    }

    buffer.position(commonHeaderLen + postHeaderLen + headerLen);
    columnLen = (int) buffer.getPackedLong();
    this.partial = partial;
    columns = buffer.getBitmap(columnLen);

    if (header.type == UPDATE_ROWS_EVENT_V1 || header.type == UPDATE_ROWS_EVENT
        || header.type == PARTIAL_UPDATE_ROWS_EVENT) {
        changeColumns = buffer.getBitmap(columnLen);
    } else {
        changeColumns = columns;
    }

    // XXX: Don't handle buffer in another thread.
    int dataSize = buffer.limit() - buffer.position();
    rowsBuf = buffer.duplicate(dataSize);
}