mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
Refactor metrics code.
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.otter.canal.parse.exception.PositionNotFoundException;
|
||||
import com.alibaba.otter.canal.common.utils.SerializedLongAdder;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.alibaba.otter.canal.parse.inbound.mysql;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.otter.canal.common.utils.SerializedLongAdder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -22,24 +22,24 @@ import com.alibaba.otter.canal.protocol.position.EntryPosition;
|
||||
|
||||
public abstract class AbstractMysqlEventParser extends AbstractEventParser {
|
||||
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
protected static final long BINLOG_START_OFFEST = 4L;
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
protected static final long BINLOG_START_OFFEST = 4L;
|
||||
|
||||
protected TableMetaTSDBFactory tableMetaTSDBFactory = new DefaultTableMetaTSDBFactory();
|
||||
protected boolean enableTsdb = false;
|
||||
protected TableMetaTSDBFactory tableMetaTSDBFactory = new DefaultTableMetaTSDBFactory();
|
||||
protected boolean enableTsdb = false;
|
||||
protected String tsdbSpringXml;
|
||||
protected TableMetaTSDB tableMetaTSDB;
|
||||
|
||||
// 编码信息
|
||||
protected byte connectionCharsetNumber = (byte) 33;
|
||||
protected Charset connectionCharset = Charset.forName("UTF-8");
|
||||
protected boolean filterQueryDcl = false;
|
||||
protected boolean filterQueryDml = false;
|
||||
protected boolean filterQueryDdl = false;
|
||||
protected boolean filterRows = false;
|
||||
protected boolean filterTableError = false;
|
||||
protected boolean useDruidDdlFilter = true;
|
||||
private final SerializedLongAdder eventsPublishBlockingTime = new SerializedLongAdder(0L);
|
||||
protected byte connectionCharsetNumber = (byte) 33;
|
||||
protected Charset connectionCharset = Charset.forName("UTF-8");
|
||||
protected boolean filterQueryDcl = false;
|
||||
protected boolean filterQueryDml = false;
|
||||
protected boolean filterQueryDdl = false;
|
||||
protected boolean filterRows = false;
|
||||
protected boolean filterTableError = false;
|
||||
protected boolean useDruidDdlFilter = true;
|
||||
private final AtomicLong eventsPublishBlockingTime = new AtomicLong(0L);
|
||||
|
||||
protected BinlogParser buildParser() {
|
||||
LogEventConvert convert = new LogEventConvert();
|
||||
@@ -207,8 +207,8 @@ public abstract class AbstractMysqlEventParser extends AbstractEventParser {
|
||||
public void setTableMetaTSDBFactory(TableMetaTSDBFactory tableMetaTSDBFactory) {
|
||||
this.tableMetaTSDBFactory = tableMetaTSDBFactory;
|
||||
}
|
||||
|
||||
public SerializedLongAdder getEventsPublishBlockingTime() {
|
||||
|
||||
public AtomicLong getEventsPublishBlockingTime() {
|
||||
return this.eventsPublishBlockingTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.net.InetSocketAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.otter.canal.common.utils.SerializedLongAdder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -52,7 +52,7 @@ public class MysqlConnection implements ErosaConnection {
|
||||
private AuthenticationInfo authInfo;
|
||||
protected int connTimeout = 5 * 1000; // 5秒
|
||||
protected int soTimeout = 60 * 60 * 1000; // 1小时
|
||||
private SerializedLongAdder receivedBinlogBytes;
|
||||
private AtomicLong receivedBinlogBytes;
|
||||
|
||||
public MysqlConnection(){
|
||||
}
|
||||
@@ -473,7 +473,7 @@ public class MysqlConnection implements ErosaConnection {
|
||||
|
||||
private void accumulateReceivedBytes(long x) {
|
||||
if (receivedBinlogBytes != null) {
|
||||
receivedBinlogBytes.add(x);
|
||||
receivedBinlogBytes.addAndGet(x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ public class MysqlConnection implements ErosaConnection {
|
||||
this.authInfo = authInfo;
|
||||
}
|
||||
|
||||
public void setReceivedBinlogBytes(SerializedLongAdder receivedBinlogBytes) {
|
||||
public void setReceivedBinlogBytes(AtomicLong receivedBinlogBytes) {
|
||||
this.receivedBinlogBytes = receivedBinlogBytes;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.Map;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.otter.canal.common.utils.SerializedLongAdder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -73,7 +72,7 @@ public class MysqlEventParser extends AbstractMysqlEventParser implements CanalE
|
||||
private int dumpErrorCountThreshold = 2; // binlogDump失败异常计数阀值
|
||||
|
||||
// instance received binlog bytes
|
||||
private final SerializedLongAdder receivedBinlogBytes = new SerializedLongAdder(0L);
|
||||
private final AtomicLong receivedBinlogBytes = new AtomicLong(0L);
|
||||
|
||||
protected ErosaConnection buildErosaConnection() {
|
||||
return buildMysqlConnection(this.runningInfo);
|
||||
@@ -516,7 +515,7 @@ public class MysqlEventParser extends AbstractMysqlEventParser implements CanalE
|
||||
private Long findTransactionBeginPosition(ErosaConnection mysqlConnection, final EntryPosition entryPosition)
|
||||
throws IOException {
|
||||
// 针对开始的第一条为非Begin记录,需要从该binlog扫描
|
||||
final AtomicLong preTransactionStartPosition = new AtomicLong(0L);
|
||||
final java.util.concurrent.atomic.AtomicLong preTransactionStartPosition = new java.util.concurrent.atomic.AtomicLong(0L);
|
||||
mysqlConnection.reconnect();
|
||||
mysqlConnection.seek(entryPosition.getJournalName(), 4L, new SinkFunction<LogEvent>() {
|
||||
|
||||
@@ -917,7 +916,7 @@ public class MysqlEventParser extends AbstractMysqlEventParser implements CanalE
|
||||
|
||||
|
||||
|
||||
public SerializedLongAdder getReceivedBinlogBytes() {
|
||||
public AtomicLong getReceivedBinlogBytes() {
|
||||
return this.receivedBinlogBytes;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.alibaba.otter.canal.parse.inbound.mysql;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import com.alibaba.otter.canal.common.utils.SerializedLongAdder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.otter.canal.common.AbstractCanalLifeCycle;
|
||||
@@ -65,7 +65,7 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
private ExecutorService stageExecutor;
|
||||
private String destination;
|
||||
private volatile CanalParseException exception;
|
||||
private SerializedLongAdder eventsPublishBlockingTime;
|
||||
private AtomicLong eventsPublishBlockingTime;
|
||||
|
||||
public MysqlMultiStageCoprocessor(int ringBufferSize, int parserThreadCount, LogEventConvert logEventConvert,
|
||||
EventTransactionBuffer transactionBuffer, String destination){
|
||||
@@ -176,7 +176,7 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
}
|
||||
disruptorMsgBuffer.publish(next);
|
||||
if (fullTimes > 0) {
|
||||
eventsPublishBlockingTime.add(System.nanoTime() - blockingStart);
|
||||
eventsPublishBlockingTime.addAndGet(System.nanoTime() - blockingStart);
|
||||
}
|
||||
break;
|
||||
} catch (InsufficientCapacityException e) {
|
||||
@@ -457,7 +457,7 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public void setEventsPublishBlockingTime(SerializedLongAdder eventsPublishBlockingTime) {
|
||||
public void setEventsPublishBlockingTime(AtomicLong eventsPublishBlockingTime) {
|
||||
this.eventsPublishBlockingTime = eventsPublishBlockingTime;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user