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

The following examples show how to use com.taobao.tddl.dbsync.binlog.LogBuffer#getPackedLong() . 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 List<TableMapLogEvent.Pair> parse_default_charset(LogBuffer buffer, int length) {
    // stores collation numbers extracted from field.
    int limit = buffer.position() + length;
    this.default_charset = (int) buffer.getPackedLong();
    List<TableMapLogEvent.Pair> datas = new ArrayList<TableMapLogEvent.Pair>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_index = (int) buffer.getPackedLong();
        int col_charset = (int) buffer.getPackedLong();

        Pair pair = new Pair();
        pair.col_index = col_index;
        pair.col_charset = col_charset;
        datas.add(pair);
    }

    return datas;
}
 
Example 2
Source File: TableMapLogEvent.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
private void parse_geometry_type(LogBuffer buffer, int length) {
    // stores geometry column's types extracted from field.
    int limit = buffer.position() + length;

    List<Integer> datas = new ArrayList<Integer>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_type = (int) buffer.getPackedLong();
        datas.add(col_type);
    }

    int index = 0;
    for (int i = 0; i < columnCnt; i++) {
        if (columnInfo[i].type == LogEvent.MYSQL_TYPE_GEOMETRY) {
            columnInfo[i].geoType = datas.get(index);
            index++;
        }
    }
}
 
Example 3
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 6 votes vote down vote up
private List<TableMapLogEvent.Pair> parse_default_charset(LogBuffer buffer, int length) {
    // stores collation numbers extracted from field.
    int limit = buffer.position() + length;
    this.default_charset = (int) buffer.getPackedLong();
    List<TableMapLogEvent.Pair> datas = new ArrayList<TableMapLogEvent.Pair>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_index = (int) buffer.getPackedLong();
        int col_charset = (int) buffer.getPackedLong();

        Pair pair = new Pair();
        pair.col_index = col_index;
        pair.col_charset = col_charset;
        datas.add(pair);
    }

    return datas;
}
 
Example 4
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 6 votes vote down vote up
private void parse_geometry_type(LogBuffer buffer, int length) {
    // stores geometry column's types extracted from field.
    int limit = buffer.position() + length;

    List<Integer> datas = new ArrayList<Integer>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_type = (int) buffer.getPackedLong();
        datas.add(col_type);
    }

    int index = 0;
    for (int i = 0; i < columnCnt; i++) {
        if (columnInfo[i].type == LogEvent.MYSQL_TYPE_GEOMETRY) {
            columnInfo[i].geoType = datas.get(index);
            index++;
        }
    }
}
 
Example 5
Source File: TableMapLogEvent.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private List<Integer> parse_column_charset(LogBuffer buffer, int length) {
    // stores collation numbers extracted from field.
    int limit = buffer.position() + length;
    List<Integer> datas = new ArrayList<Integer>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_charset = (int) buffer.getPackedLong();
        datas.add(col_charset);
    }

    return datas;
}
 
Example 6
Source File: TableMapLogEvent.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void parse_column_name(LogBuffer buffer, int length) {
    // stores column names extracted from field
    int limit = buffer.position() + length;
    int index = 0;
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int len = (int) buffer.getPackedLong();
        columnInfo[index++].name = buffer.getFixString(len);
    }
}
 
Example 7
Source File: TableMapLogEvent.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void parse_set_str_value(LogBuffer buffer, int length, boolean set) {
    // stores SET/ENUM column's string values extracted from
    // field. Each SET/ENUM column's string values are stored
    // into a string separate vector. All of them are stored
    // in 'vec'.
    int limit = buffer.position() + length;
    List<List<String>> datas = new ArrayList<List<String>>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int count = (int) buffer.getPackedLong();
        List<String> data = new ArrayList<String>(count);
        for (int i = 0; i < count; i++) {
            int len1 = (int) buffer.getPackedLong();
            data.add(buffer.getFixString(len1));
        }

        datas.add(data);
    }

    int index = 0;
    for (int i = 0; i < columnCnt; i++) {
        if (set && getRealType(columnInfo[i].type, columnInfo[i].meta) == LogEvent.MYSQL_TYPE_SET) {
            columnInfo[i].set_enum_values = datas.get(index);
            index++;
        }

        if (!set && getRealType(columnInfo[i].type, columnInfo[i].meta) == LogEvent.MYSQL_TYPE_ENUM) {
            columnInfo[i].set_enum_values = datas.get(index);
            index++;
        }
    }
}
 
