mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
format & import
This commit is contained in:
@@ -83,30 +83,27 @@ public class LocalBinLogConnection implements ErosaConnection {
|
||||
context.setLogPosition(new LogPosition(binlogfilename, binlogPosition));
|
||||
while (running) {
|
||||
boolean needContinue = true;
|
||||
LogEvent event = null;
|
||||
L:while (fetcher.fetch()) {
|
||||
/*event = decoder.decode(fetcher, context);
|
||||
if (event == null) {
|
||||
throw new CanalParseException("parse failed");
|
||||
}
|
||||
LogEvent event = null;
|
||||
L: while (fetcher.fetch()) {
|
||||
/*
|
||||
* event = decoder.decode(fetcher, context); if (event ==
|
||||
* null) { throw new CanalParseException("parse failed"); }
|
||||
* if (!func.sink(event)) { needContinue = false; break; }
|
||||
*/
|
||||
|
||||
if (!func.sink(event)) {
|
||||
needContinue = false;
|
||||
break;
|
||||
}*/
|
||||
do {
|
||||
if (event == null) {
|
||||
event = new RotateLogEvent(context.getLogPosition().getFileName(), context.getLogPosition()
|
||||
.getPosition());
|
||||
} else {
|
||||
event = decoder.decode(fetcher, context);
|
||||
}
|
||||
|
||||
do {
|
||||
if (event == null) {
|
||||
event = new RotateLogEvent(context.getLogPosition().getFileName(), context.getLogPosition().getPosition());
|
||||
} else {
|
||||
event = decoder.decode(fetcher, context);
|
||||
}
|
||||
|
||||
if (event != null && !func.sink(event)) {
|
||||
needContinue = false;
|
||||
break L;
|
||||
}
|
||||
} while (event != null);
|
||||
if (event != null && !func.sink(event)) {
|
||||
needContinue = false;
|
||||
break L;
|
||||
}
|
||||
} while (event != null);
|
||||
}
|
||||
|
||||
if (needContinue) {// 读取下一个
|
||||
|
||||
@@ -27,7 +27,7 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
||||
private EntryPosition masterPosition; // binlog信息
|
||||
private MysqlConnection metaConnection; // 查询meta信息的链接
|
||||
private TableMetaCache tableMetaCache; // 对应meta
|
||||
|
||||
|
||||
private String directory;
|
||||
private boolean needWait = false;
|
||||
private int bufferSize = 16 * 1024;
|
||||
@@ -39,24 +39,24 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
||||
@Override
|
||||
protected ErosaConnection buildErosaConnection() {
|
||||
return buildLocalBinLogConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void preDump(ErosaConnection connection) {
|
||||
metaConnection = buildMysqlConnection();
|
||||
protected void preDump(ErosaConnection connection) {
|
||||
metaConnection = buildMysqlConnection();
|
||||
try {
|
||||
metaConnection.connect();
|
||||
} catch (IOException e) {
|
||||
throw new CanalParseException(e);
|
||||
}
|
||||
|
||||
|
||||
tableMetaCache = new TableMetaCache(metaConnection);
|
||||
((LogEventConvert) binlogParser).setTableMetaCache(tableMetaCache);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterDump(ErosaConnection connection) {
|
||||
if (metaConnection != null) {
|
||||
@Override
|
||||
protected void afterDump(ErosaConnection connection) {
|
||||
if (metaConnection != null) {
|
||||
try {
|
||||
metaConnection.disconnect();
|
||||
} catch (IOException e) {
|
||||
@@ -64,19 +64,19 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
||||
.getAddress(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start() throws CanalParseException {
|
||||
public void start() throws CanalParseException {
|
||||
if (runningInfo == null) { // 第一次链接主库
|
||||
runningInfo = masterInfo;
|
||||
}
|
||||
|
||||
super.start();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (metaConnection != null) {
|
||||
public void stop() {
|
||||
if (metaConnection != null) {
|
||||
try {
|
||||
metaConnection.disconnect();
|
||||
} catch (IOException e) {
|
||||
@@ -90,9 +90,9 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
||||
}
|
||||
|
||||
super.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private ErosaConnection buildLocalBinLogConnection() {
|
||||
private ErosaConnection buildLocalBinLogConnection() {
|
||||
LocalBinLogConnection connection = new LocalBinLogConnection();
|
||||
|
||||
connection.setBufferSize(this.bufferSize);
|
||||
@@ -114,7 +114,7 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
||||
connection.setCharset(connectionCharset);
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected EntryPosition findStartPosition(ErosaConnection connection) {
|
||||
// 处理逻辑
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.alibaba.otter.canal.parse.inbound.mysql;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
@@ -148,8 +147,7 @@ public class MysqlConnection implements ErosaConnection {
|
||||
HeaderPacket binlogDumpHeader = new HeaderPacket();
|
||||
binlogDumpHeader.setPacketBodyLength(cmdBody.length);
|
||||
binlogDumpHeader.setPacketSequenceNumber((byte) 0x00);
|
||||
PacketManager.write(connector.getChannel(), binlogDumpHeader.toBytes(),
|
||||
cmdBody);
|
||||
PacketManager.write(connector.getChannel(), binlogDumpHeader.toBytes(), cmdBody);
|
||||
|
||||
connector.setDumping(true);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class DirectLogFetcher extends LogFetcher {
|
||||
throw new IOException("Unexpected End Stream");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// for (int count, n = 0; n < len; n += count) {
|
||||
// if (0 > (count = input.read(buffer, off + n, len - n))) {
|
||||
// // Reached end of input stream
|
||||
|
||||
@@ -190,9 +190,9 @@ public class BinLogFileQueue {
|
||||
files.addAll(FileUtils.listFiles(directory, new IOFileFilter() {
|
||||
|
||||
public boolean accept(File file) {
|
||||
Pattern pattern = Pattern.compile("\\d+$");
|
||||
Matcher matcher = pattern.matcher(file.getName());
|
||||
return file.getName().startsWith(baseName) && matcher.find();
|
||||
Pattern pattern = Pattern.compile("\\d+$");
|
||||
Matcher matcher = pattern.matcher(file.getName());
|
||||
return file.getName().startsWith(baseName) && matcher.find();
|
||||
}
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.alibaba.otter.canal.parse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -94,6 +93,6 @@ public class DirectLogFetcherTest {
|
||||
HeaderPacket binlogDumpHeader = new HeaderPacket();
|
||||
binlogDumpHeader.setPacketBodyLength(cmdBody.length);
|
||||
binlogDumpHeader.setPacketSequenceNumber((byte) 0x00);
|
||||
PacketManager.write(connector.getChannel(), binlogDumpHeader.toBytes(),cmdBody);
|
||||
PacketManager.write(connector.getChannel(), binlogDumpHeader.toBytes(), cmdBody);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.otter.canal.parse.inbound.EventTransactionBuffer.TransactionFlushCallback;
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest;
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest;
|
||||
|
||||
@@ -164,7 +164,7 @@ public class SimpleDdlParserTest {
|
||||
Assert.assertEquals("retl_mark1", result.getOriTableName());
|
||||
Assert.assertEquals("retl_mark3", result.getTableName());
|
||||
|
||||
//正则匹配test case
|
||||
// 正则匹配test case
|
||||
|
||||
queryString = "rename table totl_mark to totl_mark2";
|
||||
result = SimpleDdlParser.parse(queryString, "retl");
|
||||
|
||||
@@ -3,9 +3,8 @@ package com.alibaba.otter.canal.parse.index;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ package com.alibaba.otter.canal.parse.index;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.alibaba.otter.canal.parse.index;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.alibaba.otter.canal.parse.index;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user