Search in sources :

Example 6 with QueryLogEvent

use of com.taobao.tddl.dbsync.binlog.event.QueryLogEvent in project canal by alibaba.

the class DirectLogFetcherTest method testSimple.

@Test
public void testSimple() {
    DirectLogFetcher fecther = new DirectLogFetcher();
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306", "root", "hello");
        Statement statement = connection.createStatement();
        statement.execute("SET @master_binlog_checksum='@@global.binlog_checksum'");
        statement.execute("SET @mariadb_slave_capability='" + LogEvent.MARIA_SLAVE_CAPABILITY_MINE + "'");
        fecther.open(connection, "mysql-bin.000007", 89797036L, 2);
        LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
        LogContext context = new LogContext();
        while (fecther.fetch()) {
            LogEvent event = decoder.decode(fecther, context);
            int eventType = event.getHeader().getType();
            switch(eventType) {
                case LogEvent.ROTATE_EVENT:
                    binlogFileName = ((RotateLogEvent) event).getFilename();
                    break;
                case LogEvent.WRITE_ROWS_EVENT_V1:
                case LogEvent.WRITE_ROWS_EVENT:
                    parseRowsEvent((WriteRowsLogEvent) event);
                    break;
                case LogEvent.UPDATE_ROWS_EVENT_V1:
                case LogEvent.PARTIAL_UPDATE_ROWS_EVENT:
                case LogEvent.UPDATE_ROWS_EVENT:
                    parseRowsEvent((UpdateRowsLogEvent) event);
                    break;
                case LogEvent.DELETE_ROWS_EVENT_V1:
                case LogEvent.DELETE_ROWS_EVENT:
                    parseRowsEvent((DeleteRowsLogEvent) event);
                    break;
                case LogEvent.QUERY_EVENT:
                    parseQueryEvent((QueryLogEvent) event);
                    break;
                case LogEvent.ROWS_QUERY_LOG_EVENT:
                    parseRowsQueryEvent((RowsQueryLogEvent) event);
                    break;
                case LogEvent.ANNOTATE_ROWS_EVENT:
                    parseAnnotateRowsEvent((AnnotateRowsEvent) event);
                    break;
                case LogEvent.XID_EVENT:
                    parseXidEvent((XidLogEvent) event);
                    break;
                default:
                    break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    } finally {
        try {
            fecther.close();
        } catch (IOException e) {
            Assert.fail(e.getMessage());
        }
    }
}
Also used : UpdateRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent) RowsQueryLogEvent(com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent) DeleteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent) WriteRowsLogEvent(com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent) XidLogEvent(com.taobao.tddl.dbsync.binlog.event.XidLogEvent) RotateLogEvent(com.taobao.tddl.dbsync.binlog.event.RotateLogEvent) QueryLogEvent(com.taobao.tddl.dbsync.binlog.event.QueryLogEvent) Statement(java.sql.Statement) Connection(java.sql.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

QueryLogEvent (com.taobao.tddl.dbsync.binlog.event.QueryLogEvent)6 DeleteRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent)4 RotateLogEvent (com.taobao.tddl.dbsync.binlog.event.RotateLogEvent)4 RowsQueryLogEvent (com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent)4 UpdateRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent)4 WriteRowsLogEvent (com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent)4 XidLogEvent (com.taobao.tddl.dbsync.binlog.event.XidLogEvent)4 LogContext (com.taobao.tddl.dbsync.binlog.LogContext)3 LogDecoder (com.taobao.tddl.dbsync.binlog.LogDecoder)3 LogEvent (com.taobao.tddl.dbsync.binlog.LogEvent)3 File (java.io.File)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 FileLogFetcher (com.taobao.tddl.dbsync.binlog.FileLogFetcher)2 LogPosition (com.taobao.tddl.dbsync.binlog.LogPosition)2 FormatDescriptionLogEvent (com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent)2 RowsLogEvent (com.taobao.tddl.dbsync.binlog.event.RowsLogEvent)2 TableMapLogEvent (com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent)2 MysqlConnector (com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector)1 GTIDSet (com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet)1