Example 8
Source File: TableMapLogEvent.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void parse_simple_pk(LogBuffer buffer, int length) {
    // stores primary key's column information extracted from
    // field. Each column has an index and a prefix which are
    // stored as a unit_pair. prefix is always 0 for
    // SIMPLE_PRIMARY_KEY field.

    int limit = buffer.position() + length;
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_index = (int) buffer.getPackedLong();
        columnInfo[col_index].pk = true;
    }
}
 
Example 9
Source File: TableMapLogEvent.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void parse_pk_with_prefix(LogBuffer buffer, int length) {
    // stores primary key's column information extracted from
    // field. Each column has an index and a prefix which are
    // stored as a unit_pair.
    int limit = buffer.position() + length;
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_index = (int) buffer.getPackedLong();
        // prefix length, 比如 char(32)
        @SuppressWarnings("unused")
        int col_prefix = (int) buffer.getPackedLong();
        columnInfo[col_index].pk = true;
    }
}
 
Example 10
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 5 votes vote down vote up
private List<Integer> parse_column_charset(LogBuffer buffer, int length) {
    // stores collation numbers extracted from field.
    int limit = buffer.position() + length;
    List<Integer> datas = new ArrayList<Integer>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_charset = (int) buffer.getPackedLong();
        datas.add(col_charset);
    }

    return datas;
}
 
Example 11
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 5 votes vote down vote up
private void parse_column_name(LogBuffer buffer, int length) {
    // stores column names extracted from field
    int limit = buffer.position() + length;
    int index = 0;
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int len = (int) buffer.getPackedLong();
        columnInfo[index++].name = buffer.getFixString(len);
    }
}
 
Example 12
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 5 votes vote down vote up
private void parse_set_str_value(LogBuffer buffer, int length, boolean set) {
    // stores SET/ENUM column's string values extracted from
    // field. Each SET/ENUM column's string values are stored
    // into a string separate vector. All of them are stored
    // in 'vec'.
    int limit = buffer.position() + length;
    List<List<String>> datas = new ArrayList<List<String>>();
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int count = (int) buffer.getPackedLong();
        List<String> data = new ArrayList<String>(count);
        for (int i = 0; i < count; i++) {
            int len1 = (int) buffer.getPackedLong();
            data.add(buffer.getFixString(len1));
        }

        datas.add(data);
    }

    int index = 0;
    for (int i = 0; i < columnCnt; i++) {
        if (set && getRealType(columnInfo[i].type, columnInfo[i].meta) == LogEvent.MYSQL_TYPE_SET) {
            columnInfo[i].set_enum_values = datas.get(index);
            index++;
        }

        if (!set && getRealType(columnInfo[i].type, columnInfo[i].meta) == LogEvent.MYSQL_TYPE_ENUM) {
            columnInfo[i].set_enum_values = datas.get(index);
            index++;
        }
    }
}
 
Example 13
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 5 votes vote down vote up
private void parse_simple_pk(LogBuffer buffer, int length) {
    // stores primary key's column information extracted from
    // field. Each column has an index and a prefix which are
    // stored as a unit_pair. prefix is always 0 for
    // SIMPLE_PRIMARY_KEY field.

    int limit = buffer.position() + length;
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_index = (int) buffer.getPackedLong();
        columnInfo[col_index].pk = true;
    }
}
 
Example 14
Source File: TableMapLogEvent.java    From canal with Apache License 2.0 5 votes vote down vote up
private void parse_pk_with_prefix(LogBuffer buffer, int length) {
    // stores primary key's column information extracted from
    // field. Each column has an index and a prefix which are
    // stored as a unit_pair.
    int limit = buffer.position() + length;
    while (buffer.hasRemaining() && buffer.position() < limit) {
        int col_index = (int) buffer.getPackedLong();
        // prefix length, 比如 char(32)
        @SuppressWarnings("unused")
        int col_prefix = (int) buffer.getPackedLong();
        columnInfo[col_index].pk = true;
    }
}
 
Example 15
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 16
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);
}