com.taobao.tddl.dbsync.binlog.LogBuffer Java Examples
The following examples show how to use
com.taobao.tddl.dbsync.binlog.LogBuffer.
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: IncidentLogEvent.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
public IncidentLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; buffer.position(commonHeaderLen); final int incidentNumber = buffer.getUint16(); if (incidentNumber >= INCIDENT_COUNT || incidentNumber <= INCIDENT_NONE) { // If the incident is not recognized, this binlog event is // invalid. If we set incident_number to INCIDENT_NONE, the // invalidity will be detected by is_valid(). incident = INCIDENT_NONE; message = null; return; } incident = incidentNumber; buffer.position(commonHeaderLen + postHeaderLen); message = buffer.getString(); }
Example #2
Source File: RotateLogEvent.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
/** * Creates a new <code>Rotate_log_event</code> object read normally from * log. * * @throws MySQLExtractException */ public RotateLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int headerSize = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[ROTATE_EVENT - 1]; buffer.position(headerSize + R_POS_OFFSET); position = (postHeaderLen != 0) ? buffer.getLong64() : 4; // !uint8korr(buf // + // R_POS_OFFSET) final int filenameOffset = headerSize + postHeaderLen; int filenameLen = buffer.limit() - filenameOffset; if (filenameLen > FN_REFLEN - 1) filenameLen = FN_REFLEN - 1; buffer.position(filenameOffset); filename = buffer.getFixString(filenameLen); }
Example #3
Source File: TableMapLogEvent.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
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 #4
Source File: XaPrepareLogEvent.java From canal with Apache License 2.0 | 6 votes |
public XaPrepareLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.getCommonHeaderLen(); final int postHeaderLen = descriptionEvent.getPostHeaderLen()[header.getType() - 1]; int offset = commonHeaderLen + postHeaderLen; buffer.position(offset); onePhase = (buffer.getInt8() == 0x00 ? false : true); formatId = buffer.getInt32(); gtridLength = buffer.getInt32(); bqualLength = buffer.getInt32(); int MY_XIDDATASIZE = 128; if (MY_XIDDATASIZE >= gtridLength + bqualLength && gtridLength >= 0 && gtridLength <= 64 && bqualLength >= 0 && bqualLength <= 64) { data = buffer.getData(gtridLength + bqualLength); } else { formatId = -1; gtridLength = 0; bqualLength = 0; } }
Example #5
Source File: TableMapLogEvent.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
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 #6
Source File: ExecuteLoadQueryLogEvent.java From canal with Apache License 2.0 | 6 votes |
public ExecuteLoadQueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent) throws IOException{ super(header, buffer, descriptionEvent); buffer.position(descriptionEvent.commonHeaderLen + ELQ_FILE_ID_OFFSET); fileId = buffer.getUint32(); // ELQ_FILE_ID_OFFSET fnPosStart = (int) buffer.getUint32(); // ELQ_FN_POS_START_OFFSET fnPosEnd = (int) buffer.getUint32(); // ELQ_FN_POS_END_OFFSET dupHandling = buffer.getInt8(); // ELQ_DUP_HANDLING_OFFSET final int len = query.length(); if (fnPosStart > len || fnPosEnd > len || dupHandling > LOAD_DUP_REPLACE) { throw new IOException(String.format("Invalid ExecuteLoadQueryLogEvent: fn_pos_start=%d, " + "fn_pos_end=%d, dup_handling=%d", fnPosStart, fnPosEnd, dupHandling)); } }
Example #7
Source File: IncidentLogEvent.java From canal with Apache License 2.0 | 6 votes |
public IncidentLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; buffer.position(commonHeaderLen); final int incidentNumber = buffer.getUint16(); if (incidentNumber >= INCIDENT_COUNT || incidentNumber <= INCIDENT_NONE) { // If the incident is not recognized, this binlog event is // invalid. If we set incident_number to INCIDENT_NONE, the // invalidity will be detected by is_valid(). incident = INCIDENT_NONE; message = null; return; } incident = incidentNumber; buffer.position(commonHeaderLen + postHeaderLen); message = buffer.getString(); }
Example #8
Source File: XaPrepareLogEvent.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
public XaPrepareLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.getCommonHeaderLen(); final int postHeaderLen = descriptionEvent.getPostHeaderLen()[header.getType() - 1]; int offset = commonHeaderLen + postHeaderLen; buffer.position(offset); onePhase = (buffer.getInt8() == 0x00 ? false : true); formatId = buffer.getInt32(); gtridLength = buffer.getInt32(); bqualLength = buffer.getInt32(); int MY_XIDDATASIZE = 128; if (MY_XIDDATASIZE >= gtridLength + bqualLength && gtridLength >= 0 && gtridLength <= 64 && bqualLength >= 0 && bqualLength <= 64) { data = buffer.getData(gtridLength + bqualLength); } else { formatId = -1; gtridLength = 0; bqualLength = 0; } }
Example #9
Source File: MysqlConnection.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
@Override public void dump(GTIDSet gtidSet, MultiStageCoprocessor coprocessor) throws IOException { updateSettings(); loadBinlogChecksum(); sendBinlogDumpGTID(gtidSet); ((MysqlMultiStageCoprocessor) coprocessor).setConnection(this); ((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum); DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize()); try { fetcher.start(connector.getChannel()); while (fetcher.fetch()) { accumulateReceivedBytes(fetcher.limit()); LogBuffer buffer = fetcher.duplicate(); fetcher.consume(fetcher.limit()); if (!coprocessor.publish(buffer)) { break; } } } finally { fetcher.close(); } }
Example #10
Source File: TableMapLogEvent.java From canal with Apache License 2.0 | 6 votes |
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 #11
Source File: RowsLogBuffer.java From canal with Apache License 2.0 | 5 votes |
public RowsLogBuffer(LogBuffer buffer, final int columnLen, String charsetName, int jsonColumnCount, boolean partial){ this.buffer = buffer; this.columnLen = columnLen; this.charsetName = charsetName; this.partial = partial; this.jsonColumnCount = jsonColumnCount; this.nullBits = new BitSet(columnLen); this.partialBits = new BitSet(1); }
Example #12
Source File: TableMapLogEvent.java From canal with Apache License 2.0 | 5 votes |
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 #13
Source File: AppendBlockLogEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public AppendBlockLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; final int totalHeaderLen = commonHeaderLen + postHeaderLen; buffer.position(commonHeaderLen + AB_FILE_ID_OFFSET); fileId = buffer.getUint32(); buffer.position(postHeaderLen); blockLen = buffer.limit() - totalHeaderLen; blockBuf = buffer.duplicate(blockLen); }
Example #14
Source File: TableMapLogEvent.java From canal with Apache License 2.0 | 5 votes |
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 #15
Source File: TableMapLogEvent.java From canal with Apache License 2.0 | 5 votes |
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 #16
Source File: LoadLogEvent.java From canal with Apache License 2.0 | 5 votes |
public LoadLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int loadHeaderLen = FormatDescriptionLogEvent.LOAD_HEADER_LEN; /* * I (Guilhem) manually tested replication of LOAD DATA INFILE for * 3.23->5.0, 4.0->5.0 and 5.0->5.0 and it works. */ copyLogEvent(buffer, ((header.type == LOAD_EVENT) ? loadHeaderLen + descriptionEvent.commonHeaderLen : loadHeaderLen + FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN), descriptionEvent); }
Example #17
Source File: GtidLogEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
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 #18
Source File: IntvarLogEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public IntvarLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); /* The Post-Header is empty. The Varible Data part begins immediately. */ buffer.position(descriptionEvent.commonHeaderLen + descriptionEvent.postHeaderLen[INTVAR_EVENT - 1] + I_TYPE_OFFSET); type = buffer.getInt8(); // I_TYPE_OFFSET value = buffer.getLong64(); // !uint8korr(buf + I_VAL_OFFSET); }
Example #19
Source File: DeleteFileLogEvent.java From canal with Apache License 2.0 | 5 votes |
public DeleteFileLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; buffer.position(commonHeaderLen + DF_FILE_ID_OFFSET); fileId = buffer.getUint32(); // DF_FILE_ID_OFFSET }
Example #20
Source File: XidLogEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public XidLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); /* The Post-Header is empty. The Variable Data part begins immediately. */ buffer.position(descriptionEvent.commonHeaderLen + descriptionEvent.postHeaderLen[XID_EVENT - 1]); xid = buffer.getLong64(); // !uint8korr }
Example #21
Source File: StartLogEventV3.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public StartLogEventV3(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); buffer.position(descriptionEvent.commonHeaderLen); binlogVersion = buffer.getUint16(); // ST_BINLOG_VER_OFFSET serverVersion = buffer.getFixString(ST_SERVER_VER_LEN); // ST_SERVER_VER_OFFSET }
Example #22
Source File: ExecuteLoadLogEvent.java From canal with Apache License 2.0 | 5 votes |
public ExecuteLoadLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; buffer.position(commonHeaderLen + EL_FILE_ID_OFFSET); fileId = buffer.getUint32(); // EL_FILE_ID_OFFSET }
Example #23
Source File: DeleteFileLogEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public DeleteFileLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; buffer.position(commonHeaderLen + DF_FILE_ID_OFFSET); fileId = buffer.getUint32(); // DF_FILE_ID_OFFSET }
Example #24
Source File: RowsQueryLogEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public RowsQueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header, buffer, descriptionEvent); final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; /* * m_rows_query length is stored using only one byte, but that length is * ignored and the complete query is read.m_rows_query长度只使用一个字节存储,但是这个长度是 *被忽略,然后读取完整的查询。 */ int offset = commonHeaderLen + postHeaderLen + 1; int len = buffer.limit() - offset; rowsQuery = buffer.getFullString(offset, len, LogBuffer.ISO_8859_1); }
Example #25
Source File: AnnotateRowsEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public AnnotateRowsEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header, buffer, descriptionEvent); final int commonHeaderLen = descriptionEvent.getCommonHeaderLen(); final int postHeaderLen = descriptionEvent.getPostHeaderLen()[header.getType() - 1]; int offset = commonHeaderLen + postHeaderLen; int len = buffer.limit() - offset; rowsQuery = buffer.getFullString(offset, len, LogBuffer.ISO_8859_1); }
Example #26
Source File: GtidLogEvent.java From canal with Apache License 2.0 | 5 votes |
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 #27
Source File: AppendBlockLogEvent.java From canal with Apache License 2.0 | 5 votes |
public AppendBlockLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; final int totalHeaderLen = commonHeaderLen + postHeaderLen; buffer.position(commonHeaderLen + AB_FILE_ID_OFFSET); fileId = buffer.getUint32(); buffer.position(postHeaderLen); blockLen = buffer.limit() - totalHeaderLen; blockBuf = buffer.duplicate(blockLen); }
Example #28
Source File: FormatDescriptionLogEvent.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
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 #29
Source File: IntvarLogEvent.java From canal with Apache License 2.0 | 5 votes |
public IntvarLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); /* The Post-Header is empty. The Varible Data part begins immediately. */ buffer.position(descriptionEvent.commonHeaderLen + descriptionEvent.postHeaderLen[INTVAR_EVENT - 1] + I_TYPE_OFFSET); type = buffer.getInt8(); // I_TYPE_OFFSET value = buffer.getLong64(); // !uint8korr(buf + I_VAL_OFFSET); }
Example #30
Source File: AnnotateRowsEvent.java From canal with Apache License 2.0 | 5 votes |
public AnnotateRowsEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header, buffer, descriptionEvent); final int commonHeaderLen = descriptionEvent.getCommonHeaderLen(); final int postHeaderLen = descriptionEvent.getPostHeaderLen()[header.getType() - 1]; int offset = commonHeaderLen + postHeaderLen; int len = buffer.limit() - offset; rowsQuery = buffer.getFullString(offset, len, LogBuffer.ISO_8859_1); }