mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
Compare commits
26 Commits
v1.0.23
...
canal-1.0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e026f2495 | ||
|
|
2e3796cb07 | ||
|
|
b2a5f482ee | ||
|
|
e5444ae658 | ||
|
|
73627df082 | ||
|
|
2eb05b5934 | ||
|
|
83689ee519 | ||
|
|
d78b389737 | ||
|
|
20d8ac67dc | ||
|
|
19a56fb77e | ||
|
|
c629e8c899 | ||
|
|
75a5a4d7df | ||
|
|
045a2e5a50 | ||
|
|
11d0712291 | ||
|
|
03ff9512dd | ||
|
|
0ee2e767d2 | ||
|
|
ff97dcbbc9 | ||
|
|
92c1a51726 | ||
|
|
36216e63ea | ||
|
|
db4fc68a55 | ||
|
|
eef58005d9 | ||
|
|
8141ddc4e8 | ||
|
|
004f26465f | ||
|
|
5dc62bbda8 | ||
|
|
f45f1ac74f | ||
|
|
5c11c71783 |
@@ -80,3 +80,10 @@ See the wiki page for : <a href="https://github.com/alibaba/canal/wiki" >wiki文
|
|||||||
<li>新浪微博: agapple0002 </li>
|
<li>新浪微博: agapple0002 </li>
|
||||||
<li>报告issue:<a href="https://github.com/alibaba/canal/issues">issues</a></li>
|
<li>报告issue:<a href="https://github.com/alibaba/canal/issues">issues</a></li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
【招聘】阿里巴巴中间件团队招聘JAVA高级工程师
|
||||||
|
岗位主要为技术型内容(非业务部门),阿里中间件整个体系对于未来想在技术上有所沉淀的同学还是非常有帮助的
|
||||||
|
工作地点:杭州、北京均可. ps. 阿里待遇向来都是不错的,有意者可以QQ、微博私聊.
|
||||||
|
具体招聘内容:https://job.alibaba.com/zhaopin/position_detail.htm?positionId=32666
|
||||||
|
</pre>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -114,5 +114,4 @@ public class ClusterNodeAccessStrategy implements CanalNodeAccessStrategy {
|
|||||||
return zkClient;
|
return zkClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>canal.common</artifactId>
|
<artifactId>canal.common</artifactId>
|
||||||
@@ -11,6 +11,11 @@
|
|||||||
<name>canal common module for otter ${project.version}</name>
|
<name>canal common module for otter ${project.version}</name>
|
||||||
<url>http://b2b-doc.alibaba-inc.com/display/opentech/Otter</url>
|
<url>http://b2b-doc.alibaba-inc.com/display/opentech/Otter</url>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-all</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- zk -->
|
<!-- zk -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.zookeeper</groupId>
|
<groupId>org.apache.zookeeper</groupId>
|
||||||
@@ -28,7 +33,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
<version>2.6</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
@@ -61,8 +65,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!-- junit -->
|
<!-- junit -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -88,8 +88,9 @@ public class JsonUtils {
|
|||||||
|
|
||||||
public static InetAddressSerializer instance = new InetAddressSerializer();
|
public static InetAddressSerializer instance = new InetAddressSerializer();
|
||||||
|
|
||||||
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType)
|
@Override
|
||||||
throws IOException {
|
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
|
||||||
|
throws IOException {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
serializer.writeNull();
|
serializer.writeNull();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -52,23 +52,24 @@ public class JsonConversion {
|
|||||||
public static final int VALUE_ENTRY_SIZE_SMALL = (1 + SMALL_OFFSET_SIZE);
|
public static final int VALUE_ENTRY_SIZE_SMALL = (1 + SMALL_OFFSET_SIZE);
|
||||||
public static final int VALUE_ENTRY_SIZE_LARGE = (1 + LARGE_OFFSET_SIZE);
|
public static final int VALUE_ENTRY_SIZE_LARGE = (1 + LARGE_OFFSET_SIZE);
|
||||||
|
|
||||||
public static Json_Value parse_value(int type, LogBuffer buffer, long len) {
|
public static Json_Value parse_value(int type, LogBuffer buffer, long len, String charsetName) {
|
||||||
buffer = buffer.duplicate(buffer.position(), (int) len);
|
buffer = buffer.duplicate(buffer.position(), (int) len);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case JSONB_TYPE_SMALL_OBJECT:
|
case JSONB_TYPE_SMALL_OBJECT:
|
||||||
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, false);
|
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, false, charsetName);
|
||||||
case JSONB_TYPE_LARGE_OBJECT:
|
case JSONB_TYPE_LARGE_OBJECT:
|
||||||
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, true);
|
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, true, charsetName);
|
||||||
case JSONB_TYPE_SMALL_ARRAY:
|
case JSONB_TYPE_SMALL_ARRAY:
|
||||||
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, false);
|
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, false, charsetName);
|
||||||
case JSONB_TYPE_LARGE_ARRAY:
|
case JSONB_TYPE_LARGE_ARRAY:
|
||||||
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, true);
|
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, true, charsetName);
|
||||||
default:
|
default:
|
||||||
return parse_scalar(type, buffer, len);
|
return parse_scalar(type, buffer, len, charsetName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Json_Value parse_array_or_object(Json_enum_type type, LogBuffer buffer, long len, boolean large) {
|
private static Json_Value parse_array_or_object(Json_enum_type type, LogBuffer buffer, long len, boolean large,
|
||||||
|
String charsetName) {
|
||||||
long offset_size = large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
|
long offset_size = large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
|
||||||
if (len < 2 * offset_size) {
|
if (len < 2 * offset_size) {
|
||||||
throw new IllegalArgumentException("illegal json data");
|
throw new IllegalArgumentException("illegal json data");
|
||||||
@@ -95,7 +96,7 @@ public class JsonConversion {
|
|||||||
return large ? buffer.getUint32() : buffer.getUint16();
|
return large ? buffer.getUint32() : buffer.getUint16();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Json_Value parse_scalar(int type, LogBuffer buffer, long len) {
|
private static Json_Value parse_scalar(int type, LogBuffer buffer, long len, String charsetName) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case JSONB_TYPE_LITERAL:
|
case JSONB_TYPE_LITERAL:
|
||||||
/* purecov: inspected */
|
/* purecov: inspected */
|
||||||
@@ -146,12 +147,12 @@ public class JsonConversion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_len == 0 || len < n + str_len) {
|
if (len < n + str_len) {
|
||||||
throw new IllegalArgumentException("illegal json data");
|
throw new IllegalArgumentException("illegal json data");
|
||||||
}
|
}
|
||||||
return new Json_Value(Json_enum_type.STRING, buffer.rewind()
|
return new Json_Value(Json_enum_type.STRING, buffer.rewind()
|
||||||
.forward((int) n)
|
.forward((int) n)
|
||||||
.getFixString((int) str_len));
|
.getFixString((int) str_len, charsetName));
|
||||||
case JSONB_TYPE_OPAQUE:
|
case JSONB_TYPE_OPAQUE:
|
||||||
/*
|
/*
|
||||||
* There should always be at least one byte, which tells the
|
* There should always be at least one byte, which tells the
|
||||||
@@ -237,7 +238,7 @@ public class JsonConversion {
|
|||||||
this.m_large = large;
|
this.m_large = large;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String key(int i) {
|
public String key(int i, String charsetName) {
|
||||||
m_data.rewind();
|
m_data.rewind();
|
||||||
int offset_size = m_large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
|
int offset_size = m_large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
|
||||||
int key_entry_size = m_large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL;
|
int key_entry_size = m_large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL;
|
||||||
@@ -250,10 +251,10 @@ public class JsonConversion {
|
|||||||
// entry, always two
|
// entry, always two
|
||||||
// bytes.
|
// bytes.
|
||||||
long key_length = m_data.getUint16();
|
long key_length = m_data.getUint16();
|
||||||
return m_data.rewind().forward((int) key_offset).getFixString((int) key_length);
|
return m_data.rewind().forward((int) key_offset).getFixString((int) key_length, charsetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Json_Value element(int i) {
|
public Json_Value element(int i, String charsetName) {
|
||||||
m_data.rewind();
|
m_data.rewind();
|
||||||
int offset_size = m_large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
|
int offset_size = m_large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
|
||||||
int key_entry_size = m_large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL;
|
int key_entry_size = m_large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL;
|
||||||
@@ -266,13 +267,13 @@ public class JsonConversion {
|
|||||||
int type = m_data.forward(entry_offset).getUint8();
|
int type = m_data.forward(entry_offset).getUint8();
|
||||||
if (type == JSONB_TYPE_INT16 || type == JSONB_TYPE_UINT16 || type == JSONB_TYPE_LITERAL
|
if (type == JSONB_TYPE_INT16 || type == JSONB_TYPE_UINT16 || type == JSONB_TYPE_LITERAL
|
||||||
|| (m_large && (type == JSONB_TYPE_INT32 || type == JSONB_TYPE_UINT32))) {
|
|| (m_large && (type == JSONB_TYPE_INT32 || type == JSONB_TYPE_UINT32))) {
|
||||||
return parse_scalar(type, m_data, value_entry_size - 1);
|
return parse_scalar(type, m_data, value_entry_size - 1, charsetName);
|
||||||
}
|
}
|
||||||
int value_offset = (int) read_offset_or_size(m_data, m_large);
|
int value_offset = (int) read_offset_or_size(m_data, m_large);
|
||||||
return parse_value(type, m_data.rewind().forward(value_offset), (int) m_length - value_offset);
|
return parse_value(type, m_data.rewind().forward(value_offset), (int) m_length - value_offset, charsetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringBuilder toJsonString(StringBuilder buf) {
|
public StringBuilder toJsonString(StringBuilder buf, String charsetName) {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case OBJECT:
|
case OBJECT:
|
||||||
buf.append("{");
|
buf.append("{");
|
||||||
@@ -280,9 +281,9 @@ public class JsonConversion {
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
}
|
}
|
||||||
buf.append('"').append(key(i)).append('"');
|
buf.append('"').append(key(i, charsetName)).append('"');
|
||||||
buf.append(": ");
|
buf.append(": ");
|
||||||
element(i).toJsonString(buf);
|
element(i, charsetName).toJsonString(buf, charsetName);
|
||||||
}
|
}
|
||||||
buf.append("}");
|
buf.append("}");
|
||||||
break;
|
break;
|
||||||
@@ -292,7 +293,7 @@ public class JsonConversion {
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
}
|
}
|
||||||
element(i).toJsonString(buf);
|
element(i, charsetName).toJsonString(buf, charsetName);
|
||||||
}
|
}
|
||||||
buf.append("]");
|
buf.append("]");
|
||||||
break;
|
break;
|
||||||
@@ -361,7 +362,7 @@ public class JsonConversion {
|
|||||||
}
|
}
|
||||||
buf.append('"').append(text).append('"');
|
buf.append('"').append(text).append('"');
|
||||||
} else {
|
} else {
|
||||||
text = m_data.getFixString((int) m_length);
|
text = m_data.getFixString((int) m_length, charsetName);
|
||||||
buf.append('"').append(text).append('"');
|
buf.append('"').append(text).append('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,8 +168,8 @@ public class LogBuffer {
|
|||||||
* @param newLimit The new limit value; must be non-negative and no larger
|
* @param newLimit The new limit value; must be non-negative and no larger
|
||||||
* than this buffer's capacity
|
* than this buffer's capacity
|
||||||
* @return This buffer
|
* @return This buffer
|
||||||
* @throws IllegalArgumentException If the preconditions on <tt>newLimit</tt>
|
* @throws IllegalArgumentException If the preconditions on
|
||||||
* do not hold
|
* <tt>newLimit</tt> do not hold
|
||||||
*/
|
*/
|
||||||
public final LogBuffer limit(int newLimit) {
|
public final LogBuffer limit(int newLimit) {
|
||||||
if (origin + newLimit > buffer.length || newLimit < 0) throw new IllegalArgumentException("capacity excceed: "
|
if (origin + newLimit > buffer.length || newLimit < 0) throw new IllegalArgumentException("capacity excceed: "
|
||||||
|
|||||||
@@ -141,9 +141,9 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormatDescriptionLogEvent(final int binlogVersion,int binlogChecksum){
|
public FormatDescriptionLogEvent(final int binlogVersion, int binlogChecksum){
|
||||||
this(binlogVersion);
|
this(binlogVersion);
|
||||||
this.header.checksumAlg = binlogChecksum;
|
this.header.checksumAlg = binlogChecksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormatDescriptionLogEvent(final int binlogVersion){
|
public FormatDescriptionLogEvent(final int binlogVersion){
|
||||||
|
|||||||
@@ -330,17 +330,14 @@ public class QueryLogEvent extends LogEvent {
|
|||||||
* MariaDb type,
|
* MariaDb type,
|
||||||
* sec_part of NOW()
|
* sec_part of NOW()
|
||||||
*/
|
*/
|
||||||
+ 1 + (MAX_DBS_IN_EVENT_MTS * (1 + NAME_LEN)) + 3 + 1 + 16 + 1 + 60/*
|
+ 1 + (MAX_DBS_IN_EVENT_MTS * (1 + NAME_LEN)) + 3 + 1 + 32 * 3
|
||||||
* type
|
+ 1 + 60/*
|
||||||
* ,
|
* type ,
|
||||||
* user_len
|
* user_len ,
|
||||||
* ,
|
* user ,
|
||||||
* user
|
* host_len ,
|
||||||
* ,
|
* host
|
||||||
* host_len
|
*/);
|
||||||
* ,
|
|
||||||
* host
|
|
||||||
*/);
|
|
||||||
/**
|
/**
|
||||||
* Fixed data part:
|
* Fixed data part:
|
||||||
* <ul>
|
* <ul>
|
||||||
@@ -397,7 +394,7 @@ public class QueryLogEvent extends LogEvent {
|
|||||||
// inspection by the DBA
|
// inspection by the DBA
|
||||||
private final long execTime;
|
private final long execTime;
|
||||||
private final int errorCode;
|
private final int errorCode;
|
||||||
private final long sessionId; /* thread_id */
|
private final long sessionId; /* thread_id */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'flags2' is a second set of flags (on top of those in Log_event), for
|
* 'flags2' is a second set of flags (on top of those in Log_event), for
|
||||||
@@ -499,26 +496,26 @@ public class QueryLogEvent extends LogEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* query event post-header */
|
/* query event post-header */
|
||||||
public static final int Q_THREAD_ID_OFFSET = 0;
|
public static final int Q_THREAD_ID_OFFSET = 0;
|
||||||
public static final int Q_EXEC_TIME_OFFSET = 4;
|
public static final int Q_EXEC_TIME_OFFSET = 4;
|
||||||
public static final int Q_DB_LEN_OFFSET = 8;
|
public static final int Q_DB_LEN_OFFSET = 8;
|
||||||
public static final int Q_ERR_CODE_OFFSET = 9;
|
public static final int Q_ERR_CODE_OFFSET = 9;
|
||||||
public static final int Q_STATUS_VARS_LEN_OFFSET = 11;
|
public static final int Q_STATUS_VARS_LEN_OFFSET = 11;
|
||||||
public static final int Q_DATA_OFFSET = QUERY_HEADER_LEN;
|
public static final int Q_DATA_OFFSET = QUERY_HEADER_LEN;
|
||||||
|
|
||||||
/* these are codes, not offsets; not more than 256 values (1 byte). */
|
/* these are codes, not offsets; not more than 256 values (1 byte). */
|
||||||
public static final int Q_FLAGS2_CODE = 0;
|
public static final int Q_FLAGS2_CODE = 0;
|
||||||
public static final int Q_SQL_MODE_CODE = 1;
|
public static final int Q_SQL_MODE_CODE = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL
|
* Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL
|
||||||
* 5.0.x where 0<=x<=3. We have to keep it to be able to replicate these old
|
* 5.0.x where 0<=x<=3. We have to keep it to be able to replicate these old
|
||||||
* masters.
|
* masters.
|
||||||
*/
|
*/
|
||||||
public static final int Q_CATALOG_CODE = 2;
|
public static final int Q_CATALOG_CODE = 2;
|
||||||
public static final int Q_AUTO_INCREMENT = 3;
|
public static final int Q_AUTO_INCREMENT = 3;
|
||||||
public static final int Q_CHARSET_CODE = 4;
|
public static final int Q_CHARSET_CODE = 4;
|
||||||
public static final int Q_TIME_ZONE_CODE = 5;
|
public static final int Q_TIME_ZONE_CODE = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Q_CATALOG_NZ_CODE is catalog withOUT end zero stored; it is used by MySQL
|
* Q_CATALOG_NZ_CODE is catalog withOUT end zero stored; it is used by MySQL
|
||||||
@@ -528,31 +525,47 @@ public class QueryLogEvent extends LogEvent {
|
|||||||
* would crash (segfault etc) because it would expect a 0 when there is
|
* would crash (segfault etc) because it would expect a 0 when there is
|
||||||
* none.
|
* none.
|
||||||
*/
|
*/
|
||||||
public static final int Q_CATALOG_NZ_CODE = 6;
|
public static final int Q_CATALOG_NZ_CODE = 6;
|
||||||
|
|
||||||
public static final int Q_LC_TIME_NAMES_CODE = 7;
|
public static final int Q_LC_TIME_NAMES_CODE = 7;
|
||||||
|
|
||||||
public static final int Q_CHARSET_DATABASE_CODE = 8;
|
public static final int Q_CHARSET_DATABASE_CODE = 8;
|
||||||
|
|
||||||
public static final int Q_TABLE_MAP_FOR_UPDATE_CODE = 9;
|
public static final int Q_TABLE_MAP_FOR_UPDATE_CODE = 9;
|
||||||
|
|
||||||
public static final int Q_MASTER_DATA_WRITTEN_CODE = 10;
|
public static final int Q_MASTER_DATA_WRITTEN_CODE = 10;
|
||||||
|
|
||||||
public static final int Q_INVOKER = 11;
|
public static final int Q_INVOKER = 11;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Q_UPDATED_DB_NAMES status variable collects of the updated databases
|
* Q_UPDATED_DB_NAMES status variable collects of the updated databases
|
||||||
* total number and their names to be propagated to the slave in order to
|
* total number and their names to be propagated to the slave in order to
|
||||||
* facilitate the parallel applying of the Query events.
|
* facilitate the parallel applying of the Query events.
|
||||||
*/
|
*/
|
||||||
public static final int Q_UPDATED_DB_NAMES = 12;
|
public static final int Q_UPDATED_DB_NAMES = 12;
|
||||||
|
|
||||||
public static final int Q_MICROSECONDS = 13;
|
public static final int Q_MICROSECONDS = 13;
|
||||||
|
/**
|
||||||
|
* A old (unused now) code for Query_log_event status similar to
|
||||||
|
* G_COMMIT_TS.
|
||||||
|
*/
|
||||||
|
public static final int Q_COMMIT_TS = 14;
|
||||||
|
/**
|
||||||
|
* A code for Query_log_event status, similar to G_COMMIT_TS2.
|
||||||
|
*/
|
||||||
|
public static final int Q_COMMIT_TS2 = 15;
|
||||||
|
/**
|
||||||
|
* The master connection @@session.explicit_defaults_for_timestamp which is
|
||||||
|
* recorded for queries, CREATE and ALTER table that is defined with a
|
||||||
|
* TIMESTAMP column, that are dependent on that feature. For pre-WL6292
|
||||||
|
* master's the associated with this code value is zero.
|
||||||
|
*/
|
||||||
|
public static final int Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FROM MariaDB 5.5.34
|
* FROM MariaDB 5.5.34
|
||||||
*/
|
*/
|
||||||
public static final int Q_HRNOW = 128;
|
public static final int Q_HRNOW = 128;
|
||||||
|
|
||||||
private final void unpackVariables(LogBuffer buffer, final int end) throws IOException {
|
private final void unpackVariables(LogBuffer buffer, final int end) throws IOException {
|
||||||
int code = -1;
|
int code = -1;
|
||||||
@@ -632,6 +645,9 @@ public class QueryLogEvent extends LogEvent {
|
|||||||
mtsAccessedDbNames[i] = buffer.getFixString(length < NAME_LEN ? length : NAME_LEN);
|
mtsAccessedDbNames[i] = buffer.getFixString(length < NAME_LEN ? length : NAME_LEN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP:
|
||||||
|
buffer.forward(1);
|
||||||
|
break;
|
||||||
case Q_HRNOW:
|
case Q_HRNOW:
|
||||||
// int when_sec_part = buffer.getUint24();
|
// int when_sec_part = buffer.getUint24();
|
||||||
buffer.forward(3);
|
buffer.forward(3);
|
||||||
|
|||||||
@@ -952,9 +952,9 @@ public final class RowsLogBuffer {
|
|||||||
len = buffer.getUint16();
|
len = buffer.getUint16();
|
||||||
buffer.forward(meta - 2);
|
buffer.forward(meta - 2);
|
||||||
int position = buffer.position();
|
int position = buffer.position();
|
||||||
Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(), buffer, len - 1);
|
Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(), buffer, len - 1, charsetName);
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
jsonValue.toJsonString(builder);
|
jsonValue.toJsonString(builder, charsetName);
|
||||||
value = builder.toString();
|
value = builder.toString();
|
||||||
buffer.position(position + len);
|
buffer.position(position + len);
|
||||||
// byte[] binary = new byte[len];
|
// byte[] binary = new byte[len];
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
|
|||||||
private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1,
|
private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1,
|
||||||
new NamedThreadFactory("canal-instance-scan"));
|
new NamedThreadFactory("canal-instance-scan"));
|
||||||
|
|
||||||
|
private volatile boolean isFirst = true;
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
super.start();
|
super.start();
|
||||||
Assert.notNull(rootConf, "root conf dir is null!");
|
Assert.notNull(rootConf, "root conf dir is null!");
|
||||||
@@ -58,6 +60,9 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
scan();
|
scan();
|
||||||
|
if (isFirst) {
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("scan failed", e);
|
logger.error("scan failed", e);
|
||||||
}
|
}
|
||||||
@@ -122,13 +127,18 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
|
|||||||
|
|
||||||
if (!actions.containsKey(destination) && instanceConfigs.length > 0) {
|
if (!actions.containsKey(destination) && instanceConfigs.length > 0) {
|
||||||
// 存在合法的instance.properties,并且第一次添加时,进行启动操作
|
// 存在合法的instance.properties,并且第一次添加时,进行启动操作
|
||||||
notifyStart(instanceDir, destination);
|
notifyStart(instanceDir, destination, instanceConfigs);
|
||||||
} else if (actions.containsKey(destination)) {
|
} else if (actions.containsKey(destination)) {
|
||||||
// 历史已经启动过
|
// 历史已经启动过
|
||||||
if (instanceConfigs.length == 0) { // 如果不存在合法的instance.properties
|
if (instanceConfigs.length == 0) { // 如果不存在合法的instance.properties
|
||||||
notifyStop(destination);
|
notifyStop(destination);
|
||||||
} else {
|
} else {
|
||||||
InstanceConfigFiles lastFile = lastFiles.get(destination);
|
InstanceConfigFiles lastFile = lastFiles.get(destination);
|
||||||
|
// 历史启动过 所以配置文件信息必然存在
|
||||||
|
if (!isFirst && CollectionUtils.isEmpty(lastFile.getInstanceFiles())) {
|
||||||
|
logger.error("[{}] is started, but not found instance file info.", destination);
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasChanged = judgeFileChanged(instanceConfigs, lastFile.getInstanceFiles());
|
boolean hasChanged = judgeFileChanged(instanceConfigs, lastFile.getInstanceFiles());
|
||||||
// 通知变化
|
// 通知变化
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
@@ -161,10 +171,19 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyStart(File instanceDir, String destination) {
|
private void notifyStart(File instanceDir, String destination, File[] instanceConfigs) {
|
||||||
try {
|
try {
|
||||||
defaultAction.start(destination);
|
defaultAction.start(destination);
|
||||||
actions.put(destination, defaultAction);
|
actions.put(destination, defaultAction);
|
||||||
|
|
||||||
|
// 启动成功后记录配置文件信息
|
||||||
|
InstanceConfigFiles lastFile = lastFiles.get(destination);
|
||||||
|
List<FileInfo> newFileInfo = new ArrayList<FileInfo>();
|
||||||
|
for (File instanceConfig : instanceConfigs) {
|
||||||
|
newFileInfo.add(new FileInfo(instanceConfig.getName(), instanceConfig.lastModified()));
|
||||||
|
}
|
||||||
|
lastFile.setInstanceFiles(newFileInfo);
|
||||||
|
|
||||||
logger.info("auto notify start {} successful.", destination);
|
logger.info("auto notify start {} successful.", destination);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("scan add found[{}] but start failed", destination, ExceptionUtils.getFullStackTrace(e));
|
logger.error("scan add found[{}] but start failed", destination, ExceptionUtils.getFullStackTrace(e));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -27,22 +27,22 @@ import com.alibaba.otter.canal.parse.driver.mysql.utils.PacketManager;
|
|||||||
*/
|
*/
|
||||||
public class MysqlConnector {
|
public class MysqlConnector {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MysqlConnector.class);
|
private static final Logger logger = LoggerFactory.getLogger(MysqlConnector.class);
|
||||||
private InetSocketAddress address;
|
private InetSocketAddress address;
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
private byte charsetNumber = 33;
|
private byte charsetNumber = 33;
|
||||||
private String defaultSchema = "retl";
|
private String defaultSchema = "retl";
|
||||||
private int soTimeout = 30 * 1000;
|
private int soTimeout = 30 * 1000;
|
||||||
private int receiveBufferSize = 16 * 1024;
|
private int receiveBufferSize = 16 * 1024;
|
||||||
private int sendBufferSize = 16 * 1024;
|
private int sendBufferSize = 16 * 1024;
|
||||||
|
|
||||||
private SocketChannel channel;
|
private SocketChannel channel;
|
||||||
private volatile boolean dumping = false;
|
private volatile boolean dumping = false;
|
||||||
// mysql connectinnId
|
// mysql connectinnId
|
||||||
private long connectionId = -1;
|
private long connectionId = -1;
|
||||||
private AtomicBoolean connected = new AtomicBoolean(false);
|
private AtomicBoolean connected = new AtomicBoolean(false);
|
||||||
|
|
||||||
public MysqlConnector(){
|
public MysqlConnector(){
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ public class MysqlQueryExecutor {
|
|||||||
|
|
||||||
private SocketChannel channel;
|
private SocketChannel channel;
|
||||||
|
|
||||||
public MysqlQueryExecutor(MysqlConnector connector){
|
public MysqlQueryExecutor(MysqlConnector connector) throws IOException{
|
||||||
if (!connector.isConnected()) {
|
if (!connector.isConnected()) {
|
||||||
throw new RuntimeException("should execute connector.connect() first");
|
throw new IOException("should execute connector.connect() first");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.channel = connector.getChannel();
|
this.channel = connector.getChannel();
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ public class MysqlUpdateExecutor {
|
|||||||
|
|
||||||
private SocketChannel channel;
|
private SocketChannel channel;
|
||||||
|
|
||||||
public MysqlUpdateExecutor(MysqlConnector connector){
|
public MysqlUpdateExecutor(MysqlConnector connector) throws IOException{
|
||||||
if (!connector.isConnected()) {
|
if (!connector.isConnected()) {
|
||||||
throw new RuntimeException("should execute connector.connect() first");
|
throw new IOException("should execute connector.connect() first");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.channel = connector.getChannel();
|
this.channel = connector.getChannel();
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class FieldPacket extends PacketWithHeaderPacket {
|
|||||||
this.decimals = data[index];
|
this.decimals = data[index];
|
||||||
index++;
|
index++;
|
||||||
//
|
//
|
||||||
index += 2;//skip filter
|
index += 2;// skip filter
|
||||||
//
|
//
|
||||||
if (index < data.length) {
|
if (index < data.length) {
|
||||||
reader.setIndex(index);
|
reader.setIndex(index);
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.alibaba.otter.canal.parse.driver.mysql.socket;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.PooledByteBufAllocator;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装netty的通信channel和数据接收缓存,实现读、写、连接校验的功能。 2016-12-28
|
||||||
|
*
|
||||||
|
* @author luoyaogui
|
||||||
|
*/
|
||||||
|
public class SocketChannel {
|
||||||
|
|
||||||
|
private Channel channel = null;
|
||||||
|
private Object lock = new Object();
|
||||||
|
private ByteBuf cache = PooledByteBufAllocator.DEFAULT.directBuffer(1024 * 1024 * 5); // 缓存大小
|
||||||
|
|
||||||
|
public Channel getChannel() {
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannel(Channel channel, boolean notify) {
|
||||||
|
this.channel = channel;
|
||||||
|
if (notify) {// 是否需要通知,主要是channel不可用时
|
||||||
|
synchronized (this) {
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeCache(ByteBuf buf) {
|
||||||
|
synchronized (lock) {
|
||||||
|
cache.discardReadBytes();// 回收内存
|
||||||
|
cache.writeBytes(buf);
|
||||||
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeChannel(byte[]... buf) throws IOException {
|
||||||
|
if (channel != null && channel.isWritable()) {
|
||||||
|
channel.writeAndFlush(Unpooled.copiedBuffer(buf));
|
||||||
|
} else {
|
||||||
|
throw new IOException("write failed ! please checking !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int read(ByteBuffer buffer) throws IOException {
|
||||||
|
if (null == channel) {
|
||||||
|
throw new IOException("socket has Interrupted !");
|
||||||
|
}
|
||||||
|
if (cache.readableBytes() < buffer.remaining()) {
|
||||||
|
synchronized (this) {
|
||||||
|
try {
|
||||||
|
wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new IOException("socket has Interrupted !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
synchronized (lock) {
|
||||||
|
cache.readBytes(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConnected() {
|
||||||
|
return channel != null ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SocketAddress getRemoteSocketAddress() {
|
||||||
|
return channel != null ? channel.remoteAddress() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
if (channel != null) {
|
||||||
|
channel.close();
|
||||||
|
}
|
||||||
|
channel = null;
|
||||||
|
cache.discardReadBytes();// 回收已占用的内存
|
||||||
|
cache.release();// 释放整个内存
|
||||||
|
cache = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package com.alibaba.otter.canal.parse.driver.mysql.socket;
|
||||||
|
|
||||||
|
import io.netty.bootstrap.Bootstrap;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.PooledByteBufAllocator;
|
||||||
|
import io.netty.channel.AdaptiveRecvByteBufAllocator;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
|
import io.netty.channel.EventLoopGroup;
|
||||||
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author luoyaogui 实现channel的管理(监听连接、读数据、回收) 2016-12-28
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "deprecation" })
|
||||||
|
public abstract class SocketChannelPool {
|
||||||
|
|
||||||
|
private static EventLoopGroup group = new NioEventLoopGroup(); // 非阻塞IO线程组
|
||||||
|
private static Bootstrap boot = new Bootstrap(); // 主
|
||||||
|
private static Map<Channel, SocketChannel> chManager = new ConcurrentHashMap<Channel, SocketChannel>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
boot.group(group)
|
||||||
|
.channel(NioSocketChannel.class)
|
||||||
|
.option(ChannelOption.SO_RCVBUF, 32 * 1024)
|
||||||
|
.option(ChannelOption.SO_SNDBUF, 32 * 1024)
|
||||||
|
.option(ChannelOption.TCP_NODELAY, true)
|
||||||
|
// 如果是延时敏感型应用,建议关闭Nagle算法
|
||||||
|
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||||
|
.option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT)
|
||||||
|
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
|
||||||
|
//
|
||||||
|
.handler(new ChannelInitializer() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initChannel(Channel arg0) throws Exception {
|
||||||
|
arg0.pipeline().addLast(new BusinessHandler());// 命令过滤和handler添加管理
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SocketChannel open(SocketAddress address) throws Exception {
|
||||||
|
final SocketChannel socket = new SocketChannel();
|
||||||
|
boot.connect(address).addListener(new ChannelFutureListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void operationComplete(ChannelFuture arg0) throws Exception {
|
||||||
|
if (arg0.isSuccess()) {
|
||||||
|
socket.setChannel(arg0.channel(), false);
|
||||||
|
}
|
||||||
|
synchronized (socket) {
|
||||||
|
socket.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
synchronized (socket) {
|
||||||
|
socket.wait();
|
||||||
|
}
|
||||||
|
if (null == socket.getChannel()) {
|
||||||
|
throw new IOException("can't create socket!");
|
||||||
|
}
|
||||||
|
chManager.put(socket.getChannel(), socket);
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BusinessHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
|
private SocketChannel socket = null;
|
||||||
|
|
||||||
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
socket.setChannel(null, true);
|
||||||
|
chManager.remove(ctx.channel());// 移除
|
||||||
|
}
|
||||||
|
|
||||||
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
|
if (null == socket) {
|
||||||
|
socket = chManager.get(ctx.channel());
|
||||||
|
}
|
||||||
|
if (socket != null) {
|
||||||
|
socket.writeCache((ByteBuf) msg);
|
||||||
|
}
|
||||||
|
ReferenceCountUtil.release(msg);// 添加防止内存泄漏的
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
|
ctx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import java.io.IOException;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.parse.driver.mysql.packets.server.ResultSetPacket;
|
import com.alibaba.otter.canal.parse.driver.mysql.packets.server.ResultSetPacket;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.alibaba.otter.canal.filter;
|
package com.alibaba.otter.canal.filter;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.filter.aviater.AviaterELFilter;
|
import com.alibaba.otter.canal.filter.aviater.AviaterELFilter;
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.RandomStringUtils;
|
import org.apache.commons.lang.RandomStringUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter;
|
import com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>canal.instance.core</artifactId>
|
<artifactId>canal.instance.core</artifactId>
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package com.alibaba.otter.canal.instance.core;
|
package com.alibaba.otter.canal.instance.core;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.common.AbstractCanalLifeCycle;
|
import com.alibaba.otter.canal.common.AbstractCanalLifeCycle;
|
||||||
import com.alibaba.otter.canal.common.alarm.CanalAlarmHandler;
|
import com.alibaba.otter.canal.common.alarm.CanalAlarmHandler;
|
||||||
import com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter;
|
import com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter;
|
||||||
@@ -16,30 +22,22 @@ import com.alibaba.otter.canal.protocol.ClientIdentity;
|
|||||||
import com.alibaba.otter.canal.sink.CanalEventSink;
|
import com.alibaba.otter.canal.sink.CanalEventSink;
|
||||||
import com.alibaba.otter.canal.store.CanalEventStore;
|
import com.alibaba.otter.canal.store.CanalEventStore;
|
||||||
import com.alibaba.otter.canal.store.model.Event;
|
import com.alibaba.otter.canal.store.model.Event;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with Intellig IDEA.
|
* Created with Intellig IDEA. Author: yinxiu Date: 2016-01-07 Time: 22:26
|
||||||
* Author: yinxiu
|
|
||||||
* Date: 2016-01-07
|
|
||||||
* Time: 22:26
|
|
||||||
*/
|
*/
|
||||||
public class AbstractCanalInstance extends AbstractCanalLifeCycle implements CanalInstance {
|
public class AbstractCanalInstance extends AbstractCanalLifeCycle implements CanalInstance {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AbstractCanalInstance.class);
|
private static final Logger logger = LoggerFactory.getLogger(AbstractCanalInstance.class);
|
||||||
|
|
||||||
protected Long canalId; // 和manager交互唯一标示
|
protected Long canalId; // 和manager交互唯一标示
|
||||||
protected String destination; // 队列名字
|
protected String destination; // 队列名字
|
||||||
protected CanalEventStore<Event> eventStore; // 有序队列
|
protected CanalEventStore<Event> eventStore; // 有序队列
|
||||||
|
|
||||||
protected CanalEventParser eventParser; // 解析对应的数据信息
|
protected CanalEventParser eventParser; // 解析对应的数据信息
|
||||||
protected CanalEventSink<List<CanalEntry.Entry>> eventSink; // 链接parse和store的桥接器
|
protected CanalEventSink<List<CanalEntry.Entry>> eventSink; // 链接parse和store的桥接器
|
||||||
protected CanalMetaManager metaManager; // 消费信息管理器
|
protected CanalMetaManager metaManager; // 消费信息管理器
|
||||||
protected CanalAlarmHandler alarmHandler; // alarm报警机制
|
protected CanalAlarmHandler alarmHandler; // alarm报警机制
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean subscribeChange(ClientIdentity identity) {
|
public boolean subscribeChange(ClientIdentity identity) {
|
||||||
@@ -121,7 +119,6 @@ public class AbstractCanalInstance extends AbstractCanalLifeCycle implements Can
|
|||||||
alarmHandler.stop();
|
alarmHandler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logger.info("stop successful....");
|
logger.info("stop successful....");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package com.alibaba.otter.canal.instance.spring;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.instance.core.AbstractCanalInstance;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.common.alarm.CanalAlarmHandler;
|
import com.alibaba.otter.canal.common.alarm.CanalAlarmHandler;
|
||||||
|
import com.alibaba.otter.canal.instance.core.AbstractCanalInstance;
|
||||||
import com.alibaba.otter.canal.meta.CanalMetaManager;
|
import com.alibaba.otter.canal.meta.CanalMetaManager;
|
||||||
import com.alibaba.otter.canal.parse.CanalEventParser;
|
import com.alibaba.otter.canal.parse.CanalEventParser;
|
||||||
import com.alibaba.otter.canal.protocol.CanalEntry;
|
import com.alibaba.otter.canal.protocol.CanalEntry;
|
||||||
@@ -23,7 +23,7 @@ import com.alibaba.otter.canal.store.model.Event;
|
|||||||
*/
|
*/
|
||||||
public class CanalInstanceWithSpring extends AbstractCanalInstance {
|
public class CanalInstanceWithSpring extends AbstractCanalInstance {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CanalInstanceWithSpring.class);
|
private static final Logger logger = LoggerFactory.getLogger(CanalInstanceWithSpring.class);
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
logger.info("start CannalInstance for {}-{} ", new Object[] { 1, destination });
|
logger.info("start CannalInstance for {}-{} ", new Object[] { 1, destination });
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import java.io.IOException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.alibaba.otter.canal.meta;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.protocol.position.PositionRange;
|
import com.alibaba.otter.canal.protocol.position.PositionRange;
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package com.alibaba.otter.canal.meta;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package com.alibaba.otter.canal.meta;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package com.alibaba.otter.canal.meta;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>canal.parse</artifactId>
|
<artifactId>canal.parse</artifactId>
|
||||||
|
|||||||
@@ -83,30 +83,27 @@ public class LocalBinLogConnection implements ErosaConnection {
|
|||||||
context.setLogPosition(new LogPosition(binlogfilename, binlogPosition));
|
context.setLogPosition(new LogPosition(binlogfilename, binlogPosition));
|
||||||
while (running) {
|
while (running) {
|
||||||
boolean needContinue = true;
|
boolean needContinue = true;
|
||||||
LogEvent event = null;
|
LogEvent event = null;
|
||||||
L:while (fetcher.fetch()) {
|
L: while (fetcher.fetch()) {
|
||||||
/*event = decoder.decode(fetcher, context);
|
/*
|
||||||
if (event == null) {
|
* event = decoder.decode(fetcher, context); if (event ==
|
||||||
throw new CanalParseException("parse failed");
|
* null) { throw new CanalParseException("parse failed"); }
|
||||||
}
|
* if (!func.sink(event)) { needContinue = false; break; }
|
||||||
|
*/
|
||||||
|
|
||||||
if (!func.sink(event)) {
|
do {
|
||||||
needContinue = false;
|
if (event == null) {
|
||||||
break;
|
event = new RotateLogEvent(context.getLogPosition().getFileName(), context.getLogPosition()
|
||||||
}*/
|
.getPosition());
|
||||||
|
} else {
|
||||||
|
event = decoder.decode(fetcher, context);
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
if (event != null && !func.sink(event)) {
|
||||||
if (event == null) {
|
needContinue = false;
|
||||||
event = new RotateLogEvent(context.getLogPosition().getFileName(), context.getLogPosition().getPosition());
|
break L;
|
||||||
} else {
|
}
|
||||||
event = decoder.decode(fetcher, context);
|
} while (event != null);
|
||||||
}
|
|
||||||
|
|
||||||
if (event != null && !func.sink(event)) {
|
|
||||||
needContinue = false;
|
|
||||||
break L;
|
|
||||||
}
|
|
||||||
} while (event != null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needContinue) {// 读取下一个
|
if (needContinue) {// 读取下一个
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void preDump(ErosaConnection connection) {
|
protected void preDump(ErosaConnection connection) {
|
||||||
metaConnection = buildMysqlConnection();
|
metaConnection = buildMysqlConnection();
|
||||||
try {
|
try {
|
||||||
metaConnection.connect();
|
metaConnection.connect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -52,11 +52,11 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
|||||||
|
|
||||||
tableMetaCache = new TableMetaCache(metaConnection);
|
tableMetaCache = new TableMetaCache(metaConnection);
|
||||||
((LogEventConvert) binlogParser).setTableMetaCache(tableMetaCache);
|
((LogEventConvert) binlogParser).setTableMetaCache(tableMetaCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void afterDump(ErosaConnection connection) {
|
protected void afterDump(ErosaConnection connection) {
|
||||||
if (metaConnection != null) {
|
if (metaConnection != null) {
|
||||||
try {
|
try {
|
||||||
metaConnection.disconnect();
|
metaConnection.disconnect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -64,9 +64,9 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
|||||||
.getAddress(), e);
|
.getAddress(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws CanalParseException {
|
public void start() throws CanalParseException {
|
||||||
if (runningInfo == null) { // 第一次链接主库
|
if (runningInfo == null) { // 第一次链接主库
|
||||||
runningInfo = masterInfo;
|
runningInfo = masterInfo;
|
||||||
}
|
}
|
||||||
@@ -75,8 +75,8 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (metaConnection != null) {
|
if (metaConnection != null) {
|
||||||
try {
|
try {
|
||||||
metaConnection.disconnect();
|
metaConnection.disconnect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -90,9 +90,9 @@ public class LocalBinlogEventParser extends AbstractMysqlEventParser implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.stop();
|
super.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ErosaConnection buildLocalBinLogConnection() {
|
private ErosaConnection buildLocalBinLogConnection() {
|
||||||
LocalBinLogConnection connection = new LocalBinLogConnection();
|
LocalBinLogConnection connection = new LocalBinLogConnection();
|
||||||
|
|
||||||
connection.setBufferSize(this.bufferSize);
|
connection.setBufferSize(this.bufferSize);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
*/
|
*/
|
||||||
public void seek(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException {
|
public void seek(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException {
|
||||||
updateSettings();
|
updateSettings();
|
||||||
|
loadBinlogChecksum();
|
||||||
sendBinlogDump(binlogfilename, binlogPosition);
|
sendBinlogDump(binlogfilename, binlogPosition);
|
||||||
DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
|
DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
|
||||||
fetcher.start(connector.getChannel());
|
fetcher.start(connector.getChannel());
|
||||||
@@ -94,6 +94,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
decoder.handle(LogEvent.XID_EVENT);
|
decoder.handle(LogEvent.XID_EVENT);
|
||||||
LogContext context = new LogContext();
|
LogContext context = new LogContext();
|
||||||
context.setLogPosition(new LogPosition(binlogfilename));
|
context.setLogPosition(new LogPosition(binlogfilename));
|
||||||
|
context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
|
||||||
while (fetcher.fetch()) {
|
while (fetcher.fetch()) {
|
||||||
LogEvent event = null;
|
LogEvent event = null;
|
||||||
event = decoder.decode(fetcher, context);
|
event = decoder.decode(fetcher, context);
|
||||||
@@ -212,6 +213,16 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 参考:https://github.com/alibaba/canal/issues/284
|
||||||
|
// mysql5.6需要设置slave_uuid避免被server kill链接
|
||||||
|
update("set @slave_uuid=uuid()");
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!StringUtils.contains(e.getMessage(), "Unknown system variable")) {
|
||||||
|
logger.warn(ExceptionUtils.getFullStackTrace(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// mariadb针对特殊的类型,需要设置session变量
|
// mariadb针对特殊的类型,需要设置session变量
|
||||||
update("SET @mariadb_slave_capability='" + LogEvent.MARIA_SLAVE_CAPABILITY_MINE + "'");
|
update("SET @mariadb_slave_capability='" + LogEvent.MARIA_SLAVE_CAPABILITY_MINE + "'");
|
||||||
@@ -281,7 +292,8 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> columnValues = rs.getFieldValues();
|
List<String> columnValues = rs.getFieldValues();
|
||||||
if (columnValues != null && columnValues.size() >= 1 && columnValues.get(0).toUpperCase().equals("CRC32")) {
|
if (columnValues != null && columnValues.size() >= 1 && columnValues.get(0) != null
|
||||||
|
&& columnValues.get(0).toUpperCase().equals("CRC32")) {
|
||||||
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_CRC32;
|
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_CRC32;
|
||||||
} else {
|
} else {
|
||||||
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
|
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public class MysqlEventParser extends AbstractMysqlEventParser implements CanalE
|
|||||||
protected void stopHeartBeat() {
|
protected void stopHeartBeat() {
|
||||||
TimerTask heartBeatTimerTask = this.heartBeatTimerTask;
|
TimerTask heartBeatTimerTask = this.heartBeatTimerTask;
|
||||||
super.stopHeartBeat();
|
super.stopHeartBeat();
|
||||||
if (heartBeatTimerTask != null) {
|
if (heartBeatTimerTask != null && heartBeatTimerTask instanceof MysqlDetectingTimeTask) {
|
||||||
MysqlConnection mysqlConnection = ((MysqlDetectingTimeTask) heartBeatTimerTask).getMysqlConnection();
|
MysqlConnection mysqlConnection = ((MysqlDetectingTimeTask) heartBeatTimerTask).getMysqlConnection();
|
||||||
try {
|
try {
|
||||||
mysqlConnection.disconnect();
|
mysqlConnection.disconnect();
|
||||||
|
|||||||
@@ -190,9 +190,9 @@ public class BinLogFileQueue {
|
|||||||
files.addAll(FileUtils.listFiles(directory, new IOFileFilter() {
|
files.addAll(FileUtils.listFiles(directory, new IOFileFilter() {
|
||||||
|
|
||||||
public boolean accept(File file) {
|
public boolean accept(File file) {
|
||||||
Pattern pattern = Pattern.compile("\\d+$");
|
Pattern pattern = Pattern.compile("\\d+$");
|
||||||
Matcher matcher = pattern.matcher(file.getName());
|
Matcher matcher = pattern.matcher(file.getName());
|
||||||
return file.getName().startsWith(baseName) && matcher.find();
|
return file.getName().startsWith(baseName) && matcher.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.parse.inbound.EventTransactionBuffer.TransactionFlushCallback;
|
import com.alibaba.otter.canal.parse.inbound.EventTransactionBuffer.TransactionFlushCallback;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.nio.charset.Charset;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest;
|
import com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.nio.charset.Charset;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest;
|
import com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest;
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class SimpleDdlParserTest {
|
|||||||
Assert.assertEquals("retl_mark1", result.getOriTableName());
|
Assert.assertEquals("retl_mark1", result.getOriTableName());
|
||||||
Assert.assertEquals("retl_mark3", result.getTableName());
|
Assert.assertEquals("retl_mark3", result.getTableName());
|
||||||
|
|
||||||
//正则匹配test case
|
// 正则匹配test case
|
||||||
|
|
||||||
queryString = "rename table totl_mark to totl_mark2";
|
queryString = "rename table totl_mark to totl_mark2";
|
||||||
result = SimpleDdlParser.parse(queryString, "retl");
|
result = SimpleDdlParser.parse(queryString, "retl");
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package com.alibaba.otter.canal.parse.index;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package com.alibaba.otter.canal.parse.index;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.alibaba.otter.canal.parse.index;
|
package com.alibaba.otter.canal.parse.index;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.alibaba.otter.canal.parse.index;
|
package com.alibaba.otter.canal.parse.index;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|||||||
9
pom.xml
9
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>canal module for otter ${project.version}</name>
|
<name>canal module for otter ${project.version}</name>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<url>https://github.com/alibaba/canal</url>
|
<url>https://github.com/alibaba/canal</url>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.sonatype.oss</groupId>
|
<groupId>org.sonatype.oss</groupId>
|
||||||
@@ -177,7 +177,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.1.35</version>
|
<version>1.2.28</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
@@ -199,6 +199,11 @@
|
|||||||
<artifactId>netty</artifactId>
|
<artifactId>netty</artifactId>
|
||||||
<version>3.2.5.Final</version>
|
<version>3.2.5.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-all</artifactId>
|
||||||
|
<version>4.1.6.Final</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.protobuf</groupId>
|
<groupId>com.google.protobuf</groupId>
|
||||||
<artifactId>protobuf-java</artifactId>
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>canal.server</artifactId>
|
<artifactId>canal.server</artifactId>
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class CanalServerWithEmbedded extends AbstractCanalLifeCycle implements C
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void subscribe(ClientIdentity clientIdentity) throws CanalServerException {
|
public void subscribe(ClientIdentity clientIdentity) throws CanalServerException {
|
||||||
checkStart(clientIdentity.getDestination());
|
checkStart(clientIdentity.getDestination());
|
||||||
|
|
||||||
CanalInstance canalInstance = canalInstances.get(clientIdentity.getDestination());
|
CanalInstance canalInstance = canalInstances.get(clientIdentity.getDestination());
|
||||||
if (!canalInstance.getMetaManager().isStart()) {
|
if (!canalInstance.getMetaManager().isStart()) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
<artifactId>canal</artifactId>
|
<artifactId>canal</artifactId>
|
||||||
<version>1.0.24-SNAPSHOT</version>
|
<version>1.0.24</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.otter</groupId>
|
<groupId>com.alibaba.otter</groupId>
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|||||||
Reference in New Issue
Block a user