private Entry parserQueryEvent(QueryLogEvent event) {
String queryString = event.getQuery();
if (StringUtils.endsWithIgnoreCase(queryString, BEGIN)) {
TransactionBegin transactionBegin = createTransactionBegin(event.getExecTime());
Header header = createHeader(binlogFileName, event.getHeader(), "", "");
return createEntry(header, EntryType.TRANSACTIONBEGIN, transactionBegin.toByteString());
} else if (StringUtils.endsWithIgnoreCase(queryString, COMMIT)) {
TransactionEnd transactionEnd = createTransactionEnd(0L, event.getWhen()); // MyISAM可能不会有xid事件
Header header = createHeader(binlogFileName, event.getHeader(), "", "");
return createEntry(header, EntryType.TRANSACTIONEND, transactionEnd.toByteString());
} else {
// DDL语句处理
DdlResult result = SimpleDdlParser.parse(queryString, event.getDbName());
if (result == null) {
logger.warn(
"WARN ## sql = {} , position = {}:{} is not create table/alter table/drop table ddl sql,so will ignore",
new Object[] { queryString, binlogFileName,
event.getHeader().getLogPos() - event.getHeader().getEventLen() });
return null;
}
String schemaName = event.getDbName();
String tableName = result.getTableName();
if (tableMetaCache != null && (result.getType() == EventType.ALTER || result.getType() == EventType.ERASE)) {
if (StringUtils.isNotEmpty(tableName)) {
// 如果解析到了正确的表信息,则根据全名进行清除
tableMetaCache.clearTableMetaWithFullName(schemaName + "." + tableName);
} else {
// 如果无法解析正确的表信息,则根据schema进行清除
tableMetaCache.clearTableMetaWithSchemaName(schemaName);
}
}
Header header = createHeader(binlogFileName, event.getHeader(), schemaName, tableName);
RowChange.Builder rowChangeBuider = RowChange.newBuilder();
rowChangeBuider.setIsDdl(true);
rowChangeBuider.setSql(queryString);
rowChangeBuider.setEventType(result.getType());
return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());