mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #726 , 优化完毕
This commit is contained in:
@@ -8,15 +8,6 @@ import java.sql.Statement;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent;
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.QueryLogEvent;
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.RotateLogEvent;
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent;
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.UpdateRowsLogEvent;
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent;
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.XidLogEvent;
|
|
||||||
import com.taobao.tddl.dbsync.binlog.event.mariadb.AnnotateRowsEvent;
|
|
||||||
|
|
||||||
public class DirectLogFetcherTest extends BaseLogFetcherTest {
|
public class DirectLogFetcherTest extends BaseLogFetcherTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -24,56 +15,54 @@ public class DirectLogFetcherTest extends BaseLogFetcherTest {
|
|||||||
DirectLogFetcher fecther = new DirectLogFetcher();
|
DirectLogFetcher fecther = new DirectLogFetcher();
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306", "root", "hello");
|
Connection connection = DriverManager.getConnection("jdbc:mysql://100.81.154.142:3306", "root", "hello");
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
statement.execute("SET @master_binlog_checksum='@@global.binlog_checksum'");
|
statement.execute("SET @master_binlog_checksum='@@global.binlog_checksum'");
|
||||||
statement.execute("SET @mariadb_slave_capability='" + LogEvent.MARIA_SLAVE_CAPABILITY_MINE + "'");
|
statement.execute("SET @mariadb_slave_capability='" + LogEvent.MARIA_SLAVE_CAPABILITY_MINE + "'");
|
||||||
|
|
||||||
fecther.open(connection, "mysql-bin.000001", 4L, 2);
|
fecther.open(connection, "mysql-bin.000006", 120L, 2);
|
||||||
|
|
||||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.UNKNOWN_EVENT);
|
||||||
LogContext context = new LogContext();
|
LogContext context = new LogContext();
|
||||||
while (fecther.fetch()) {
|
while (fecther.fetch()) {
|
||||||
LogEvent event = null;
|
decoder.decode(fecther, context);
|
||||||
event = decoder.decode(fecther, context);
|
continue;
|
||||||
|
// if (event == null) {
|
||||||
if (event == null) {
|
// continue;
|
||||||
continue;
|
// }
|
||||||
// throw new RuntimeException("parse failed");
|
//
|
||||||
}
|
// int eventType = event.getHeader().getType();
|
||||||
|
// switch (eventType) {
|
||||||
int eventType = event.getHeader().getType();
|
// case LogEvent.ROTATE_EVENT:
|
||||||
switch (eventType) {
|
// binlogFileName = ((RotateLogEvent) event).getFilename();
|
||||||
case LogEvent.ROTATE_EVENT:
|
// break;
|
||||||
binlogFileName = ((RotateLogEvent) event).getFilename();
|
// case LogEvent.WRITE_ROWS_EVENT_V1:
|
||||||
break;
|
// case LogEvent.WRITE_ROWS_EVENT:
|
||||||
case LogEvent.WRITE_ROWS_EVENT_V1:
|
// parseRowsEvent((WriteRowsLogEvent) event);
|
||||||
case LogEvent.WRITE_ROWS_EVENT:
|
// break;
|
||||||
parseRowsEvent((WriteRowsLogEvent) event);
|
// case LogEvent.UPDATE_ROWS_EVENT_V1:
|
||||||
break;
|
// case LogEvent.UPDATE_ROWS_EVENT:
|
||||||
case LogEvent.UPDATE_ROWS_EVENT_V1:
|
// parseRowsEvent((UpdateRowsLogEvent) event);
|
||||||
case LogEvent.UPDATE_ROWS_EVENT:
|
// break;
|
||||||
parseRowsEvent((UpdateRowsLogEvent) event);
|
// case LogEvent.DELETE_ROWS_EVENT_V1:
|
||||||
break;
|
// case LogEvent.DELETE_ROWS_EVENT:
|
||||||
case LogEvent.DELETE_ROWS_EVENT_V1:
|
// parseRowsEvent((DeleteRowsLogEvent) event);
|
||||||
case LogEvent.DELETE_ROWS_EVENT:
|
// break;
|
||||||
parseRowsEvent((DeleteRowsLogEvent) event);
|
// case LogEvent.QUERY_EVENT:
|
||||||
break;
|
// parseQueryEvent((QueryLogEvent) event);
|
||||||
case LogEvent.QUERY_EVENT:
|
// break;
|
||||||
parseQueryEvent((QueryLogEvent) event);
|
// case LogEvent.ROWS_QUERY_LOG_EVENT:
|
||||||
break;
|
// parseRowsQueryEvent((RowsQueryLogEvent) event);
|
||||||
case LogEvent.ROWS_QUERY_LOG_EVENT:
|
// break;
|
||||||
parseRowsQueryEvent((RowsQueryLogEvent) event);
|
// case LogEvent.ANNOTATE_ROWS_EVENT:
|
||||||
break;
|
// parseAnnotateRowsEvent((AnnotateRowsEvent) event);
|
||||||
case LogEvent.ANNOTATE_ROWS_EVENT:
|
// break;
|
||||||
parseAnnotateRowsEvent((AnnotateRowsEvent) event);
|
// case LogEvent.XID_EVENT:
|
||||||
break;
|
// parseXidEvent((XidLogEvent) event);
|
||||||
case LogEvent.XID_EVENT:
|
// break;
|
||||||
parseXidEvent((XidLogEvent) event);
|
// default:
|
||||||
break;
|
// break;
|
||||||
default:
|
// }
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.alibaba.otter.canal.parse.driver.mysql.socket;
|
package com.alibaba.otter.canal.parse.driver.mysql.socket;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -24,7 +25,7 @@ public class BioSocketChannel implements SocketChannel {
|
|||||||
|
|
||||||
BioSocketChannel(Socket socket) throws IOException{
|
BioSocketChannel(Socket socket) throws IOException{
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.input = socket.getInputStream();
|
this.input = new BufferedInputStream(socket.getInputStream(), 16384);
|
||||||
this.output = socket.getOutputStream();
|
this.output = socket.getOutputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,5 +165,4 @@ public class BioSocketChannel implements SocketChannel {
|
|||||||
this.socket = null;
|
this.socket = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ public abstract class BioSocketChannelPool {
|
|||||||
socket.setKeepAlive(true);
|
socket.setKeepAlive(true);
|
||||||
socket.setReuseAddress(true);
|
socket.setReuseAddress(true);
|
||||||
socket.connect(address, BioSocketChannel.DEFAULT_CONNECT_TIMEOUT);
|
socket.connect(address, BioSocketChannel.DEFAULT_CONNECT_TIMEOUT);
|
||||||
|
System.out.println(socket.getReceiveBufferSize());
|
||||||
|
System.out.println(socket.getSendBufferSize());
|
||||||
return new BioSocketChannel(socket);
|
return new BioSocketChannel(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ public class MysqlDumpTest {
|
|||||||
controller.setTsdbSpringXml("classpath:tsdb/h2-tsdb.xml");
|
controller.setTsdbSpringXml("classpath:tsdb/h2-tsdb.xml");
|
||||||
controller.setEventFilter(new AviaterRegexFilter("test\\..*"));
|
controller.setEventFilter(new AviaterRegexFilter("test\\..*"));
|
||||||
controller.setEventBlackFilter(new AviaterRegexFilter("canal_tsdb\\..*"));
|
controller.setEventBlackFilter(new AviaterRegexFilter("canal_tsdb\\..*"));
|
||||||
|
controller.setParallel(true);
|
||||||
|
controller.setParallelBufferSize(4096);
|
||||||
|
controller.setParallelThreadSize(16);
|
||||||
controller.setIsGTIDMode(false);
|
controller.setIsGTIDMode(false);
|
||||||
controller.setEventSink(new AbstractCanalEventSinkTest<List<Entry>>() {
|
controller.setEventSink(new AbstractCanalEventSinkTest<List<Entry>>() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user