mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #726, 优化SessionHandler里直接拼byte[],绕过protobuf的多次拷贝
This commit is contained in:
@@ -331,6 +331,11 @@ public abstract class AbstractEventParser<EVENT> extends AbstractCanalLifeCycle
|
||||
stopHeartBeat(); // 先停止心跳
|
||||
parseThread.interrupt(); // 尝试中断
|
||||
eventSink.interrupt();
|
||||
|
||||
if (multiStageCoprocessor != null && multiStageCoprocessor.isStart()) {
|
||||
multiStageCoprocessor.stop();
|
||||
}
|
||||
|
||||
try {
|
||||
parseThread.join();// 等待其结束
|
||||
} catch (InterruptedException e) {
|
||||
@@ -343,10 +348,6 @@ public abstract class AbstractEventParser<EVENT> extends AbstractCanalLifeCycle
|
||||
if (transactionBuffer.isStart()) {
|
||||
transactionBuffer.stop();
|
||||
}
|
||||
|
||||
if (multiStageCoprocessor != null && multiStageCoprocessor.isStart()) {
|
||||
multiStageCoprocessor.stop();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean consumeTheEventAndProfilingIfNecessary(List<CanalEntry.Entry> entrys) throws CanalSinkException,
|
||||
|
||||
@@ -21,9 +21,9 @@ public interface MultiStageCoprocessor extends CanalLifeCycle {
|
||||
/**
|
||||
* 网络数据投递
|
||||
*/
|
||||
public void publish(LogBuffer buffer);
|
||||
public boolean publish(LogBuffer buffer);
|
||||
|
||||
public void publish(LogBuffer buffer, String binlogFileName);
|
||||
public boolean publish(LogBuffer buffer, String binlogFileName);
|
||||
|
||||
public void reset();
|
||||
}
|
||||
|
||||
@@ -221,7 +221,11 @@ public class LocalBinLogConnection implements ErosaConnection {
|
||||
while (fetcher.fetch()) {
|
||||
LogBuffer buffer = fetcher.duplicate();
|
||||
fetcher.consume(fetcher.limit());
|
||||
coprocessor.publish(buffer, binlogfilename); // set filename
|
||||
// set filename
|
||||
if (!coprocessor.publish(buffer, binlogfilename)) {
|
||||
needContinue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (needContinue) {// 读取下一个
|
||||
|
||||
@@ -206,7 +206,9 @@ public class MysqlConnection implements ErosaConnection {
|
||||
while (fetcher.fetch()) {
|
||||
LogBuffer buffer = fetcher.duplicate();
|
||||
fetcher.consume(fetcher.limit());
|
||||
coprocessor.publish(buffer);
|
||||
if (!coprocessor.publish(buffer)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fetcher.close();
|
||||
@@ -230,7 +232,9 @@ public class MysqlConnection implements ErosaConnection {
|
||||
while (fetcher.fetch()) {
|
||||
LogBuffer buffer = fetcher.duplicate();
|
||||
fetcher.consume(fetcher.limit());
|
||||
coprocessor.publish(buffer);
|
||||
if (!coprocessor.publish(buffer)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fetcher.close();
|
||||
|
||||
@@ -135,20 +135,22 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
} catch (Throwable e) {
|
||||
// ignore
|
||||
}
|
||||
disruptorMsgBuffer = null;
|
||||
super.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* 网络数据投递
|
||||
*/
|
||||
public void publish(LogBuffer buffer) {
|
||||
publish(buffer, null);
|
||||
public boolean publish(LogBuffer buffer) {
|
||||
return publish(buffer, null);
|
||||
}
|
||||
|
||||
public void publish(LogBuffer buffer, String binlogFileName) {
|
||||
if (!isStart() && exception != null) {
|
||||
throw exception;
|
||||
public boolean publish(LogBuffer buffer, String binlogFileName) {
|
||||
if (!isStart()) {
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean interupted = false;
|
||||
@@ -172,6 +174,8 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
return isStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user