Compare commits

..

31 Commits

Author SHA1 Message Date
agapple
452fae15fc [maven-release-plugin] prepare release canal-1.0.20 2015-06-30 10:23:45 +08:00
agapple
3d6174f857 fixed issue #119 , support binlog row image noblob/minimal 2015-06-29 23:52:37 +08:00
agapple
21abbbfe47 fixed issue #116 , process create index bug 2015-05-05 10:52:56 +08:00
agapple
89056490c3 upgrade fastjson version 2015-04-30 11:25:24 +08:00
agapple
c935f06344 remove compiler warning 2015-04-30 11:20:25 +08:00
agapple
eeaf5ce910 fixed issue #116 , process empty array 2015-04-30 11:06:10 +08:00
agapple
c3f2ad08cd fixed warning 2015-04-28 21:33:28 +08:00
agapple
7ebb3fd1ab fixed code template and format 2015-04-28 21:11:41 +08:00
agapple
ea889cb004 Merge pull request #115 from wenerme/master
Typo,javadoc 修正, 更新 guava 到18.0
2015-04-28 20:26:41 +08:00
wener
596b060649 cleanup code, extract CanalService 2015-04-27 14:57:01 +08:00
wener
fc9b616f4a 添加遗漏的 MigrateMap 2015-04-24 09:36:47 +08:00
wener
6a0733bbab update guava to 18.0, magriate compute map by package level implement 2015-04-23 22:15:57 +08:00
wener
bdf3b0c861 typo, javadoc,code cleanup 2015-04-23 17:25:36 +08:00
wener
d01e82ce3c fix typo embeded -> embedded 2015-04-23 16:23:34 +08:00
agapple
ae521195c5 Merge pull request #113 from WalterInSH/master
add missing api parameter doc
2015-04-10 12:39:38 +08:00
Walter
5529dad14b add missing api parameter doc 2015-04-09 17:35:28 +08:00
agapple
b0143520eb fixed issue #112 , add mysql 5.6 useconds parse 2015-03-30 18:04:26 +08:00
agapple
5b56a027e5 Merge pull request #110 from frew/master
FileLogFetcher's fetch() method should fix up position and origin even i...
2015-01-30 20:54:22 +08:00
agapple
50d4b18556 Update README.md 2015-01-30 14:27:06 +08:00
Fred Wulff
f9edeca6d2 FileLogFetcher's fetch() method should fix up position and origin even if we weren't successful at fetching anything from the file 2015-01-29 11:51:34 -08:00
agapple
5ade057113 fixed issue #106 , logger exception 2014-12-26 20:23:59 +08:00
agapple
befc31146a fixed parse instance 2014-12-26 11:29:00 +08:00
agapple
ac4970ef3a fixed issue #105 , seek method add format eventType parse 2014-12-17 22:08:36 +08:00
agapple
13bf7c85a0 fixed search by time 2014-12-17 20:57:12 +08:00
agapple
a2ae8cda50 remove setEventFilter 2014-12-10 13:48:50 +08:00
agapple
42b164f860 Merge pull request #104 from mczcl/master
修复了重复订阅没有真正修改过滤器的问题
2014-12-10 13:37:48 +08:00
zelin.miao
aac4d95b19 修复了重复订阅没有真正修改过滤器的问题 2014-12-05 23:56:42 +08:00
agapple
0e283bb52d Merge pull request #102 from diguage/master
修正插件的声明
2014-10-21 11:05:52 +08:00
D瓜哥
9ad328c5ad 增加插件maven-jar-plugin的版本声明 2014-10-14 16:22:39 +08:00
D瓜哥
5d1e952c6d 给插件maven-source-plugin\maven-compiler-plugin增加版本声明,删除重复的插件声明 2014-10-14 16:22:09 +08:00
agapple
4ba814da26 [maven-release-plugin] prepare for next development iteration 2014-09-23 16:10:57 +08:00
150 changed files with 3471 additions and 3849 deletions

View File

@@ -62,6 +62,12 @@ See the wiki page for : <a href="https://github.com/alibaba/canal/wiki" >wiki文
<li><a href="https://github.com/alibaba/canal/releases">Download</a></li> <li><a href="https://github.com/alibaba/canal/releases">Download</a></li>
</ul> </ul>
<h1>相关资料: </h1>
* ADC阿里技术嘉年华分享ppt (放在google docs上,可能需要翻墙): <a href="https://docs.google.com/presentation/d/1MkszUPYRDkfVPz9IqOT1LLT5d9tuwde_WC8GZvjaDRg/edit?usp=sharing">ppt下载</href>
* [与阿里巴巴的RocketMQ配合使用](https://github.com/alibaba/RocketMQ)
<h1>问题反馈</h1> <h1>问题反馈</h1>
<ol> <ol>
<li>qq交流群: 161559791 </li> <li>qq交流群: 161559791 </li>

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -19,14 +19,14 @@ public interface CanalConnector {
* *
* @throws CanalClientException * @throws CanalClientException
*/ */
public void connect() throws CanalClientException; void connect() throws CanalClientException;
/** /**
* 释放链接 * 释放链接
* *
* @throws CanalClientException * @throws CanalClientException
*/ */
public void disconnect() throws CanalClientException; void disconnect() throws CanalClientException;
/** /**
* 检查下链接是否合法 * 检查下链接是否合法
@@ -43,7 +43,7 @@ public interface CanalConnector {
* *
* @throws CanalClientException * @throws CanalClientException
*/ */
public boolean checkValid() throws CanalClientException; boolean checkValid() throws CanalClientException;
/** /**
* 客户端订阅,重复订阅时会更新对应的filter信息 * 客户端订阅,重复订阅时会更新对应的filter信息
@@ -56,7 +56,6 @@ public interface CanalConnector {
* TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表 * TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表
* </pre> * </pre>
* *
* @param clientIdentity
* @throws CanalClientException * @throws CanalClientException
*/ */
void subscribe(String filter) throws CanalClientException; void subscribe(String filter) throws CanalClientException;
@@ -64,7 +63,6 @@ public interface CanalConnector {
/** /**
* 客户端订阅,不提交客户端filter,以服务端的filter为准 * 客户端订阅,不提交客户端filter,以服务端的filter为准
* *
* @param clientIdentity
* @throws CanalClientException * @throws CanalClientException
*/ */
void subscribe() throws CanalClientException; void subscribe() throws CanalClientException;
@@ -72,7 +70,6 @@ public interface CanalConnector {
/** /**
* 取消订阅 * 取消订阅
* *
* @param clientIdentity
* @throws CanalClientException * @throws CanalClientException
*/ */
void unsubscribe() throws CanalClientException; void unsubscribe() throws CanalClientException;
@@ -140,14 +137,14 @@ public interface CanalConnector {
void ack(long batchId) throws CanalClientException; void ack(long batchId) throws CanalClientException;
/** /**
* 回滚到未进行 {@link ack} 的地方,指定回滚具体的batchId * 回滚到未进行 {@link #ack} 的地方,指定回滚具体的batchId
* *
* @throws CanalClientException * @throws CanalClientException
*/ */
void rollback(long batchId) throws CanalClientException; void rollback(long batchId) throws CanalClientException;
/** /**
* 回滚到未进行 {@link ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link ack} 的地方开始拿 * 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿
* *
* @throws CanalClientException * @throws CanalClientException
*/ */

View File

@@ -19,8 +19,9 @@ public class CanalConnectors {
/** /**
* 创建单链接的客户端链接 * 创建单链接的客户端链接
* *
* @param address * @param address
* @param destination
* @param username * @param username
* @param password * @param password
* @return * @return
@@ -34,36 +35,38 @@ public class CanalConnectors {
/** /**
* 创建带cluster模式的客户端链接,自动完成failover切换 * 创建带cluster模式的客户端链接,自动完成failover切换
* *
* @param addresses * @param addresses
* @param destination
* @param username * @param username
* @param password * @param password
* @return * @return
*/ */
public static CanalConnector newClusterConnector(List<? extends SocketAddress> addresses, String destination, public static CanalConnector newClusterConnector(List<? extends SocketAddress> addresses, String destination,
String username, String password) { String username, String password) {
ClusterCanalConnector canalConnector = new ClusterCanalConnector(username, password, destination, ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
new SimpleNodeAccessStrategy(addresses)); password,
destination,
new SimpleNodeAccessStrategy(addresses));
canalConnector.setSoTimeout(30 * 1000); canalConnector.setSoTimeout(30 * 1000);
return canalConnector; return canalConnector;
} }
/** /**
* 创建带cluster模式的客户端链接,自动完成failover切换,服务器列表自动扫描 * 创建带cluster模式的客户端链接,自动完成failover切换,服务器列表自动扫描
* *
* @param zkServers
* @param destination
* @param username * @param username
* @param password * @param password
* @return * @return
*/ */
public static CanalConnector newClusterConnector(String zkServers, String destination, String username, public static CanalConnector newClusterConnector(String zkServers, String destination, String username,
String password) { String password) {
ClusterCanalConnector canalConnector = new ClusterCanalConnector( ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
username, password,
password, destination,
destination, new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkServers)));
new ClusterNodeAccessStrategy(
destination,
ZkClientx.getZkClient(zkServers)));
canalConnector.setSoTimeout(30 * 1000); canalConnector.setSoTimeout(30 * 1000);
return canalConnector; return canalConnector;
} }

View File

@@ -102,7 +102,7 @@ public class SimpleCanalConnector implements CanalConnector {
rollback(); rollback();
} }
} }
connected = true; connected = true;
} }
@@ -411,7 +411,6 @@ public class SimpleCanalConnector implements CanalConnector {
} }
} }
private void waitClientRunning() { private void waitClientRunning() {
try { try {
if (zkClientx != null) { if (zkClientx != null) {

291
codeformat.xml Normal file
View File

@@ -0,0 +1,291 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="canal-format" version="12">
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="84"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="84"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="84"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="84"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="84"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="true"/>
</profile>
</profiles>

27
codetemplates.xml Normal file
View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
* @return the ${bare_field_name}
*/</template><template autoinsert="true" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/**
* @param ${param} the ${bare_field_name} to set
*/</template><template autoinsert="true" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
* ${tags}
*/</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment"/><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
* @author ${user} ${date} ${time}
* @since 1.0.0
*/</template><template autoinsert="true" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**
*
*/</template><template autoinsert="true" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
* ${tags}
*/</template><template autoinsert="false" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment"/><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
* ${tags}
* ${see_to_target}
*/</template><template autoinsert="false" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">${filecomment}
${package_declaration}
${typecomment}
${type_declaration}</template><template autoinsert="true" context="classbody_context" deleted="false" description="Code in new class type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.classbody" name="classbody">
</template><template autoinsert="true" context="interfacebody_context" deleted="false" description="Code in new interface type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name="interfacebody">
</template><template autoinsert="true" context="enumbody_context" deleted="false" description="Code in new enum type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.enumbody" name="enumbody">
</template><template autoinsert="true" context="annotationbody_context" deleted="false" description="Code in new annotation type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name="annotationbody">
</template><template autoinsert="true" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.catchblock" name="catchblock">// ${todo} Auto-generated catch block
${exception_var}.printStackTrace();</template><template autoinsert="true" context="methodbody_context" deleted="false" description="Code in created method stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodbody" name="methodbody">// ${todo} Auto-generated method stub
${body_statement}</template><template autoinsert="true" context="constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name="constructorbody">${body_statement}
// ${todo} Auto-generated constructor stub</template><template autoinsert="true" context="getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.getterbody" name="getterbody">return ${field};</template><template autoinsert="true" context="setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.setterbody" name="setterbody">${field} = ${param};</template></templates>

View File

@@ -3,10 +3,9 @@
<parent> <parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>
<artifactId>canal</artifactId> <artifactId>canal</artifactId>
<version>1.0.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId>
<artifactId>canal.common</artifactId> <artifactId>canal.common</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>canal common module for otter ${project.version}</name> <name>canal common module for otter ${project.version}</name>

View File

@@ -6,9 +6,9 @@ package com.alibaba.otter.canal.common;
*/ */
public interface CanalLifeCycle { public interface CanalLifeCycle {
public void start(); void start();
public void stop(); void stop();
public boolean isStart(); boolean isStart();
} }

View File

@@ -14,8 +14,7 @@ public interface CanalAlarmHandler extends CanalLifeCycle {
* 发送对应destination的报警 * 发送对应destination的报警
* *
* @param destination * @param destination
* @param title
* @param msg * @param msg
*/ */
public void sendAlarm(String destination, String msg); void sendAlarm(String destination, String msg);
} }

View File

@@ -38,7 +38,8 @@ public class AddressUtils {
private static boolean isValidHostAddress(InetAddress address) { private static boolean isValidHostAddress(InetAddress address) {
if (address == null || address.isLoopbackAddress()) return false; if (address == null || address.isLoopbackAddress()) return false;
String name = address.getHostAddress(); String name = address.getHostAddress();
return (name != null && !EMPTY_IP.equals(name) && !LOCALHOST_IP.equals(name) && IP_PATTERN.matcher(name).matches()); return (name != null && !EMPTY_IP.equals(name) && !LOCALHOST_IP.equals(name) && IP_PATTERN.matcher(name)
.matches());
} }
public static String getHostIp() { public static String getHostIp() {

View File

@@ -54,6 +54,7 @@ public final class UriUtils {
} }
String query = uri.getRawQuery(); String query = uri.getRawQuery();
HashMap<String, String> params = new HashMap<String, String>(); HashMap<String, String> params = new HashMap<String, String>();
@SuppressWarnings("resource")
Scanner scan = new Scanner(query); Scanner scan = new Scanner(query);
scan.useDelimiter(SPLIT); scan.useDelimiter(SPLIT);
while (scan.hasNext()) { while (scan.hasNext()) {

View File

@@ -12,7 +12,7 @@ import org.I0Itec.zkclient.serialize.ZkSerializer;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.MapMaker; import com.google.common.collect.MigrateMap;
/** /**
* 使用自定义的ZooKeeperx for zk connection * 使用自定义的ZooKeeperx for zk connection
@@ -23,7 +23,7 @@ import com.google.common.collect.MapMaker;
public class ZkClientx extends ZkClient { public class ZkClientx extends ZkClient {
// 对于zkclient进行一次缓存,避免一个jvm内部使用多个zk connection // 对于zkclient进行一次缓存,避免一个jvm内部使用多个zk connection
private static Map<String, ZkClientx> clients = new MapMaker().makeComputingMap(new Function<String, ZkClientx>() { private static Map<String, ZkClientx> clients = MigrateMap.makeComputingMap(new Function<String, ZkClientx>() {
public ZkClientx apply(String servers) { public ZkClientx apply(String servers) {
return new ZkClientx(servers); return new ZkClientx(servers);
@@ -62,10 +62,12 @@ public class ZkClientx extends ZkClient {
* Create a persistent Sequential node. * Create a persistent Sequential node.
* *
* @param path * @param path
* @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown * @param createParents if true all parent dirs are created as well and no
* in case the path already exists * {@link ZkNodeExistsException} is thrown in case the path already exists
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted * @throws ZkInterruptedException if operation was interrupted, or a
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread * required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the
* ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred * @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs * @throws RuntimeException if any other exception occurs
*/ */
@@ -89,10 +91,12 @@ public class ZkClientx extends ZkClient {
* *
* @param path * @param path
* @param data * @param data
* @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown * @param createParents if true all parent dirs are created as well and no
* in case the path already exists * {@link ZkNodeExistsException} is thrown in case the path already exists
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted * @throws ZkInterruptedException if operation was interrupted, or a
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread * required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the
* ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred * @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs * @throws RuntimeException if any other exception occurs
*/ */
@@ -118,10 +122,12 @@ public class ZkClientx extends ZkClient {
* *
* @param path * @param path
* @param data * @param data
* @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown * @param createParents if true all parent dirs are created as well and no
* in case the path already exists * {@link ZkNodeExistsException} is thrown in case the path already exists
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted * @throws ZkInterruptedException if operation was interrupted, or a
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread * required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the
* ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred * @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs * @throws RuntimeException if any other exception occurs
*/ */

View File

@@ -15,8 +15,8 @@ import org.apache.zookeeper.ClientCnxn;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.Watcher; import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States; import org.apache.zookeeper.ZooKeeper.States;
import org.apache.zookeeper.client.ConnectStringParser; import org.apache.zookeeper.client.ConnectStringParser;
import org.apache.zookeeper.client.HostProvider; import org.apache.zookeeper.client.HostProvider;
@@ -39,7 +39,7 @@ public class ZooKeeperx implements IZkConnection {
private static final Field clientCnxnField = ReflectionUtils.findField(ZooKeeper.class, "cnxn"); private static final Field clientCnxnField = ReflectionUtils.findField(ZooKeeper.class, "cnxn");
private static final Field hostProviderField = ReflectionUtils.findField(ClientCnxn.class, "hostProvider"); private static final Field hostProviderField = ReflectionUtils.findField(ClientCnxn.class, "hostProvider");
private static final Field serverAddressesField = ReflectionUtils.findField(StaticHostProvider.class, private static final Field serverAddressesField = ReflectionUtils.findField(StaticHostProvider.class,
"serverAddresses"); "serverAddresses");
private static final int DEFAULT_SESSION_TIMEOUT = 90000; private static final int DEFAULT_SESSION_TIMEOUT = 90000;
private ZooKeeper _zk = null; private ZooKeeper _zk = null;
@@ -159,9 +159,8 @@ public class ZooKeeperx implements IZkConnection {
// 强制获取zk中的地址信息 // 强制获取zk中的地址信息
ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk); ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn); HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField( List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(serverAddressesField,
serverAddressesField, hostProvider);
hostProvider);
// 添加第二组集群列表 // 添加第二组集群列表
serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses()); serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
} }

View File

@@ -120,8 +120,10 @@ public class ZookeeperPathUtils {
} }
public static String getBatchMarkWithIdPath(String destinationName, short clientId, Long batchId) { public static String getBatchMarkWithIdPath(String destinationName, short clientId, Long batchId) {
return MessageFormat.format(DESTINATION_CLIENTID_BATCH_MARK_WITH_ID_PATH, destinationName, return MessageFormat.format(DESTINATION_CLIENTID_BATCH_MARK_WITH_ID_PATH,
String.valueOf(clientId), getBatchMarkNode(batchId)); destinationName,
String.valueOf(clientId),
getBatchMarkNode(batchId));
} }
public static String getCursorPath(String destination, short clientId) { public static String getCursorPath(String destination, short clientId) {

View File

@@ -11,7 +11,8 @@ import java.util.Map;
public class ServerRunningMonitors { public class ServerRunningMonitors {
private static ServerRunningData serverData; private static ServerRunningData serverData;
private static Map runningMonitors; // <String, ServerRunningMonitor> private static Map runningMonitors; // <String,
// ServerRunningMonitor>
public static ServerRunningData getServerData() { public static ServerRunningData getServerData() {
return serverData; return serverData;

View File

@@ -0,0 +1,19 @@
package com.google.common.collect;
import java.util.concurrent.ConcurrentMap;
import com.google.common.base.Function;
public class MigrateMap {
@SuppressWarnings("deprecation")
public static <K, V> ConcurrentMap<K, V> makeComputingMap(MapMaker maker,
Function<? super K, ? extends V> computingFunction) {
return maker.makeComputingMap(computingFunction);
}
@SuppressWarnings("deprecation")
public static <K, V> ConcurrentMap<K, V> makeComputingMap(Function<? super K, ? extends V> computingFunction) {
return new MapMaker().makeComputingMap(computingFunction);
}
}

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -6,24 +6,24 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
* An utility class implements MySQL/Java charsets conversion. you can see com.mysql.jdbc.CharsetMapping. * An utility class implements MySQL/Java charsets conversion. you can see
* com.mysql.jdbc.CharsetMapping.
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
*/ */
public final class CharsetConversion public final class CharsetConversion {
{
static final Log logger = LogFactory.getLog(CharsetConversion.class); static final Log logger = LogFactory.getLog(CharsetConversion.class);
static final class Entry static final class Entry {
{
protected final int charsetId; protected final int charsetId;
protected final String mysqlCharset; protected final String mysqlCharset;
protected final String mysqlCollation; protected final String mysqlCollation;
protected final String javaCharset; protected final String javaCharset;
Entry(final int id, String mysqlCharset, // NL Entry(final int id, String mysqlCharset, // NL
String mysqlCollation, String javaCharset) String mysqlCollation, String javaCharset){
{
this.charsetId = id; this.charsetId = id;
this.mysqlCharset = mysqlCharset; this.mysqlCharset = mysqlCharset;
this.mysqlCollation = mysqlCollation; this.mysqlCollation = mysqlCollation;
@@ -34,38 +34,31 @@ public final class CharsetConversion
// Character set data used in lookups. The array will be sparse. // Character set data used in lookups. The array will be sparse.
static final Entry[] entries = new Entry[0xff]; static final Entry[] entries = new Entry[0xff];
static Entry getEntry(final int id) static Entry getEntry(final int id) {
{ if (id >= 0 && id < entries.length) {
if (id >= 0 && id < entries.length)
{
return entries[id]; return entries[id];
} } else {
else
{
throw new IllegalArgumentException("Invalid charset id: " + id); throw new IllegalArgumentException("Invalid charset id: " + id);
} }
} }
// Loads character set information. // Loads character set information.
static void putEntry(final int charsetId, String mysqlCharset, static void putEntry(final int charsetId, String mysqlCharset, String mysqlCollation, String javaCharset) {
String mysqlCollation, String javaCharset)
{
entries[charsetId] = new Entry(charsetId, mysqlCharset, // NL entries[charsetId] = new Entry(charsetId, mysqlCharset, // NL
mysqlCollation, javaCharset); mysqlCollation,
javaCharset);
} }
// Loads character set information. // Loads character set information.
@Deprecated @Deprecated
static void putEntry(final int charsetId, String mysqlCharset, static void putEntry(final int charsetId, String mysqlCharset, String mysqlCollation) {
String mysqlCollation)
{
entries[charsetId] = new Entry(charsetId, mysqlCharset, // NL entries[charsetId] = new Entry(charsetId, mysqlCharset, // NL
mysqlCollation, /* Unknown java charset */null); mysqlCollation, /* Unknown java charset */
null);
} }
// Load character set data statically. // Load character set data statically.
static static {
{
putEntry(1, "big5", "big5_chinese_ci", "Big5"); putEntry(1, "big5", "big5_chinese_ci", "Big5");
putEntry(2, "latin2", "latin2_czech_cs", "ISO8859_2"); putEntry(2, "latin2", "latin2_czech_cs", "ISO8859_2");
putEntry(3, "dec8", "dec8_swedish_ci", "ISO8859_1"); putEntry(3, "dec8", "dec8_swedish_ci", "ISO8859_1");
@@ -135,7 +128,7 @@ public final class CharsetConversion
putEntry(69, "dec8", "dec8_bin", "US-ASCII"); putEntry(69, "dec8", "dec8_bin", "US-ASCII");
putEntry(70, "greek", "greek_bin", "ISO8859_7"); putEntry(70, "greek", "greek_bin", "ISO8859_7");
putEntry(71, "hebrew", "hebrew_bin", "ISO8859_8"); putEntry(71, "hebrew", "hebrew_bin", "ISO8859_8");
putEntry(72, "hp8", "hp8_bin" , "US-ASCII"); putEntry(72, "hp8", "hp8_bin", "US-ASCII");
putEntry(73, "keybcs2", "keybcs2_bin", "Cp895"); putEntry(73, "keybcs2", "keybcs2_bin", "Cp895");
putEntry(74, "koi8r", "koi8r_bin", "KOI8_R"); putEntry(74, "koi8r", "koi8r_bin", "KOI8_R");
putEntry(75, "koi8u", "koi8u_bin", "KOI8_U"); putEntry(75, "koi8u", "koi8u_bin", "KOI8_U");
@@ -274,16 +267,12 @@ public final class CharsetConversion
/** /**
* Return defined charset name for mysql. * Return defined charset name for mysql.
*/ */
public static String getCharset(final int id) public static String getCharset(final int id) {
{
Entry entry = getEntry(id); Entry entry = getEntry(id);
if (entry != null) if (entry != null) {
{
return entry.mysqlCharset; return entry.mysqlCharset;
} } else {
else
{
logger.warn("Unexpect mysql charset: " + id); logger.warn("Unexpect mysql charset: " + id);
return null; return null;
} }
@@ -292,16 +281,12 @@ public final class CharsetConversion
/** /**
* Return defined collaction name for mysql. * Return defined collaction name for mysql.
*/ */
public static String getCollation(final int id) public static String getCollation(final int id) {
{
Entry entry = getEntry(id); Entry entry = getEntry(id);
if (entry != null) if (entry != null) {
{
return entry.mysqlCollation; return entry.mysqlCollation;
} } else {
else
{
logger.warn("Unexpect mysql charset: " + id); logger.warn("Unexpect mysql charset: " + id);
return null; return null;
} }
@@ -310,55 +295,41 @@ public final class CharsetConversion
/** /**
* Return converted charset name for java. * Return converted charset name for java.
*/ */
public static String getJavaCharset(final int id) public static String getJavaCharset(final int id) {
{
Entry entry = getEntry(id); Entry entry = getEntry(id);
if (entry != null) if (entry != null) {
{ if (entry.javaCharset != null) {
if (entry.javaCharset != null)
{
return entry.javaCharset; return entry.javaCharset;
} } else {
else logger.warn("Unknown java charset for: id = " + id + ", name = " + entry.mysqlCharset + ", coll = "
{ + entry.mysqlCollation);
logger.warn("Unknown java charset for: id = " + id
+ ", name = " + entry.mysqlCharset + ", coll = "
+ entry.mysqlCollation);
return null; return null;
} }
} } else {
else
{
logger.warn("Unexpect mysql charset: " + id); logger.warn("Unexpect mysql charset: " + id);
return null; return null;
} }
} }
public static void main(String[] args) public static void main(String[] args) {
{ for (int i = 0; i < entries.length; i++) {
for (int i = 0; i < entries.length; i++)
{
Entry entry = entries[i]; Entry entry = entries[i];
System.out.print(i); System.out.print(i);
System.out.print(','); System.out.print(',');
System.out.print(' '); System.out.print(' ');
if (entry != null) if (entry != null) {
{
System.out.print(entry.mysqlCharset); System.out.print(entry.mysqlCharset);
System.out.print(','); System.out.print(',');
System.out.print(' '); System.out.print(' ');
System.out.print(entry.javaCharset); System.out.print(entry.javaCharset);
if (entry.javaCharset != null) if (entry.javaCharset != null) {
{
System.out.print(','); System.out.print(',');
System.out.print(' '); System.out.print(' ');
System.out.print(Charset.forName(entry.javaCharset).name()); System.out.print(Charset.forName(entry.javaCharset).name());
} }
} } else {
else
{
System.out.print("null"); System.out.print("null");
} }
System.out.println(); System.out.println();

View File

@@ -21,16 +21,13 @@ import org.apache.commons.logging.LogFactory;
* DirectLogFetcher fetcher = new DirectLogFetcher(); * DirectLogFetcher fetcher = new DirectLogFetcher();
* fetcher.open(conn, file, 0, 13); * fetcher.open(conn, file, 0, 13);
* *
* while (fetcher.fetch()) * while (fetcher.fetch()) {
* {
* LogEvent event; * LogEvent event;
* do * do {
* {
* event = decoder.decode(fetcher, context); * event = decoder.decode(fetcher, context);
* *
* // process log event. * // process log event.
* } * } while (event != null);
* while (event != null);
* } * }
* // connection closed. * // connection closed.
* </pre> * </pre>
@@ -38,97 +35,79 @@ import org.apache.commons.logging.LogFactory;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class DirectLogFetcher extends LogFetcher public final class DirectLogFetcher extends LogFetcher {
{
protected static final Log logger = LogFactory.getLog(DirectLogFetcher.class); protected static final Log logger = LogFactory.getLog(DirectLogFetcher.class);
/** Command to dump binlog */ /** Command to dump binlog */
public static final byte COM_BINLOG_DUMP = 18; public static final byte COM_BINLOG_DUMP = 18;
/** Packet header sizes */ /** Packet header sizes */
public static final int NET_HEADER_SIZE = 4; public static final int NET_HEADER_SIZE = 4;
public static final int SQLSTATE_LENGTH = 5; public static final int SQLSTATE_LENGTH = 5;
/** Packet offsets */ /** Packet offsets */
public static final int PACKET_LEN_OFFSET = 0; public static final int PACKET_LEN_OFFSET = 0;
public static final int PACKET_SEQ_OFFSET = 3; public static final int PACKET_SEQ_OFFSET = 3;
/** Maximum packet length */ /** Maximum packet length */
public static final int MAX_PACKET_LENGTH = (256 * 256 * 256 - 1); public static final int MAX_PACKET_LENGTH = (256 * 256 * 256 - 1);
/** BINLOG_DUMP options */ /** BINLOG_DUMP options */
public static final int BINLOG_DUMP_NON_BLOCK = 1; public static final int BINLOG_DUMP_NON_BLOCK = 1;
public static final int BINLOG_SEND_ANNOTATE_ROWS_EVENT = 2; public static final int BINLOG_SEND_ANNOTATE_ROWS_EVENT = 2;
private Connection conn; private Connection conn;
private OutputStream mysqlOutput; private OutputStream mysqlOutput;
private InputStream mysqlInput; private InputStream mysqlInput;
public DirectLogFetcher() public DirectLogFetcher(){
{
super(DEFAULT_INITIAL_CAPACITY, DEFAULT_GROWTH_FACTOR); super(DEFAULT_INITIAL_CAPACITY, DEFAULT_GROWTH_FACTOR);
} }
public DirectLogFetcher(final int initialCapacity) public DirectLogFetcher(final int initialCapacity){
{
super(initialCapacity, DEFAULT_GROWTH_FACTOR); super(initialCapacity, DEFAULT_GROWTH_FACTOR);
} }
public DirectLogFetcher(final int initialCapacity, final float growthFactor) public DirectLogFetcher(final int initialCapacity, final float growthFactor){
{
super(initialCapacity, growthFactor); super(initialCapacity, growthFactor);
} }
private static final Object unwrapConnection(Object conn, Class<?> connClazz) private static final Object unwrapConnection(Object conn, Class<?> connClazz) throws IOException {
throws IOException while (!connClazz.isInstance(conn)) {
{ try {
while (!connClazz.isInstance(conn))
{
try
{
Class<?> connProxy = Class.forName("org.springframework.jdbc.datasource.ConnectionProxy"); Class<?> connProxy = Class.forName("org.springframework.jdbc.datasource.ConnectionProxy");
if (connProxy.isInstance(conn)) if (connProxy.isInstance(conn)) {
{
conn = invokeMethod(conn, connProxy, "getTargetConnection"); conn = invokeMethod(conn, connProxy, "getTargetConnection");
continue; continue;
} }
} } catch (ClassNotFoundException e) {
catch (ClassNotFoundException e) // org.springframework.jdbc.datasource.ConnectionProxy not
{ // found.
// org.springframework.jdbc.datasource.ConnectionProxy not found.
} }
try try {
{
Class<?> connProxy = Class.forName("org.apache.commons.dbcp.DelegatingConnection"); Class<?> connProxy = Class.forName("org.apache.commons.dbcp.DelegatingConnection");
if (connProxy.isInstance(conn)) if (connProxy.isInstance(conn)) {
{
conn = getDeclaredField(conn, connProxy, "_conn"); conn = getDeclaredField(conn, connProxy, "_conn");
continue; continue;
} }
} } catch (ClassNotFoundException e) {
catch (ClassNotFoundException e)
{
// org.apache.commons.dbcp.DelegatingConnection not found. // org.apache.commons.dbcp.DelegatingConnection not found.
} }
try try {
{ if (conn instanceof java.sql.Wrapper) {
if (conn instanceof java.sql.Wrapper)
{
Class<?> connIface = Class.forName("com.mysql.jdbc.Connection"); Class<?> connIface = Class.forName("com.mysql.jdbc.Connection");
conn = ((java.sql.Wrapper) conn).unwrap(connIface); conn = ((java.sql.Wrapper) conn).unwrap(connIface);
continue; continue;
} }
} } catch (ClassNotFoundException e) {
catch (ClassNotFoundException e)
{
// com.mysql.jdbc.Connection not found. // com.mysql.jdbc.Connection not found.
} } catch (SQLException e) {
catch (SQLException e) logger.warn("Unwrap " + conn.getClass().getName() + " to " + connClazz.getName() + " failed: "
{ + e.getMessage(),
logger.warn("Unwrap " + conn.getClass().getName() + " to " e);
+ connClazz.getName() + " failed: " + e.getMessage(), e);
} }
return null; return null;
@@ -136,127 +115,85 @@ public final class DirectLogFetcher extends LogFetcher
return conn; return conn;
} }
private static final Object invokeMethod(Object obj, Class<?> objClazz, private static final Object invokeMethod(Object obj, Class<?> objClazz, String name) {
String name) try {
{
try
{
Method method = objClazz.getMethod(name, (Class<?>[]) null); Method method = objClazz.getMethod(name, (Class<?>[]) null);
return method.invoke(obj, (Object[]) null); return method.invoke(obj, (Object[]) null);
} } catch (NoSuchMethodException e) {
catch (NoSuchMethodException e) throw new IllegalArgumentException("No such method: \'" + name + "\' @ " + objClazz.getName(), e);
{ } catch (IllegalAccessException e) {
throw new IllegalArgumentException("No such method: \'" + name throw new IllegalArgumentException("Cannot invoke method: \'" + name + "\' @ " + objClazz.getName(), e);
+ "\' @ " + objClazz.getName(), e); } catch (InvocationTargetException e) {
} throw new IllegalArgumentException("Invoke method failed: \'" + name + "\' @ " + objClazz.getName(),
catch (IllegalAccessException e) e.getTargetException());
{
throw new IllegalArgumentException("Cannot invoke method: \'"
+ name + "\' @ " + objClazz.getName(), e);
}
catch (InvocationTargetException e)
{
throw new IllegalArgumentException("Invoke method failed: \'"
+ name + "\' @ " + objClazz.getName(),
e.getTargetException());
} }
} }
private static final Object getDeclaredField(Object obj, Class<?> objClazz, private static final Object getDeclaredField(Object obj, Class<?> objClazz, String name) {
String name) try {
{
try
{
Field field = objClazz.getDeclaredField(name); Field field = objClazz.getDeclaredField(name);
field.setAccessible(true); field.setAccessible(true);
return field.get(obj); return field.get(obj);
} } catch (NoSuchFieldException e) {
catch (NoSuchFieldException e) throw new IllegalArgumentException("No such field: \'" + name + "\' @ " + objClazz.getName(), e);
{ } catch (IllegalAccessException e) {
throw new IllegalArgumentException("No such field: \'" + name throw new IllegalArgumentException("Cannot get field: \'" + name + "\' @ " + objClazz.getName(), e);
+ "\' @ " + objClazz.getName(), e);
}
catch (IllegalAccessException e)
{
throw new IllegalArgumentException("Cannot get field: \'" + name
+ "\' @ " + objClazz.getName(), e);
} }
} }
/** /**
* Connect MySQL master to fetch binlog. * Connect MySQL master to fetch binlog.
*/ */
public void open(Connection conn, String fileName, final int serverId) public void open(Connection conn, String fileName, final int serverId) throws IOException {
throws IOException
{
open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, false); open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, false);
} }
/** /**
* Connect MySQL master to fetch binlog. * Connect MySQL master to fetch binlog.
*/ */
public void open(Connection conn, String fileName, final int serverId, public void open(Connection conn, String fileName, final int serverId, boolean nonBlocking) throws IOException {
boolean nonBlocking) throws IOException
{
open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, nonBlocking); open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, nonBlocking);
} }
/** /**
* Connect MySQL master to fetch binlog. * Connect MySQL master to fetch binlog.
*/ */
public void open(Connection conn, String fileName, final long filePosition, public void open(Connection conn, String fileName, final long filePosition, final int serverId) throws IOException {
final int serverId) throws IOException
{
open(conn, fileName, filePosition, serverId, false); open(conn, fileName, filePosition, serverId, false);
} }
/** /**
* Connect MySQL master to fetch binlog. * Connect MySQL master to fetch binlog.
*/ */
public void open(Connection conn, String fileName, long filePosition, public void open(Connection conn, String fileName, long filePosition, final int serverId, boolean nonBlocking)
final int serverId, boolean nonBlocking) throws IOException throws IOException {
{ try {
try
{
this.conn = conn; this.conn = conn;
Class<?> connClazz = Class.forName("com.mysql.jdbc.ConnectionImpl"); Class<?> connClazz = Class.forName("com.mysql.jdbc.ConnectionImpl");
Object unwrapConn = unwrapConnection(conn, connClazz); Object unwrapConn = unwrapConnection(conn, connClazz);
if (unwrapConn == null) if (unwrapConn == null) {
{ throw new IOException("Unable to unwrap " + conn.getClass().getName()
throw new IOException("Unable to unwrap " + " to com.mysql.jdbc.ConnectionImpl");
+ conn.getClass().getName()
+ " to com.mysql.jdbc.ConnectionImpl");
} }
// Get underlying IO streams for network communications. // Get underlying IO streams for network communications.
Object connIo = getDeclaredField(unwrapConn, connClazz, "io"); Object connIo = getDeclaredField(unwrapConn, connClazz, "io");
if (connIo == null) if (connIo == null) {
{ throw new IOException("Get null field:" + conn.getClass().getName() + "#io");
throw new IOException("Get null field:"
+ conn.getClass().getName() + "#io");
} }
mysqlOutput = (OutputStream) getDeclaredField(connIo, mysqlOutput = (OutputStream) getDeclaredField(connIo, connIo.getClass(), "mysqlOutput");
connIo.getClass(), "mysqlOutput"); mysqlInput = (InputStream) getDeclaredField(connIo, connIo.getClass(), "mysqlInput");
mysqlInput = (InputStream) getDeclaredField(connIo,
connIo.getClass(), "mysqlInput");
if (filePosition == 0) if (filePosition == 0) filePosition = BIN_LOG_HEADER_SIZE;
filePosition = BIN_LOG_HEADER_SIZE;
sendBinlogDump(fileName, filePosition, serverId, nonBlocking); sendBinlogDump(fileName, filePosition, serverId, nonBlocking);
position = 0; position = 0;
} } catch (IOException e) {
catch (IOException e)
{
close(); /* Do cleanup */ close(); /* Do cleanup */
logger.error("Error on COM_BINLOG_DUMP: file = " + fileName logger.error("Error on COM_BINLOG_DUMP: file = " + fileName + ", position = " + filePosition);
+ ", position = " + filePosition);
throw e; throw e;
} } catch (ClassNotFoundException e) {
catch (ClassNotFoundException e)
{
close(); /* Do cleanup */ close(); /* Do cleanup */
throw new IOException( throw new IOException("Unable to load com.mysql.jdbc.ConnectionImpl", e);
"Unable to load com.mysql.jdbc.ConnectionImpl", e);
} }
} }
@@ -265,8 +202,7 @@ public final class DirectLogFetcher extends LogFetcher
* *
* @param b the byte to put in the buffer * @param b the byte to put in the buffer
*/ */
protected final void putByte(byte b) protected final void putByte(byte b) {
{
ensureCapacity(position + 1); ensureCapacity(position + 1);
buffer[position++] = b; buffer[position++] = b;
@@ -277,8 +213,7 @@ public final class DirectLogFetcher extends LogFetcher
* *
* @param i16 the integer to put in the buffer * @param i16 the integer to put in the buffer
*/ */
protected final void putInt16(int i16) protected final void putInt16(int i16) {
{
ensureCapacity(position + 2); ensureCapacity(position + 2);
byte[] buf = buffer; byte[] buf = buffer;
@@ -291,8 +226,7 @@ public final class DirectLogFetcher extends LogFetcher
* *
* @param i32 the integer to put in the buffer * @param i32 the integer to put in the buffer
*/ */
protected final void putInt32(long i32) protected final void putInt32(long i32) {
{
ensureCapacity(position + 4); ensureCapacity(position + 4);
byte[] buf = buffer; byte[] buf = buffer;
@@ -307,8 +241,7 @@ public final class DirectLogFetcher extends LogFetcher
* *
* @param s the value to put in the buffer * @param s the value to put in the buffer
*/ */
protected final void putString(String s) protected final void putString(String s) {
{
ensureCapacity(position + (s.length() * 2) + 1); ensureCapacity(position + (s.length() * 2) + 1);
System.arraycopy(s.getBytes(), 0, buffer, position, s.length()); System.arraycopy(s.getBytes(), 0, buffer, position, s.length());
@@ -316,10 +249,8 @@ public final class DirectLogFetcher extends LogFetcher
buffer[position++] = 0; buffer[position++] = 0;
} }
protected final void sendBinlogDump(String fileName, protected final void sendBinlogDump(String fileName, final long filePosition, final int serverId,
final long filePosition, final int serverId, boolean nonBlocking) boolean nonBlocking) throws IOException {
throws IOException
{
position = NET_HEADER_SIZE; position = NET_HEADER_SIZE;
putByte(COM_BINLOG_DUMP); putByte(COM_BINLOG_DUMP);
@@ -327,7 +258,7 @@ public final class DirectLogFetcher extends LogFetcher
int binlog_flags = nonBlocking ? BINLOG_DUMP_NON_BLOCK : 0; int binlog_flags = nonBlocking ? BINLOG_DUMP_NON_BLOCK : 0;
binlog_flags |= BINLOG_SEND_ANNOTATE_ROWS_EVENT; binlog_flags |= BINLOG_SEND_ANNOTATE_ROWS_EVENT;
putInt16(binlog_flags); // binlog_flags putInt16(binlog_flags); // binlog_flags
putInt32(serverId); // slave's server-id putInt32(serverId); // slave's server-id
putString(fileName); putString(fileName);
final byte[] buf = buffer; final byte[] buf = buffer;
@@ -345,13 +276,10 @@ public final class DirectLogFetcher extends LogFetcher
* *
* @see com.taobao.tddl.dbsync.binlog.LogFetcher#fetch() * @see com.taobao.tddl.dbsync.binlog.LogFetcher#fetch()
*/ */
public boolean fetch() throws IOException public boolean fetch() throws IOException {
{ try {
try
{
// Fetching packet header from input. // Fetching packet header from input.
if (!fetch0(0, NET_HEADER_SIZE)) if (!fetch0(0, NET_HEADER_SIZE)) {
{
logger.warn("Reached end of input stream while fetching header"); logger.warn("Reached end of input stream while fetching header");
return false; return false;
} }
@@ -359,61 +287,48 @@ public final class DirectLogFetcher extends LogFetcher
// Fetching the first packet(may a multi-packet). // Fetching the first packet(may a multi-packet).
int netlen = getUint24(PACKET_LEN_OFFSET); int netlen = getUint24(PACKET_LEN_OFFSET);
int netnum = getUint8(PACKET_SEQ_OFFSET); int netnum = getUint8(PACKET_SEQ_OFFSET);
if (!fetch0(NET_HEADER_SIZE, netlen)) if (!fetch0(NET_HEADER_SIZE, netlen)) {
{ logger.warn("Reached end of input stream: packet #" + netnum + ", len = " + netlen);
logger.warn("Reached end of input stream: packet #" + netnum
+ ", len = " + netlen);
return false; return false;
} }
// Detecting error code. // Detecting error code.
final int mark = getUint8(NET_HEADER_SIZE); final int mark = getUint8(NET_HEADER_SIZE);
if (mark != 0) if (mark != 0) {
{
if (mark == 255) // error from master if (mark == 255) // error from master
{ {
// Indicates an error, for example trying to fetch from wrong // Indicates an error, for example trying to fetch from
// wrong
// binlog position. // binlog position.
position = NET_HEADER_SIZE + 1; position = NET_HEADER_SIZE + 1;
final int errno = getInt16(); final int errno = getInt16();
String sqlstate = forward(1).getFixString(SQLSTATE_LENGTH); String sqlstate = forward(1).getFixString(SQLSTATE_LENGTH);
String errmsg = getFixString(limit - position); String errmsg = getFixString(limit - position);
throw new IOException("Received error packet:" throw new IOException("Received error packet:" + " errno = " + errno + ", sqlstate = " + sqlstate
+ " errno = " + errno + ", sqlstate = " + sqlstate + " errmsg = " + errmsg);
+ " errmsg = " + errmsg); } else if (mark == 254) {
}
else if (mark == 254)
{
// Indicates end of stream. It's not clear when this would // Indicates end of stream. It's not clear when this would
// be sent. // be sent.
logger.warn("Received EOF packet from server, apparent" logger.warn("Received EOF packet from server, apparent" + " master disconnected.");
+ " master disconnected.");
return false; return false;
} } else {
else
{
// Should not happen. // Should not happen.
throw new IOException("Unexpected response " + mark throw new IOException("Unexpected response " + mark + " while fetching binlog: packet #" + netnum
+ " while fetching binlog: packet #" + netnum + ", len = " + netlen);
+ ", len = " + netlen);
} }
} }
// The first packet is a multi-packet, concatenate the packets. // The first packet is a multi-packet, concatenate the packets.
while (netlen == MAX_PACKET_LENGTH) while (netlen == MAX_PACKET_LENGTH) {
{ if (!fetch0(0, NET_HEADER_SIZE)) {
if (!fetch0(0, NET_HEADER_SIZE))
{
logger.warn("Reached end of input stream while fetching header"); logger.warn("Reached end of input stream while fetching header");
return false; return false;
} }
netlen = getUint24(PACKET_LEN_OFFSET); netlen = getUint24(PACKET_LEN_OFFSET);
netnum = getUint8(PACKET_SEQ_OFFSET); netnum = getUint8(PACKET_SEQ_OFFSET);
if (!fetch0(limit, netlen)) if (!fetch0(limit, netlen)) {
{ logger.warn("Reached end of input stream: packet #" + netnum + ", len = " + netlen);
logger.warn("Reached end of input stream: packet #"
+ netnum + ", len = " + netlen);
return false; return false;
} }
} }
@@ -423,43 +338,32 @@ public final class DirectLogFetcher extends LogFetcher
position = origin; position = origin;
limit -= origin; limit -= origin;
return true; return true;
} } catch (SocketTimeoutException e) {
catch (SocketTimeoutException e)
{
close(); /* Do cleanup */ close(); /* Do cleanup */
logger.error("Socket timeout expired, closing connection", e); logger.error("Socket timeout expired, closing connection", e);
throw e; throw e;
} } catch (InterruptedIOException e) {
catch (InterruptedIOException e)
{
close(); /* Do cleanup */ close(); /* Do cleanup */
logger.warn("I/O interrupted while reading from client socket", e); logger.warn("I/O interrupted while reading from client socket", e);
throw e; throw e;
} } catch (IOException e) {
catch (IOException e)
{
close(); /* Do cleanup */ close(); /* Do cleanup */
logger.error("I/O error while reading from client socket", e); logger.error("I/O error while reading from client socket", e);
throw e; throw e;
} }
} }
private final boolean fetch0(final int off, final int len) private final boolean fetch0(final int off, final int len) throws IOException {
throws IOException
{
ensureCapacity(off + len); ensureCapacity(off + len);
for (int count, n = 0; n < len; n += count) for (int count, n = 0; n < len; n += count) {
{ if (0 > (count = mysqlInput.read(buffer, off + n, len - n))) {
if (0 > (count = mysqlInput.read(buffer, off + n, len - n)))
{
// Reached end of input stream // Reached end of input stream
return false; return false;
} }
} }
if (limit < off + len) if (limit < off + len) limit = off + len;
limit = off + len;
return true; return true;
} }
@@ -468,19 +372,14 @@ public final class DirectLogFetcher extends LogFetcher
* *
* @see com.taobao.tddl.dbsync.binlog.LogFetcher#close() * @see com.taobao.tddl.dbsync.binlog.LogFetcher#close()
*/ */
public void close() throws IOException public void close() throws IOException {
{ try {
try if (conn != null) conn.close();
{
if (conn != null)
conn.close();
conn = null; conn = null;
mysqlInput = null; mysqlInput = null;
mysqlOutput = null; mysqlOutput = null;
} } catch (SQLException e) {
catch (SQLException e)
{
logger.warn("Unable to close connection", e); logger.warn("Unable to close connection", e);
} }
} }

View File

@@ -129,11 +129,11 @@ public final class FileLogFetcher extends LogFetcher {
} }
} else if (limit > 0) { } else if (limit > 0) {
System.arraycopy(buffer, origin, buffer, 0, limit); System.arraycopy(buffer, origin, buffer, 0, limit);
position -= origin;
origin = 0;
final int len = fin.read(buffer, limit, buffer.length - limit); final int len = fin.read(buffer, limit, buffer.length - limit);
if (len >= 0) { if (len >= 0) {
limit += len; limit += len;
position -= origin;
origin = 0;
/* More binlog to fetch */ /* More binlog to fetch */
return true; return true;

View File

@@ -7,69 +7,56 @@ import com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent;
import com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent; import com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent;
/** /**
* TODO: Document Me!! * TODO: Document Me!! NOTE: Log context will NOT write multi-threaded.
*
* NOTE: Log context will NOT write multi-threaded.
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class LogContext public final class LogContext {
{
private final Map<Long, TableMapLogEvent> mapOfTable = new HashMap<Long, TableMapLogEvent>(); private final Map<Long, TableMapLogEvent> mapOfTable = new HashMap<Long, TableMapLogEvent>();
private FormatDescriptionLogEvent formatDescription; private FormatDescriptionLogEvent formatDescription;
private LogPosition logPosition; private LogPosition logPosition;
public LogContext() public LogContext(){
{
this.formatDescription = FormatDescriptionLogEvent.FORMAT_DESCRIPTION_EVENT_5_x; this.formatDescription = FormatDescriptionLogEvent.FORMAT_DESCRIPTION_EVENT_5_x;
} }
public LogContext(FormatDescriptionLogEvent descriptionEvent) public LogContext(FormatDescriptionLogEvent descriptionEvent){
{
this.formatDescription = descriptionEvent; this.formatDescription = descriptionEvent;
} }
public final LogPosition getLogPosition() public final LogPosition getLogPosition() {
{
return logPosition; return logPosition;
} }
public final void setLogPosition(LogPosition logPosition) public final void setLogPosition(LogPosition logPosition) {
{
this.logPosition = logPosition; this.logPosition = logPosition;
} }
public final FormatDescriptionLogEvent getFormatDescription() public final FormatDescriptionLogEvent getFormatDescription() {
{
return formatDescription; return formatDescription;
} }
public final void setFormatDescription( public final void setFormatDescription(FormatDescriptionLogEvent formatDescription) {
FormatDescriptionLogEvent formatDescription)
{
this.formatDescription = formatDescription; this.formatDescription = formatDescription;
} }
public final void putTable(TableMapLogEvent mapEvent) public final void putTable(TableMapLogEvent mapEvent) {
{
mapOfTable.put(Long.valueOf(mapEvent.getTableId()), mapEvent); mapOfTable.put(Long.valueOf(mapEvent.getTableId()), mapEvent);
} }
public final TableMapLogEvent getTable(final long tableId) public final TableMapLogEvent getTable(final long tableId) {
{
return mapOfTable.get(Long.valueOf(tableId)); return mapOfTable.get(Long.valueOf(tableId));
} }
public final void clearAllTables() public final void clearAllTables() {
{
mapOfTable.clear(); mapOfTable.clear();
} }
public void reset() public void reset() {
{
formatDescription = FormatDescriptionLogEvent.FORMAT_DESCRIPTION_EVENT_5_x; formatDescription = FormatDescriptionLogEvent.FORMAT_DESCRIPTION_EVENT_5_x;
mapOfTable.clear(); mapOfTable.clear();

View File

@@ -61,28 +61,24 @@ import com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidLogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class LogDecoder public final class LogDecoder {
{
protected static final Log logger = LogFactory.getLog(LogDecoder.class); protected static final Log logger = LogFactory.getLog(LogDecoder.class);
protected final BitSet handleSet = new BitSet(LogEvent.ENUM_END_EVENT); protected final BitSet handleSet = new BitSet(LogEvent.ENUM_END_EVENT);
public LogDecoder() public LogDecoder(){
{
} }
public LogDecoder(final int fromIndex, final int toIndex) public LogDecoder(final int fromIndex, final int toIndex){
{
handleSet.set(fromIndex, toIndex); handleSet.set(fromIndex, toIndex);
} }
public final void handle(final int fromIndex, final int toIndex) public final void handle(final int fromIndex, final int toIndex) {
{
handleSet.set(fromIndex, toIndex); handleSet.set(fromIndex, toIndex);
} }
public final void handle(final int flagIndex) public final void handle(final int flagIndex) {
{
handleSet.set(flagIndex); handleSet.set(flagIndex);
} }
@@ -90,48 +86,32 @@ public final class LogDecoder
* Decoding an event from binary-log buffer. * Decoding an event from binary-log buffer.
* *
* @return <code>UknownLogEvent</code> if event type is unknown or skipped, * @return <code>UknownLogEvent</code> if event type is unknown or skipped,
* <code>null</code> if buffer is not including a full event. * <code>null</code> if buffer is not including a full event.
*/ */
public LogEvent decode(LogBuffer buffer, LogContext context) public LogEvent decode(LogBuffer buffer, LogContext context) throws IOException {
throws IOException
{
final int limit = buffer.limit(); final int limit = buffer.limit();
if (limit >= FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN) if (limit >= FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN) {
{ LogHeader header = new LogHeader(buffer, context.getFormatDescription());
LogHeader header = new LogHeader(buffer,
context.getFormatDescription());
final int len = header.getEventLen(); final int len = header.getEventLen();
if (limit >= len) if (limit >= len) {
{
LogEvent event; LogEvent event;
/* Checking binary-log's header */ /* Checking binary-log's header */
if (handleSet.get(header.getType())) if (handleSet.get(header.getType())) {
{
buffer.limit(len); buffer.limit(len);
try try {
{
/* Decoding binary-log to event */ /* Decoding binary-log to event */
event = decode(buffer, header, context); event = decode(buffer, header, context);
} } catch (IOException e) {
catch (IOException e) if (logger.isWarnEnabled()) logger.warn("Decoding " + LogEvent.getTypeName(header.getType())
{ + " failed from: " + context.getLogPosition(), e);
if (logger.isWarnEnabled())
logger.warn("Decoding "
+ LogEvent.getTypeName(header.getType())
+ " failed from: "
+ context.getLogPosition(), e);
throw e; throw e;
} } finally {
finally
{
buffer.limit(limit); /* Restore limit */ buffer.limit(limit); /* Restore limit */
} }
} } else {
else
{
/* Ignore unsupported binary-log. */ /* Ignore unsupported binary-log. */
event = new UnknownLogEvent(header); event = new UnknownLogEvent(header);
} }
@@ -152,338 +132,275 @@ public final class LogDecoder
* *
* @return <code>UknownLogEvent</code> if event type is unknown or skipped. * @return <code>UknownLogEvent</code> if event type is unknown or skipped.
*/ */
public static LogEvent decode(LogBuffer buffer, LogHeader header, public static LogEvent decode(LogBuffer buffer, LogHeader header, LogContext context) throws IOException {
LogContext context) throws IOException
{
FormatDescriptionLogEvent descriptionEvent = context.getFormatDescription(); FormatDescriptionLogEvent descriptionEvent = context.getFormatDescription();
LogPosition logPosition = context.getLogPosition(); LogPosition logPosition = context.getLogPosition();
int checksumAlg = LogEvent.BINLOG_CHECKSUM_ALG_UNDEF; int checksumAlg = LogEvent.BINLOG_CHECKSUM_ALG_UNDEF;
if (header.getType() != LogEvent.FORMAT_DESCRIPTION_EVENT) { if (header.getType() != LogEvent.FORMAT_DESCRIPTION_EVENT) {
checksumAlg = descriptionEvent.header.getChecksumAlg(); checksumAlg = descriptionEvent.header.getChecksumAlg();
}else { } else {
// 如果是format事件自己,也需要处理checksum // 如果是format事件自己,也需要处理checksum
checksumAlg = header.getChecksumAlg(); checksumAlg = header.getChecksumAlg();
} }
if (checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_OFF && checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_UNDEF) { if (checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_OFF && checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_UNDEF) {
// remove checksum bytes // remove checksum bytes
buffer.limit(header.getEventLen() - LogEvent.BINLOG_CHECKSUM_LEN); buffer.limit(header.getEventLen() - LogEvent.BINLOG_CHECKSUM_LEN);
} }
switch (header.getType()) switch (header.getType()) {
{ case LogEvent.QUERY_EVENT: {
case LogEvent.QUERY_EVENT: QueryLogEvent event = new QueryLogEvent(header, buffer, descriptionEvent);
{
QueryLogEvent event = new QueryLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
return event; return event;
} }
case LogEvent.XID_EVENT: case LogEvent.XID_EVENT: {
{ XidLogEvent event = new XidLogEvent(header, buffer, descriptionEvent);
XidLogEvent event = new XidLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
return event; return event;
} }
case LogEvent.TABLE_MAP_EVENT: case LogEvent.TABLE_MAP_EVENT: {
{ TableMapLogEvent mapEvent = new TableMapLogEvent(header, buffer, descriptionEvent);
TableMapLogEvent mapEvent = new TableMapLogEvent(header,
buffer, descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
context.putTable(mapEvent); context.putTable(mapEvent);
return mapEvent; return mapEvent;
} }
case LogEvent.WRITE_ROWS_EVENT_V1: case LogEvent.WRITE_ROWS_EVENT_V1: {
{
RowsLogEvent event = new WriteRowsLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
case LogEvent.UPDATE_ROWS_EVENT_V1:
{
RowsLogEvent event = new UpdateRowsLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
case LogEvent.DELETE_ROWS_EVENT_V1:
{
RowsLogEvent event = new DeleteRowsLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
case LogEvent.ROTATE_EVENT:
{
RotateLogEvent event = new RotateLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition = new LogPosition(event.getFilename(),
event.getPosition());
context.setLogPosition(logPosition);
return event;
}
case LogEvent.LOAD_EVENT:
case LogEvent.NEW_LOAD_EVENT:
{
LoadLogEvent event = new LoadLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.SLAVE_EVENT: /* can never happen (unused event) */
{
if (logger.isWarnEnabled())
logger.warn("Skipping unsupported SLAVE_EVENT from: "
+ context.getLogPosition());
break;
}
case LogEvent.CREATE_FILE_EVENT:
{
CreateFileLogEvent event = new CreateFileLogEvent(header,
buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.APPEND_BLOCK_EVENT:
{
AppendBlockLogEvent event = new AppendBlockLogEvent(header,
buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.DELETE_FILE_EVENT:
{
DeleteFileLogEvent event = new DeleteFileLogEvent(header,
buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.EXEC_LOAD_EVENT:
{
ExecuteLoadLogEvent event = new ExecuteLoadLogEvent(header,
buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.START_EVENT_V3:
{
/* This is sent only by MySQL <=4.x */
StartLogEventV3 event = new StartLogEventV3(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.STOP_EVENT:
{
StopLogEvent event = new StopLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.INTVAR_EVENT:
{
IntvarLogEvent event = new IntvarLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.RAND_EVENT:
{
RandLogEvent event = new RandLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.USER_VAR_EVENT:
{
UserVarLogEvent event = new UserVarLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.FORMAT_DESCRIPTION_EVENT:
{
descriptionEvent = new FormatDescriptionLogEvent(header,
buffer, descriptionEvent);
context.setFormatDescription(descriptionEvent);
return descriptionEvent;
}
case LogEvent.PRE_GA_WRITE_ROWS_EVENT:
{
if (logger.isWarnEnabled())
logger.warn("Skipping unsupported PRE_GA_WRITE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Write_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.PRE_GA_UPDATE_ROWS_EVENT:
{
if (logger.isWarnEnabled())
logger.warn("Skipping unsupported PRE_GA_UPDATE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Update_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.PRE_GA_DELETE_ROWS_EVENT:
{
if (logger.isWarnEnabled())
logger.warn("Skipping unsupported PRE_GA_DELETE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Delete_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.BEGIN_LOAD_QUERY_EVENT:
{
BeginLoadQueryLogEvent event = new BeginLoadQueryLogEvent(
header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.EXECUTE_LOAD_QUERY_EVENT:
{
ExecuteLoadQueryLogEvent event = new ExecuteLoadQueryLogEvent(
header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.INCIDENT_EVENT:
{
IncidentLogEvent event = new IncidentLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.HEARTBEAT_LOG_EVENT:
{
HeartbeatLogEvent event = new HeartbeatLogEvent(header, buffer,
descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.IGNORABLE_LOG_EVENT:
{
IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.ROWS_QUERY_LOG_EVENT:
{
RowsQueryLogEvent event = new RowsQueryLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.WRITE_ROWS_EVENT: {
RowsLogEvent event = new WriteRowsLogEvent(header, buffer, descriptionEvent); RowsLogEvent event = new WriteRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
event.fillTable(context); event.fillTable(context);
return event; return event;
} }
case LogEvent.UPDATE_ROWS_EVENT: { case LogEvent.UPDATE_ROWS_EVENT_V1: {
RowsLogEvent event = new UpdateRowsLogEvent(header, buffer, descriptionEvent); RowsLogEvent event = new UpdateRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
event.fillTable(context); event.fillTable(context);
return event; return event;
} }
case LogEvent.DELETE_ROWS_EVENT: { case LogEvent.DELETE_ROWS_EVENT_V1: {
RowsLogEvent event = new DeleteRowsLogEvent(header, buffer, descriptionEvent); RowsLogEvent event = new DeleteRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
event.fillTable(context); event.fillTable(context);
return event; return event;
} }
case LogEvent.GTID_LOG_EVENT: case LogEvent.ROTATE_EVENT: {
case LogEvent.ANONYMOUS_GTID_LOG_EVENT: RotateLogEvent event = new RotateLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition = new LogPosition(event.getFilename(), event.getPosition());
context.setLogPosition(logPosition);
return event;
}
case LogEvent.LOAD_EVENT:
case LogEvent.NEW_LOAD_EVENT: {
LoadLogEvent event = new LoadLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.SLAVE_EVENT: /* can never happen (unused event) */
{ {
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported SLAVE_EVENT from: "
+ context.getLogPosition());
break;
}
case LogEvent.CREATE_FILE_EVENT: {
CreateFileLogEvent event = new CreateFileLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.APPEND_BLOCK_EVENT: {
AppendBlockLogEvent event = new AppendBlockLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.DELETE_FILE_EVENT: {
DeleteFileLogEvent event = new DeleteFileLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.EXEC_LOAD_EVENT: {
ExecuteLoadLogEvent event = new ExecuteLoadLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.START_EVENT_V3: {
/* This is sent only by MySQL <=4.x */
StartLogEventV3 event = new StartLogEventV3(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.STOP_EVENT: {
StopLogEvent event = new StopLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.INTVAR_EVENT: {
IntvarLogEvent event = new IntvarLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.RAND_EVENT: {
RandLogEvent event = new RandLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.USER_VAR_EVENT: {
UserVarLogEvent event = new UserVarLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.FORMAT_DESCRIPTION_EVENT: {
descriptionEvent = new FormatDescriptionLogEvent(header, buffer, descriptionEvent);
context.setFormatDescription(descriptionEvent);
return descriptionEvent;
}
case LogEvent.PRE_GA_WRITE_ROWS_EVENT: {
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_WRITE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Write_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.PRE_GA_UPDATE_ROWS_EVENT: {
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_UPDATE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Update_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.PRE_GA_DELETE_ROWS_EVENT: {
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_DELETE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Delete_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.BEGIN_LOAD_QUERY_EVENT: {
BeginLoadQueryLogEvent event = new BeginLoadQueryLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.EXECUTE_LOAD_QUERY_EVENT: {
ExecuteLoadQueryLogEvent event = new ExecuteLoadQueryLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.INCIDENT_EVENT: {
IncidentLogEvent event = new IncidentLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.HEARTBEAT_LOG_EVENT: {
HeartbeatLogEvent event = new HeartbeatLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.IGNORABLE_LOG_EVENT: {
IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.ROWS_QUERY_LOG_EVENT: {
RowsQueryLogEvent event = new RowsQueryLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.WRITE_ROWS_EVENT: {
RowsLogEvent event = new WriteRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
case LogEvent.UPDATE_ROWS_EVENT: {
RowsLogEvent event = new UpdateRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
case LogEvent.DELETE_ROWS_EVENT: {
RowsLogEvent event = new DeleteRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
case LogEvent.GTID_LOG_EVENT:
case LogEvent.ANONYMOUS_GTID_LOG_EVENT: {
GtidLogEvent event = new GtidLogEvent(header, buffer, descriptionEvent); GtidLogEvent event = new GtidLogEvent(header, buffer, descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
return event; return event;
} }
case LogEvent.PREVIOUS_GTIDS_LOG_EVENT: case LogEvent.PREVIOUS_GTIDS_LOG_EVENT: {
{
PreviousGtidsLogEvent event = new PreviousGtidsLogEvent(header, buffer, descriptionEvent); PreviousGtidsLogEvent event = new PreviousGtidsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
return event; return event;
} }
case LogEvent.ANNOTATE_ROWS_EVENT: case LogEvent.ANNOTATE_ROWS_EVENT: {
{ AnnotateRowsEvent event = new AnnotateRowsEvent(header, buffer, descriptionEvent);
AnnotateRowsEvent event = new AnnotateRowsEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.BINLOG_CHECKPOINT_EVENT:
{
BinlogCheckPointLogEvent event = new BinlogCheckPointLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.GTID_EVENT:
{
MariaGtidLogEvent event = new MariaGtidLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.GTID_LIST_EVENT:
{
MariaGtidListLogEvent event = new MariaGtidListLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
default:
/*
Create an object of Ignorable_log_event for unrecognized sub-class.
So that SLAVE SQL THREAD will only update the position and continue.
*/
if((buffer.getUint16(LogEvent.FLAGS_OFFSET) & LogEvent.LOG_EVENT_IGNORABLE_F) > 0){
IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
/* updating position in context */ /* updating position in context */
logPosition.position = header.getLogPos(); logPosition.position = header.getLogPos();
return event; return event;
}else {
if (logger.isWarnEnabled())
logger.warn("Skipping unrecognized binlog event "
+ LogEvent.getTypeName(header.getType()) + " from: "
+ context.getLogPosition());
} }
case LogEvent.BINLOG_CHECKPOINT_EVENT: {
BinlogCheckPointLogEvent event = new BinlogCheckPointLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.GTID_EVENT: {
MariaGtidLogEvent event = new MariaGtidLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.GTID_LIST_EVENT: {
MariaGtidListLogEvent event = new MariaGtidListLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
default:
/*
* Create an object of Ignorable_log_event for unrecognized
* sub-class. So that SLAVE SQL THREAD will only update the
* position and continue.
*/
if ((buffer.getUint16(LogEvent.FLAGS_OFFSET) & LogEvent.LOG_EVENT_IGNORABLE_F) > 0) {
IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
} else {
if (logger.isWarnEnabled()) logger.warn("Skipping unrecognized binlog event "
+ LogEvent.getTypeName(header.getType()) + " from: "
+ context.getLogPosition());
}
} }
/* updating position in context */ /* updating position in context */

View File

@@ -7,239 +7,218 @@ import com.taobao.tddl.dbsync.binlog.event.LogHeader;
/** /**
* Binary log event definitions. This includes generic code common to all types * Binary log event definitions. This includes generic code common to all types
* of log events, as well as specific code for each type of log event. * of log events, as well as specific code for each type of log event. - All
* * numbers, whether they are 16-, 24-, 32-, or 64-bit numbers, are stored in
* - All numbers, whether they are 16-, 24-, 32-, or 64-bit numbers, are stored * little endian, i.e., the least significant byte first, unless otherwise
* in little endian, i.e., the least significant byte first, unless otherwise * specified. representation of unsigned integers, called Packed Integer. A
* specified. * Packed Integer has the capacity of storing up to 8-byte integers, while small
* * integers still can use 1, 3, or 4 bytes. The value of the first byte
* representation of unsigned integers, called Packed Integer. A Packed Integer * determines how to read the number, according to the following table:
* has the capacity of storing up to 8-byte integers, while small integers still
* can use 1, 3, or 4 bytes. The value of the first byte determines how to read
* the number, according to the following table:
*
* <table> * <table>
* <caption>Format of Packed Integer</caption> * <caption>Format of Packed Integer</caption>
*
* <tr> * <tr>
* <th>First byte</th> * <th>First byte</th>
* <th>Format</th> * <th>Format</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>0-250</td> * <td>0-250</td>
* <td>The first byte is the number (in the range 0-250), and no more bytes are * <td>The first byte is the number (in the range 0-250), and no more bytes are
* used.</td> * used.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>252</td> * <td>252</td>
* <td>Two more bytes are used. The number is in the range 251-0xffff.</td> * <td>Two more bytes are used. The number is in the range 251-0xffff.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>253</td> * <td>253</td>
* <td>Three more bytes are used. The number is in the range 0xffff-0xffffff.</td> * <td>Three more bytes are used. The number is in the range 0xffff-0xffffff.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>254</td> * <td>254</td>
* <td>Eight more bytes are used. The number is in the range * <td>Eight more bytes are used. The number is in the range
* 0xffffff-0xffffffffffffffff.</td> * 0xffffff-0xffffffffffffffff.</td>
* </tr> * </tr>
*
* </table> * </table>
*
* - Strings are stored in various formats. The format of each string is * - Strings are stored in various formats. The format of each string is
* documented separately. * documented separately.
* *
* @see mysql-5.1.60/sql/log_event.h * @see mysql-5.1.60/sql/log_event.h
*
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public abstract class LogEvent public abstract class LogEvent {
{
/* /*
* 3 is MySQL 4.x; 4 is MySQL 5.0.0. * 3 is MySQL 4.x; 4 is MySQL 5.0.0. Compared to version 3, version 4 has: -
* Compared to version 3, version 4 has: * a different Start_log_event, which includes info about the binary log
* - a different Start_log_event, which includes info about the binary log
* (sizes of headers); this info is included for better compatibility if the * (sizes of headers); this info is included for better compatibility if the
* master's MySQL version is different from the slave's. * master's MySQL version is different from the slave's. - all events have a
* - all events have a unique ID (the triplet (server_id, timestamp at server * unique ID (the triplet (server_id, timestamp at server start, other) to
* start, other) to be sure an event is not executed more than once in a * be sure an event is not executed more than once in a multimaster setup,
* multimaster setup, example: * example: M1 / \ v v M2 M3 \ / v v S if a query is run on M1, it will
* M1 * arrive twice on S, so we need that S remembers the last unique ID it has
* / \ * processed, to compare and know if the event should be skipped or not.
* v v * Example of ID: we already have the server id (4 bytes), plus:
* M2 M3
* \ /
* v v
* S
* if a query is run on M1, it will arrive twice on S, so we need that S
* remembers the last unique ID it has processed, to compare and know if the
* event should be skipped or not. Example of ID: we already have the server id
* (4 bytes), plus:
* timestamp_when_the_master_started (4 bytes), a counter (a sequence number * timestamp_when_the_master_started (4 bytes), a counter (a sequence number
* which increments every time we write an event to the binlog) (3 bytes). * which increments every time we write an event to the binlog) (3 bytes).
* Q: how do we handle when the counter is overflowed and restarts from 0 ? * Q: how do we handle when the counter is overflowed and restarts from 0 ?
*
* - Query and Load (Create or Execute) events may have a more precise * - Query and Load (Create or Execute) events may have a more precise
* timestamp (with microseconds), number of matched/affected/warnings rows * timestamp (with microseconds), number of matched/affected/warnings rows
* and fields of session variables: SQL_MODE, * and fields of session variables: SQL_MODE, FOREIGN_KEY_CHECKS,
* FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, SQL_AUTO_IS_NULL, the collations and * UNIQUE_CHECKS, SQL_AUTO_IS_NULL, the collations and charsets, the
* charsets, the PASSWORD() version (old/new/...). * PASSWORD() version (old/new/...).
*/ */
public static final int BINLOG_VERSION = 4; public static final int BINLOG_VERSION = 4;
/* Default 5.0 server version */ /* Default 5.0 server version */
public static final String SERVER_VERSION = "5.0"; public static final String SERVER_VERSION = "5.0";
/** /**
* Event header offsets; these point to places inside the fixed header. * Event header offsets; these point to places inside the fixed header.
*/ */
public static final int EVENT_TYPE_OFFSET = 4; public static final int EVENT_TYPE_OFFSET = 4;
public static final int SERVER_ID_OFFSET = 5; public static final int SERVER_ID_OFFSET = 5;
public static final int EVENT_LEN_OFFSET = 9; public static final int EVENT_LEN_OFFSET = 9;
public static final int LOG_POS_OFFSET = 13; public static final int LOG_POS_OFFSET = 13;
public static final int FLAGS_OFFSET = 17; public static final int FLAGS_OFFSET = 17;
/* event-specific post-header sizes */ /* event-specific post-header sizes */
// where 3.23, 4.x and 5.0 agree // where 3.23, 4.x and 5.0 agree
public static final int QUERY_HEADER_MINIMAL_LEN = (4 + 4 + 1 + 2); public static final int QUERY_HEADER_MINIMAL_LEN = (4 + 4 + 1 + 2);
// where 5.0 differs: 2 for len of N-bytes vars. // where 5.0 differs: 2 for len of N-bytes vars.
public static final int QUERY_HEADER_LEN = (QUERY_HEADER_MINIMAL_LEN + 2); public static final int QUERY_HEADER_LEN = (QUERY_HEADER_MINIMAL_LEN + 2);
/* Enumeration type for the different types of log events. */ /* Enumeration type for the different types of log events. */
public static final int UNKNOWN_EVENT = 0; public static final int UNKNOWN_EVENT = 0;
public static final int START_EVENT_V3 = 1; public static final int START_EVENT_V3 = 1;
public static final int QUERY_EVENT = 2; public static final int QUERY_EVENT = 2;
public static final int STOP_EVENT = 3; public static final int STOP_EVENT = 3;
public static final int ROTATE_EVENT = 4; public static final int ROTATE_EVENT = 4;
public static final int INTVAR_EVENT = 5; public static final int INTVAR_EVENT = 5;
public static final int LOAD_EVENT = 6; public static final int LOAD_EVENT = 6;
public static final int SLAVE_EVENT = 7; public static final int SLAVE_EVENT = 7;
public static final int CREATE_FILE_EVENT = 8; public static final int CREATE_FILE_EVENT = 8;
public static final int APPEND_BLOCK_EVENT = 9; public static final int APPEND_BLOCK_EVENT = 9;
public static final int EXEC_LOAD_EVENT = 10; public static final int EXEC_LOAD_EVENT = 10;
public static final int DELETE_FILE_EVENT = 11; public static final int DELETE_FILE_EVENT = 11;
/** /**
* NEW_LOAD_EVENT is like LOAD_EVENT except that it has a longer sql_ex, * NEW_LOAD_EVENT is like LOAD_EVENT except that it has a longer sql_ex,
* allowing multibyte TERMINATED BY etc; both types share the same class * allowing multibyte TERMINATED BY etc; both types share the same class
* (Load_log_event) * (Load_log_event)
*/ */
public static final int NEW_LOAD_EVENT = 12; public static final int NEW_LOAD_EVENT = 12;
public static final int RAND_EVENT = 13; public static final int RAND_EVENT = 13;
public static final int USER_VAR_EVENT = 14; public static final int USER_VAR_EVENT = 14;
public static final int FORMAT_DESCRIPTION_EVENT = 15; public static final int FORMAT_DESCRIPTION_EVENT = 15;
public static final int XID_EVENT = 16; public static final int XID_EVENT = 16;
public static final int BEGIN_LOAD_QUERY_EVENT = 17; public static final int BEGIN_LOAD_QUERY_EVENT = 17;
public static final int EXECUTE_LOAD_QUERY_EVENT = 18; public static final int EXECUTE_LOAD_QUERY_EVENT = 18;
public static final int TABLE_MAP_EVENT = 19; public static final int TABLE_MAP_EVENT = 19;
/** /**
* These event numbers were used for 5.1.0 to 5.1.15 and are therefore * These event numbers were used for 5.1.0 to 5.1.15 and are therefore
* obsolete. * obsolete.
*/ */
public static final int PRE_GA_WRITE_ROWS_EVENT = 20; public static final int PRE_GA_WRITE_ROWS_EVENT = 20;
public static final int PRE_GA_UPDATE_ROWS_EVENT = 21; public static final int PRE_GA_UPDATE_ROWS_EVENT = 21;
public static final int PRE_GA_DELETE_ROWS_EVENT = 22; public static final int PRE_GA_DELETE_ROWS_EVENT = 22;
/** /**
* These event numbers are used from 5.1.16 and forward * These event numbers are used from 5.1.16 and forward
*/ */
public static final int WRITE_ROWS_EVENT_V1 = 23; public static final int WRITE_ROWS_EVENT_V1 = 23;
public static final int UPDATE_ROWS_EVENT_V1 = 24; public static final int UPDATE_ROWS_EVENT_V1 = 24;
public static final int DELETE_ROWS_EVENT_V1 = 25; public static final int DELETE_ROWS_EVENT_V1 = 25;
/** /**
* Something out of the ordinary happened on the master * Something out of the ordinary happened on the master
*/ */
public static final int INCIDENT_EVENT = 26; public static final int INCIDENT_EVENT = 26;
/** /**
* Heartbeat event to be send by master at its idle time to ensure master's online status to slave * Heartbeat event to be send by master at its idle time to ensure master's
* online status to slave
*/ */
public static final int HEARTBEAT_LOG_EVENT = 27; public static final int HEARTBEAT_LOG_EVENT = 27;
/** /**
* In some situations, it is necessary to send over ignorable data to the slave: data that a slave can handle in * In some situations, it is necessary to send over ignorable data to the
* case there is code for handling it, but which can be ignored if it is not recognized. * slave: data that a slave can handle in case there is code for handling
* it, but which can be ignored if it is not recognized.
*/ */
public static final int IGNORABLE_LOG_EVENT = 28; public static final int IGNORABLE_LOG_EVENT = 28;
public static final int ROWS_QUERY_LOG_EVENT = 29; public static final int ROWS_QUERY_LOG_EVENT = 29;
/** Version 2 of the Row events */ /** Version 2 of the Row events */
public static final int WRITE_ROWS_EVENT = 30; public static final int WRITE_ROWS_EVENT = 30;
public static final int UPDATE_ROWS_EVENT = 31; public static final int UPDATE_ROWS_EVENT = 31;
public static final int DELETE_ROWS_EVENT = 32; public static final int DELETE_ROWS_EVENT = 32;
public static final int GTID_LOG_EVENT = 33; public static final int GTID_LOG_EVENT = 33;
public static final int ANONYMOUS_GTID_LOG_EVENT = 34; public static final int ANONYMOUS_GTID_LOG_EVENT = 34;
public static final int PREVIOUS_GTIDS_LOG_EVENT = 35;
public static final int PREVIOUS_GTIDS_LOG_EVENT = 35;
// mariaDb 5.5.34 // mariaDb 5.5.34
/* New MySQL/Sun events are to be added right above this comment */ /* New MySQL/Sun events are to be added right above this comment */
public static final int MYSQL_EVENTS_END = 36; public static final int MYSQL_EVENTS_END = 36;
public static final int MARIA_EVENTS_BEGIN = 160; public static final int MARIA_EVENTS_BEGIN = 160;
/* New Maria event numbers start from here */ /* New Maria event numbers start from here */
public static final int ANNOTATE_ROWS_EVENT = 160; public static final int ANNOTATE_ROWS_EVENT = 160;
/* /*
Binlog checkpoint event. Used for XA crash recovery on the master, not used * Binlog checkpoint event. Used for XA crash recovery on the master, not
in replication. * used in replication. A binlog checkpoint event specifies a binlog file
A binlog checkpoint event specifies a binlog file such that XA crash * such that XA crash recovery can start from that file - and it is
recovery can start from that file - and it is guaranteed to find all XIDs * guaranteed to find all XIDs that are prepared in storage engines but not
that are prepared in storage engines but not yet committed. * yet committed.
*/ */
public static final int BINLOG_CHECKPOINT_EVENT = 161; public static final int BINLOG_CHECKPOINT_EVENT = 161;
/* /*
Gtid event. For global transaction ID, used to start a new event group, * Gtid event. For global transaction ID, used to start a new event group,
instead of the old BEGIN query event, and also to mark stand-alone * instead of the old BEGIN query event, and also to mark stand-alone
events. * events.
*/ */
public static final int GTID_EVENT = 162; public static final int GTID_EVENT = 162;
/* /*
Gtid list event. Logged at the start of every binlog, to record the * Gtid list event. Logged at the start of every binlog, to record the
current replication state. This consists of the last GTID seen for * current replication state. This consists of the last GTID seen for each
each replication domain. * replication domain.
*/ */
public static final int GTID_LIST_EVENT = 163; public static final int GTID_LIST_EVENT = 163;
/** end marker */ /** end marker */
public static final int ENUM_END_EVENT = 164; public static final int ENUM_END_EVENT = 164;
/** /**
1 byte length, 1 byte format * 1 byte length, 1 byte format Length is total length in bytes, including 2
Length is total length in bytes, including 2 byte header * byte header Length values 0 and 1 are currently invalid and reserved.
Length values 0 and 1 are currently invalid and reserved. */
*/ public static final int EXTRA_ROW_INFO_LEN_OFFSET = 0;
public static final int EXTRA_ROW_INFO_LEN_OFFSET = 0; public static final int EXTRA_ROW_INFO_FORMAT_OFFSET = 1;
public static final int EXTRA_ROW_INFO_FORMAT_OFFSET = 1; public static final int EXTRA_ROW_INFO_HDR_BYTES = 2;
public static final int EXTRA_ROW_INFO_HDR_BYTES = 2; public static final int EXTRA_ROW_INFO_MAX_PAYLOAD = (255 - EXTRA_ROW_INFO_HDR_BYTES);
public static final int EXTRA_ROW_INFO_MAX_PAYLOAD = (255 - EXTRA_ROW_INFO_HDR_BYTES);
// Events are without checksum though its generator // Events are without checksum though its generator
public static final int BINLOG_CHECKSUM_ALG_OFF = 0; public static final int BINLOG_CHECKSUM_ALG_OFF = 0;
// is checksum-capable New Master (NM). // is checksum-capable New Master (NM).
// CRC32 of zlib algorithm. // CRC32 of zlib algorithm.
public static final int BINLOG_CHECKSUM_ALG_CRC32 = 1; public static final int BINLOG_CHECKSUM_ALG_CRC32 = 1;
// the cut line: valid alg range is [1, 0x7f]. // the cut line: valid alg range is [1, 0x7f].
public static final int BINLOG_CHECKSUM_ALG_ENUM_END = 2; public static final int BINLOG_CHECKSUM_ALG_ENUM_END = 2;
// special value to tag undetermined yet checksum // special value to tag undetermined yet checksum
public static final int BINLOG_CHECKSUM_ALG_UNDEF = 255; public static final int BINLOG_CHECKSUM_ALG_UNDEF = 255;
// or events from checksum-unaware servers // or events from checksum-unaware servers
public static final int CHECKSUM_CRC32_SIGNATURE_LEN = 4; public static final int CHECKSUM_CRC32_SIGNATURE_LEN = 4;
public static final int BINLOG_CHECKSUM_ALG_DESC_LEN = 1; public static final int BINLOG_CHECKSUM_ALG_DESC_LEN = 1;
/** /**
* defined statically while there is just one alg implemented * defined statically while there is just one alg implemented
*/ */
public static final int BINLOG_CHECKSUM_LEN = CHECKSUM_CRC32_SIGNATURE_LEN; public static final int BINLOG_CHECKSUM_LEN = CHECKSUM_CRC32_SIGNATURE_LEN;
/* MySQL or old MariaDB slave with no announced capability. */ /* MySQL or old MariaDB slave with no announced capability. */
public static final int MARIA_SLAVE_CAPABILITY_UNKNOWN = 0; public static final int MARIA_SLAVE_CAPABILITY_UNKNOWN = 0;
@@ -258,124 +237,121 @@ public abstract class LogEvent
/* Our capability. */ /* Our capability. */
public static final int MARIA_SLAVE_CAPABILITY_MINE = MARIA_SLAVE_CAPABILITY_GTID; public static final int MARIA_SLAVE_CAPABILITY_MINE = MARIA_SLAVE_CAPABILITY_GTID;
/**
For an event, 'e', carrying a type code, that a slave,
's', does not recognize, 's' will check 'e' for
LOG_EVENT_IGNORABLE_F, and if the flag is set, then 'e'
is ignored. Otherwise, 's' acknowledges that it has
found an unknown event in the relay log.
*/
public static final int LOG_EVENT_IGNORABLE_F = 0x80;
/** enum_field_types */
public static final int MYSQL_TYPE_DECIMAL = 0;
public static final int MYSQL_TYPE_TINY = 1;
public static final int MYSQL_TYPE_SHORT = 2;
public static final int MYSQL_TYPE_LONG = 3;
public static final int MYSQL_TYPE_FLOAT = 4;
public static final int MYSQL_TYPE_DOUBLE = 5;
public static final int MYSQL_TYPE_NULL = 6;
public static final int MYSQL_TYPE_TIMESTAMP = 7;
public static final int MYSQL_TYPE_LONGLONG = 8;
public static final int MYSQL_TYPE_INT24 = 9;
public static final int MYSQL_TYPE_DATE = 10;
public static final int MYSQL_TYPE_TIME = 11;
public static final int MYSQL_TYPE_DATETIME = 12;
public static final int MYSQL_TYPE_YEAR = 13;
public static final int MYSQL_TYPE_NEWDATE = 14;
public static final int MYSQL_TYPE_VARCHAR = 15;
public static final int MYSQL_TYPE_BIT = 16;
public static final int MYSQL_TYPE_TIMESTAMP2 = 17;
public static final int MYSQL_TYPE_DATETIME2 = 18;
public static final int MYSQL_TYPE_TIME2 = 19;
public static final int MYSQL_TYPE_NEWDECIMAL = 246;
public static final int MYSQL_TYPE_ENUM = 247;
public static final int MYSQL_TYPE_SET = 248;
public static final int MYSQL_TYPE_TINY_BLOB = 249;
public static final int MYSQL_TYPE_MEDIUM_BLOB = 250;
public static final int MYSQL_TYPE_LONG_BLOB = 251;
public static final int MYSQL_TYPE_BLOB = 252;
public static final int MYSQL_TYPE_VAR_STRING = 253;
public static final int MYSQL_TYPE_STRING = 254;
public static final int MYSQL_TYPE_GEOMETRY = 255;
public static String getTypeName(final int type) /**
{ * For an event, 'e', carrying a type code, that a slave, 's', does not
switch (type) * recognize, 's' will check 'e' for LOG_EVENT_IGNORABLE_F, and if the flag
{ * is set, then 'e' is ignored. Otherwise, 's' acknowledges that it has
case START_EVENT_V3: * found an unknown event in the relay log.
return "Start_v3"; */
case STOP_EVENT: public static final int LOG_EVENT_IGNORABLE_F = 0x80;
return "Stop";
case QUERY_EVENT: /** enum_field_types */
return "Query"; public static final int MYSQL_TYPE_DECIMAL = 0;
case ROTATE_EVENT: public static final int MYSQL_TYPE_TINY = 1;
return "Rotate"; public static final int MYSQL_TYPE_SHORT = 2;
case INTVAR_EVENT: public static final int MYSQL_TYPE_LONG = 3;
return "Intvar"; public static final int MYSQL_TYPE_FLOAT = 4;
case LOAD_EVENT: public static final int MYSQL_TYPE_DOUBLE = 5;
return "Load"; public static final int MYSQL_TYPE_NULL = 6;
case NEW_LOAD_EVENT: public static final int MYSQL_TYPE_TIMESTAMP = 7;
return "New_load"; public static final int MYSQL_TYPE_LONGLONG = 8;
case SLAVE_EVENT: public static final int MYSQL_TYPE_INT24 = 9;
return "Slave"; public static final int MYSQL_TYPE_DATE = 10;
case CREATE_FILE_EVENT: public static final int MYSQL_TYPE_TIME = 11;
return "Create_file"; public static final int MYSQL_TYPE_DATETIME = 12;
case APPEND_BLOCK_EVENT: public static final int MYSQL_TYPE_YEAR = 13;
return "Append_block"; public static final int MYSQL_TYPE_NEWDATE = 14;
case DELETE_FILE_EVENT: public static final int MYSQL_TYPE_VARCHAR = 15;
return "Delete_file"; public static final int MYSQL_TYPE_BIT = 16;
case EXEC_LOAD_EVENT: public static final int MYSQL_TYPE_TIMESTAMP2 = 17;
return "Exec_load"; public static final int MYSQL_TYPE_DATETIME2 = 18;
case RAND_EVENT: public static final int MYSQL_TYPE_TIME2 = 19;
return "RAND"; public static final int MYSQL_TYPE_NEWDECIMAL = 246;
case XID_EVENT: public static final int MYSQL_TYPE_ENUM = 247;
return "Xid"; public static final int MYSQL_TYPE_SET = 248;
case USER_VAR_EVENT: public static final int MYSQL_TYPE_TINY_BLOB = 249;
return "User var"; public static final int MYSQL_TYPE_MEDIUM_BLOB = 250;
case FORMAT_DESCRIPTION_EVENT: public static final int MYSQL_TYPE_LONG_BLOB = 251;
return "Format_desc"; public static final int MYSQL_TYPE_BLOB = 252;
case TABLE_MAP_EVENT: public static final int MYSQL_TYPE_VAR_STRING = 253;
return "Table_map"; public static final int MYSQL_TYPE_STRING = 254;
case PRE_GA_WRITE_ROWS_EVENT: public static final int MYSQL_TYPE_GEOMETRY = 255;
return "Write_rows_event_old";
case PRE_GA_UPDATE_ROWS_EVENT: public static String getTypeName(final int type) {
return "Update_rows_event_old"; switch (type) {
case PRE_GA_DELETE_ROWS_EVENT: case START_EVENT_V3:
return "Delete_rows_event_old"; return "Start_v3";
case WRITE_ROWS_EVENT_V1: case STOP_EVENT:
return "Write_rows_v1"; return "Stop";
case UPDATE_ROWS_EVENT_V1: case QUERY_EVENT:
return "Update_rows_v1"; return "Query";
case DELETE_ROWS_EVENT_V1: case ROTATE_EVENT:
return "Delete_rows_v1"; return "Rotate";
case BEGIN_LOAD_QUERY_EVENT: case INTVAR_EVENT:
return "Begin_load_query"; return "Intvar";
case EXECUTE_LOAD_QUERY_EVENT: case LOAD_EVENT:
return "Execute_load_query"; return "Load";
case INCIDENT_EVENT: case NEW_LOAD_EVENT:
return "Incident"; return "New_load";
case HEARTBEAT_LOG_EVENT: case SLAVE_EVENT:
return "Heartbeat"; return "Slave";
case IGNORABLE_LOG_EVENT: case CREATE_FILE_EVENT:
return "Ignorable"; return "Create_file";
case ROWS_QUERY_LOG_EVENT: case APPEND_BLOCK_EVENT:
return "Rows_query"; return "Append_block";
case WRITE_ROWS_EVENT: case DELETE_FILE_EVENT:
return "Write_rows"; return "Delete_file";
case UPDATE_ROWS_EVENT: case EXEC_LOAD_EVENT:
return "Update_rows"; return "Exec_load";
case DELETE_ROWS_EVENT: case RAND_EVENT:
return "Delete_rows"; return "RAND";
case GTID_LOG_EVENT: case XID_EVENT:
return "Gtid"; return "Xid";
case ANONYMOUS_GTID_LOG_EVENT: case USER_VAR_EVENT:
return "Anonymous_Gtid"; return "User var";
case PREVIOUS_GTIDS_LOG_EVENT: case FORMAT_DESCRIPTION_EVENT:
return "Previous_gtids"; return "Format_desc";
default: case TABLE_MAP_EVENT:
return "Unknown"; /* impossible */ return "Table_map";
case PRE_GA_WRITE_ROWS_EVENT:
return "Write_rows_event_old";
case PRE_GA_UPDATE_ROWS_EVENT:
return "Update_rows_event_old";
case PRE_GA_DELETE_ROWS_EVENT:
return "Delete_rows_event_old";
case WRITE_ROWS_EVENT_V1:
return "Write_rows_v1";
case UPDATE_ROWS_EVENT_V1:
return "Update_rows_v1";
case DELETE_ROWS_EVENT_V1:
return "Delete_rows_v1";
case BEGIN_LOAD_QUERY_EVENT:
return "Begin_load_query";
case EXECUTE_LOAD_QUERY_EVENT:
return "Execute_load_query";
case INCIDENT_EVENT:
return "Incident";
case HEARTBEAT_LOG_EVENT:
return "Heartbeat";
case IGNORABLE_LOG_EVENT:
return "Ignorable";
case ROWS_QUERY_LOG_EVENT:
return "Rows_query";
case WRITE_ROWS_EVENT:
return "Write_rows";
case UPDATE_ROWS_EVENT:
return "Update_rows";
case DELETE_ROWS_EVENT:
return "Delete_rows";
case GTID_LOG_EVENT:
return "Gtid";
case ANONYMOUS_GTID_LOG_EVENT:
return "Anonymous_Gtid";
case PREVIOUS_GTIDS_LOG_EVENT:
return "Previous_gtids";
default:
return "Unknown"; /* impossible */
} }
} }
@@ -383,16 +359,14 @@ public abstract class LogEvent
protected final LogHeader header; protected final LogHeader header;
protected LogEvent(LogHeader header) protected LogEvent(LogHeader header){
{
this.header = header; this.header = header;
} }
/** /**
* Return event header. * Return event header.
*/ */
public final LogHeader getHeader() public final LogHeader getHeader() {
{
return header; return header;
} }
@@ -400,16 +374,14 @@ public abstract class LogEvent
* The total size of this event, in bytes. In other words, this is the sum * The total size of this event, in bytes. In other words, this is the sum
* of the sizes of Common-Header, Post-Header, and Body. * of the sizes of Common-Header, Post-Header, and Body.
*/ */
public final int getEventLen() public final int getEventLen() {
{
return header.getEventLen(); return header.getEventLen();
} }
/** /**
* Server ID of the server that created the event. * Server ID of the server that created the event.
*/ */
public final long getServerId() public final long getServerId() {
{
return header.getServerId(); return header.getServerId();
} }
@@ -420,18 +392,15 @@ public abstract class LogEvent
* file. In a relay log, this is the position of the next event in the * file. In a relay log, this is the position of the next event in the
* master's binlog. * master's binlog.
*/ */
public final long getLogPos() public final long getLogPos() {
{
return header.getLogPos(); return header.getLogPos();
} }
/** /**
* The time when the query started, in seconds since 1970. * The time when the query started, in seconds since 1970.
*/ */
public final long getWhen() public final long getWhen() {
{
return header.getWhen(); return header.getWhen();
} }
} }

View File

@@ -29,8 +29,8 @@ import java.util.Arrays;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public abstract class LogFetcher extends LogBuffer implements Closeable public abstract class LogFetcher extends LogBuffer implements Closeable {
{
/** Default initial capacity. */ /** Default initial capacity. */
public static final int DEFAULT_INITIAL_CAPACITY = 8192; public static final int DEFAULT_INITIAL_CAPACITY = 8192;
@@ -42,18 +42,15 @@ public abstract class LogFetcher extends LogBuffer implements Closeable
protected final float factor; protected final float factor;
public LogFetcher() public LogFetcher(){
{
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_GROWTH_FACTOR); this(DEFAULT_INITIAL_CAPACITY, DEFAULT_GROWTH_FACTOR);
} }
public LogFetcher(final int initialCapacity) public LogFetcher(final int initialCapacity){
{
this(initialCapacity, DEFAULT_GROWTH_FACTOR); this(initialCapacity, DEFAULT_GROWTH_FACTOR);
} }
public LogFetcher(final int initialCapacity, final float growthFactor) public LogFetcher(final int initialCapacity, final float growthFactor){
{
this.buffer = new byte[initialCapacity]; this.buffer = new byte[initialCapacity];
this.factor = growthFactor; this.factor = growthFactor;
} }
@@ -65,15 +62,12 @@ public abstract class LogFetcher extends LogBuffer implements Closeable
* *
* @param minCapacity the desired minimum capacity * @param minCapacity the desired minimum capacity
*/ */
protected final void ensureCapacity(final int minCapacity) protected final void ensureCapacity(final int minCapacity) {
{
final int oldCapacity = buffer.length; final int oldCapacity = buffer.length;
if (minCapacity > oldCapacity) if (minCapacity > oldCapacity) {
{
int newCapacity = (int) (oldCapacity * factor); int newCapacity = (int) (oldCapacity * factor);
if (newCapacity < minCapacity) if (newCapacity < minCapacity) newCapacity = minCapacity;
newCapacity = minCapacity;
buffer = Arrays.copyOf(buffer, newCapacity); buffer = Arrays.copyOf(buffer, newCapacity);
} }

View File

@@ -6,8 +6,8 @@ package com.taobao.tddl.dbsync.binlog;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public class LogPosition implements Cloneable, Comparable<LogPosition> public class LogPosition implements Cloneable, Comparable<LogPosition> {
{
/* binlog file's name */ /* binlog file's name */
protected String fileName; protected String fileName;
@@ -19,8 +19,7 @@ public class LogPosition implements Cloneable, Comparable<LogPosition>
* *
* @param fileName file name for binlog files: mysql-bin.000001 * @param fileName file name for binlog files: mysql-bin.000001
*/ */
public LogPosition(String fileName) public LogPosition(String fileName){
{
this.fileName = fileName; this.fileName = fileName;
this.position = 0L; this.position = 0L;
} }
@@ -30,8 +29,7 @@ public class LogPosition implements Cloneable, Comparable<LogPosition>
* *
* @param fileName file name for binlog files: mysql-bin.000001 * @param fileName file name for binlog files: mysql-bin.000001
*/ */
public LogPosition(String fileName, final long position) public LogPosition(String fileName, final long position){
{
this.fileName = fileName; this.fileName = fileName;
this.position = position; this.position = position;
} }
@@ -39,31 +37,24 @@ public class LogPosition implements Cloneable, Comparable<LogPosition>
/** /**
* Binlog position copy init. * Binlog position copy init.
*/ */
public LogPosition(LogPosition source) public LogPosition(LogPosition source){
{
this.fileName = source.fileName; this.fileName = source.fileName;
this.position = source.position; this.position = source.position;
} }
public final String getFileName() public final String getFileName() {
{
return fileName; return fileName;
} }
public final long getPosition() public final long getPosition() {
{
return position; return position;
} }
/* Clone binlog position without CloneNotSupportedException */ /* Clone binlog position without CloneNotSupportedException */
public LogPosition clone() public LogPosition clone() {
{ try {
try
{
return (LogPosition) super.clone(); return (LogPosition) super.clone();
} } catch (CloneNotSupportedException e) {
catch (CloneNotSupportedException e)
{
// Never happend // Never happend
return null; return null;
} }
@@ -72,12 +63,10 @@ public class LogPosition implements Cloneable, Comparable<LogPosition>
/** /**
* Compares with the specified fileName and position. * Compares with the specified fileName and position.
*/ */
public final int compareTo(String fileName, final long position) public final int compareTo(String fileName, final long position) {
{
final int val = this.fileName.compareTo(fileName); final int val = this.fileName.compareTo(fileName);
if (val == 0) if (val == 0) {
{
return (int) (this.position - position); return (int) (this.position - position);
} }
return val; return val;
@@ -88,12 +77,10 @@ public class LogPosition implements Cloneable, Comparable<LogPosition>
* *
* @see java.lang.Comparable#compareTo(java.lang.Object) * @see java.lang.Comparable#compareTo(java.lang.Object)
*/ */
public int compareTo(LogPosition o) public int compareTo(LogPosition o) {
{
final int val = fileName.compareTo(o.fileName); final int val = fileName.compareTo(o.fileName);
if (val == 0) if (val == 0) {
{
return (int) (position - o.position); return (int) (position - o.position);
} }
return val; return val;
@@ -104,13 +91,10 @@ public class LogPosition implements Cloneable, Comparable<LogPosition>
* *
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if (obj instanceof LogPosition) {
if (obj instanceof LogPosition)
{
LogPosition pos = ((LogPosition) obj); LogPosition pos = ((LogPosition) obj);
return fileName.equals(pos.fileName) return fileName.equals(pos.fileName) && (this.position == pos.position);
&& (this.position == pos.position);
} }
return false; return false;
} }
@@ -120,8 +104,7 @@ public class LogPosition implements Cloneable, Comparable<LogPosition>
* *
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
public String toString() public String toString() {
{
return fileName + ':' + position; return fileName + ':' + position;
} }
} }

View File

@@ -9,8 +9,8 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public class AppendBlockLogEvent extends LogEvent public class AppendBlockLogEvent extends LogEvent {
{
private final LogBuffer blockBuf; private final LogBuffer blockBuf;
private final int blockLen; private final int blockLen;
@@ -19,9 +19,7 @@ public class AppendBlockLogEvent extends LogEvent
/* AB = "Append Block" */ /* AB = "Append Block" */
public static final int AB_FILE_ID_OFFSET = 0; public static final int AB_FILE_ID_OFFSET = 0;
public AppendBlockLogEvent(LogHeader header, LogBuffer buffer, public AppendBlockLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int commonHeaderLen = descriptionEvent.commonHeaderLen;
@@ -36,18 +34,15 @@ public class AppendBlockLogEvent extends LogEvent
blockBuf = buffer.duplicate(blockLen); blockBuf = buffer.duplicate(blockLen);
} }
public final long getFileId() public final long getFileId() {
{
return fileId; return fileId;
} }
public final LogBuffer getBuffer() public final LogBuffer getBuffer() {
{
return blockBuf; return blockBuf;
} }
public final byte[] getData() public final byte[] getData() {
{
return blockBuf.getData(); return blockBuf.getData();
} }
} }

View File

@@ -10,11 +10,9 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class BeginLoadQueryLogEvent extends AppendBlockLogEvent public final class BeginLoadQueryLogEvent extends AppendBlockLogEvent {
{
public BeginLoadQueryLogEvent(LogHeader header, LogBuffer buffer, public BeginLoadQueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header, buffer, descriptionEvent); super(header, buffer, descriptionEvent);
} }
} }

View File

@@ -8,8 +8,8 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class CreateFileLogEvent extends LoadLogEvent public final class CreateFileLogEvent extends LoadLogEvent {
{
protected LogBuffer blockBuf; protected LogBuffer blockBuf;
protected int blockLen; protected int blockLen;
protected long fileId; protected long fileId;
@@ -20,9 +20,7 @@ public final class CreateFileLogEvent extends LoadLogEvent
public static final int CF_FILE_ID_OFFSET = 0; public static final int CF_FILE_ID_OFFSET = 0;
public static final int CF_DATA_OFFSET = FormatDescriptionLogEvent.CREATE_FILE_HEADER_LEN; public static final int CF_DATA_OFFSET = FormatDescriptionLogEvent.CREATE_FILE_HEADER_LEN;
public CreateFileLogEvent(LogHeader header, LogBuffer buffer, public CreateFileLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header, buffer, descriptionEvent); super(header, buffer, descriptionEvent);
final int headerLen = descriptionEvent.commonHeaderLen; final int headerLen = descriptionEvent.commonHeaderLen;
@@ -30,44 +28,37 @@ public final class CreateFileLogEvent extends LoadLogEvent
final int createFileHeaderLen = descriptionEvent.postHeaderLen[CREATE_FILE_EVENT - 1]; final int createFileHeaderLen = descriptionEvent.postHeaderLen[CREATE_FILE_EVENT - 1];
copyLogEvent(buffer, copyLogEvent(buffer,
((header.type == LOAD_EVENT) ? (loadHeaderLen + headerLen) ((header.type == LOAD_EVENT) ? (loadHeaderLen + headerLen) : (headerLen + loadHeaderLen + createFileHeaderLen)),
: (headerLen + loadHeaderLen + createFileHeaderLen)), descriptionEvent);
descriptionEvent);
if (descriptionEvent.binlogVersion != 1) if (descriptionEvent.binlogVersion != 1) {
{ fileId = buffer.getUint32(headerLen + loadHeaderLen + CF_FILE_ID_OFFSET);
fileId = buffer.getUint32(headerLen + loadHeaderLen
+ CF_FILE_ID_OFFSET);
/* /*
Note that it's ok to use get_data_size() below, because it is computed * Note that it's ok to use get_data_size() below, because it is
with values we have already read from this event (because we called * computed with values we have already read from this event
copy_log_event()); we are not using slave's format info to decode * (because we called copy_log_event()); we are not using slave's
master's format, we are really using master's format info. * format info to decode master's format, we are really using
Anyway, both formats should be identical (except the common_header_len) * master's format info. Anyway, both formats should be identical
as these Load events are not changed between 4.0 and 5.0 (as logging of * (except the common_header_len) as these Load events are not
LOAD DATA INFILE does not use Load_log_event in 5.0). * changed between 4.0 and 5.0 (as logging of LOAD DATA INFILE does
*/ * not use Load_log_event in 5.0).
*/
blockLen = buffer.limit() - buffer.position(); blockLen = buffer.limit() - buffer.position();
blockBuf = buffer.duplicate(blockLen); blockBuf = buffer.duplicate(blockLen);
} } else {
else
{
initedFromOld = true; initedFromOld = true;
} }
} }
public final long getFileId() public final long getFileId() {
{
return fileId; return fileId;
} }
public final LogBuffer getBuffer() public final LogBuffer getBuffer() {
{
return blockBuf; return blockBuf;
} }
public final byte[] getData() public final byte[] getData() {
{
return blockBuf.getData(); return blockBuf.getData();
} }
} }

View File

@@ -9,25 +9,22 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class DeleteFileLogEvent extends LogEvent public final class DeleteFileLogEvent extends LogEvent {
{
private final long fileId; private final long fileId;
/* DF = "Delete File" */ /* DF = "Delete File" */
public static final int DF_FILE_ID_OFFSET = 0; public static final int DF_FILE_ID_OFFSET = 0;
public DeleteFileLogEvent(LogHeader header, LogBuffer buffer, public DeleteFileLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int commonHeaderLen = descriptionEvent.commonHeaderLen;
buffer.position(commonHeaderLen + DF_FILE_ID_OFFSET); buffer.position(commonHeaderLen + DF_FILE_ID_OFFSET);
fileId = buffer.getUint32(); // DF_FILE_ID_OFFSET fileId = buffer.getUint32(); // DF_FILE_ID_OFFSET
} }
public final long getFileId() public final long getFileId() {
{
return fileId; return fileId;
} }
} }

View File

@@ -9,11 +9,9 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class DeleteRowsLogEvent extends RowsLogEvent public final class DeleteRowsLogEvent extends RowsLogEvent {
{
public DeleteRowsLogEvent(LogHeader header, LogBuffer buffer, public DeleteRowsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header, buffer, descriptionEvent); super(header, buffer, descriptionEvent);
} }
} }

View File

@@ -9,25 +9,22 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class ExecuteLoadLogEvent extends LogEvent public final class ExecuteLoadLogEvent extends LogEvent {
{
private final long fileId; private final long fileId;
/* EL = "Execute Load" */ /* EL = "Execute Load" */
public static final int EL_FILE_ID_OFFSET = 0; public static final int EL_FILE_ID_OFFSET = 0;
public ExecuteLoadLogEvent(LogHeader header, LogBuffer buffer, public ExecuteLoadLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int commonHeaderLen = descriptionEvent.commonHeaderLen;
buffer.position(commonHeaderLen + EL_FILE_ID_OFFSET); buffer.position(commonHeaderLen + EL_FILE_ID_OFFSET);
fileId = buffer.getUint32(); // EL_FILE_ID_OFFSET fileId = buffer.getUint32(); // EL_FILE_ID_OFFSET
} }
public final long getFileId() public final long getFileId() {
{
return fileId; return fileId;
} }
} }

View File

@@ -8,7 +8,6 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* Event responsible for LOAD DATA execution, it similar to Query_log_event but * Event responsible for LOAD DATA execution, it similar to Query_log_event but
* before executing the query it substitutes original filename in LOAD DATA * before executing the query it substitutes original filename in LOAD DATA
* query with name of temporary file. * query with name of temporary file.
*
* <ul> * <ul>
* <li>4 bytes. The ID of the file to load.</li> * <li>4 bytes. The ID of the file to load.</li>
* <li>4 bytes. The start position within the statement for filename * <li>4 bytes. The start position within the statement for filename
@@ -22,8 +21,8 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class ExecuteLoadQueryLogEvent extends QueryLogEvent public final class ExecuteLoadQueryLogEvent extends QueryLogEvent {
{
/** file_id of temporary file */ /** file_id of temporary file */
private long fileId; private long fileId;
@@ -53,9 +52,8 @@ public final class ExecuteLoadQueryLogEvent extends QueryLogEvent
public static final int ELQ_FN_POS_END_OFFSET = ELQ_FILE_ID_OFFSET + 8; public static final int ELQ_FN_POS_END_OFFSET = ELQ_FILE_ID_OFFSET + 8;
public static final int ELQ_DUP_HANDLING_OFFSET = ELQ_FILE_ID_OFFSET + 12; public static final int ELQ_DUP_HANDLING_OFFSET = ELQ_FILE_ID_OFFSET + 12;
public ExecuteLoadQueryLogEvent(LogHeader header, LogBuffer buffer, public ExecuteLoadQueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
FormatDescriptionLogEvent descriptionEvent) throws IOException throws IOException{
{
super(header, buffer, descriptionEvent); super(header, buffer, descriptionEvent);
buffer.position(descriptionEvent.commonHeaderLen + ELQ_FILE_ID_OFFSET); buffer.position(descriptionEvent.commonHeaderLen + ELQ_FILE_ID_OFFSET);
@@ -66,36 +64,27 @@ public final class ExecuteLoadQueryLogEvent extends QueryLogEvent
dupHandling = buffer.getInt8(); // ELQ_DUP_HANDLING_OFFSET dupHandling = buffer.getInt8(); // ELQ_DUP_HANDLING_OFFSET
final int len = query.length(); final int len = query.length();
if (fnPosStart > len || fnPosEnd > len if (fnPosStart > len || fnPosEnd > len || dupHandling > LOAD_DUP_REPLACE) {
|| dupHandling > LOAD_DUP_REPLACE) throw new IOException(String.format("Invalid ExecuteLoadQueryLogEvent: fn_pos_start=%d, "
{ + "fn_pos_end=%d, dup_handling=%d", fnPosStart, fnPosEnd, dupHandling));
throw new IOException(String.format(
"Invalid ExecuteLoadQueryLogEvent: fn_pos_start=%d, "
+ "fn_pos_end=%d, dup_handling=%d", fnPosStart,
fnPosEnd, dupHandling));
} }
} }
public final int getFilenamePosStart() public final int getFilenamePosStart() {
{
return fnPosStart; return fnPosStart;
} }
public final int getFilenamePosEnd() public final int getFilenamePosEnd() {
{
return fnPosEnd; return fnPosEnd;
} }
public final String getFilename() public final String getFilename() {
{ if (query != null) return query.substring(fnPosStart, fnPosEnd).trim();
if (query != null)
return query.substring(fnPosStart, fnPosEnd).trim();
return null; return null;
} }
public final long getFileId() public final long getFileId() {
{
return fileId; return fileId;
} }
} }

View File

@@ -5,8 +5,8 @@ import java.io.IOException;
import com.taobao.tddl.dbsync.binlog.LogBuffer; import com.taobao.tddl.dbsync.binlog.LogBuffer;
/** /**
* For binlog version 4. This event is saved by threads which read it, as they need it for future use (to decode the * For binlog version 4. This event is saved by threads which read it, as they
* ordinary events). * need it for future use (to decode the ordinary events).
* *
* @see mysql-5.1.60/sql/log_event.cc - Format_description_log_event * @see mysql-5.1.60/sql/log_event.cc - Format_description_log_event
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
@@ -15,23 +15,24 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
public final class FormatDescriptionLogEvent extends StartLogEventV3 { public final class FormatDescriptionLogEvent extends StartLogEventV3 {
/** /**
* The number of types we handle in Format_description_log_event (UNKNOWN_EVENT is not to be handled, it does not * The number of types we handle in Format_description_log_event
* exist in binlogs, it does not have a format). * (UNKNOWN_EVENT is not to be handled, it does not exist in binlogs, it
* does not have a format).
*/ */
public static final int LOG_EVENT_TYPES = (ENUM_END_EVENT - 1); public static final int LOG_EVENT_TYPES = (ENUM_END_EVENT - 1);
public static final int ST_COMMON_HEADER_LEN_OFFSET = (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN + 4); public static final int ST_COMMON_HEADER_LEN_OFFSET = (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN + 4);
public static final int OLD_HEADER_LEN = 13; public static final int OLD_HEADER_LEN = 13;
public static final int LOG_EVENT_HEADER_LEN = 19; public static final int LOG_EVENT_HEADER_LEN = 19;
public static final int LOG_EVENT_MINIMAL_HEADER_LEN = 19; public static final int LOG_EVENT_MINIMAL_HEADER_LEN = 19;
/* event-specific post-header sizes */ /* event-specific post-header sizes */
public static final int STOP_HEADER_LEN = 0; public static final int STOP_HEADER_LEN = 0;
public static final int LOAD_HEADER_LEN = (4 + 4 + 4 + 1 + 1 + 4); public static final int LOAD_HEADER_LEN = (4 + 4 + 4 + 1 + 1 + 4);
public static final int SLAVE_HEADER_LEN = 0; public static final int SLAVE_HEADER_LEN = 0;
public static final int START_V3_HEADER_LEN = (2 + ST_SERVER_VER_LEN + 4); public static final int START_V3_HEADER_LEN = (2 + ST_SERVER_VER_LEN + 4);
public static final int ROTATE_HEADER_LEN = 8; // this public static final int ROTATE_HEADER_LEN = 8; // this
// is // is
// FROZEN // FROZEN
// (the // (the
@@ -39,47 +40,48 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
// post-header // post-header
// is // is
// frozen) // frozen)
public static final int INTVAR_HEADER_LEN = 0; public static final int INTVAR_HEADER_LEN = 0;
public static final int CREATE_FILE_HEADER_LEN = 4; public static final int CREATE_FILE_HEADER_LEN = 4;
public static final int APPEND_BLOCK_HEADER_LEN = 4; public static final int APPEND_BLOCK_HEADER_LEN = 4;
public static final int EXEC_LOAD_HEADER_LEN = 4; public static final int EXEC_LOAD_HEADER_LEN = 4;
public static final int DELETE_FILE_HEADER_LEN = 4; public static final int DELETE_FILE_HEADER_LEN = 4;
public static final int NEW_LOAD_HEADER_LEN = LOAD_HEADER_LEN; public static final int NEW_LOAD_HEADER_LEN = LOAD_HEADER_LEN;
public static final int RAND_HEADER_LEN = 0; public static final int RAND_HEADER_LEN = 0;
public static final int USER_VAR_HEADER_LEN = 0; public static final int USER_VAR_HEADER_LEN = 0;
public static final int FORMAT_DESCRIPTION_HEADER_LEN = (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES); public static final int FORMAT_DESCRIPTION_HEADER_LEN = (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES);
public static final int XID_HEADER_LEN = 0; public static final int XID_HEADER_LEN = 0;
public static final int BEGIN_LOAD_QUERY_HEADER_LEN = APPEND_BLOCK_HEADER_LEN; public static final int BEGIN_LOAD_QUERY_HEADER_LEN = APPEND_BLOCK_HEADER_LEN;
public static final int ROWS_HEADER_LEN_V1 = 8; public static final int ROWS_HEADER_LEN_V1 = 8;
public static final int TABLE_MAP_HEADER_LEN = 8; public static final int TABLE_MAP_HEADER_LEN = 8;
public static final int EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN = (4 + 4 + 4 + 1); public static final int EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN = (4 + 4 + 4 + 1);
public static final int EXECUTE_LOAD_QUERY_HEADER_LEN = (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN); public static final int EXECUTE_LOAD_QUERY_HEADER_LEN = (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
public static final int INCIDENT_HEADER_LEN = 2; public static final int INCIDENT_HEADER_LEN = 2;
public static final int HEARTBEAT_HEADER_LEN = 0; public static final int HEARTBEAT_HEADER_LEN = 0;
public static final int IGNORABLE_HEADER_LEN = 0; public static final int IGNORABLE_HEADER_LEN = 0;
public static final int ROWS_HEADER_LEN_V2 = 10; public static final int ROWS_HEADER_LEN_V2 = 10;
public static final int ANNOTATE_ROWS_HEADER_LEN = 0; public static final int ANNOTATE_ROWS_HEADER_LEN = 0;
public static final int BINLOG_CHECKPOINT_HEADER_LEN = 4; public static final int BINLOG_CHECKPOINT_HEADER_LEN = 4;
public static final int GTID_HEADER_LEN = 19; public static final int GTID_HEADER_LEN = 19;
public static final int GTID_LIST_HEADER_LEN = 4; public static final int GTID_LIST_HEADER_LEN = 4;
public static final int POST_HEADER_LENGTH = 11; public static final int POST_HEADER_LENGTH = 11;
public static final int BINLOG_CHECKSUM_ALG_DESC_LEN = 1; public static final int BINLOG_CHECKSUM_ALG_DESC_LEN = 1;
public static final int[] checksumVersionSplit = { 5, 6, 1 }; public static final int[] checksumVersionSplit = { 5, 6, 1 };
public static final long checksumVersionProduct = (checksumVersionSplit[0] * 256 + checksumVersionSplit[1]) public static final long checksumVersionProduct = (checksumVersionSplit[0] * 256 + checksumVersionSplit[1])
* 256 + checksumVersionSplit[2]; * 256 + checksumVersionSplit[2];
/** /**
* The size of the fixed header which _all_ events have (for binlogs written by this version, this is equal to * The size of the fixed header which _all_ events have (for binlogs written
* LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT (those have a header of size * by this version, this is equal to LOG_EVENT_HEADER_LEN), except
* FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT (those have a header of size
* LOG_EVENT_MINIMAL_HEADER_LEN). * LOG_EVENT_MINIMAL_HEADER_LEN).
*/ */
protected final int commonHeaderLen; protected final int commonHeaderLen;
protected int numberOfEventTypes; protected int numberOfEventTypes;
/** The list of post-headers' lengthes */ /** The list of post-headers' lengthes */
protected final short[] postHeaderLen; protected final short[] postHeaderLen;
protected int[] serverVersionSplit = new int[3]; protected int[] serverVersionSplit = new int[3];
public FormatDescriptionLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent) public FormatDescriptionLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
throws IOException{ throws IOException{
@@ -105,12 +107,15 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
calcServerVersionSplit(); calcServerVersionSplit();
long calc = getVersionProduct(); long calc = getVersionProduct();
if (calc >= checksumVersionProduct) { if (calc >= checksumVersionProduct) {
/* the last bytes are the checksum alg desc and value (or value's room) */ /*
* the last bytes are the checksum alg desc and value (or value's
* room)
*/
numberOfEventTypes -= BINLOG_CHECKSUM_ALG_DESC_LEN; numberOfEventTypes -= BINLOG_CHECKSUM_ALG_DESC_LEN;
} }
if (logger.isInfoEnabled()) logger.info("common_header_len= " + commonHeaderLen + ", number_of_event_types= " if (logger.isInfoEnabled()) logger.info("common_header_len= " + commonHeaderLen + ", number_of_event_types= "
+ numberOfEventTypes); + numberOfEventTypes);
} }
/** MySQL 5.0 format descriptions. */ /** MySQL 5.0 format descriptions. */
@@ -147,7 +152,10 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
commonHeaderLen = LOG_EVENT_HEADER_LEN; commonHeaderLen = LOG_EVENT_HEADER_LEN;
numberOfEventTypes = LOG_EVENT_TYPES; numberOfEventTypes = LOG_EVENT_TYPES;
/* Note: all event types must explicitly fill in their lengths here. */ /*
* Note: all event types must explicitly fill in their lengths
* here.
*/
postHeaderLen[START_EVENT_V3 - 1] = START_V3_HEADER_LEN; postHeaderLen[START_EVENT_V3 - 1] = START_V3_HEADER_LEN;
postHeaderLen[QUERY_EVENT - 1] = QUERY_HEADER_LEN; postHeaderLen[QUERY_EVENT - 1] = QUERY_HEADER_LEN;
postHeaderLen[STOP_EVENT - 1] = STOP_HEADER_LEN; postHeaderLen[STOP_EVENT - 1] = STOP_HEADER_LEN;
@@ -171,11 +179,14 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
postHeaderLen[UPDATE_ROWS_EVENT_V1 - 1] = ROWS_HEADER_LEN_V1; postHeaderLen[UPDATE_ROWS_EVENT_V1 - 1] = ROWS_HEADER_LEN_V1;
postHeaderLen[DELETE_ROWS_EVENT_V1 - 1] = ROWS_HEADER_LEN_V1; postHeaderLen[DELETE_ROWS_EVENT_V1 - 1] = ROWS_HEADER_LEN_V1;
/* /*
* We here have the possibility to simulate a master of before we changed the table map id to be stored * We here have the possibility to simulate a master of before
* in 6 bytes: when it was stored in 4 bytes (=> post_header_len was 6). This is used to test backward * we changed the table map id to be stored in 6 bytes: when it
* compatibility. This code can be removed after a few months (today is Dec 21st 2005), when we know * was stored in 4 bytes (=> post_header_len was 6). This is
* that the 4-byte masters are not deployed anymore (check with Tomas Ulin first!), and the accompanying * used to test backward compatibility. This code can be removed
* test (rpl_row_4_bytes) too. * after a few months (today is Dec 21st 2005), when we know
* that the 4-byte masters are not deployed anymore (check with
* Tomas Ulin first!), and the accompanying test
* (rpl_row_4_bytes) too.
*/ */
postHeaderLen[HEARTBEAT_LOG_EVENT - 1] = 0; postHeaderLen[HEARTBEAT_LOG_EVENT - 1] = 0;
postHeaderLen[IGNORABLE_LOG_EVENT - 1] = IGNORABLE_HEADER_LEN; postHeaderLen[IGNORABLE_LOG_EVENT - 1] = IGNORABLE_HEADER_LEN;
@@ -195,17 +206,19 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
case 3: /* 4.0.x x>=2 */ case 3: /* 4.0.x x>=2 */
/* /*
* We build an artificial (i.e. not sent by the master) event, which describes what those old master * We build an artificial (i.e. not sent by the master) event,
* versions send. * which describes what those old master versions send.
*/ */
serverVersion = "4.0"; serverVersion = "4.0";
commonHeaderLen = LOG_EVENT_MINIMAL_HEADER_LEN; commonHeaderLen = LOG_EVENT_MINIMAL_HEADER_LEN;
/* /*
* The first new event in binlog version 4 is Format_desc. So any event type after that does not exist * The first new event in binlog version 4 is Format_desc. So
* in older versions. We use the events known by version 3, even if version 1 had only a subset of them * any event type after that does not exist in older versions.
* (this is not a problem: it uses a few bytes for nothing but unifies code; it does not make the slave * We use the events known by version 3, even if version 1 had
* detect less corruptions). * only a subset of them (this is not a problem: it uses a few
* bytes for nothing but unifies code; it does not make the
* slave detect less corruptions).
*/ */
numberOfEventTypes = FORMAT_DESCRIPTION_EVENT - 1; numberOfEventTypes = FORMAT_DESCRIPTION_EVENT - 1;
@@ -222,17 +235,19 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
case 1: /* 3.23 */ case 1: /* 3.23 */
/* /*
* We build an artificial (i.e. not sent by the master) event, which describes what those old master * We build an artificial (i.e. not sent by the master) event,
* versions send. * which describes what those old master versions send.
*/ */
serverVersion = "3.23"; serverVersion = "3.23";
commonHeaderLen = OLD_HEADER_LEN; commonHeaderLen = OLD_HEADER_LEN;
/* /*
* The first new event in binlog version 4 is Format_desc. So any event type after that does not exist * The first new event in binlog version 4 is Format_desc. So
* in older versions. We use the events known by version 3, even if version 1 had only a subset of them * any event type after that does not exist in older versions.
* (this is not a problem: it uses a few bytes for nothing but unifies code; it does not make the slave * We use the events known by version 3, even if version 1 had
* detect less corruptions). * only a subset of them (this is not a problem: it uses a few
* bytes for nothing but unifies code; it does not make the
* slave detect less corruptions).
*/ */
numberOfEventTypes = FORMAT_DESCRIPTION_EVENT - 1; numberOfEventTypes = FORMAT_DESCRIPTION_EVENT - 1;
@@ -251,7 +266,7 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
commonHeaderLen = 0; commonHeaderLen = 0;
} }
} }
public void calcServerVersionSplit() { public void calcServerVersionSplit() {
doServerVersionSplit(serverVersion, serverVersionSplit); doServerVersionSplit(serverVersion, serverVersionSplit);
} }

View File

@@ -6,19 +6,19 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* <pre> * <pre>
* Base class for ignorable log events. Events deriving from * Base class for ignorable log events. Events deriving from
this class can be safely ignored by slaves that cannot * this class can be safely ignored by slaves that cannot
recognize them. Newer slaves, will be able to read and * recognize them. Newer slaves, will be able to read and
handle them. This has been designed to be an open-ended * handle them. This has been designed to be an open-ended
architecture, so adding new derived events shall not harm * architecture, so adding new derived events shall not harm
the old slaves that support ignorable log event mechanism * the old slaves that support ignorable log event mechanism
(they will just ignore unrecognized ignorable events). * (they will just ignore unrecognized ignorable events).
*
@note The only thing that makes an event ignorable is that it has * @note The only thing that makes an event ignorable is that it has
the LOG_EVENT_IGNORABLE_F flag set. It is not strictly necessary * the LOG_EVENT_IGNORABLE_F flag set. It is not strictly necessary
that ignorable event types derive from Ignorable_log_event; they may * that ignorable event types derive from Ignorable_log_event; they may
just as well derive from Log_event and pass LOG_EVENT_IGNORABLE_F as * just as well derive from Log_event and pass LOG_EVENT_IGNORABLE_F as
argument to the Log_event constructor. * argument to the Log_event constructor.
</pre> * </pre>
* *
* @author jianghang 2013-4-8 上午12:36:29 * @author jianghang 2013-4-8 上午12:36:29
* @version 1.0.3 * @version 1.0.3

View File

@@ -5,12 +5,9 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* Class representing an incident, an occurance out of the ordinary, that * Class representing an incident, an occurance out of the ordinary, that
* happened on the master. * happened on the master. The event is used to inform the slave that something
* * out of the ordinary happened on the master that might cause the database to
* The event is used to inform the slave that something out of the ordinary * be in an inconsistent state.
* happened on the master that might cause the database to be in an inconsistent
* state.
*
* <table id="IncidentFormat"> * <table id="IncidentFormat">
* <caption>Incident event format</caption> * <caption>Incident event format</caption>
* <tr> * <tr>
@@ -38,8 +35,8 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class IncidentLogEvent extends LogEvent public final class IncidentLogEvent extends LogEvent {
{
public static final int INCIDENT_NONE = 0; public static final int INCIDENT_NONE = 0;
/** There are possibly lost events in the replication stream */ /** There are possibly lost events in the replication stream */
@@ -51,9 +48,7 @@ public final class IncidentLogEvent extends LogEvent
private final int incident; private final int incident;
private final String message; private final String message;
public IncidentLogEvent(LogHeader header, LogBuffer buffer, public IncidentLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int commonHeaderLen = descriptionEvent.commonHeaderLen;
@@ -61,10 +56,9 @@ public final class IncidentLogEvent extends LogEvent
buffer.position(commonHeaderLen); buffer.position(commonHeaderLen);
final int incidentNumber = buffer.getUint16(); final int incidentNumber = buffer.getUint16();
if (incidentNumber >= INCIDENT_COUNT || incidentNumber <= INCIDENT_NONE) if (incidentNumber >= INCIDENT_COUNT || incidentNumber <= INCIDENT_NONE) {
{
// If the incident is not recognized, this binlog event is // If the incident is not recognized, this binlog event is
// invalid. If we set incident_number to INCIDENT_NONE, the // invalid. If we set incident_number to INCIDENT_NONE, the
// invalidity will be detected by is_valid(). // invalidity will be detected by is_valid().
incident = INCIDENT_NONE; incident = INCIDENT_NONE;
message = null; message = null;
@@ -76,13 +70,11 @@ public final class IncidentLogEvent extends LogEvent
message = buffer.getString(); message = buffer.getString();
} }
public final int getIncident() public final int getIncident() {
{
return incident; return incident;
} }
public final String getMessage() public final String getMessage() {
{
return message; return message;
} }
} }

View File

@@ -6,54 +6,43 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* An Intvar_log_event will be created just before a Query_log_event, if the * An Intvar_log_event will be created just before a Query_log_event, if the
* query uses one of the variables LAST_INSERT_ID or INSERT_ID. Each * query uses one of the variables LAST_INSERT_ID or INSERT_ID. Each
* Intvar_log_event holds the value of one of these variables. * Intvar_log_event holds the value of one of these variables. Binary Format The
* * Post-Header for this event type is empty. The Body has two components:
* Binary Format
*
* The Post-Header for this event type is empty. The Body has two components:
*
* <table> * <table>
* <caption>Body for Intvar_log_event</caption> * <caption>Body for Intvar_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>type</td> * <td>type</td>
* <td>1 byte enumeration</td> * <td>1 byte enumeration</td>
* <td>One byte identifying the type of variable stored. Currently, two * <td>One byte identifying the type of variable stored. Currently, two
* identifiers are supported: LAST_INSERT_ID_EVENT==1 and INSERT_ID_EVENT==2.</td> * identifiers are supported: LAST_INSERT_ID_EVENT==1 and INSERT_ID_EVENT==2.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>value</td> * <td>value</td>
* <td>8 byte unsigned integer</td> * <td>8 byte unsigned integer</td>
* <td>The value of the variable.</td> * <td>The value of the variable.</td>
* </tr> * </tr>
*
* </table> * </table>
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class IntvarLogEvent extends LogEvent public final class IntvarLogEvent extends LogEvent {
{
/** /**
* Fixed data part: Empty * Fixed data part: Empty
*
* <p> * <p>
* Variable data part: * Variable data part:
*
* <ul> * <ul>
* <li>1 byte. A value indicating the variable type: LAST_INSERT_ID_EVENT = * <li>1 byte. A value indicating the variable type: LAST_INSERT_ID_EVENT =
* 1 or INSERT_ID_EVENT = 2.</li> * 1 or INSERT_ID_EVENT = 2.</li>
* <li>8 bytes. An unsigned integer indicating the value to be used for the * <li>8 bytes. An unsigned integer indicating the value to be used for the
* LAST_INSERT_ID() invocation or AUTO_INCREMENT column.</li> * LAST_INSERT_ID() invocation or AUTO_INCREMENT column.</li>
* </ul> * </ul>
*
* Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log * Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log
*/ */
private final long value; private final long value;
@@ -68,31 +57,25 @@ public final class IntvarLogEvent extends LogEvent
public static final int LAST_INSERT_ID_EVENT = 1; public static final int LAST_INSERT_ID_EVENT = 1;
public static final int INSERT_ID_EVENT = 2; public static final int INSERT_ID_EVENT = 2;
public IntvarLogEvent(LogHeader header, LogBuffer buffer, public IntvarLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
/* The Post-Header is empty. The Varible Data part begins immediately. */ /* The Post-Header is empty. The Varible Data part begins immediately. */
buffer.position(descriptionEvent.commonHeaderLen buffer.position(descriptionEvent.commonHeaderLen + descriptionEvent.postHeaderLen[INTVAR_EVENT - 1]
+ descriptionEvent.postHeaderLen[INTVAR_EVENT - 1] + I_TYPE_OFFSET);
+ I_TYPE_OFFSET);
type = buffer.getInt8(); // I_TYPE_OFFSET type = buffer.getInt8(); // I_TYPE_OFFSET
value = buffer.getLong64(); // !uint8korr(buf + I_VAL_OFFSET); value = buffer.getLong64(); // !uint8korr(buf + I_VAL_OFFSET);
} }
public final int getType() public final int getType() {
{
return type; return type;
} }
public final long getValue() public final long getValue() {
{
return value; return value;
} }
public final String getQuery() public final String getQuery() {
{
return "SET INSERT_ID = " + value; return "SET INSERT_ID = " + value;
} }
} }

View File

@@ -26,16 +26,13 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* </pre> * </pre>
* *
* Binary Format: The Post-Header consists of the following six components. * Binary Format: The Post-Header consists of the following six components.
*
* <table> * <table>
* <caption>Post-Header for Load_log_event</caption> * <caption>Post-Header for Load_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>slave_proxy_id</td> * <td>slave_proxy_id</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
@@ -45,71 +42,57 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* temporary table local to the client. The slave_proxy_id is used to * temporary table local to the client. The slave_proxy_id is used to
* distinguish temporary tables that belong to different clients.</td> * distinguish temporary tables that belong to different clients.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>exec_time</td> * <td>exec_time</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
* <td>The time from when the query started to when it was logged in the binlog, * <td>The time from when the query started to when it was logged in the binlog,
* in seconds.</td> * in seconds.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>skip_lines</td> * <td>skip_lines</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
* <td>The number on line (14) above, if present, or 0 if line (14) is left out. * <td>The number on line (14) above, if present, or 0 if line (14) is left out.
* </td> * </td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>table_name_len</td> * <td>table_name_len</td>
* <td>1 byte unsigned integer</td> * <td>1 byte unsigned integer</td>
* <td>The length of 'table_name' on line (4) above.</td> * <td>The length of 'table_name' on line (4) above.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>db_len</td> * <td>db_len</td>
* <td>1 byte unsigned integer</td> * <td>1 byte unsigned integer</td>
* <td>The length of 'db' on line (1) above.</td> * <td>The length of 'db' on line (1) above.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>num_fields</td> * <td>num_fields</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
* <td>The number n of fields on line (15) above.</td> * <td>The number n of fields on line (15) above.</td>
* </tr> * </tr>
* </table> * </table>
*
* The Body contains the following components. * The Body contains the following components.
*
* <table> * <table>
* <caption>Body of Load_log_event</caption> * <caption>Body of Load_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>sql_ex</td> * <td>sql_ex</td>
* <td>variable length</td> * <td>variable length</td>
*
* <td>Describes the part of the query on lines (3) and (5)&ndash;(13) above. * <td>Describes the part of the query on lines (3) and (5)&ndash;(13) above.
* More precisely, it stores the five strings (on lines) field_term (6), * More precisely, it stores the five strings (on lines) field_term (6),
* enclosed (7), escaped (8), line_term (11), and line_start (12); as well as a * enclosed (7), escaped (8), line_term (11), and line_start (12); as well as a
* bitfield indicating the presence of the keywords REPLACE (3), IGNORE (3), and * bitfield indicating the presence of the keywords REPLACE (3), IGNORE (3), and
* OPTIONALLY (7). * OPTIONALLY (7). The data is stored in one of two formats, called "old" and
* * "new". The type field of Common-Header determines which of these two formats
* The data is stored in one of two formats, called "old" and "new". The type * is used: type LOAD_EVENT means that the old format is used, and type
* field of Common-Header determines which of these two formats is used: type * NEW_LOAD_EVENT means that the new format is used. When MySQL writes a
* LOAD_EVENT means that the old format is used, and type NEW_LOAD_EVENT means * Load_log_event, it uses the new format if at least one of the five strings is
* that the new format is used. When MySQL writes a Load_log_event, it uses the * two or more bytes long. Otherwise (i.e., if all strings are 0 or 1 bytes
* new format if at least one of the five strings is two or more bytes long. * long), the old format is used. The new and old format differ in the way the
* Otherwise (i.e., if all strings are 0 or 1 bytes long), the old format is * five strings are stored.
* used.
*
* The new and old format differ in the way the five strings are stored.
*
* <ul> * <ul>
* <li>In the new format, the strings are stored in the order field_term, * <li>In the new format, the strings are stored in the order field_term,
* enclosed, escaped, line_term, line_start. Each string consists of a length (1 * enclosed, escaped, line_term, line_start. Each string consists of a length (1
@@ -117,7 +100,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* combination of the following flags is stored in 1 byte: REPLACE_FLAG==0x4, * combination of the following flags is stored in 1 byte: REPLACE_FLAG==0x4,
* IGNORE_FLAG==0x8, and OPT_ENCLOSED_FLAG==0x2. If a flag is set, it indicates * IGNORE_FLAG==0x8, and OPT_ENCLOSED_FLAG==0x2. If a flag is set, it indicates
* the presence of the corresponding keyword in the SQL query. * the presence of the corresponding keyword in the SQL query.
*
* <li>In the old format, we know that each string has length 0 or 1. Therefore, * <li>In the old format, we know that each string has length 0 or 1. Therefore,
* only the first byte of each string is stored. The order of the strings is the * only the first byte of each string is stored. The order of the strings is the
* same as in the new format. These five bytes are followed by the same 1 byte * same as in the new format. These five bytes are followed by the same 1 byte
@@ -128,18 +110,15 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* FIELD_TERM_EMPTY==0x1, ENCLOSED_EMPTY==0x2, LINE_TERM_EMPTY==0x4, * FIELD_TERM_EMPTY==0x1, ENCLOSED_EMPTY==0x2, LINE_TERM_EMPTY==0x4,
* LINE_START_EMPTY==0x8, ESCAPED_EMPTY==0x10. * LINE_START_EMPTY==0x8, ESCAPED_EMPTY==0x10.
* </ul> * </ul>
*
* Thus, the size of the new format is 6 bytes + the sum of the sizes of the * Thus, the size of the new format is 6 bytes + the sum of the sizes of the
* five strings. The size of the old format is always 7 bytes.</td> * five strings. The size of the old format is always 7 bytes.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>field_lens</td> * <td>field_lens</td>
* <td>num_fields 1 byte unsigned integers</td> * <td>num_fields 1 byte unsigned integers</td>
* <td>An array of num_fields integers representing the length of each field in * <td>An array of num_fields integers representing the length of each field in
* the query. (num_fields is from the Post-Header).</td> * the query. (num_fields is from the Post-Header).</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>fields</td> * <td>fields</td>
* <td>num_fields null-terminated strings</td> * <td>num_fields null-terminated strings</td>
@@ -148,7 +127,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* the num_fields array.) The total length of all strings equals to the sum of * the num_fields array.) The total length of all strings equals to the sum of
* all field_lens, plus num_fields bytes for all the trailing zeros.</td> * all field_lens, plus num_fields bytes for all the trailing zeros.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>table_name</td> * <td>table_name</td>
* <td>null-terminated string of length table_len+1 bytes</td> * <td>null-terminated string of length table_len+1 bytes</td>
@@ -156,31 +134,27 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* trailing zero is actually redundant since the table_len is known from * trailing zero is actually redundant since the table_len is known from
* Post-Header.)</td> * Post-Header.)</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>db</td> * <td>db</td>
* <td>null-terminated string of length db_len+1 bytes</td> * <td>null-terminated string of length db_len+1 bytes</td>
* <td>The 'db' from the query, as a null-terminated string. (The trailing zero * <td>The 'db' from the query, as a null-terminated string. (The trailing zero
* is actually redundant since the db_len is known from Post-Header.)</td> * is actually redundant since the db_len is known from Post-Header.)</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>file_name</td> * <td>file_name</td>
* <td>variable length string without trailing zero, extending to the end of the * <td>variable length string without trailing zero, extending to the end of the
* event (determined by the length field of the Common-Header)</td> * event (determined by the length field of the Common-Header)</td>
* <td>The 'file_name' from the query.</td> * <td>The 'file_name' from the query.</td>
* </tr> * </tr>
*
* </table> * </table>
*
* This event type is understood by current versions, but only generated by * This event type is understood by current versions, but only generated by
* MySQL 3.23 and earlier. * MySQL 3.23 and earlier.
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public class LoadLogEvent extends LogEvent public class LoadLogEvent extends LogEvent {
{
private String table; private String table;
private String db; private String db;
private String fname; private String fname;
@@ -210,11 +184,10 @@ public class LoadLogEvent extends LogEvent
public static final int L_DATA_OFFSET = FormatDescriptionLogEvent.LOAD_HEADER_LEN; public static final int L_DATA_OFFSET = FormatDescriptionLogEvent.LOAD_HEADER_LEN;
/* /*
These are flags and structs to handle all the LOAD DATA INFILE options (LINES * These are flags and structs to handle all the LOAD DATA INFILE options
TERMINATED etc). * (LINES TERMINATED etc). DUMPFILE_FLAG is probably useless (DUMPFILE is a
DUMPFILE_FLAG is probably useless (DUMPFILE is a clause of SELECT, not of LOAD * clause of SELECT, not of LOAD DATA).
DATA). */
*/
public static final int DUMPFILE_FLAG = 0x1; public static final int DUMPFILE_FLAG = 0x1;
public static final int OPT_ENCLOSED_FLAG = 0x2; public static final int OPT_ENCLOSED_FLAG = 0x2;
public static final int REPLACE_FLAG = 0x4; public static final int REPLACE_FLAG = 0x4;
@@ -226,9 +199,7 @@ public class LoadLogEvent extends LogEvent
public static final int LINE_START_EMPTY = 0x8; public static final int LINE_START_EMPTY = 0x8;
public static final int ESCAPED_EMPTY = 0x10; public static final int ESCAPED_EMPTY = 0x10;
public LoadLogEvent(LogHeader header, LogBuffer buffer, public LoadLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int loadHeaderLen = FormatDescriptionLogEvent.LOAD_HEADER_LEN; final int loadHeaderLen = FormatDescriptionLogEvent.LOAD_HEADER_LEN;
@@ -236,18 +207,16 @@ public class LoadLogEvent extends LogEvent
* I (Guilhem) manually tested replication of LOAD DATA INFILE for * I (Guilhem) manually tested replication of LOAD DATA INFILE for
* 3.23->5.0, 4.0->5.0 and 5.0->5.0 and it works. * 3.23->5.0, 4.0->5.0 and 5.0->5.0 and it works.
*/ */
copyLogEvent(buffer, ((header.type == LOAD_EVENT) ? loadHeaderLen copyLogEvent(buffer,
+ descriptionEvent.commonHeaderLen : loadHeaderLen ((header.type == LOAD_EVENT) ? loadHeaderLen + descriptionEvent.commonHeaderLen : loadHeaderLen
+ FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN), + FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN),
descriptionEvent); descriptionEvent);
} }
/** /**
* @see mysql-5.1.60/sql/log_event.cc - Load_log_event::copy_log_event * @see mysql-5.1.60/sql/log_event.cc - Load_log_event::copy_log_event
*/ */
protected final void copyLogEvent(LogBuffer buffer, final int bodyOffset, protected final void copyLogEvent(LogBuffer buffer, final int bodyOffset, FormatDescriptionLogEvent descriptionEvent) {
FormatDescriptionLogEvent descriptionEvent)
{
/* this is the beginning of the post-header */ /* this is the beginning of the post-header */
buffer.position(descriptionEvent.commonHeaderLen + L_EXEC_TIME_OFFSET); buffer.position(descriptionEvent.commonHeaderLen + L_EXEC_TIME_OFFSET);
@@ -262,8 +231,7 @@ public class LoadLogEvent extends LogEvent
* Sql_ex.init() on success returns the pointer to the first byte after * Sql_ex.init() on success returns the pointer to the first byte after
* the sql_ex structure, which is the start of field lengths array. * the sql_ex structure, which is the start of field lengths array.
*/ */
if (header.type != LOAD_EVENT /* use_new_format */) if (header.type != LOAD_EVENT /* use_new_format */) {
{
/* /*
* The code below assumes that buf will not disappear from under our * The code below assumes that buf will not disappear from under our
* feet during the lifetime of the event. This assumption holds true * feet during the lifetime of the event. This assumption holds true
@@ -279,9 +247,7 @@ public class LoadLogEvent extends LogEvent
escaped = buffer.getString(); escaped = buffer.getString();
optFlags = buffer.getInt8(); optFlags = buffer.getInt8();
emptyFlags = 0; emptyFlags = 0;
} } else {
else
{
fieldTerm = buffer.getFixString(1); fieldTerm = buffer.getFixString(1);
enclosed = buffer.getFixString(1); enclosed = buffer.getFixString(1);
lineTerm = buffer.getFixString(1); lineTerm = buffer.getFixString(1);
@@ -290,23 +256,17 @@ public class LoadLogEvent extends LogEvent
optFlags = buffer.getUint8(); optFlags = buffer.getUint8();
emptyFlags = buffer.getUint8(); emptyFlags = buffer.getUint8();
if ((emptyFlags & FIELD_TERM_EMPTY) != 0) if ((emptyFlags & FIELD_TERM_EMPTY) != 0) fieldTerm = null;
fieldTerm = null; if ((emptyFlags & ENCLOSED_EMPTY) != 0) enclosed = null;
if ((emptyFlags & ENCLOSED_EMPTY) != 0) if ((emptyFlags & LINE_TERM_EMPTY) != 0) lineTerm = null;
enclosed = null; if ((emptyFlags & LINE_START_EMPTY) != 0) lineStart = null;
if ((emptyFlags & LINE_TERM_EMPTY) != 0) if ((emptyFlags & ESCAPED_EMPTY) != 0) escaped = null;
lineTerm = null;
if ((emptyFlags & LINE_START_EMPTY) != 0)
lineStart = null;
if ((emptyFlags & ESCAPED_EMPTY) != 0)
escaped = null;
} }
final int fieldLenPos = buffer.position(); final int fieldLenPos = buffer.position();
buffer.forward(numFields); buffer.forward(numFields);
fields = new String[numFields]; fields = new String[numFields];
for (int i = 0; i < numFields; i++) for (int i = 0; i < numFields; i++) {
{
final int fieldLen = buffer.getUint8(fieldLenPos + i); final int fieldLen = buffer.getUint8(fieldLenPos + i);
fields[i] = buffer.getFixString(fieldLen + 1); fields[i] = buffer.getFixString(fieldLen + 1);
} }
@@ -314,78 +274,65 @@ public class LoadLogEvent extends LogEvent
table = buffer.getFixString(tableNameLen + 1); table = buffer.getFixString(tableNameLen + 1);
db = buffer.getFixString(dbLen + 1); db = buffer.getFixString(dbLen + 1);
// null termination is accomplished by the caller // null termination is accomplished by the caller
final int from = buffer.position(); final int from = buffer.position();
final int end = from + buffer.limit(); final int end = from + buffer.limit();
int found = from; int found = from;
for (; (found < end) && buffer.getInt8(found) != '\0'; found++) for (; (found < end) && buffer.getInt8(found) != '\0'; found++)
/* empty loop */; /* empty loop */;
fname = buffer.getString(found); fname = buffer.getString(found);
buffer.forward(1); // The + 1 is for \0 terminating fname buffer.forward(1); // The + 1 is for \0 terminating fname
} }
public final String getTable() public final String getTable() {
{
return table; return table;
} }
public final String getDb() public final String getDb() {
{
return db; return db;
} }
public final String getFname() public final String getFname() {
{
return fname; return fname;
} }
public final int getSkipLines() public final int getSkipLines() {
{
return skipLines; return skipLines;
} }
public final String[] getFields() public final String[] getFields() {
{
return fields; return fields;
} }
public final String getFieldTerm() public final String getFieldTerm() {
{
return fieldTerm; return fieldTerm;
} }
public final String getLineTerm() public final String getLineTerm() {
{
return lineTerm; return lineTerm;
} }
public final String getLineStart() public final String getLineStart() {
{
return lineStart; return lineStart;
} }
public final String getEnclosed() public final String getEnclosed() {
{
return enclosed; return enclosed;
} }
public final String getEscaped() public final String getEscaped() {
{
return escaped; return escaped;
} }
public final int getOptFlags() public final int getOptFlags() {
{
return optFlags; return optFlags;
} }
public final int getEmptyFlags() public final int getEmptyFlags() {
{
return emptyFlags; return emptyFlags;
} }
public final long getExecTime() public final long getExecTime() {
{
return execTime; return execTime;
} }
} }

View File

@@ -11,41 +11,34 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* different format and length even for different events of the same type. The * different format and length even for different events of the same type. The
* binary formats of Post-Header and Body are documented separately in each * binary formats of Post-Header and Body are documented separately in each
* subclass. The binary format of Common-Header is as follows. * subclass. The binary format of Common-Header is as follows.
*
* <table> * <table>
* <caption>Common-Header</caption> * <caption>Common-Header</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>timestamp</td> * <td>timestamp</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
* <td>The time when the query started, in seconds since 1970.</td> * <td>The time when the query started, in seconds since 1970.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>type</td> * <td>type</td>
* <td>1 byte enumeration</td> * <td>1 byte enumeration</td>
* <td>See enum #Log_event_type.</td> * <td>See enum #Log_event_type.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>server_id</td> * <td>server_id</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
* <td>Server ID of the server that created the event.</td> * <td>Server ID of the server that created the event.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>total_size</td> * <td>total_size</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
* <td>The total size of this event, in bytes. In other words, this is the sum * <td>The total size of this event, in bytes. In other words, this is the sum
* of the sizes of Common-Header, Post-Header, and Body.</td> * of the sizes of Common-Header, Post-Header, and Body.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>master_position</td> * <td>master_position</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
@@ -54,24 +47,21 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* the position of the next event, in bytes from the beginning of the file. In a * the position of the next event, in bytes from the beginning of the file. In a
* relay log, this is the position of the next event in the master's binlog.</td> * relay log, this is the position of the next event in the master's binlog.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>flags</td> * <td>flags</td>
* <td>2 byte bitfield</td> * <td>2 byte bitfield</td>
* <td>See Log_event::flags.</td> * <td>See Log_event::flags.</td>
* </tr> * </tr>
* </table> * </table>
*
* Summing up the numbers above, we see that the total size of the common header * Summing up the numbers above, we see that the total size of the common header
* is 19 bytes. * is 19 bytes.
* *
* @see mysql-5.1.60/sql/log_event.cc * @see mysql-5.1.60/sql/log_event.cc
*
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class LogHeader public final class LogHeader {
{
protected final int type; protected final int type;
/** /**
@@ -111,37 +101,32 @@ public final class LogHeader
* LOG_EVENT_SUPPRESS_USE_F for notes. * LOG_EVENT_SUPPRESS_USE_F for notes.
*/ */
protected int flags; protected int flags;
/** /**
* The value is set by caller of FD constructor and * The value is set by caller of FD constructor and
* Log_event::write_header() for the rest. * Log_event::write_header() for the rest. In the FD case it's propagated
* In the FD case it's propagated into the last byte * into the last byte of post_header_len[] at FD::write(). On the slave side
* of post_header_len[] at FD::write(). * the value is assigned from post_header_len[last] of the last seen FD
* On the slave side the value is assigned from post_header_len[last] * event.
* of the last seen FD event.
*/ */
protected int checksumAlg; protected int checksumAlg;
/** /**
Placeholder for event checksum while writing to binlog. * Placeholder for event checksum while writing to binlog.
*/ */
protected long crc; // ha_checksum protected long crc; // ha_checksum
/* for Start_event_v3 */ /* for Start_event_v3 */
public LogHeader(final int type) public LogHeader(final int type){
{
this.type = type; this.type = type;
} }
public LogHeader(LogBuffer buffer, public LogHeader(LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
when = buffer.getUint32(); when = buffer.getUint32();
type = buffer.getUint8(); // LogEvent.EVENT_TYPE_OFFSET; type = buffer.getUint8(); // LogEvent.EVENT_TYPE_OFFSET;
serverId = buffer.getUint32(); // LogEvent.SERVER_ID_OFFSET; serverId = buffer.getUint32(); // LogEvent.SERVER_ID_OFFSET;
eventLen = (int) buffer.getUint32(); // LogEvent.EVENT_LEN_OFFSET; eventLen = (int) buffer.getUint32(); // LogEvent.EVENT_LEN_OFFSET;
if (descriptionEvent.binlogVersion == 1) if (descriptionEvent.binlogVersion == 1) {
{
logPos = 0; logPos = 0;
flags = 0; flags = 0;
return; return;
@@ -150,50 +135,45 @@ public final class LogHeader
/* 4.0 or newer */ /* 4.0 or newer */
logPos = buffer.getUint32(); // LogEvent.LOG_POS_OFFSET logPos = buffer.getUint32(); // LogEvent.LOG_POS_OFFSET
/* /*
If the log is 4.0 (so here it can only be a 4.0 relay log read by * If the log is 4.0 (so here it can only be a 4.0 relay log read by the
the SQL thread or a 4.0 master binlog read by the I/O thread), * SQL thread or a 4.0 master binlog read by the I/O thread), log_pos is
log_pos is the beginning of the event: we transform it into the end * the beginning of the event: we transform it into the end of the
of the event, which is more useful. * event, which is more useful. But how do you know that the log is 4.0:
But how do you know that the log is 4.0: you know it if * you know it if description_event is version 3 *and* you are not
description_event is version 3 *and* you are not reading a * reading a Format_desc (remember that mysqlbinlog starts by assuming
Format_desc (remember that mysqlbinlog starts by assuming that 5.0 * that 5.0 logs are in 4.0 format, until it finds a Format_desc).
logs are in 4.0 format, until it finds a Format_desc). */
*/ if (descriptionEvent.binlogVersion == 3 && type < LogEvent.FORMAT_DESCRIPTION_EVENT && logPos != 0) {
if (descriptionEvent.binlogVersion == 3
&& type < LogEvent.FORMAT_DESCRIPTION_EVENT && logPos != 0)
{
/* /*
If log_pos=0, don't change it. log_pos==0 is a marker to mean * If log_pos=0, don't change it. log_pos==0 is a marker to mean
"don't change rli->group_master_log_pos" (see * "don't change rli->group_master_log_pos" (see
inc_group_relay_log_pos()). As it is unreal log_pos, adding the * inc_group_relay_log_pos()). As it is unreal log_pos, adding the
event len's is nonsense. For example, a fake Rotate event should * event len's is nonsense. For example, a fake Rotate event should
not have its log_pos (which is 0) changed or it will modify * not have its log_pos (which is 0) changed or it will modify
Exec_master_log_pos in SHOW SLAVE STATUS, displaying a nonsense * Exec_master_log_pos in SHOW SLAVE STATUS, displaying a nonsense
value of (a non-zero offset which does not exist in the master's * value of (a non-zero offset which does not exist in the master's
binlog, so which will cause problems if the user uses this value * binlog, so which will cause problems if the user uses this value
in CHANGE MASTER). * in CHANGE MASTER).
*/ */
logPos += eventLen; /* purecov: inspected */ logPos += eventLen; /* purecov: inspected */
} }
flags = buffer.getUint16(); // LogEvent.FLAGS_OFFSET flags = buffer.getUint16(); // LogEvent.FLAGS_OFFSET
if ((type == LogEvent.FORMAT_DESCRIPTION_EVENT) if ((type == LogEvent.FORMAT_DESCRIPTION_EVENT) || (type == LogEvent.ROTATE_EVENT)) {
|| (type == LogEvent.ROTATE_EVENT))
{
/* /*
These events always have a header which stops here (i.e. their * These events always have a header which stops here (i.e. their
header is FROZEN). * header is FROZEN).
*/ */
/* /*
Initialization to zero of all other Log_event members as they're * Initialization to zero of all other Log_event members as they're
not specified. Currently there are no such members; in the future * not specified. Currently there are no such members; in the future
there will be an event UID (but Format_description and Rotate * there will be an event UID (but Format_description and Rotate
don't need this UID, as they are not propagated through * don't need this UID, as they are not propagated through
--log-slave-updates (remember the UID is used to not play a query * --log-slave-updates (remember the UID is used to not play a query
twice when you have two masters which are slaves of a 3rd master). * twice when you have two masters which are slaves of a 3rd
Then we are done. * master). Then we are done.
*/ */
if (type == LogEvent.FORMAT_DESCRIPTION_EVENT) { if (type == LogEvent.FORMAT_DESCRIPTION_EVENT) {
int commonHeaderLen = buffer.getUint8(FormatDescriptionLogEvent.LOG_EVENT_MINIMAL_HEADER_LEN int commonHeaderLen = buffer.getUint8(FormatDescriptionLogEvent.LOG_EVENT_MINIMAL_HEADER_LEN
+ FormatDescriptionLogEvent.ST_COMMON_HEADER_LEN_OFFSET); + FormatDescriptionLogEvent.ST_COMMON_HEADER_LEN_OFFSET);
@@ -211,27 +191,24 @@ public final class LogHeader
} }
return; return;
} }
/* /*
CRC verification by SQL and Show-Binlog-Events master side. * CRC verification by SQL and Show-Binlog-Events master side. The
The caller has to provide @description_event->checksum_alg to * caller has to provide @description_event->checksum_alg to be the last
be the last seen FD's (A) descriptor. * seen FD's (A) descriptor. If event is FD the descriptor is in it.
If event is FD the descriptor is in it. * Notice, FD of the binlog can be only in one instance and therefore
Notice, FD of the binlog can be only in one instance and therefore * Show-Binlog-Events executing master side thread needs just to know
Show-Binlog-Events executing master side thread needs just to know * the only FD's (A) value - whereas RL can contain more. In the RL
the only FD's (A) value - whereas RL can contain more. * case, the alg is kept in FD_e (@description_event) which is reset to
In the RL case, the alg is kept in FD_e (@description_event) which is reset * the newer read-out event after its execution with possibly new alg
to the newer read-out event after its execution with possibly new alg descriptor. * descriptor. Therefore in a typical sequence of RL: {FD_s^0, FD_m,
Therefore in a typical sequence of RL: * E_m^1} E_m^1 will be verified with (A) of FD_m. See legends
{FD_s^0, FD_m, E_m^1} E_m^1 * definition on MYSQL_BIN_LOG::relay_log_checksum_alg docs lines
will be verified with (A) of FD_m. * (log.h). Notice, a pre-checksum FD version forces alg :=
* BINLOG_CHECKSUM_ALG_UNDEF.
See legends definition on MYSQL_BIN_LOG::relay_log_checksum_alg docs */
lines (log.h). checksumAlg = descriptionEvent.getHeader().checksumAlg; // fetch
// checksum alg
Notice, a pre-checksum FD version forces alg := BINLOG_CHECKSUM_ALG_UNDEF.
*/
checksumAlg = descriptionEvent.getHeader().checksumAlg; // fetch checksum alg
processCheckSum(buffer); processCheckSum(buffer);
/* otherwise, go on with reading the header from buf (nothing now) */ /* otherwise, go on with reading the header from buf (nothing now) */
} }
@@ -239,8 +216,7 @@ public final class LogHeader
/** /**
* The different types of log events. * The different types of log events.
*/ */
public final int getType() public final int getType() {
{
return type; return type;
} }
@@ -251,8 +227,7 @@ public final class LogHeader
* file. In a relay log, this is the position of the next event in the * file. In a relay log, this is the position of the next event in the
* master's binlog. * master's binlog.
*/ */
public final long getLogPos() public final long getLogPos() {
{
return logPos; return logPos;
} }
@@ -260,24 +235,21 @@ public final class LogHeader
* The total size of this event, in bytes. In other words, this is the sum * The total size of this event, in bytes. In other words, this is the sum
* of the sizes of Common-Header, Post-Header, and Body. * of the sizes of Common-Header, Post-Header, and Body.
*/ */
public final int getEventLen() public final int getEventLen() {
{
return eventLen; return eventLen;
} }
/** /**
* The time when the query started, in seconds since 1970. * The time when the query started, in seconds since 1970.
*/ */
public final long getWhen() public final long getWhen() {
{
return when; return when;
} }
/** /**
* Server ID of the server that created the event. * Server ID of the server that created the event.
*/ */
public final long getServerId() public final long getServerId() {
{
return serverId; return serverId;
} }
@@ -286,25 +258,21 @@ public final class LogHeader
* LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and * LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
* LOG_EVENT_SUPPRESS_USE_F for notes. * LOG_EVENT_SUPPRESS_USE_F for notes.
*/ */
public final int getFlags() public final int getFlags() {
{
return flags; return flags;
} }
public long getCrc() { public long getCrc() {
return crc; return crc;
} }
public int getChecksumAlg() { public int getChecksumAlg() {
return checksumAlg; return checksumAlg;
} }
private void processCheckSum(LogBuffer buffer) { private void processCheckSum(LogBuffer buffer) {
if (checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_OFF && if (checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_OFF && checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_UNDEF) {
checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_UNDEF){ crc = buffer.getUint32(eventLen - LogEvent.BINLOG_CHECKSUM_LEN);
crc = buffer.getUint32(eventLen - LogEvent.BINLOG_CHECKSUM_LEN);
} }
} }
} }

View File

@@ -4,16 +4,14 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent; import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
*
* @author jianghang 2013-4-8 上午12:36:29 * @author jianghang 2013-4-8 上午12:36:29
* @version 1.0.3 * @version 1.0.3
* @since mysql 5.6 * @since mysql 5.6
*/ */
public class PreviousGtidsLogEvent extends LogEvent{ public class PreviousGtidsLogEvent extends LogEvent {
public PreviousGtidsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ public PreviousGtidsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header); super(header);
// do nothing , just for mysql gtid search function // do nothing , just for mysql gtid search function
} }
} }

View File

@@ -9,19 +9,14 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* A Query_log_event is created for each query that modifies the database, * A Query_log_event is created for each query that modifies the database,
* unless the query is logged row-based. * unless the query is logged row-based. The Post-Header has five components:
*
* The Post-Header has five components:
*
* <table> * <table>
* <caption>Post-Header for Query_log_event</caption> * <caption>Post-Header for Query_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>slave_proxy_id</td> * <td>slave_proxy_id</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
@@ -31,20 +26,17 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* temporary table local to the client. The slave_proxy_id is used to * temporary table local to the client. The slave_proxy_id is used to
* distinguish temporary tables that belong to different clients.</td> * distinguish temporary tables that belong to different clients.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>exec_time</td> * <td>exec_time</td>
* <td>4 byte unsigned integer</td> * <td>4 byte unsigned integer</td>
* <td>The time from when the query started to when it was logged in the binlog, * <td>The time from when the query started to when it was logged in the binlog,
* in seconds.</td> * in seconds.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>db_len</td> * <td>db_len</td>
* <td>1 byte integer</td> * <td>1 byte integer</td>
* <td>The length of the name of the currently selected database.</td> * <td>The length of the name of the currently selected database.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>error_code</td> * <td>error_code</td>
* <td>2 byte unsigned integer</td> * <td>2 byte unsigned integer</td>
@@ -52,7 +44,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* fail with the same error code, except for the error codes ER_DB_CREATE_EXISTS * fail with the same error code, except for the error codes ER_DB_CREATE_EXISTS
* == 1007 and ER_DB_DROP_EXISTS == 1008.</td> * == 1007 and ER_DB_DROP_EXISTS == 1008.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>status_vars_len</td> * <td>status_vars_len</td>
* <td>2 byte unsigned integer</td> * <td>2 byte unsigned integer</td>
@@ -60,18 +51,14 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* query_log_event_status_vars "below".</td> * query_log_event_status_vars "below".</td>
* </tr> * </tr>
* </table> * </table>
*
* The Body has the following components: * The Body has the following components:
*
* <table> * <table>
* <caption>Body for Query_log_event</caption> * <caption>Body for Query_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>query_log_event_status_vars status_vars</td> * <td>query_log_event_status_vars status_vars</td>
* <td>status_vars_len bytes</td> * <td>status_vars_len bytes</td>
@@ -81,16 +68,13 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* Table_query_log_event_status_vars "below". MySQL always writes events in the * Table_query_log_event_status_vars "below". MySQL always writes events in the
* order defined below; however, it is capable of reading them in any order.</td> * order defined below; however, it is capable of reading them in any order.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>db</td> * <td>db</td>
* <td>db_len+1</td> * <td>db_len+1</td>
* <td>The currently selected database, as a null-terminated string. * <td>The currently selected database, as a null-terminated string. (The
* * trailing zero is redundant since the length is already known; it is db_len
* (The trailing zero is redundant since the length is already known; it is * from Post-Header.)</td>
* db_len from Post-Header.)</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>query</td> * <td>query</td>
* <td>variable length string without trailing zero, extending to the end of the * <td>variable length string without trailing zero, extending to the end of the
@@ -98,20 +82,16 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td>The SQL query.</td> * <td>The SQL query.</td>
* </tr> * </tr>
* </table> * </table>
*
* The following table lists the status variables that may appear in the * The following table lists the status variables that may appear in the
* status_vars field. Table_query_log_event_status_vars * status_vars field. Table_query_log_event_status_vars
*
* <table> * <table>
* <caption>Status variables for Query_log_event</caption> * <caption>Status variables for Query_log_event</caption>
*
* <tr> * <tr>
* <th>Status variable</th> * <th>Status variable</th>
* <th>1 byte identifier</th> * <th>1 byte identifier</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>flags2</td> * <td>flags2</td>
* <td>Q_FLAGS2_CODE == 0</td> * <td>Q_FLAGS2_CODE == 0</td>
@@ -121,16 +101,12 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* identifies those options that need to be written to the binlog (not all do). * identifies those options that need to be written to the binlog (not all do).
* Specifically, OPTIONS_WRITTEN_TO_BIN_LOG equals (OPTION_AUTO_IS_NULL | * Specifically, OPTIONS_WRITTEN_TO_BIN_LOG equals (OPTION_AUTO_IS_NULL |
* OPTION_NO_FOREIGN_KEY_CHECKS | OPTION_RELAXED_UNIQUE_CHECKS | * OPTION_NO_FOREIGN_KEY_CHECKS | OPTION_RELAXED_UNIQUE_CHECKS |
* OPTION_NOT_AUTOCOMMIT), or 0x0c084000 in hex. * OPTION_NOT_AUTOCOMMIT), or 0x0c084000 in hex. These flags correspond to the
* * SQL variables SQL_AUTO_IS_NULL, FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, and
* These flags correspond to the SQL variables SQL_AUTO_IS_NULL, * AUTOCOMMIT, documented in the "SET Syntax" section of the MySQL Manual. This
* FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, and AUTOCOMMIT, documented in the * field is always written to the binlog in version >= 5.0, and never written in
* "SET Syntax" section of the MySQL Manual. * version < 5.0.</td>
*
* This field is always written to the binlog in version >= 5.0, and never
* written in version < 5.0.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>sql_mode</td> * <td>sql_mode</td>
* <td>Q_SQL_MODE_CODE == 1</td> * <td>Q_SQL_MODE_CODE == 1</td>
@@ -177,11 +153,9 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* All these flags are replicated from the server. However, all flags except * All these flags are replicated from the server. However, all flags except
* MODE_NO_DIR_IN_CREATE are honored by the slave; the slave always preserves * MODE_NO_DIR_IN_CREATE are honored by the slave; the slave always preserves
* its old value of MODE_NO_DIR_IN_CREATE. For a rationale, see comment in * its old value of MODE_NO_DIR_IN_CREATE. For a rationale, see comment in
* Query_log_event::do_apply_event in log_event.cc. * Query_log_event::do_apply_event in log_event.cc. This field is always written
* * to the binlog.</td>
* This field is always written to the binlog.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>catalog</td> * <td>catalog</td>
* <td>Q_CATALOG_NZ_CODE == 6</td> * <td>Q_CATALOG_NZ_CODE == 6</td>
@@ -189,23 +163,17 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* characters (at most 255 bytes)</td> * characters (at most 255 bytes)</td>
* <td>Stores the client's current catalog. Every database belongs to a catalog, * <td>Stores the client's current catalog. Every database belongs to a catalog,
* the same way that every table belongs to a database. Currently, there is only * the same way that every table belongs to a database. Currently, there is only
* one catalog, "std". * one catalog, "std". This field is written if the length of the catalog is >
* * 0; otherwise it is not written.</td>
* This field is written if the length of the catalog is > 0; otherwise it is
* not written.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>auto_increment</td> * <td>auto_increment</td>
* <td>Q_AUTO_INCREMENT == 3</td> * <td>Q_AUTO_INCREMENT == 3</td>
* <td>two 2 byte unsigned integers, totally 2+2=4 bytes</td> * <td>two 2 byte unsigned integers, totally 2+2=4 bytes</td>
*
* <td>The two variables auto_increment_increment and auto_increment_offset, in * <td>The two variables auto_increment_increment and auto_increment_offset, in
* that order. For more information, see "System variables" in the MySQL manual. * that order. For more information, see "System variables" in the MySQL manual.
*
* This field is written if auto_increment > 1. Otherwise, it is not written.</td> * This field is written if auto_increment > 1. Otherwise, it is not written.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>charset</td> * <td>charset</td>
* <td>Q_CHARSET_CODE == 4</td> * <td>Q_CHARSET_CODE == 4</td>
@@ -216,33 +184,22 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* collation_connection identifies the character set and collation that the * collation_connection identifies the character set and collation that the
* master converts the query to when it receives it; this is useful when * master converts the query to when it receives it; this is useful when
* comparing literal strings. collation_server is the default character set and * comparing literal strings. collation_server is the default character set and
* collation used when a new database is created. * collation used when a new database is created. See also
* * "Connection Character Sets and Collations" in the MySQL 5.1 manual. All three
* See also "Connection Character Sets and Collations" in the MySQL 5.1 manual. * variables are codes identifying a (character set, collation) pair. To see
* * which codes map to which pairs, run the query "SELECT id, character_set_name,
* All three variables are codes identifying a (character set, collation) pair. * collation_name FROM COLLATIONS". Cf. Q_CHARSET_DATABASE_CODE below. This
* To see which codes map to which pairs, run the query "SELECT id, * field is always written.</td>
* character_set_name, collation_name FROM COLLATIONS".
*
* Cf. Q_CHARSET_DATABASE_CODE below.
*
* This field is always written.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>time_zone</td> * <td>time_zone</td>
* <td>Q_TIME_ZONE_CODE == 5</td> * <td>Q_TIME_ZONE_CODE == 5</td>
* <td>Variable-length string: the length in bytes (1 byte) followed by the * <td>Variable-length string: the length in bytes (1 byte) followed by the
* characters (at most 255 bytes). * characters (at most 255 bytes).
* <td>The time_zone of the master. * <td>The time_zone of the master. See also "System Variables" and
* * "MySQL Server Time Zone Support" in the MySQL manual. This field is written
* See also "System Variables" and "MySQL Server Time Zone Support" in the MySQL * if the length of the time zone string is > 0; otherwise, it is not written.</td>
* manual.
*
* This field is written if the length of the time zone string is > 0;
* otherwise, it is not written.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>lc_time_names_number</td> * <td>lc_time_names_number</td>
* <td>Q_LC_TIME_NAMES_CODE == 7</td> * <td>Q_LC_TIME_NAMES_CODE == 7</td>
@@ -251,84 +208,68 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* to languages is defined in sql_locale.cc. This field is written if it is not * to languages is defined in sql_locale.cc. This field is written if it is not
* 0, i.e., if the locale is not en_US.</td> * 0, i.e., if the locale is not en_US.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>charset_database_number</td> * <td>charset_database_number</td>
* <td>Q_CHARSET_DATABASE_CODE == 8</td> * <td>Q_CHARSET_DATABASE_CODE == 8</td>
* <td>2 byte integer</td> * <td>2 byte integer</td>
*
* <td>The value of the collation_database system variable (in the source code * <td>The value of the collation_database system variable (in the source code
* stored in thd->variables.collation_database), which holds the code for a * stored in thd->variables.collation_database), which holds the code for a
* (character set, collation) pair as described above (see Q_CHARSET_CODE). * (character set, collation) pair as described above (see Q_CHARSET_CODE).
*
* collation_database was used in old versions (???WHEN). Its value was loaded * collation_database was used in old versions (???WHEN). Its value was loaded
* when issuing a "use db" query and could be changed by issuing a * when issuing a "use db" query and could be changed by issuing a
* "SET collation_database=xxx" query. It used to affect the "LOAD DATA INFILE" * "SET collation_database=xxx" query. It used to affect the "LOAD DATA INFILE"
* and "CREATE TABLE" commands. * and "CREATE TABLE" commands. In newer versions, "CREATE TABLE" has been
* * changed to take the character set from the database of the created table,
* In newer versions, "CREATE TABLE" has been changed to take the character set * rather than the character set of the current database. This makes a
* from the database of the created table, rather than the character set of the * difference when creating a table in another database than the current one.
* current database. This makes a difference when creating a table in another * "LOAD DATA INFILE" has not yet changed to do this, but there are plans to
* database than the current one. "LOAD DATA INFILE" has not yet changed to do * eventually do it, and to make collation_database read-only. This field is
* this, but there are plans to eventually do it, and to make collation_database * written if it is not 0.</td>
* read-only.
*
* This field is written if it is not 0.</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>table_map_for_update</td> * <td>table_map_for_update</td>
* <td>Q_TABLE_MAP_FOR_UPDATE_CODE == 9</td> * <td>Q_TABLE_MAP_FOR_UPDATE_CODE == 9</td>
* <td>8 byte integer</td> * <td>8 byte integer</td>
*
* <td>The value of the table map that is to be updated by the multi-table * <td>The value of the table map that is to be updated by the multi-table
* update query statement. Every bit of this variable represents a table, and is * update query statement. Every bit of this variable represents a table, and is
* set to 1 if the corresponding table is to be updated by this statement. * set to 1 if the corresponding table is to be updated by this statement. The
* * value of this variable is set when executing a multi-table update statement
* The value of this variable is set when executing a multi-table update * and used by slave to apply filter rules without opening all the tables on
* statement and used by slave to apply filter rules without opening all the * slave. This is required because some tables may not exist on slave because of
* tables on slave. This is required because some tables may not exist on slave * the filter rules.</td>
* because of the filter rules.</td>
* </tr> * </tr>
* </table> * </table>
* * Query_log_event_notes_on_previous_versions Notes on Previous Versions Status
* Query_log_event_notes_on_previous_versions Notes on Previous Versions * vars were introduced in version 5.0. To read earlier versions correctly,
* * check the length of the Post-Header. The status variable Q_CATALOG_CODE == 2
* Status vars were introduced in version 5.0. To read earlier versions * existed in MySQL 5.0.x, where 0<=x<=3. It was identical to Q_CATALOG_CODE,
* correctly, check the length of the Post-Header. * except that the string had a trailing '\0'. The '\0' was removed in 5.0.4
* * since it was redundant (the string length is stored before the string). The
* The status variable Q_CATALOG_CODE == 2 existed in MySQL 5.0.x, where * Q_CATALOG_CODE will never be written by a new master, but can still be
* 0<=x<=3. It was identical to Q_CATALOG_CODE, except that the string had a * understood by a new slave. See Q_CHARSET_DATABASE_CODE in the table above.
* trailing '\0'. The '\0' was removed in 5.0.4 since it was redundant (the
* string length is stored before the string). The Q_CATALOG_CODE will never be
* written by a new master, but can still be understood by a new slave.
*
* See Q_CHARSET_DATABASE_CODE in the table above.
*
* When adding new status vars, please don't forget to update the * When adding new status vars, please don't forget to update the
* MAX_SIZE_LOG_EVENT_STATUS, and update function code_name * MAX_SIZE_LOG_EVENT_STATUS, and update function code_name
* *
* @see mysql-5.1.6/sql/logevent.cc - Query_log_event * @see mysql-5.1.6/sql/logevent.cc - Query_log_event
*
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public class QueryLogEvent extends LogEvent public class QueryLogEvent extends LogEvent {
{
/** /**
The maximum number of updated databases that a status of * The maximum number of updated databases that a status of Query-log-event
Query-log-event can carry. It can redefined within a range * can carry. It can redefined within a range [1..
[1.. OVER_MAX_DBS_IN_EVENT_MTS]. * OVER_MAX_DBS_IN_EVENT_MTS].
*/ */
public static final int MAX_DBS_IN_EVENT_MTS = 16; public static final int MAX_DBS_IN_EVENT_MTS = 16;
/** /**
When the actual number of databases exceeds MAX_DBS_IN_EVENT_MTS * When the actual number of databases exceeds MAX_DBS_IN_EVENT_MTS the
the value of OVER_MAX_DBS_IN_EVENT_MTS is is put into the * value of OVER_MAX_DBS_IN_EVENT_MTS is is put into the mts_accessed_dbs
mts_accessed_dbs status. * status.
*/ */
public static final int OVER_MAX_DBS_IN_EVENT_MTS = 254; public static final int OVER_MAX_DBS_IN_EVENT_MTS = 254;
public static final int SYSTEM_CHARSET_MBMAXLEN = 3; public static final int SYSTEM_CHARSET_MBMAXLEN = 3;
public static final int NAME_CHAR_LEN = 64; public static final int NAME_CHAR_LEN = 64;
/* Field/table name length */ /* Field/table name length */
@@ -340,23 +281,68 @@ public class QueryLogEvent extends LogEvent
* log_event status vars estimation: * log_event status vars estimation:
*/ */
public static final int MAX_SIZE_LOG_EVENT_STATUS = (1 + 4 /* type, flags2 */ public static final int MAX_SIZE_LOG_EVENT_STATUS = (1 + 4 /* type, flags2 */
+ 1 + 8 /* type, sql_mode */ + 1 + 8 /*
+ 1 + 1 + 255 /* type, length, catalog */ * type,
+ 1 + 4 /* type, auto_increment */ * sql_mode
+ 1 + 6 /* type, charset */ */
+ 1 + 1 + 255 /* type, length, time_zone */ + 1 + 1 + 255 /*
+ 1 + 2 /* type, lc_time_names_number */ * type,
+ 1 + 2 /* type, charset_database_number */ * length
+ 1 + 8 /* type, table_map_for_update */ * ,
+ 1 + 4 /* type, master_data_written */ * catalog
/* type, db_1, db_2, ... */ */
/* type, microseconds */ + 1 + 4 /*
/* MariaDb type, sec_part of NOW() */ * type,
+ 1 + (MAX_DBS_IN_EVENT_MTS * (1 + NAME_LEN)) + 3 * auto_increment
+ 1 + 16 + 1 + 60/* type, user_len, user, host_len, host */); */
+ 1 + 6 /*
* type,
* charset
*/
+ 1 + 1 + 255 /*
* type,
* length
* ,
* time_zone
*/
+ 1 + 2 /*
* type,
* lc_time_names_number
*/
+ 1 + 2 /*
* type,
* charset_database_number
*/
+ 1 + 8 /*
* type,
* table_map_for_update
*/
+ 1 + 4 /*
* type,
* master_data_written
*/
/*
* type, db_1, db_2,
* ...
*/
/* type, microseconds */
/*
* MariaDb type,
* sec_part of NOW()
*/
+ 1 + (MAX_DBS_IN_EVENT_MTS * (1 + NAME_LEN)) + 3 + 1 + 16 + 1 + 60/*
* type
* ,
* user_len
* ,
* user
* ,
* host_len
* ,
* host
*/);
/** /**
* Fixed data part: * Fixed data part:
*
* <ul> * <ul>
* <li>4 bytes. The ID of the thread that issued this statement. Needed for * <li>4 bytes. The ID of the thread that issued this statement. Needed for
* temporary tables. This is also useful for a DBA for knowing who did what * temporary tables. This is also useful for a DBA for knowing who did what
@@ -385,7 +371,6 @@ public class QueryLogEvent extends LogEvent
* <li>2 bytes (not present in v1, v3). The length of the status variable * <li>2 bytes (not present in v1, v3). The length of the status variable
* block.</li> * block.</li>
* </ul> * </ul>
*
* Variable part: * Variable part:
* <ul> * <ul>
* <li>Zero or more status variables (not present in v1, v3). Each status * <li>Zero or more status variables (not present in v1, v3). Each status
@@ -397,7 +382,6 @@ public class QueryLogEvent extends LogEvent
* the variable part (the sizes are given in the fixed data part), so by * the variable part (the sizes are given in the fixed data part), so by
* subtraction it can know the size of the statement.</li> * subtraction it can know the size of the statement.</li>
* </ul> * </ul>
*
* Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log * Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log
*/ */
private String user; private String user;
@@ -409,10 +393,11 @@ public class QueryLogEvent extends LogEvent
protected final String dbname; protected final String dbname;
/** The number of seconds the query took to run on the master. */ /** The number of seconds the query took to run on the master. */
// The time in seconds that the statement took to execute. Only useful for inspection by the DBA // The time in seconds that the statement took to execute. Only useful for
// 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
@@ -434,9 +419,8 @@ public class QueryLogEvent extends LogEvent
private String timezone; private String timezone;
public QueryLogEvent(LogHeader header, LogBuffer buffer, public QueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
FormatDescriptionLogEvent descriptionEvent) throws IOException throws IOException{
{
super(header); super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int commonHeaderLen = descriptionEvent.commonHeaderLen;
@@ -447,8 +431,7 @@ public class QueryLogEvent extends LogEvent
* format-tolerant. We use QUERY_HEADER_MINIMAL_LEN which is the same * format-tolerant. We use QUERY_HEADER_MINIMAL_LEN which is the same
* for 3.23, 4.0 & 5.0. * for 3.23, 4.0 & 5.0.
*/ */
if (buffer.limit() < (commonHeaderLen + postHeaderLen)) if (buffer.limit() < (commonHeaderLen + postHeaderLen)) {
{
throw new IOException("Query event length is too short."); throw new IOException("Query event length is too short.");
} }
int dataLen = buffer.limit() - (commonHeaderLen + postHeaderLen); int dataLen = buffer.limit() - (commonHeaderLen + postHeaderLen);
@@ -462,24 +445,21 @@ public class QueryLogEvent extends LogEvent
errorCode = buffer.getUint16(); // Q_ERR_CODE_OFFSET errorCode = buffer.getUint16(); // Q_ERR_CODE_OFFSET
/* /*
* 5.0 format starts here. Depending on the format, we may or not * 5.0 format starts here. Depending on the format, we may or not have
* have affected/warnings etc The remaining post-header to be parsed * affected/warnings etc The remaining post-header to be parsed has
* has length: * length:
*/ */
int statusVarsLen = 0; int statusVarsLen = 0;
if (postHeaderLen > QUERY_HEADER_MINIMAL_LEN) if (postHeaderLen > QUERY_HEADER_MINIMAL_LEN) {
{
statusVarsLen = buffer.getUint16(); // Q_STATUS_VARS_LEN_OFFSET statusVarsLen = buffer.getUint16(); // Q_STATUS_VARS_LEN_OFFSET
/* /*
Check if status variable length is corrupt and will lead to very * Check if status variable length is corrupt and will lead to very
wrong data. We could be even more strict and require data_len to * wrong data. We could be even more strict and require data_len to
be even bigger, but this will suffice to catch most corruption * be even bigger, but this will suffice to catch most corruption
errors that can lead to a crash. * errors that can lead to a crash.
*/ */
if (statusVarsLen > Math.min(dataLen, MAX_SIZE_LOG_EVENT_STATUS)) if (statusVarsLen > Math.min(dataLen, MAX_SIZE_LOG_EVENT_STATUS)) {
{ throw new IOException("status_vars_len (" + statusVarsLen + ") > data_len (" + dataLen + ")");
throw new IOException("status_vars_len (" + statusVarsLen
+ ") > data_len (" + dataLen + ")");
} }
dataLen -= statusVarsLen; dataLen -= statusVarsLen;
} }
@@ -489,7 +469,7 @@ public class QueryLogEvent extends LogEvent
* dedicated to derived events (e.g. Execute_load_query...) * dedicated to derived events (e.g. Execute_load_query...)
*/ */
/* variable-part: the status vars; only in MySQL 5.0 */ /* variable-part: the status vars; only in MySQL 5.0 */
final int start = commonHeaderLen + postHeaderLen; final int start = commonHeaderLen + postHeaderLen;
final int limit = buffer.limit(); /* for restore */ final int limit = buffer.limit(); /* for restore */
final int end = start + statusVarsLen; final int end = start + statusVarsLen;
@@ -501,27 +481,19 @@ public class QueryLogEvent extends LogEvent
/* A 2nd variable part; this is common to all versions */ /* A 2nd variable part; this is common to all versions */
final int queryLen = dataLen - dbLen - 1; final int queryLen = dataLen - dbLen - 1;
dbname = buffer.getFixString(dbLen + 1); dbname = buffer.getFixString(dbLen + 1);
if (clientCharset >= 0) if (clientCharset >= 0) {
{
charsetName = CharsetConversion.getJavaCharset(clientCharset); charsetName = CharsetConversion.getJavaCharset(clientCharset);
if ((charsetName != null) && (Charset.isSupported(charsetName))) if ((charsetName != null) && (Charset.isSupported(charsetName))) {
{
query = buffer.getFixString(queryLen, charsetName); query = buffer.getFixString(queryLen, charsetName);
} } else {
else logger.warn("unsupported character set in query log: " + "\n ID = " + clientCharset + ", Charset = "
{ + CharsetConversion.getCharset(clientCharset) + ", Collation = "
logger.warn("unsupported character set in query log: " + CharsetConversion.getCollation(clientCharset));
+ "\n ID = " + clientCharset + ", Charset = "
+ CharsetConversion.getCharset(clientCharset)
+ ", Collation = "
+ CharsetConversion.getCollation(clientCharset));
query = buffer.getFixString(queryLen); query = buffer.getFixString(queryLen);
} }
} } else {
else
{
query = buffer.getFixString(queryLen); query = buffer.getFixString(queryLen);
} }
} }
@@ -567,215 +539,198 @@ public class QueryLogEvent extends LogEvent
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 * total number and their names to be propagated to the slave in order to
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;
/** /**
* 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) private final void unpackVariables(LogBuffer buffer, final int end) throws IOException {
throws IOException
{
int code = -1; int code = -1;
try try {
{ while (buffer.position() < end) {
while (buffer.position() < end) switch (code = buffer.getUint8()) {
{ case Q_FLAGS2_CODE:
switch (code = buffer.getUint8()) flags2 = buffer.getUint32();
{
case Q_FLAGS2_CODE:
flags2 = buffer.getUint32();
break;
case Q_SQL_MODE_CODE:
sql_mode = buffer.getLong64(); // QQ: Fix when sql_mode is ulonglong
break;
case Q_CATALOG_NZ_CODE:
catalog = buffer.getString();
break;
case Q_AUTO_INCREMENT:
autoIncrementIncrement = buffer.getUint16();
autoIncrementOffset = buffer.getUint16();
break;
case Q_CHARSET_CODE:
// Charset: 6 byte character set flag.
// 1-2 = character set client
// 3-4 = collation client
// 5-6 = collation server
clientCharset = buffer.getUint16();
clientCollation = buffer.getUint16();
serverCollation = buffer.getUint16();
break;
case Q_TIME_ZONE_CODE:
timezone = buffer.getString();
break;
case Q_CATALOG_CODE: /* for 5.0.x where 0<=x<=3 masters */
final int len = buffer.getUint8();
catalog = buffer.getFixString(len + 1);
break;
case Q_LC_TIME_NAMES_CODE:
// lc_time_names_number = buffer.getUint16();
buffer.forward(2);
break;
case Q_CHARSET_DATABASE_CODE:
// charset_database_number = buffer.getUint16();
buffer.forward(2);
break;
case Q_TABLE_MAP_FOR_UPDATE_CODE:
// table_map_for_update = buffer.getUlong64();
buffer.forward(8);
break;
case Q_MASTER_DATA_WRITTEN_CODE:
// data_written = master_data_written = buffer.getUint32();
buffer.forward(4);
break;
case Q_INVOKER:
user = buffer.getString();
host = buffer.getString();
break;
case Q_MICROSECONDS:
// when.tv_usec= uint3korr(pos);
buffer.forward(3);
break;
case Q_UPDATED_DB_NAMES:
int mtsAccessedDbs = buffer.getUint8();
/**
Notice, the following check is positive also in case of
the master's MAX_DBS_IN_EVENT_MTS > the slave's one and the event
contains e.g the master's MAX_DBS_IN_EVENT_MTS db:s.
*/
if (mtsAccessedDbs > MAX_DBS_IN_EVENT_MTS) {
mtsAccessedDbs = OVER_MAX_DBS_IN_EVENT_MTS;
break; break;
} case Q_SQL_MODE_CODE:
String mtsAccessedDbNames[] = new String[mtsAccessedDbs]; sql_mode = buffer.getLong64(); // QQ: Fix when sql_mode
for (int i = 0; i < mtsAccessedDbs && buffer.position() < end; i++) { // is ulonglong
int length = end - buffer.position(); break;
mtsAccessedDbNames[i] = buffer.getFixString(length < NAME_LEN ? length : NAME_LEN); case Q_CATALOG_NZ_CODE:
} catalog = buffer.getString();
break; break;
case Q_HRNOW: case Q_AUTO_INCREMENT:
// int when_sec_part = buffer.getUint24(); autoIncrementIncrement = buffer.getUint16();
buffer.forward(3); autoIncrementOffset = buffer.getUint16();
break; break;
default: case Q_CHARSET_CODE:
/* That's why you must write status vars in growing order of code */ // Charset: 6 byte character set flag.
if (logger.isDebugEnabled()) // 1-2 = character set client
logger.debug("Query_log_event has unknown status vars (first has code: " // 3-4 = collation client
+ code + "), skipping the rest of them"); // 5-6 = collation server
break; // Break loop clientCharset = buffer.getUint16();
clientCollation = buffer.getUint16();
serverCollation = buffer.getUint16();
break;
case Q_TIME_ZONE_CODE:
timezone = buffer.getString();
break;
case Q_CATALOG_CODE: /* for 5.0.x where 0<=x<=3 masters */
final int len = buffer.getUint8();
catalog = buffer.getFixString(len + 1);
break;
case Q_LC_TIME_NAMES_CODE:
// lc_time_names_number = buffer.getUint16();
buffer.forward(2);
break;
case Q_CHARSET_DATABASE_CODE:
// charset_database_number = buffer.getUint16();
buffer.forward(2);
break;
case Q_TABLE_MAP_FOR_UPDATE_CODE:
// table_map_for_update = buffer.getUlong64();
buffer.forward(8);
break;
case Q_MASTER_DATA_WRITTEN_CODE:
// data_written = master_data_written =
// buffer.getUint32();
buffer.forward(4);
break;
case Q_INVOKER:
user = buffer.getString();
host = buffer.getString();
break;
case Q_MICROSECONDS:
// when.tv_usec= uint3korr(pos);
buffer.forward(3);
break;
case Q_UPDATED_DB_NAMES:
int mtsAccessedDbs = buffer.getUint8();
/**
* Notice, the following check is positive also in case
* of the master's MAX_DBS_IN_EVENT_MTS > the slave's
* one and the event contains e.g the master's
* MAX_DBS_IN_EVENT_MTS db:s.
*/
if (mtsAccessedDbs > MAX_DBS_IN_EVENT_MTS) {
mtsAccessedDbs = OVER_MAX_DBS_IN_EVENT_MTS;
break;
}
String mtsAccessedDbNames[] = new String[mtsAccessedDbs];
for (int i = 0; i < mtsAccessedDbs && buffer.position() < end; i++) {
int length = end - buffer.position();
mtsAccessedDbNames[i] = buffer.getFixString(length < NAME_LEN ? length : NAME_LEN);
}
break;
case Q_HRNOW:
// int when_sec_part = buffer.getUint24();
buffer.forward(3);
break;
default:
/*
* That's why you must write status vars in growing
* order of code
*/
if (logger.isDebugEnabled()) logger.debug("Query_log_event has unknown status vars (first has code: "
+ code + "), skipping the rest of them");
break; // Break loop
} }
} }
} } catch (RuntimeException e) {
catch (RuntimeException e) throw new IOException("Read " + findCodeName(code) + " error: " + e.getMessage(), e);
{
throw new IOException("Read " + findCodeName(code) + " error: "
+ e.getMessage(), e);
} }
} }
private static final String findCodeName(final int code) private static final String findCodeName(final int code) {
{ switch (code) {
switch (code) case Q_FLAGS2_CODE:
{ return "Q_FLAGS2_CODE";
case Q_FLAGS2_CODE: case Q_SQL_MODE_CODE:
return "Q_FLAGS2_CODE"; return "Q_SQL_MODE_CODE";
case Q_SQL_MODE_CODE: case Q_CATALOG_CODE:
return "Q_SQL_MODE_CODE"; return "Q_CATALOG_CODE";
case Q_CATALOG_CODE: case Q_AUTO_INCREMENT:
return "Q_CATALOG_CODE"; return "Q_AUTO_INCREMENT";
case Q_AUTO_INCREMENT: case Q_CHARSET_CODE:
return "Q_AUTO_INCREMENT"; return "Q_CHARSET_CODE";
case Q_CHARSET_CODE: case Q_TIME_ZONE_CODE:
return "Q_CHARSET_CODE"; return "Q_TIME_ZONE_CODE";
case Q_TIME_ZONE_CODE: case Q_CATALOG_NZ_CODE:
return "Q_TIME_ZONE_CODE"; return "Q_CATALOG_NZ_CODE";
case Q_CATALOG_NZ_CODE: case Q_LC_TIME_NAMES_CODE:
return "Q_CATALOG_NZ_CODE"; return "Q_LC_TIME_NAMES_CODE";
case Q_LC_TIME_NAMES_CODE: case Q_CHARSET_DATABASE_CODE:
return "Q_LC_TIME_NAMES_CODE"; return "Q_CHARSET_DATABASE_CODE";
case Q_CHARSET_DATABASE_CODE: case Q_TABLE_MAP_FOR_UPDATE_CODE:
return "Q_CHARSET_DATABASE_CODE"; return "Q_TABLE_MAP_FOR_UPDATE_CODE";
case Q_TABLE_MAP_FOR_UPDATE_CODE: case Q_MASTER_DATA_WRITTEN_CODE:
return "Q_TABLE_MAP_FOR_UPDATE_CODE"; return "Q_MASTER_DATA_WRITTEN_CODE";
case Q_MASTER_DATA_WRITTEN_CODE: case Q_UPDATED_DB_NAMES:
return "Q_MASTER_DATA_WRITTEN_CODE"; return "Q_UPDATED_DB_NAMES";
case Q_UPDATED_DB_NAMES: case Q_MICROSECONDS:
return "Q_UPDATED_DB_NAMES"; return "Q_MICROSECONDS";
case Q_MICROSECONDS:
return "Q_MICROSECONDS";
} }
return "CODE#" + code; return "CODE#" + code;
} }
public final String getUser() public final String getUser() {
{
return user; return user;
} }
public final String getHost() public final String getHost() {
{
return host; return host;
} }
public final String getQuery() public final String getQuery() {
{
return query; return query;
} }
public final String getCatalog() public final String getCatalog() {
{
return catalog; return catalog;
} }
public final String getDbName() public final String getDbName() {
{
return dbname; return dbname;
} }
/** /**
* The number of seconds the query took to run on the master. * The number of seconds the query took to run on the master.
*/ */
public final long getExecTime() public final long getExecTime() {
{
return execTime; return execTime;
} }
public final int getErrorCode() public final int getErrorCode() {
{
return errorCode; return errorCode;
} }
public final long getSessionId() public final long getSessionId() {
{
return sessionId; return sessionId;
} }
public final long getAutoIncrementIncrement() public final long getAutoIncrementIncrement() {
{
return autoIncrementIncrement; return autoIncrementIncrement;
} }
public final long getAutoIncrementOffset() public final long getAutoIncrementOffset() {
{
return autoIncrementOffset; return autoIncrementOffset;
} }
public final String getCharsetName() public final String getCharsetName() {
{
return charsetName; return charsetName;
} }
public final String getTimezone() public final String getTimezone() {
{
return timezone; return timezone;
} }
@@ -784,8 +739,7 @@ public class QueryLogEvent extends LogEvent
* *
* @return Returns the charsetID. * @return Returns the charsetID.
*/ */
public final int getClientCharset() public final int getClientCharset() {
{
return clientCharset; return clientCharset;
} }
@@ -794,8 +748,7 @@ public class QueryLogEvent extends LogEvent
* *
* @return Returns the clientCollationId. * @return Returns the clientCollationId.
*/ */
public final int getClientCollation() public final int getClientCollation() {
{
return clientCollation; return clientCollation;
} }
@@ -804,19 +757,16 @@ public class QueryLogEvent extends LogEvent
* *
* @return Returns the serverCollationId. * @return Returns the serverCollationId.
*/ */
public final int getServerCollation() public final int getServerCollation() {
{
return serverCollation; return serverCollation;
} }
/** /**
* Returns the sql_mode value. * Returns the sql_mode value.
*
* <p> * <p>
* The sql_mode variable. See the section "SQL Modes" in the MySQL manual, * The sql_mode variable. See the section "SQL Modes" in the MySQL manual,
* and see mysql_priv.h for a list of the possible flags. Currently * and see mysql_priv.h for a list of the possible flags. Currently
* (2007-10-04), the following flags are available: * (2007-10-04), the following flags are available:
*
* <ul> * <ul>
* <li>MODE_REAL_AS_FLOAT==0x1</li> * <li>MODE_REAL_AS_FLOAT==0x1</li>
* <li>MODE_PIPES_AS_CONCAT==0x2</li> * <li>MODE_PIPES_AS_CONCAT==0x2</li>
@@ -851,14 +801,12 @@ public class QueryLogEvent extends LogEvent
* <li>MODE_NO_ENGINE_SUBSTITUTION=0x40000000</li> * <li>MODE_NO_ENGINE_SUBSTITUTION=0x40000000</li>
* <li>MODE_PAD_CHAR_TO_FULL_LENGTH==0x80000000</li> * <li>MODE_PAD_CHAR_TO_FULL_LENGTH==0x80000000</li>
* </ul> * </ul>
*
* All these flags are replicated from the server. However, all flags except * All these flags are replicated from the server. However, all flags except
* MODE_NO_DIR_IN_CREATE are honored by the slave; the slave always * MODE_NO_DIR_IN_CREATE are honored by the slave; the slave always
* preserves its old value of MODE_NO_DIR_IN_CREATE. This field is always * preserves its old value of MODE_NO_DIR_IN_CREATE. This field is always
* written to the binlog. * written to the binlog.
*/ */
public final long getSqlMode() public final long getSqlMode() {
{
return sql_mode; return sql_mode;
} }
@@ -880,40 +828,35 @@ public class QueryLogEvent extends LogEvent
* Manual. This field is always written to the binlog in version >= 5.0, and * Manual. This field is always written to the binlog in version >= 5.0, and
* never written in version < 5.0. * never written in version < 5.0.
*/ */
public final long getFlags2() public final long getFlags2() {
{
return flags2; return flags2;
} }
/** /**
* Returns the OPTION_AUTO_IS_NULL flag. * Returns the OPTION_AUTO_IS_NULL flag.
*/ */
public final boolean isAutoIsNull() public final boolean isAutoIsNull() {
{
return ((flags2 & OPTION_AUTO_IS_NULL) == OPTION_AUTO_IS_NULL); return ((flags2 & OPTION_AUTO_IS_NULL) == OPTION_AUTO_IS_NULL);
} }
/** /**
* Returns the OPTION_NO_FOREIGN_KEY_CHECKS flag. * Returns the OPTION_NO_FOREIGN_KEY_CHECKS flag.
*/ */
public final boolean isForeignKeyChecks() public final boolean isForeignKeyChecks() {
{
return ((flags2 & OPTION_NO_FOREIGN_KEY_CHECKS) != OPTION_NO_FOREIGN_KEY_CHECKS); return ((flags2 & OPTION_NO_FOREIGN_KEY_CHECKS) != OPTION_NO_FOREIGN_KEY_CHECKS);
} }
/** /**
* Returns the OPTION_NOT_AUTOCOMMIT flag. * Returns the OPTION_NOT_AUTOCOMMIT flag.
*/ */
public final boolean isAutocommit() public final boolean isAutocommit() {
{
return ((flags2 & OPTION_NOT_AUTOCOMMIT) != OPTION_NOT_AUTOCOMMIT); return ((flags2 & OPTION_NOT_AUTOCOMMIT) != OPTION_NOT_AUTOCOMMIT);
} }
/** /**
* Returns the OPTION_NO_FOREIGN_KEY_CHECKS flag. * Returns the OPTION_NO_FOREIGN_KEY_CHECKS flag.
*/ */
public final boolean isUniqueChecks() public final boolean isUniqueChecks() {
{
return ((flags2 & OPTION_RELAXED_UNIQUE_CHECKS) != OPTION_RELAXED_UNIQUE_CHECKS); return ((flags2 & OPTION_RELAXED_UNIQUE_CHECKS) != OPTION_RELAXED_UNIQUE_CHECKS);
} }

View File

@@ -7,30 +7,21 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0. 4.1.1 * Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0. 4.1.1
* does not need it (it's repeatable again) so this event needn't be written in * does not need it (it's repeatable again) so this event needn't be written in
* 4.1.1 for PASSWORD() (but the fact that it is written is just a waste, it * 4.1.1 for PASSWORD() (but the fact that it is written is just a waste, it
* does not cause bugs). * does not cause bugs). The state of the random number generation consists of
* * 128 bits, which are stored internally as two 64-bit numbers. Binary Format
* The state of the random number generation consists of 128 bits, which are
* stored internally as two 64-bit numbers.
*
* Binary Format
*
* The Post-Header for this event type is empty. The Body has two components: * The Post-Header for this event type is empty. The Body has two components:
*
* <table> * <table>
* <caption>Body for Rand_log_event</caption> * <caption>Body for Rand_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>seed1</td> * <td>seed1</td>
* <td>8 byte unsigned integer</td> * <td>8 byte unsigned integer</td>
* <td>64 bit random seed1.</td> * <td>64 bit random seed1.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>seed2</td> * <td>seed2</td>
* <td>8 byte unsigned integer</td> * <td>8 byte unsigned integer</td>
@@ -41,19 +32,16 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class RandLogEvent extends LogEvent public final class RandLogEvent extends LogEvent {
{
/** /**
* Fixed data part: Empty * Fixed data part: Empty
*
* <p> * <p>
* Variable data part: * Variable data part:
*
* <ul> * <ul>
* <li>8 bytes. The value for the first seed.</li> * <li>8 bytes. The value for the first seed.</li>
* <li>8 bytes. The value for the second seed.</li> * <li>8 bytes. The value for the second seed.</li>
* </ul> * </ul>
*
* Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log * Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log
*/ */
private final long seed1; private final long seed1;
@@ -63,21 +51,17 @@ public final class RandLogEvent extends LogEvent
public static final int RAND_SEED1_OFFSET = 0; public static final int RAND_SEED1_OFFSET = 0;
public static final int RAND_SEED2_OFFSET = 8; public static final int RAND_SEED2_OFFSET = 8;
public RandLogEvent(LogHeader header, LogBuffer buffer, public RandLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
/* The Post-Header is empty. The Variable Data part begins immediately. */ /* The Post-Header is empty. The Variable Data part begins immediately. */
buffer.position(descriptionEvent.commonHeaderLen buffer.position(descriptionEvent.commonHeaderLen + descriptionEvent.postHeaderLen[RAND_EVENT - 1]
+ descriptionEvent.postHeaderLen[RAND_EVENT - 1] + RAND_SEED1_OFFSET);
+ RAND_SEED1_OFFSET);
seed1 = buffer.getLong64(); // !uint8korr(buf+RAND_SEED1_OFFSET); seed1 = buffer.getLong64(); // !uint8korr(buf+RAND_SEED1_OFFSET);
seed2 = buffer.getLong64(); // !uint8korr(buf+RAND_SEED2_OFFSET); seed2 = buffer.getLong64(); // !uint8korr(buf+RAND_SEED2_OFFSET);
} }
public final String getQuery() public final String getQuery() {
{
return "SET SESSION rand_seed1 = " + seed1 + " , rand_seed2 = " + seed2; return "SET SESSION rand_seed1 = " + seed1 + " , rand_seed2 = " + seed2;
} }
} }

View File

@@ -4,57 +4,44 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent; import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* This will be deprecated when we move to using sequence ids. * This will be deprecated when we move to using sequence ids. Binary Format The
* * Post-Header has one component:
* Binary Format
*
* The Post-Header has one component:
*
* <table> * <table>
* <caption>Post-Header for Rotate_log_event</caption> * <caption>Post-Header for Rotate_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>position</td> * <td>position</td>
* <td>8 byte integer</td> * <td>8 byte integer</td>
* <td>The position within the binlog to rotate to.</td> * <td>The position within the binlog to rotate to.</td>
* </tr> * </tr>
*
* </table> * </table>
*
* The Body has one component: * The Body has one component:
*
* <table> * <table>
* <caption>Body for Rotate_log_event</caption> * <caption>Body for Rotate_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>new_log</td> * <td>new_log</td>
* <td>variable length string without trailing zero, extending to the end of the * <td>variable length string without trailing zero, extending to the end of the
* event (determined by the length field of the Common-Header)</td> * event (determined by the length field of the Common-Header)</td>
* <td>Name of the binlog to rotate to.</td> * <td>Name of the binlog to rotate to.</td>
* </tr> * </tr>
*
* </table> * </table>
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class RotateLogEvent extends LogEvent public final class RotateLogEvent extends LogEvent {
{
/** /**
* Fixed data part: * Fixed data part:
*
* <ul> * <ul>
* <li>8 bytes. The position of the first event in the next log file. Always * <li>8 bytes. The position of the first event in the next log file. Always
* contains the number 4 (meaning the next event starts at position 4 in the * contains the number 4 (meaning the next event starts at position 4 in the
@@ -62,14 +49,11 @@ public final class RotateLogEvent extends LogEvent
* is assumed to be 4.</li> * is assumed to be 4.</li>
* </ul> * </ul>
* <p> * <p>
*
* Variable data part: * Variable data part:
*
* <ul> * <ul>
* <li>The name of the next binary log. The filename is not null-terminated. * <li>The name of the next binary log. The filename is not null-terminated.
* Its length is the event size minus the size of the fixed parts.</li> * Its length is the event size minus the size of the fixed parts.</li>
* </ul> * </ul>
*
* Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log * Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log
*/ */
private final String filename; private final String filename;
@@ -91,21 +75,20 @@ public final class RotateLogEvent extends LogEvent
* *
* @throws MySQLExtractException * @throws MySQLExtractException
*/ */
public RotateLogEvent(LogHeader header, LogBuffer buffer, public RotateLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int headerSize = descriptionEvent.commonHeaderLen; final int headerSize = descriptionEvent.commonHeaderLen;
final int postHeaderLen = descriptionEvent.postHeaderLen[ROTATE_EVENT - 1]; final int postHeaderLen = descriptionEvent.postHeaderLen[ROTATE_EVENT - 1];
buffer.position(headerSize + R_POS_OFFSET); buffer.position(headerSize + R_POS_OFFSET);
position = (postHeaderLen != 0) ? buffer.getLong64() : 4; // !uint8korr(buf + R_POS_OFFSET) position = (postHeaderLen != 0) ? buffer.getLong64() : 4; // !uint8korr(buf
// +
// R_POS_OFFSET)
final int filenameOffset = headerSize + postHeaderLen; final int filenameOffset = headerSize + postHeaderLen;
int filenameLen = buffer.limit() - filenameOffset; int filenameLen = buffer.limit() - filenameOffset;
if (filenameLen > FN_REFLEN - 1) if (filenameLen > FN_REFLEN - 1) filenameLen = FN_REFLEN - 1;
filenameLen = FN_REFLEN - 1;
buffer.position(filenameOffset); buffer.position(filenameOffset);
filename = buffer.getFixString(filenameLen); filename = buffer.getFixString(filenameLen);
} }
@@ -114,8 +97,7 @@ public final class RotateLogEvent extends LogEvent
* Creates a new <code>Rotate_log_event</code> without log information. This * Creates a new <code>Rotate_log_event</code> without log information. This
* is used to generate missing log rotation events. * is used to generate missing log rotation events.
*/ */
public RotateLogEvent(String filename) public RotateLogEvent(String filename){
{
super(ROTATE_HEADER); super(ROTATE_HEADER);
this.filename = filename; this.filename = filename;
@@ -125,21 +107,18 @@ public final class RotateLogEvent extends LogEvent
/** /**
* Creates a new <code>Rotate_log_event</code> without log information. * Creates a new <code>Rotate_log_event</code> without log information.
*/ */
public RotateLogEvent(String filename, final long position) public RotateLogEvent(String filename, final long position){
{
super(ROTATE_HEADER); super(ROTATE_HEADER);
this.filename = filename; this.filename = filename;
this.position = position; this.position = position;
} }
public final String getFilename() public final String getFilename() {
{
return filename; return filename;
} }
public final long getPosition() public final long getPosition() {
{
return position; return position;
} }
} }

View File

@@ -24,6 +24,7 @@ public final class RowsLogBuffer {
public static final long DATETIMEF_INT_OFS = 0x8000000000L; public static final long DATETIMEF_INT_OFS = 0x8000000000L;
public static final long TIMEF_INT_OFS = 0x800000L; public static final long TIMEF_INT_OFS = 0x800000L;
public static final long TIMEF_OFS = 0x800000000000L;
private final LogBuffer buffer; private final LogBuffer buffer;
private final int columnLen; private final int columnLen;
private final String charsetName; private final String charsetName;
@@ -437,14 +438,23 @@ public final class RowsLogBuffer {
break; break;
} }
String second = null;
if (tv_sec == 0) { if (tv_sec == 0) {
value = "0000-00-00 00:00:00"; second = "0000-00-00 00:00:00";
} else { } else {
Timestamp time = new Timestamp(tv_sec * 1000); Timestamp time = new Timestamp(tv_sec * 1000);
time.setNanos(tv_usec * 1000); second = time.toString();
String v = time.toString(); second = second.substring(0, second.length() - 2);// 去掉毫秒精度.0
value = v.substring(0, v.length() - 2);
} }
if (meta >= 1) {
String microSecond = usecondsToStr(tv_usec, meta);
microSecond = microSecond.substring(0, meta);
value = second + '.' + microSecond;
} else {
value = second;
}
javaType = Types.TIMESTAMP; javaType = Types.TIMESTAMP;
length = 4 + (meta + 1) / 2; length = 4 + (meta + 1) / 2;
break; break;
@@ -487,7 +497,6 @@ public final class RowsLogBuffer {
* .YYdddddh.hhhhmmmm.mmssssss.ffffffff.ffffffff.ffffffff * .YYdddddh.hhhhmmmm.mmssssss.ffffffff.ffffffff.ffffffff
*/ */
long intpart = buffer.getBeUlong40() - DATETIMEF_INT_OFS; // big-endian long intpart = buffer.getBeUlong40() - DATETIMEF_INT_OFS; // big-endian
@SuppressWarnings("unused")
int frac = 0; int frac = 0;
switch (meta) { switch (meta) {
case 0: case 0:
@@ -510,8 +519,9 @@ public final class RowsLogBuffer {
break; break;
} }
String second = null;
if (intpart == 0) { if (intpart == 0) {
value = "0000-00-00 00:00:00"; second = "0000-00-00 00:00:00";
} else { } else {
// 构造TimeStamp只处理到秒 // 构造TimeStamp只处理到秒
long ymd = intpart >> 17; long ymd = intpart >> 17;
@@ -524,7 +534,7 @@ public final class RowsLogBuffer {
// % (1 << 5)), (int) (hms >> 12), // % (1 << 5)), (int) (hms >> 12),
// (int) ((hms >> 6) % (1 << 6)), (int) (hms % (1 << 6))); // (int) ((hms >> 6) % (1 << 6)), (int) (hms % (1 << 6)));
// value = new Timestamp(cal.getTimeInMillis()); // value = new Timestamp(cal.getTimeInMillis());
value = String.format("%04d-%02d-%02d %02d:%02d:%02d", second = String.format("%04d-%02d-%02d %02d:%02d:%02d",
(int) (ym / 13), (int) (ym / 13),
(int) (ym % 13), (int) (ym % 13),
(int) (ymd % (1 << 5)), (int) (ymd % (1 << 5)),
@@ -532,6 +542,15 @@ public final class RowsLogBuffer {
(int) ((hms >> 6) % (1 << 6)), (int) ((hms >> 6) % (1 << 6)),
(int) (hms % (1 << 6))); (int) (hms % (1 << 6)));
} }
if (meta >= 1) {
String microSecond = usecondsToStr(frac, meta);
microSecond = microSecond.substring(0, meta);
value = second + '.' + microSecond;
} else {
value = second;
}
javaType = Types.TIMESTAMP; javaType = Types.TIMESTAMP;
length = 5 + (meta + 1) / 2; length = 5 + (meta + 1) / 2;
break; break;
@@ -603,7 +622,8 @@ public final class RowsLogBuffer {
frac -= 0x100; /* -(0x100 - frac) */ frac -= 0x100; /* -(0x100 - frac) */
// fraclong = frac * 10000; // fraclong = frac * 10000;
} }
ltime = intpart << 24 + frac * 10000; frac = frac * 10000;
ltime = intpart << 24;
break; break;
case 3: case 3:
case 4: case 4:
@@ -619,12 +639,14 @@ public final class RowsLogBuffer {
frac -= 0x10000; /* -(0x10000-frac) */ frac -= 0x10000; /* -(0x10000-frac) */
// fraclong = frac * 100; // fraclong = frac * 100;
} }
ltime = intpart << 24 + frac * 100; frac = frac * 100;
ltime = intpart << 24;
break; break;
case 5: case 5:
case 6: case 6:
intpart = buffer.getBeUlong48() - TIMEF_INT_OFS; intpart = buffer.getBeUlong48() - TIMEF_OFS;
ltime = intpart; ltime = intpart;
frac = (int) (intpart % (1L << 24));
break; break;
default: default:
intpart = buffer.getBeUint24() - TIMEF_INT_OFS; intpart = buffer.getBeUint24() - TIMEF_INT_OFS;
@@ -632,8 +654,9 @@ public final class RowsLogBuffer {
break; break;
} }
String second = null;
if (intpart == 0) { if (intpart == 0) {
value = "00:00:00"; second = "00:00:00";
} else { } else {
// 目前只记录秒,不处理us frac // 目前只记录秒,不处理us frac
// if (cal == null) cal = Calendar.getInstance(); // if (cal == null) cal = Calendar.getInstance();
@@ -644,13 +667,21 @@ public final class RowsLogBuffer {
// value = new Time(cal.getTimeInMillis()); // value = new Time(cal.getTimeInMillis());
long ultime = Math.abs(ltime); long ultime = Math.abs(ltime);
intpart = ultime >> 24; intpart = ultime >> 24;
value = String.format("%s%02d:%02d:%02d", second = String.format("%s%02d:%02d:%02d",
ltime >= 0 ? "" : "-", ltime >= 0 ? "" : "-",
(int) ((intpart >> 12) % (1 << 10)), (int) ((intpart >> 12) % (1 << 10)),
(int) ((intpart >> 6) % (1 << 6)), (int) ((intpart >> 6) % (1 << 6)),
(int) (intpart % (1 << 6))); (int) (intpart % (1 << 6)));
} }
if (meta >= 1) {
String microSecond = usecondsToStr(Math.abs(frac), meta);
microSecond = microSecond.substring(0, meta);
value = second + '.' + microSecond;
} else {
value = second;
}
javaType = Types.TIME; javaType = Types.TIME;
length = 3 + (meta + 1) / 2; length = 3 + (meta + 1) / 2;
break; break;
@@ -973,4 +1004,23 @@ public final class RowsLogBuffer {
public final int getLength() { public final int getLength() {
return length; return length;
} }
private String usecondsToStr(int frac, int meta) {
String sec = String.valueOf(frac);
if (meta > 6) {
throw new IllegalArgumentException("unknow useconds meta : " + meta);
}
if (sec.length() < 6) {
StringBuilder result = new StringBuilder(6);
int len = 6 - sec.length();
for (; len > 0; len--) {
result.append('0');
}
result.append(sec);
sec = result.toString();
}
return sec.substring(0, meta);
}
} }

View File

@@ -12,41 +12,33 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public abstract class RowsLogEvent extends LogEvent public abstract class RowsLogEvent extends LogEvent {
{
/** /**
* Fixed data part: * Fixed data part:
*
* <ul> * <ul>
* <li>6 bytes. The table ID.</li> * <li>6 bytes. The table ID.</li>
* <li>2 bytes. Reserved for future use.</li> * <li>2 bytes. Reserved for future use.</li>
* </ul> * </ul>
*
* <p> * <p>
* Variable data part: * Variable data part:
*
* <ul> * <ul>
* <li>Packed integer. The number of columns in the table.</li> * <li>Packed integer. The number of columns in the table.</li>
*
* <li>Variable-sized. Bit-field indicating whether each column is used, one * <li>Variable-sized. Bit-field indicating whether each column is used, one
* bit per column. For this field, the amount of storage required for N * bit per column. For this field, the amount of storage required for N
* columns is INT((N+7)/8) bytes.</li> * columns is INT((N+7)/8) bytes.</li>
*
* <li>Variable-sized (for UPDATE_ROWS_LOG_EVENT only). Bit-field indicating * <li>Variable-sized (for UPDATE_ROWS_LOG_EVENT only). Bit-field indicating
* whether each column is used in the UPDATE_ROWS_LOG_EVENT after-image; one * whether each column is used in the UPDATE_ROWS_LOG_EVENT after-image; one
* bit per column. For this field, the amount of storage required for N * bit per column. For this field, the amount of storage required for N
* columns is INT((N+7)/8) bytes.</li> * columns is INT((N+7)/8) bytes.</li>
*
* <li>Variable-sized. A sequence of zero or more rows. The end is * <li>Variable-sized. A sequence of zero or more rows. The end is
* determined by the size of the event. Each row has the following format: * determined by the size of the event. Each row has the following format:
*
* <ul> * <ul>
* <li>Variable-sized. Bit-field indicating whether each field in the row is * <li>Variable-sized. Bit-field indicating whether each field in the row is
* NULL. Only columns that are "used" according to the second field in the * NULL. Only columns that are "used" according to the second field in the
* variable data part are listed here. If the second field in the variable * variable data part are listed here. If the second field in the variable
* data part has N one-bits, the amount of storage required for this field * data part has N one-bits, the amount of storage required for this field
* is INT((N+7)/8) bytes.</li> * is INT((N+7)/8) bytes.</li>
*
* <li>Variable-sized. The row-image, containing values of all table fields. * <li>Variable-sized. The row-image, containing values of all table fields.
* This only lists table fields that are used (according to the second field * This only lists table fields that are used (according to the second field
* of the variable data part) and non-NULL (according to the previous * of the variable data part) and non-NULL (according to the previous
@@ -54,16 +46,18 @@ public abstract class RowsLogEvent extends LogEvent
* number of zero bits in the previous field (not counting padding bits in * number of zero bits in the previous field (not counting padding bits in
* the last byte). The format of each value is described in the * the last byte). The format of each value is described in the
* log_event_print_value() function in log_event.cc.</li> * log_event_print_value() function in log_event.cc.</li>
*
* <li>(for UPDATE_ROWS_EVENT only) the previous two fields are repeated, * <li>(for UPDATE_ROWS_EVENT only) the previous two fields are repeated,
* representing a second table row.</li> * representing a second table row.</li>
* </ul> * </ul>
* </ul> * </ul>
*
* Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log * Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log
*/ */
private final long tableId; /* Table ID */ private final long tableId; /* Table ID */
private TableMapLogEvent table; /* The table the rows belong to */ private TableMapLogEvent table; /*
* The table
* the rows
* belong to
*/
/** Bitmap denoting columns available */ /** Bitmap denoting columns available */
protected final int columnLen; protected final int columnLen;
@@ -78,15 +72,17 @@ public abstract class RowsLogEvent extends LogEvent
protected final BitSet changeColumns; protected final BitSet changeColumns;
/** XXX: Don't handle buffer in another thread. */ /** XXX: Don't handle buffer in another thread. */
private final LogBuffer rowsBuf; /* The rows in packed format */ private final LogBuffer rowsBuf; /*
* The rows in
* packed
* format
*/
/** /**
* enum enum_flag * enum enum_flag These definitions allow you to combine the flags into an
* * appropriate flag set using the normal bitwise operators. The implicit
* These definitions allow you to combine the flags into an appropriate flag * conversion from an enum-constant to an integer is accepted by the
* set using the normal bitwise operators. The implicit conversion from an * compiler, which is then used to set the real set of flags.
* enum-constant to an integer is accepted by the compiler, which is then
* used to set the real set of flags.
*/ */
private final int flags; private final int flags;
@@ -112,43 +108,40 @@ public abstract class RowsLogEvent extends LogEvent
public static final int RW_V_TAG_LEN = 1; public static final int RW_V_TAG_LEN = 1;
public static final int RW_V_EXTRAINFO_TAG = 0; public static final int RW_V_EXTRAINFO_TAG = 0;
public RowsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
public RowsLogEvent(LogHeader header, LogBuffer buffer,
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int commonHeaderLen = descriptionEvent.commonHeaderLen;
final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];
int headerLen = 0; int headerLen = 0;
buffer.position(commonHeaderLen + RW_MAPID_OFFSET); buffer.position(commonHeaderLen + RW_MAPID_OFFSET);
if (postHeaderLen == 6) if (postHeaderLen == 6) {
{ /*
/* Master is of an intermediate source tree before 5.1.4. Id is 4 bytes */ * Master is of an intermediate source tree before 5.1.4. Id is 4
* bytes
*/
tableId = buffer.getUint32(); tableId = buffer.getUint32();
} } else {
else
{
tableId = buffer.getUlong48(); // RW_FLAGS_OFFSET tableId = buffer.getUlong48(); // RW_FLAGS_OFFSET
} }
flags = buffer.getUint16(); flags = buffer.getUint16();
if (postHeaderLen == FormatDescriptionLogEvent.ROWS_HEADER_LEN_V2) if (postHeaderLen == FormatDescriptionLogEvent.ROWS_HEADER_LEN_V2) {
{
headerLen = buffer.getUint16(); headerLen = buffer.getUint16();
headerLen -= 2; headerLen -= 2;
int start = buffer.position(); int start = buffer.position();
int end = start + headerLen; int end = start + headerLen;
for(int i = start ;i < end; ){ for (int i = start; i < end;) {
switch (buffer.getUint8(i++)) { switch (buffer.getUint8(i++)) {
case RW_V_EXTRAINFO_TAG: case RW_V_EXTRAINFO_TAG:
// int infoLen = buffer.getUint8(); // int infoLen = buffer.getUint8();
buffer.position(i + EXTRA_ROW_INFO_LEN_OFFSET); buffer.position(i + EXTRA_ROW_INFO_LEN_OFFSET);
int checkLen = buffer.getUint8(); // EXTRA_ROW_INFO_LEN_OFFSET int checkLen = buffer.getUint8(); // EXTRA_ROW_INFO_LEN_OFFSET
int val= checkLen - EXTRA_ROW_INFO_HDR_BYTES; int val = checkLen - EXTRA_ROW_INFO_HDR_BYTES;
assert(buffer.getUint8() == val); //EXTRA_ROW_INFO_FORMAT_OFFSET assert (buffer.getUint8() == val); // EXTRA_ROW_INFO_FORMAT_OFFSET
for (int j= 0; j < val; j++) { for (int j = 0; j < val; j++) {
assert(buffer.getUint8() == val); // EXTRA_ROW_INFO_HDR_BYTES + i assert (buffer.getUint8() == val); // EXTRA_ROW_INFO_HDR_BYTES
// + i
} }
break; break;
default: default:
@@ -157,17 +150,14 @@ public abstract class RowsLogEvent extends LogEvent
} }
} }
} }
buffer.position(commonHeaderLen + postHeaderLen + headerLen); buffer.position(commonHeaderLen + postHeaderLen + headerLen);
columnLen = (int) buffer.getPackedLong(); columnLen = (int) buffer.getPackedLong();
columns = buffer.getBitmap(columnLen); columns = buffer.getBitmap(columnLen);
if (header.type == UPDATE_ROWS_EVENT_V1 || header.type == UPDATE_ROWS_EVENT) if (header.type == UPDATE_ROWS_EVENT_V1 || header.type == UPDATE_ROWS_EVENT) {
{
changeColumns = buffer.getBitmap(columnLen); changeColumns = buffer.getBitmap(columnLen);
} } else {
else
{
changeColumns = columns; changeColumns = columns;
} }
@@ -176,46 +166,38 @@ public abstract class RowsLogEvent extends LogEvent
rowsBuf = buffer.duplicate(dataSize); rowsBuf = buffer.duplicate(dataSize);
} }
public final void fillTable(LogContext context) public final void fillTable(LogContext context) {
{
table = context.getTable(tableId); table = context.getTable(tableId);
// end of statement check: // end of statement check:
if ((flags & RowsLogEvent.STMT_END_F) != 0) if ((flags & RowsLogEvent.STMT_END_F) != 0) {
{
// Now is safe to clear ignored map (clear_tables will also // Now is safe to clear ignored map (clear_tables will also
// delete original table map events stored in the map). // delete original table map events stored in the map).
context.clearAllTables(); context.clearAllTables();
} }
} }
public final long getTableId() public final long getTableId() {
{
return tableId; return tableId;
} }
public final TableMapLogEvent getTable() public final TableMapLogEvent getTable() {
{
return table; return table;
} }
public final BitSet getColumns() public final BitSet getColumns() {
{
return columns; return columns;
} }
public final BitSet getChangeColumns() public final BitSet getChangeColumns() {
{
return changeColumns; return changeColumns;
} }
public final RowsLogBuffer getRowsBuf(String charsetName) public final RowsLogBuffer getRowsBuf(String charsetName) {
{
return new RowsLogBuffer(rowsBuf.duplicate(), columnLen, charsetName); return new RowsLogBuffer(rowsBuf.duplicate(), columnLen, charsetName);
} }
public final int getFlags(final int flags) public final int getFlags(final int flags) {
{
return this.flags & flags; return this.flags & flags;
} }
} }

View File

@@ -5,21 +5,18 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* Start_log_event_v3 is the Start_log_event of binlog format 3 (MySQL 3.23 and * Start_log_event_v3 is the Start_log_event of binlog format 3 (MySQL 3.23 and
* 4.x). * 4.x). Format_description_log_event derives from Start_log_event_v3; it is the
*
* Format_description_log_event derives from Start_log_event_v3; it is the
* Start_log_event of binlog format 4 (MySQL 5.0), that is, the event that * Start_log_event of binlog format 4 (MySQL 5.0), that is, the event that
* describes the other events' Common-Header/Post-Header lengths. This event is * describes the other events' Common-Header/Post-Header lengths. This event is
* sent by MySQL 5.0 whenever it starts sending a new binlog if the requested * sent by MySQL 5.0 whenever it starts sending a new binlog if the requested
* position is >4 (otherwise if ==4 the event will be sent naturally). * position is >4 (otherwise if ==4 the event will be sent naturally).
* *
* @see mysql-5.1.60/sql/log_event.cc - Start_log_event_v3 * @see mysql-5.1.60/sql/log_event.cc - Start_log_event_v3
*
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public class StartLogEventV3 extends LogEvent public class StartLogEventV3 extends LogEvent {
{
/** /**
* We could have used SERVER_VERSION_LENGTH, but this introduces an obscure * We could have used SERVER_VERSION_LENGTH, but this introduces an obscure
* dependency - if somebody decided to change SERVER_VERSION_LENGTH this * dependency - if somebody decided to change SERVER_VERSION_LENGTH this
@@ -34,9 +31,7 @@ public class StartLogEventV3 extends LogEvent
protected int binlogVersion; protected int binlogVersion;
protected String serverVersion; protected String serverVersion;
public StartLogEventV3(LogHeader header, LogBuffer buffer, public StartLogEventV3(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
buffer.position(descriptionEvent.commonHeaderLen); buffer.position(descriptionEvent.commonHeaderLen);
@@ -44,18 +39,15 @@ public class StartLogEventV3 extends LogEvent
serverVersion = buffer.getFixString(ST_SERVER_VER_LEN); // ST_SERVER_VER_OFFSET serverVersion = buffer.getFixString(ST_SERVER_VER_LEN); // ST_SERVER_VER_OFFSET
} }
public StartLogEventV3() public StartLogEventV3(){
{
super(new LogHeader(START_EVENT_V3)); super(new LogHeader(START_EVENT_V3));
} }
public final String getServerVersion() public final String getServerVersion() {
{
return serverVersion; return serverVersion;
} }
public final int getBinlogVersion() public final int getBinlogVersion() {
{
return binlogVersion; return binlogVersion;
} }
} }

View File

@@ -4,19 +4,15 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent; import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* Stop_log_event. * Stop_log_event. The Post-Header and Body for this event type are empty; it
* * only has the Common-Header.
* The Post-Header and Body for this event type are empty; it only has the
* Common-Header.
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class StopLogEvent extends LogEvent public final class StopLogEvent extends LogEvent {
{
public StopLogEvent(LogHeader header, LogBuffer buffer, public StopLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent description_event){
FormatDescriptionLogEvent description_event)
{
super(header); super(header);
} }
} }

View File

@@ -8,44 +8,34 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* In row-based mode, every row operation event is preceded by a * In row-based mode, every row operation event is preceded by a
* Table_map_log_event which maps a table definition to a number. The table * Table_map_log_event which maps a table definition to a number. The table
* definition consists of database name, table name, and column definitions. * definition consists of database name, table name, and column definitions. The
* * Post-Header has the following components:
* The Post-Header has the following components:
*
* <table> * <table>
* <caption>Post-Header for Table_map_log_event</caption> * <caption>Post-Header for Table_map_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>table_id</td> * <td>table_id</td>
* <td>6 bytes unsigned integer</td> * <td>6 bytes unsigned integer</td>
* <td>The number that identifies the table.</td> * <td>The number that identifies the table.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>flags</td> * <td>flags</td>
* <td>2 byte bitfield</td> * <td>2 byte bitfield</td>
* <td>Reserved for future use; currently always 0.</td> * <td>Reserved for future use; currently always 0.</td>
* </tr> * </tr>
*
* </table> * </table>
*
* The Body has the following components: * The Body has the following components:
*
* <table> * <table>
* <caption>Body for Table_map_log_event</caption> * <caption>Body for Table_map_log_event</caption>
*
* <tr> * <tr>
* <th>Name</th> * <th>Name</th>
* <th>Format</th> * <th>Format</th>
* <th>Description</th> * <th>Description</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>database_name</td> * <td>database_name</td>
* <td>one byte string length, followed by null-terminated string</td> * <td>one byte string length, followed by null-terminated string</td>
@@ -55,20 +45,17 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* by a terminating 0 byte. (Note the redundancy in the representation of the * by a terminating 0 byte. (Note the redundancy in the representation of the
* length.)</td> * length.)</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>table_name</td> * <td>table_name</td>
* <td>one byte string length, followed by null-terminated string</td> * <td>one byte string length, followed by null-terminated string</td>
* <td>The name of the table, encoded the same way as the database name above.</td> * <td>The name of the table, encoded the same way as the database name above.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>column_count</td> * <td>column_count</td>
* <td>packed_integer "Packed Integer"</td> * <td>packed_integer "Packed Integer"</td>
* <td>The number of columns in the table, represented as a packed * <td>The number of columns in the table, represented as a packed
* variable-length integer.</td> * variable-length integer.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>column_type</td> * <td>column_type</td>
* <td>List of column_count 1 byte enumeration values</td> * <td>List of column_count 1 byte enumeration values</td>
@@ -78,13 +65,11 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* listed in the table Table_table_map_log_event_column_types "below" (along * listed in the table Table_table_map_log_event_column_types "below" (along
* with description of the associated metadata field).</td> * with description of the associated metadata field).</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>metadata_length</td> * <td>metadata_length</td>
* <td>packed_integer "Packed Integer"</td> * <td>packed_integer "Packed Integer"</td>
* <td>The length of the following metadata block</td> * <td>The length of the following metadata block</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>metadata</td> * <td>metadata</td>
* <td>list of metadata for each column</td> * <td>list of metadata for each column</td>
@@ -93,7 +78,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* metadata for each column are listed in the table * metadata for each column are listed in the table
* Table_table_map_log_event_column_types "below".</td> * Table_table_map_log_event_column_types "below".</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>null_bits</td> * <td>null_bits</td>
* <td>column_count bits, rounded up to nearest byte</td> * <td>column_count bits, rounded up to nearest byte</td>
@@ -104,13 +88,10 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* first byte, the ninth is in the least significant bit of the second byte, and * first byte, the ninth is in the least significant bit of the second byte, and
* so on.</td> * so on.</td>
* </tr> * </tr>
*
* </table> * </table>
*
* The table below lists all column types, along with the numerical identifier * The table below lists all column types, along with the numerical identifier
* for it and the size and interpretation of meta-data used to describe the * for it and the size and interpretation of meta-data used to describe the
* type. * type.
*
* <table> * <table>
* <caption>Table_map_log_event column types: numerical identifier and * <caption>Table_map_log_event column types: numerical identifier and
* metadata</caption> * metadata</caption>
@@ -120,35 +101,30 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <th>Size of metadata in bytes</th> * <th>Size of metadata in bytes</th>
* <th>Description of metadata</th> * <th>Description of metadata</th>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_DECIMAL</td> * <td>MYSQL_TYPE_DECIMAL</td>
* <td>0</td> * <td>0</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_TINY</td> * <td>MYSQL_TYPE_TINY</td>
* <td>1</td> * <td>1</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_SHORT</td> * <td>MYSQL_TYPE_SHORT</td>
* <td>2</td> * <td>2</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_LONG</td> * <td>MYSQL_TYPE_LONG</td>
* <td>3</td> * <td>3</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_FLOAT</td> * <td>MYSQL_TYPE_FLOAT</td>
* <td>4</td> * <td>4</td>
@@ -156,7 +132,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td>1 byte unsigned integer, representing the "pack_length", which is equal * <td>1 byte unsigned integer, representing the "pack_length", which is equal
* to sizeof(float) on the server from which the event originates.</td> * to sizeof(float) on the server from which the event originates.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_DOUBLE</td> * <td>MYSQL_TYPE_DOUBLE</td>
* <td>5</td> * <td>5</td>
@@ -164,63 +139,54 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td>1 byte unsigned integer, representing the "pack_length", which is equal * <td>1 byte unsigned integer, representing the "pack_length", which is equal
* to sizeof(double) on the server from which the event originates.</td> * to sizeof(double) on the server from which the event originates.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_NULL</td> * <td>MYSQL_TYPE_NULL</td>
* <td>6</td> * <td>6</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_TIMESTAMP</td> * <td>MYSQL_TYPE_TIMESTAMP</td>
* <td>7</td> * <td>7</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_LONGLONG</td> * <td>MYSQL_TYPE_LONGLONG</td>
* <td>8</td> * <td>8</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_INT24</td> * <td>MYSQL_TYPE_INT24</td>
* <td>9</td> * <td>9</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_DATE</td> * <td>MYSQL_TYPE_DATE</td>
* <td>10</td> * <td>10</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_TIME</td> * <td>MYSQL_TYPE_TIME</td>
* <td>11</td> * <td>11</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_DATETIME</td> * <td>MYSQL_TYPE_DATETIME</td>
* <td>12</td> * <td>12</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_YEAR</td> * <td>MYSQL_TYPE_YEAR</td>
* <td>13</td> * <td>13</td>
* <td>0</td> * <td>0</td>
* <td>No column metadata.</td> * <td>No column metadata.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td><i>MYSQL_TYPE_NEWDATE</i></td> * <td><i>MYSQL_TYPE_NEWDATE</i></td>
* <td><i>14</i></td> * <td><i>14</i></td>
@@ -228,14 +194,12 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td><i>This enumeration value is only used internally and cannot exist in a * <td><i>This enumeration value is only used internally and cannot exist in a
* binlog.</i></td> * binlog.</i></td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_VARCHAR</td> * <td>MYSQL_TYPE_VARCHAR</td>
* <td>15</td> * <td>15</td>
* <td>2 bytes</td> * <td>2 bytes</td>
* <td>2 byte unsigned integer representing the maximum length of the string.</td> * <td>2 byte unsigned integer representing the maximum length of the string.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_BIT</td> * <td>MYSQL_TYPE_BIT</td>
* <td>16</td> * <td>16</td>
@@ -245,7 +209,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* occupied by the bitfield. The number of bytes is either int((length+7)/8) or * occupied by the bitfield. The number of bytes is either int((length+7)/8) or
* int(length/8).</td> * int(length/8).</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_NEWDECIMAL</td> * <td>MYSQL_TYPE_NEWDECIMAL</td>
* <td>246</td> * <td>246</td>
@@ -253,7 +216,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td>A 1 byte unsigned int representing the precision, followed by a 1 byte * <td>A 1 byte unsigned int representing the precision, followed by a 1 byte
* unsigned int representing the number of decimals.</td> * unsigned int representing the number of decimals.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td><i>MYSQL_TYPE_ENUM</i></td> * <td><i>MYSQL_TYPE_ENUM</i></td>
* <td><i>247</i></td> * <td><i>247</i></td>
@@ -261,7 +223,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td><i>This enumeration value is only used internally and cannot exist in a * <td><i>This enumeration value is only used internally and cannot exist in a
* binlog.</i></td> * binlog.</i></td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td><i>MYSQL_TYPE_SET</i></td> * <td><i>MYSQL_TYPE_SET</i></td>
* <td><i>248</i></td> * <td><i>248</i></td>
@@ -269,7 +230,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td><i>This enumeration value is only used internally and cannot exist in a * <td><i>This enumeration value is only used internally and cannot exist in a
* binlog.</i></td> * binlog.</i></td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_TINY_BLOB</td> * <td>MYSQL_TYPE_TINY_BLOB</td>
* <td>249</td> * <td>249</td>
@@ -277,7 +237,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td><i>This enumeration value is only used internally and cannot exist in a * <td><i>This enumeration value is only used internally and cannot exist in a
* binlog.</i></td> * binlog.</i></td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td><i>MYSQL_TYPE_MEDIUM_BLOB</i></td> * <td><i>MYSQL_TYPE_MEDIUM_BLOB</i></td>
* <td><i>250</i></td> * <td><i>250</i></td>
@@ -285,7 +244,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td><i>This enumeration value is only used internally and cannot exist in a * <td><i>This enumeration value is only used internally and cannot exist in a
* binlog.</i></td> * binlog.</i></td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td><i>MYSQL_TYPE_LONG_BLOB</i></td> * <td><i>MYSQL_TYPE_LONG_BLOB</i></td>
* <td><i>251</i></td> * <td><i>251</i></td>
@@ -293,7 +251,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td><i>This enumeration value is only used internally and cannot exist in a * <td><i>This enumeration value is only used internally and cannot exist in a
* binlog.</i></td> * binlog.</i></td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_BLOB</td> * <td>MYSQL_TYPE_BLOB</td>
* <td>252</td> * <td>252</td>
@@ -301,7 +258,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td>The pack length, i.e., the number of bytes needed to represent the length * <td>The pack length, i.e., the number of bytes needed to represent the length
* of the blob: 1, 2, 3, or 4.</td> * of the blob: 1, 2, 3, or 4.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_VAR_STRING</td> * <td>MYSQL_TYPE_VAR_STRING</td>
* <td>253</td> * <td>253</td>
@@ -312,7 +268,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* unsigned integer representing the field size, i.e., the number of bytes * unsigned integer representing the field size, i.e., the number of bytes
* needed to store the length of the string.</td> * needed to store the length of the string.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_STRING</td> * <td>MYSQL_TYPE_STRING</td>
* <td>254</td> * <td>254</td>
@@ -321,7 +276,6 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* byte is the field size, i.e., the number of bytes in the representation of * byte is the field size, i.e., the number of bytes in the representation of
* size of the string: 3 or 4.</td> * size of the string: 3 or 4.</td>
* </tr> * </tr>
*
* <tr> * <tr>
* <td>MYSQL_TYPE_GEOMETRY</td> * <td>MYSQL_TYPE_GEOMETRY</td>
* <td>255</td> * <td>255</td>
@@ -329,21 +283,19 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* <td>The pack length, i.e., the number of bytes needed to represent the length * <td>The pack length, i.e., the number of bytes needed to represent the length
* of the geometry: 1, 2, 3, or 4.</td> * of the geometry: 1, 2, 3, or 4.</td>
* </tr> * </tr>
*
* </table> * </table>
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class TableMapLogEvent extends LogEvent public final class TableMapLogEvent extends LogEvent {
{
/** /**
* Fixed data part: * Fixed data part:
* <ul> * <ul>
* <li>6 bytes. The table ID.</li> * <li>6 bytes. The table ID.</li>
* <li>2 bytes. Reserved for future use.</li> * <li>2 bytes. Reserved for future use.</li>
* </ul> * </ul>
*
* <p> * <p>
* Variable data part: * Variable data part:
* <ul> * <ul>
@@ -360,7 +312,6 @@ public final class TableMapLogEvent extends LogEvent
* one bit per column. For this field, the amount of storage required for N * one bit per column. For this field, the amount of storage required for N
* columns is INT((N+7)/8) bytes.</li> * columns is INT((N+7)/8) bytes.</li>
* </ul> * </ul>
*
* Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log * Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log
*/ */
protected final String dbname; protected final String dbname;
@@ -369,14 +320,15 @@ public final class TableMapLogEvent extends LogEvent
/** /**
* Holding mysql column information. * Holding mysql column information.
*/ */
public static final class ColumnInfo public static final class ColumnInfo {
{
public int type; public int type;
public int meta; public int meta;
} }
protected final int columnCnt; protected final int columnCnt;
protected final ColumnInfo[] columnInfo; // buffer for field metadata protected final ColumnInfo[] columnInfo; // buffer for field
// metadata
protected final long tableId; protected final long tableId;
protected BitSet nullBits; protected BitSet nullBits;
@@ -388,22 +340,20 @@ public final class TableMapLogEvent extends LogEvent
/** /**
* Constructor used by slave to read the event from the binary log. * Constructor used by slave to read the event from the binary log.
*/ */
public TableMapLogEvent(LogHeader header, LogBuffer buffer, public TableMapLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int commonHeaderLen = descriptionEvent.commonHeaderLen;
final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];
/* Read the post-header */ /* Read the post-header */
buffer.position(commonHeaderLen + TM_MAPID_OFFSET); buffer.position(commonHeaderLen + TM_MAPID_OFFSET);
if (postHeaderLen == 6) if (postHeaderLen == 6) {
{ /*
/* Master is of an intermediate source tree before 5.1.4. Id is 4 bytes */ * Master is of an intermediate source tree before 5.1.4. Id is 4
* bytes
*/
tableId = buffer.getUint32(); tableId = buffer.getUint32();
} } else {
else
{
// DBUG_ASSERT(post_header_len == TABLE_MAP_HEADER_LEN); // DBUG_ASSERT(post_header_len == TABLE_MAP_HEADER_LEN);
tableId = buffer.getUlong48(); tableId = buffer.getUlong48();
} }
@@ -419,15 +369,13 @@ public final class TableMapLogEvent extends LogEvent
// Read column information from buffer // Read column information from buffer
columnCnt = (int) buffer.getPackedLong(); columnCnt = (int) buffer.getPackedLong();
columnInfo = new ColumnInfo[columnCnt]; columnInfo = new ColumnInfo[columnCnt];
for (int i = 0; i < columnCnt; i++) for (int i = 0; i < columnCnt; i++) {
{
ColumnInfo info = new ColumnInfo(); ColumnInfo info = new ColumnInfo();
info.type = buffer.getUint8(); info.type = buffer.getUint8();
columnInfo[i] = info; columnInfo[i] = info;
} }
if (buffer.position() < buffer.limit()) if (buffer.position() < buffer.limit()) {
{
final int fieldSize = (int) buffer.getPackedLong(); final int fieldSize = (int) buffer.getPackedLong();
decodeFields(buffer, fieldSize); decodeFields(buffer, fieldSize);
nullBits = buffer.getBitmap(columnCnt); nullBits = buffer.getBitmap(columnCnt);
@@ -439,41 +387,37 @@ public final class TableMapLogEvent extends LogEvent
* *
* @see mysql-5.1.60/sql/rpl_utility.h * @see mysql-5.1.60/sql/rpl_utility.h
*/ */
private final void decodeFields(LogBuffer buffer, final int len) private final void decodeFields(LogBuffer buffer, final int len) {
{
final int limit = buffer.limit(); final int limit = buffer.limit();
buffer.limit(len + buffer.position()); buffer.limit(len + buffer.position());
for (int i = 0; i < columnCnt; i++) for (int i = 0; i < columnCnt; i++) {
{
ColumnInfo info = columnInfo[i]; ColumnInfo info = columnInfo[i];
switch (info.type) switch (info.type) {
{ case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_BLOB: case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_DOUBLE: case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_GEOMETRY: /*
/* * These types store a single byte.
These types store a single byte. */
*/ info.meta = buffer.getUint8();
info.meta = buffer.getUint8(); break;
break; case MYSQL_TYPE_SET:
case MYSQL_TYPE_SET: case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_ENUM: /*
/* * log_event.h : MYSQL_TYPE_SET & MYSQL_TYPE_ENUM : This
* log_event.h : MYSQL_TYPE_SET & MYSQL_TYPE_ENUM : This * enumeration value is only used internally and cannot
* enumeration value is only used internally and cannot * exist in a binlog.
* exist in a binlog. */
*/ logger.warn("This enumeration value is only used internally "
logger.warn("This enumeration value is only used internally " + "and cannot exist in a binlog: type=" + info.type);
+ "and cannot exist in a binlog: type=" + info.type); break;
break; case MYSQL_TYPE_STRING: {
case MYSQL_TYPE_STRING:
{
/* /*
* log_event.h : The first byte is always * log_event.h : The first byte is always
* MYSQL_TYPE_VAR_STRING (i.e., 253). The second byte is the * MYSQL_TYPE_VAR_STRING (i.e., 253). The second byte is the
@@ -485,59 +429,52 @@ public final class TableMapLogEvent extends LogEvent
info.meta = x; info.meta = x;
break; break;
} }
case MYSQL_TYPE_BIT: case MYSQL_TYPE_BIT:
info.meta = buffer.getUint16(); info.meta = buffer.getUint16();
break; break;
case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VARCHAR:
/* /*
* These types store two bytes. * These types store two bytes.
*/ */
info.meta = buffer.getUint16(); info.meta = buffer.getUint16();
break; break;
case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_NEWDECIMAL: {
{
int x = buffer.getUint8() << 8; // precision int x = buffer.getUint8() << 8; // precision
x += buffer.getUint8(); // decimals x += buffer.getUint8(); // decimals
info.meta = x; info.meta = x;
break; break;
} }
case MYSQL_TYPE_TIME2: case MYSQL_TYPE_TIME2:
case MYSQL_TYPE_DATETIME2: case MYSQL_TYPE_DATETIME2:
case MYSQL_TYPE_TIMESTAMP2: case MYSQL_TYPE_TIMESTAMP2: {
{
info.meta = buffer.getUint8(); info.meta = buffer.getUint8();
break; break;
} }
default: default:
info.meta = 0; info.meta = 0;
break; break;
} }
} }
buffer.limit(limit); buffer.limit(limit);
} }
public final String getDbName() public final String getDbName() {
{
return dbname; return dbname;
} }
public final String getTableName() public final String getTableName() {
{
return tblname; return tblname;
} }
public final int getColumnCnt() public final int getColumnCnt() {
{
return columnCnt; return columnCnt;
} }
public final ColumnInfo[] getColumnInfo() public final ColumnInfo[] getColumnInfo() {
{
return columnInfo; return columnInfo;
} }
public final long getTableId() public final long getTableId() {
{
return tableId; return tableId;
} }
} }

View File

@@ -8,10 +8,9 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class UnknownLogEvent extends LogEvent public final class UnknownLogEvent extends LogEvent {
{
public UnknownLogEvent(LogHeader header) public UnknownLogEvent(LogHeader header){
{
super(header); super(header);
} }
} }

View File

@@ -4,19 +4,16 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
/** /**
* Log row updates with a before image. The event contain several update rows * Log row updates with a before image. The event contain several update rows
* for a table. Note that each event contains only rows for one table. * for a table. Note that each event contains only rows for one table. Also note
* * that the row data consists of pairs of row data: one row for the old data and
* Also note that the row data consists of pairs of row data: one row for the * one row for the new data.
* old data and one row for the new data.
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class UpdateRowsLogEvent extends RowsLogEvent public final class UpdateRowsLogEvent extends RowsLogEvent {
{
public UpdateRowsLogEvent(LogHeader header, LogBuffer buffer, public UpdateRowsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header, buffer, descriptionEvent); super(header, buffer, descriptionEvent);
} }
} }

View File

@@ -8,22 +8,19 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent; import com.taobao.tddl.dbsync.binlog.LogEvent;
/** /**
* User_var_log_event. * User_var_log_event. Every time a query uses the value of a user variable, a
* * User_var_log_event is written before the Query_log_event, to set the user
* Every time a query uses the value of a user variable, a User_var_log_event is * variable.
* written before the Query_log_event, to set the user variable.
* *
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class UserVarLogEvent extends LogEvent public final class UserVarLogEvent extends LogEvent {
{
/** /**
* Fixed data part: Empty * Fixed data part: Empty
*
* <p> * <p>
* Variable data part: * Variable data part:
*
* <ul> * <ul>
* <li>4 bytes. the size of the user variable name.</li> * <li>4 bytes. the size of the user variable name.</li>
* <li>The user variable name.</li> * <li>The user variable name.</li>
@@ -39,7 +36,6 @@ public final class UserVarLogEvent extends LogEvent
* <li>Variable-sized. For a string variable, this is the string. For a * <li>Variable-sized. For a string variable, this is the string. For a
* float or integer variable, this is its value in 8 bytes.</li> * float or integer variable, this is its value in 8 bytes.</li>
* </ul> * </ul>
*
* Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log * Source : http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log
*/ */
private final String name; private final String name;
@@ -66,80 +62,65 @@ public final class UserVarLogEvent extends LogEvent
public static final int UV_NAME_LEN_SIZE = 4; public static final int UV_NAME_LEN_SIZE = 4;
public static final int UV_CHARSET_NUMBER_SIZE = 4; public static final int UV_CHARSET_NUMBER_SIZE = 4;
public UserVarLogEvent(LogHeader header, LogBuffer buffer, public UserVarLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
FormatDescriptionLogEvent descriptionEvent) throws IOException throws IOException{
{
super(header); super(header);
/* The Post-Header is empty. The Variable Data part begins immediately. */ /* The Post-Header is empty. The Variable Data part begins immediately. */
buffer.position(descriptionEvent.commonHeaderLen buffer.position(descriptionEvent.commonHeaderLen + descriptionEvent.postHeaderLen[USER_VAR_EVENT - 1]);
+ descriptionEvent.postHeaderLen[USER_VAR_EVENT - 1]);
final int nameLen = (int) buffer.getUint32(); final int nameLen = (int) buffer.getUint32();
name = buffer.getFixString(nameLen); // UV_NAME_LEN_SIZE name = buffer.getFixString(nameLen); // UV_NAME_LEN_SIZE
isNull = (0 != buffer.getInt8()); isNull = (0 != buffer.getInt8());
if (isNull) if (isNull) {
{
type = STRING_RESULT; type = STRING_RESULT;
charsetNumber = 63; /* binary */ charsetNumber = 63; /* binary */
value = null; value = null;
} } else {
else
{
type = buffer.getInt8(); // UV_VAL_IS_NULL type = buffer.getInt8(); // UV_VAL_IS_NULL
charsetNumber = (int) buffer.getUint32(); // buf + UV_VAL_TYPE_SIZE charsetNumber = (int) buffer.getUint32(); // buf + UV_VAL_TYPE_SIZE
final int valueLen = (int) buffer.getUint32(); // buf + UV_CHARSET_NUMBER_SIZE final int valueLen = (int) buffer.getUint32(); // buf +
// UV_CHARSET_NUMBER_SIZE
final int limit = buffer.limit(); /* for restore */ final int limit = buffer.limit(); /* for restore */
buffer.limit(buffer.position() + valueLen); buffer.limit(buffer.position() + valueLen);
/* @see User_var_log_event::print */ /* @see User_var_log_event::print */
switch (type) switch (type) {
{ case REAL_RESULT:
case REAL_RESULT: value = Double.valueOf(buffer.getDouble64()); // float8get
value = Double.valueOf(buffer.getDouble64()); // float8get break;
break; case INT_RESULT:
case INT_RESULT: if (valueLen == 8) value = Long.valueOf(buffer.getLong64()); // !uint8korr
if (valueLen == 8) else if (valueLen == 4) value = Long.valueOf(buffer.getUint32());
value = Long.valueOf(buffer.getLong64()); // !uint8korr else throw new IOException("Error INT_RESULT length: " + valueLen);
else if (valueLen == 4) break;
value = Long.valueOf(buffer.getUint32()); case DECIMAL_RESULT:
else final int precision = buffer.getInt8();
throw new IOException("Error INT_RESULT length: " final int scale = buffer.getInt8();
+ valueLen); value = buffer.getDecimal(precision, scale); // bin2decimal
break; break;
case DECIMAL_RESULT: case STRING_RESULT:
final int precision = buffer.getInt8(); String charsetName = CharsetConversion.getJavaCharset(charsetNumber);
final int scale = buffer.getInt8(); value = buffer.getFixString(valueLen, charsetName);
value = buffer.getDecimal(precision, scale); // bin2decimal break;
break; case ROW_RESULT:
case STRING_RESULT: // this seems to be banned in MySQL altogether
String charsetName = CharsetConversion.getJavaCharset(charsetNumber); throw new IOException("ROW_RESULT is unsupported");
value = buffer.getFixString(valueLen, charsetName); default:
break; value = null;
case ROW_RESULT: break;
// this seems to be banned in MySQL altogether
throw new IOException("ROW_RESULT is unsupported");
default:
value = null;
break;
} }
buffer.limit(limit); buffer.limit(limit);
} }
} }
public final String getQuery() public final String getQuery() {
{ if (value == null) {
if (value == null)
{
return "SET @" + name + " := NULL"; return "SET @" + name + " := NULL";
} } else if (type == STRING_RESULT) {
else if (type == STRING_RESULT)
{
// TODO: do escaping !? // TODO: do escaping !?
return "SET @" + name + " := \'" + value + '\''; return "SET @" + name + " := \'" + value + '\'';
} } else {
else
{
return "SET @" + name + " := " + String.valueOf(value); return "SET @" + name + " := " + String.valueOf(value);
} }
} }

View File

@@ -9,11 +9,9 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class WriteRowsLogEvent extends RowsLogEvent public final class WriteRowsLogEvent extends RowsLogEvent {
{
public WriteRowsLogEvent(LogHeader header, LogBuffer buffer, public WriteRowsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header, buffer, descriptionEvent); super(header, buffer, descriptionEvent);
} }
} }

View File

@@ -10,23 +10,19 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a> * @author <a href="mailto:changyuan.lh@taobao.com">Changyuan.lh</a>
* @version 1.0 * @version 1.0
*/ */
public final class XidLogEvent extends LogEvent public final class XidLogEvent extends LogEvent {
{
private final long xid; private final long xid;
public XidLogEvent(LogHeader header, LogBuffer buffer, public XidLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
FormatDescriptionLogEvent descriptionEvent)
{
super(header); super(header);
/* The Post-Header is empty. The Variable Data part begins immediately. */ /* The Post-Header is empty. The Variable Data part begins immediately. */
buffer.position(descriptionEvent.commonHeaderLen buffer.position(descriptionEvent.commonHeaderLen + descriptionEvent.postHeaderLen[XID_EVENT - 1]);
+ descriptionEvent.postHeaderLen[XID_EVENT - 1]);
xid = buffer.getLong64(); // !uint8korr xid = buffer.getLong64(); // !uint8korr
} }
public final long getXid() public final long getXid() {
{
return xid; return xid;
} }
} }

View File

@@ -10,8 +10,8 @@ import com.taobao.tddl.dbsync.binlog.event.RowsLogBuffer;
import com.taobao.tddl.dbsync.binlog.event.RowsLogEvent; import com.taobao.tddl.dbsync.binlog.event.RowsLogEvent;
import com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent; import com.taobao.tddl.dbsync.binlog.event.RowsQueryLogEvent;
import com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent; import com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent;
import com.taobao.tddl.dbsync.binlog.event.XidLogEvent;
import com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent.ColumnInfo; import com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent.ColumnInfo;
import com.taobao.tddl.dbsync.binlog.event.XidLogEvent;
import com.taobao.tddl.dbsync.binlog.event.mariadb.AnnotateRowsEvent; import com.taobao.tddl.dbsync.binlog.event.mariadb.AnnotateRowsEvent;
public class BaseLogFetcherTest { public class BaseLogFetcherTest {
@@ -20,36 +20,38 @@ public class BaseLogFetcherTest {
protected Charset charset = Charset.forName("utf-8"); protected Charset charset = Charset.forName("utf-8");
protected void parseQueryEvent(QueryLogEvent event) { protected void parseQueryEvent(QueryLogEvent event) {
System.out.println(String.format("================> binlog[%s:%s] , name[%s]", binlogFileName, System.out.println(String.format("================> binlog[%s:%s] , name[%s]",
event.getHeader().getLogPos() - event.getHeader().getEventLen(), binlogFileName,
event.getCatalog())); event.getHeader().getLogPos() - event.getHeader().getEventLen(),
event.getCatalog()));
System.out.println("sql : " + event.getQuery()); System.out.println("sql : " + event.getQuery());
} }
protected void parseRowsQueryEvent(RowsQueryLogEvent event) throws Exception { protected void parseRowsQueryEvent(RowsQueryLogEvent event) throws Exception {
System.out.println(String.format("================> binlog[%s:%s]", binlogFileName, System.out.println(String.format("================> binlog[%s:%s]", binlogFileName, event.getHeader()
event.getHeader().getLogPos() - event.getHeader().getEventLen())); .getLogPos() - event.getHeader().getEventLen()));
System.out.println("sql : " + new String(event.getRowsQuery().getBytes("ISO-8859-1"), charset.name())); System.out.println("sql : " + new String(event.getRowsQuery().getBytes("ISO-8859-1"), charset.name()));
} }
protected void parseAnnotateRowsEvent(AnnotateRowsEvent event) throws Exception { protected void parseAnnotateRowsEvent(AnnotateRowsEvent event) throws Exception {
System.out.println(String.format("================> binlog[%s:%s]", binlogFileName, System.out.println(String.format("================> binlog[%s:%s]", binlogFileName, event.getHeader()
event.getHeader().getLogPos() - event.getHeader().getEventLen())); .getLogPos() - event.getHeader().getEventLen()));
System.out.println("sql : " + new String(event.getRowsQuery().getBytes("ISO-8859-1"), charset.name())); System.out.println("sql : " + new String(event.getRowsQuery().getBytes("ISO-8859-1"), charset.name()));
} }
protected void parseXidEvent(XidLogEvent event) throws Exception { protected void parseXidEvent(XidLogEvent event) throws Exception {
System.out.println(String.format("================> binlog[%s:%s]", binlogFileName, System.out.println(String.format("================> binlog[%s:%s]", binlogFileName, event.getHeader()
event.getHeader().getLogPos() - event.getHeader().getEventLen())); .getLogPos() - event.getHeader().getEventLen()));
System.out.println("xid : " + event.getXid()); System.out.println("xid : " + event.getXid());
} }
protected void parseRowsEvent(RowsLogEvent event) { protected void parseRowsEvent(RowsLogEvent event) {
try { try {
System.out.println(String.format("================> binlog[%s:%s] , name[%s,%s]", binlogFileName, System.out.println(String.format("================> binlog[%s:%s] , name[%s,%s]",
event.getHeader().getLogPos() - event.getHeader().getEventLen(), binlogFileName,
event.getTable().getDbName(), event.getTable().getTableName())); event.getHeader().getLogPos() - event.getHeader().getEventLen(),
event.getTable().getDbName(),
event.getTable().getTableName()));
RowsLogBuffer buffer = event.getRowsBuf(charset.name()); RowsLogBuffer buffer = event.getRowsBuf(charset.name());
BitSet columns = event.getColumns(); BitSet columns = event.getColumns();
BitSet changeColumns = event.getChangeColumns(); BitSet changeColumns = event.getChangeColumns();
@@ -90,6 +92,10 @@ public class BaseLogFetcherTest {
final ColumnInfo[] columnInfo = map.getColumnInfo(); final ColumnInfo[] columnInfo = map.getColumnInfo();
for (int i = 0; i < columnCnt; i++) { for (int i = 0; i < columnCnt; i++) {
if (!cols.get(i)) {
continue;
}
ColumnInfo info = columnInfo[i]; ColumnInfo info = columnInfo[i];
buffer.nextValue(info.type, info.meta); buffer.nextValue(info.type, info.meta);

View File

@@ -5,8 +5,7 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.Statement; import java.sql.Statement;
import junit.framework.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.DeleteRowsLogEvent;
@@ -25,12 +24,12 @@ 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", "xxxxx", "xxxxx"); Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1: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.000003", 4L, 2); fecther.open(connection, "mysql-bin.000001", 4L, 2);
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT); LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
LogContext context = new LogContext(); LogContext context = new LogContext();
@@ -39,7 +38,8 @@ public class DirectLogFetcherTest extends BaseLogFetcherTest {
event = decoder.decode(fecther, context); event = decoder.decode(fecther, context);
if (event == null) { if (event == null) {
throw new RuntimeException("parse failed"); continue;
// throw new RuntimeException("parse failed");
} }
int eventType = event.getHeader().getType(); int eventType = event.getHeader().getType();

View File

@@ -4,8 +4,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import junit.framework.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -27,7 +26,6 @@ public class FileLogFetcherTest extends BaseLogFetcherTest {
URL url = Thread.currentThread().getContextClassLoader().getResource("dummy.txt"); URL url = Thread.currentThread().getContextClassLoader().getResource("dummy.txt");
File dummyFile = new File(url.getFile()); File dummyFile = new File(url.getFile());
directory = new File(dummyFile.getParent() + "/binlog").getPath(); directory = new File(dummyFile.getParent() + "/binlog").getPath();
// directory = "/home/jianghang/tmp/binlog";
} }
@Test @Test
@@ -37,8 +35,8 @@ public class FileLogFetcherTest extends BaseLogFetcherTest {
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT); LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
LogContext context = new LogContext(); LogContext context = new LogContext();
File current = new File(directory, "mysql-bin.000006"); File current = new File(directory, "mysql-bin.000001");
fetcher.open(current); fetcher.open(current, 2051L);
context.setLogPosition(new LogPosition(current.getName())); context.setLogPosition(new LogPosition(current.getName()));
while (fetcher.fetch()) { while (fetcher.fetch()) {
@@ -48,23 +46,22 @@ public class FileLogFetcherTest extends BaseLogFetcherTest {
int eventType = event.getHeader().getType(); int eventType = event.getHeader().getType();
switch (eventType) { switch (eventType) {
case LogEvent.ROTATE_EVENT: case LogEvent.ROTATE_EVENT:
binlogFileName = ((RotateLogEvent) binlogFileName = ((RotateLogEvent) event).getFilename();
event).getFilename();
break; break;
case LogEvent.WRITE_ROWS_EVENT_V1: case LogEvent.WRITE_ROWS_EVENT_V1:
case LogEvent.WRITE_ROWS_EVENT: case LogEvent.WRITE_ROWS_EVENT:
parseRowsEvent((WriteRowsLogEvent) event); parseRowsEvent((WriteRowsLogEvent) event);
break; break;
case LogEvent.UPDATE_ROWS_EVENT_V1: case LogEvent.UPDATE_ROWS_EVENT_V1:
case LogEvent.UPDATE_ROWS_EVENT: case LogEvent.UPDATE_ROWS_EVENT:
parseRowsEvent((UpdateRowsLogEvent) event); parseRowsEvent((UpdateRowsLogEvent) event);
break; break;
case LogEvent.DELETE_ROWS_EVENT_V1: case LogEvent.DELETE_ROWS_EVENT_V1:
case LogEvent.DELETE_ROWS_EVENT: case LogEvent.DELETE_ROWS_EVENT:
parseRowsEvent((DeleteRowsLogEvent) event); parseRowsEvent((DeleteRowsLogEvent) event);
break; break;
case LogEvent.QUERY_EVENT: case LogEvent.QUERY_EVENT:
parseQueryEvent((QueryLogEvent) event); parseQueryEvent((QueryLogEvent) event);
break; break;
case LogEvent.ROWS_QUERY_LOG_EVENT: case LogEvent.ROWS_QUERY_LOG_EVENT:
parseRowsQueryEvent((RowsQueryLogEvent) event); parseRowsQueryEvent((RowsQueryLogEvent) event);

View File

@@ -5,14 +5,11 @@ import java.math.BigInteger;
import junit.framework.TestCase; import junit.framework.TestCase;
import com.taobao.tddl.dbsync.binlog.LogBuffer; public class LogBufferTest extends TestCase {
public class LogBufferTest extends TestCase
{
public static final int LOOP = 10000; public static final int LOOP = 10000;
public void testSigned() public void testSigned() {
{
byte[] array = { 0, 0, 0, (byte) 0xff }; byte[] array = { 0, 0, 0, (byte) 0xff };
LogBuffer buffer = new LogBuffer(array, 0, array.length); LogBuffer buffer = new LogBuffer(array, 0, array.length);
@@ -24,17 +21,15 @@ public class LogBufferTest extends TestCase
System.out.println(buffer.getUint24(1)); System.out.println(buffer.getUint24(1));
} }
public void testBigInteger() public void testBigInteger() {
{ byte[] array = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
byte[] array = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
LogBuffer buffer = new LogBuffer(array, 0, array.length); LogBuffer buffer = new LogBuffer(array, 0, array.length);
long tt1 = 0; long tt1 = 0;
long l1 = 0; long l1 = 0;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t1 = System.nanoTime(); final long t1 = System.nanoTime();
l1 = buffer.getLong64(0); l1 = buffer.getLong64(0);
tt1 += System.nanoTime() - t1; tt1 += System.nanoTime() - t1;
@@ -45,8 +40,7 @@ public class LogBufferTest extends TestCase
long tt2 = 0; long tt2 = 0;
BigInteger l2 = null; BigInteger l2 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t2 = System.nanoTime(); final long t2 = System.nanoTime();
l2 = buffer.getUlong64(0); l2 = buffer.getUlong64(0);
tt2 += System.nanoTime() - t2; tt2 += System.nanoTime() - t2;
@@ -57,18 +51,15 @@ public class LogBufferTest extends TestCase
} }
/* Reads big-endian integer from no more than 4 bytes */ /* Reads big-endian integer from no more than 4 bytes */
private static int convertNBytesToInt(byte[] buffer, int offset, int length) private static int convertNBytesToInt(byte[] buffer, int offset, int length) {
{
int ret = 0; int ret = 0;
for (int i = offset; i < (offset + length); i++) for (int i = offset; i < (offset + length); i++) {
{
ret = (ret << 8) | (0xff & buffer[i]); ret = (ret << 8) | (0xff & buffer[i]);
} }
return ret; return ret;
} }
private static int convert4BytesToInt(byte[] buffer, int offset) private static int convert4BytesToInt(byte[] buffer, int offset) {
{
int value; int value;
value = (0xff & buffer[offset + 3]); value = (0xff & buffer[offset + 3]);
value += (0xff & buffer[offset + 2]) << 8; value += (0xff & buffer[offset + 2]) << 8;
@@ -77,24 +68,20 @@ public class LogBufferTest extends TestCase
return value; return value;
} }
public static short convert1ByteToShort(byte[] buffer, int offset) public static short convert1ByteToShort(byte[] buffer, int offset) {
{
short value; short value;
value = (short) buffer[offset + 0]; value = (short) buffer[offset + 0];
return value; return value;
} }
public static short convert2bytesToShort(byte[] buffer, int offset) public static short convert2bytesToShort(byte[] buffer, int offset) {
{
short value; short value;
value = (short) (buffer[offset + 0] << 8); value = (short) (buffer[offset + 0] << 8);
value += (short) (buffer[offset + 1] & 0xff); value += (short) (buffer[offset + 1] & 0xff);
return value; return value;
} }
public static final BigDecimal extractDecimal(byte[] buffer, int precision, public static final BigDecimal extractDecimal(byte[] buffer, int precision, int scale) {
int scale)
{
// //
// Decimal representation in binlog seems to be as follows: // Decimal representation in binlog seems to be as follows:
// 1 byte - 'precision' // 1 byte - 'precision'
@@ -113,7 +100,7 @@ public class LogBufferTest extends TestCase
// 0x00000005 0x1b38b060 0x00 // 0x00000005 0x1b38b060 0x00
// 5 456700000 0 // 5 456700000 0
// 54567000000 / 10^{10} = 5.4567 // 54567000000 / 10^{10} = 5.4567
// //
// int_size below shows how long is integer part // int_size below shows how long is integer part
// //
// offset = offset + 2; // offset of the number part // offset = offset + 2; // offset of the number part
@@ -129,34 +116,28 @@ public class LogBufferTest extends TestCase
int sign = (buffer[offset] & 0x80) == 0x80 ? 1 : -1; int sign = (buffer[offset] & 0x80) == 0x80 ? 1 : -1;
// how many bytes are used to represent given amount of digits? // how many bytes are used to represent given amount of digits?
int integerSize = intg0 * LogBuffer.SIZE_OF_INT32 int integerSize = intg0 * LogBuffer.SIZE_OF_INT32 + LogBuffer.dig2bytes[intg0x];
+ LogBuffer.dig2bytes[intg0x]; int decimalSize = frac0 * LogBuffer.SIZE_OF_INT32 + LogBuffer.dig2bytes[frac0x];
int decimalSize = frac0 * LogBuffer.SIZE_OF_INT32
+ LogBuffer.dig2bytes[frac0x];
int bin_size = integerSize + decimalSize; // total bytes int bin_size = integerSize + decimalSize; // total bytes
byte[] d_copy = new byte[bin_size]; byte[] d_copy = new byte[bin_size];
if (bin_size > buffer.length) if (bin_size > buffer.length) {
{ throw new ArrayIndexOutOfBoundsException("Calculated bin_size: " + bin_size + ", available bytes: "
throw new ArrayIndexOutOfBoundsException("Calculated bin_size: " + buffer.length);
+ bin_size + ", available bytes: " + buffer.length);
} }
// Invert first bit // Invert first bit
d_copy[0] = buffer[0]; d_copy[0] = buffer[0];
d_copy[0] ^= 0x80; d_copy[0] ^= 0x80;
if (sign == -1) if (sign == -1) {
{
// Invert every byte // Invert every byte
d_copy[0] ^= 0xFF; d_copy[0] ^= 0xFF;
} }
for (int i = 1; i < bin_size; i++) for (int i = 1; i < bin_size; i++) {
{
d_copy[i] = buffer[i]; d_copy[i] = buffer[i];
if (sign == -1) if (sign == -1) {
{
// Invert every byte // Invert every byte
d_copy[i] ^= 0xFF; d_copy[i] ^= 0xFF;
} }
@@ -167,62 +148,49 @@ public class LogBufferTest extends TestCase
BigDecimal intPart = new BigDecimal(0); BigDecimal intPart = new BigDecimal(0);
if (offset > 0) if (offset > 0) intPart = BigDecimal.valueOf(convertNBytesToInt(d_copy, 0, offset));
intPart = BigDecimal.valueOf(convertNBytesToInt(d_copy, 0, offset));
while (offset < integerSize) while (offset < integerSize) {
{ intPart = intPart.movePointRight(LogBuffer.DIG_PER_DEC1).add(BigDecimal.valueOf(convert4BytesToInt(d_copy,
intPart = intPart.movePointRight(LogBuffer.DIG_PER_DEC1).add( offset)));
BigDecimal.valueOf(convert4BytesToInt(d_copy, offset)));
offset += 4; offset += 4;
} }
// Decimal part // Decimal part
BigDecimal fracPart = new BigDecimal(0); BigDecimal fracPart = new BigDecimal(0);
int shift = 0; int shift = 0;
for (int i = 0; i < frac0; i++) for (int i = 0; i < frac0; i++) {
{
shift += LogBuffer.DIG_PER_DEC1; shift += LogBuffer.DIG_PER_DEC1;
fracPart = fracPart.add(BigDecimal.valueOf( fracPart = fracPart.add(BigDecimal.valueOf(convert4BytesToInt(d_copy, offset)).movePointLeft(shift));
convert4BytesToInt(d_copy, offset)).movePointLeft(shift));
offset += 4; offset += 4;
} }
if (LogBuffer.dig2bytes[frac0x] > 0) if (LogBuffer.dig2bytes[frac0x] > 0) {
{ fracPart = fracPart.add(BigDecimal.valueOf(convertNBytesToInt(d_copy, offset, LogBuffer.dig2bytes[frac0x]))
fracPart = fracPart.add(BigDecimal.valueOf( .movePointLeft(shift + frac0x));
convertNBytesToInt(d_copy, offset,
LogBuffer.dig2bytes[frac0x])).movePointLeft(
shift + frac0x));
} }
return BigDecimal.valueOf(sign).multiply(intPart.add(fracPart)); return BigDecimal.valueOf(sign).multiply(intPart.add(fracPart));
} }
public static final byte[] array1 = { (byte) 0x80, 0x00, 0x00, 0x05, 0x1b, public static final byte[] array1 = { (byte) 0x80, 0x00, 0x00, 0x05, 0x1b, 0x38, (byte) 0xb0, 0x60, 0x00 };
0x38, (byte) 0xb0, 0x60, 0x00 };
public static final byte[] array2 = { (byte) 0x7f, (byte) 0xff, public static final byte[] array2 = { (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xfb, (byte) 0xe4, (byte) 0xc7,
(byte) 0xff, (byte) 0xfb, (byte) 0xe4, (byte) 0xc7, (byte) 0x4f, (byte) 0x4f, (byte) 0xa0, (byte) 0xff };
(byte) 0xa0, (byte) 0xff };
public static final byte[] array3 = { -128, 0, 6, 20, 113, 56, 6, 26, -123 }; public static final byte[] array3 = { -128, 0, 6, 20, 113, 56, 6, 26, -123 };
public static final byte[] array4 = { -128, 7, 0, 0, 0, 1, 0, 0, 3 }; public static final byte[] array4 = { -128, 7, 0, 0, 0, 1, 0, 0, 3 };
public static final byte[] array5 = { -128, 0, 0, 0, 0, 1, 1, -122, -96, public static final byte[] array5 = { -128, 0, 0, 0, 0, 1, 1, -122, -96, -108 };
-108 };
public void testBigDecimal() throws InterruptedException public void testBigDecimal() throws InterruptedException {
{ do {
do
{
System.out.println("old extract decimal: "); System.out.println("old extract decimal: ");
long tt1 = 0; long tt1 = 0;
BigDecimal bd1 = null; BigDecimal bd1 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t1 = System.nanoTime(); final long t1 = System.nanoTime();
bd1 = extractDecimal(array2, 19, 10); bd1 = extractDecimal(array2, 19, 10);
tt1 += System.nanoTime() - t1; tt1 += System.nanoTime() - t1;
@@ -233,8 +201,7 @@ public class LogBufferTest extends TestCase
long tt2 = 0; long tt2 = 0;
BigDecimal bd2 = null; BigDecimal bd2 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t2 = System.nanoTime(); final long t2 = System.nanoTime();
bd2 = extractDecimal(array1, 19, 10); bd2 = extractDecimal(array1, 19, 10);
tt2 += System.nanoTime() - t2; tt2 += System.nanoTime() - t2;
@@ -245,8 +212,7 @@ public class LogBufferTest extends TestCase
long tt3 = 0; long tt3 = 0;
BigDecimal bd3 = null; BigDecimal bd3 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t3 = System.nanoTime(); final long t3 = System.nanoTime();
bd3 = extractDecimal(array3, 18, 6); bd3 = extractDecimal(array3, 18, 6);
tt3 += System.nanoTime() - t3; tt3 += System.nanoTime() - t3;
@@ -257,8 +223,7 @@ public class LogBufferTest extends TestCase
long tt4 = 0; long tt4 = 0;
BigDecimal bd4 = null; BigDecimal bd4 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t4 = System.nanoTime(); final long t4 = System.nanoTime();
bd4 = extractDecimal(array4, 18, 6); bd4 = extractDecimal(array4, 18, 6);
tt4 += System.nanoTime() - t4; tt4 += System.nanoTime() - t4;
@@ -269,8 +234,7 @@ public class LogBufferTest extends TestCase
long tt5 = 0; long tt5 = 0;
BigDecimal bd5 = null; BigDecimal bd5 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t5 = System.nanoTime(); final long t5 = System.nanoTime();
bd5 = extractDecimal(array5, 18, 6); bd5 = extractDecimal(array5, 18, 6);
tt5 += System.nanoTime() - t5; tt5 += System.nanoTime() - t5;
@@ -278,11 +242,9 @@ public class LogBufferTest extends TestCase
System.out.print(tt5 / LOOP); System.out.print(tt5 / LOOP);
System.out.print("ns >> "); System.out.print("ns >> ");
System.out.println(bd5); System.out.println(bd5);
} } while (false);
while (false);
do do {
{
System.out.println("new extract decimal: "); System.out.println("new extract decimal: ");
LogBuffer buffer1 = new LogBuffer(array2, 0, array2.length); LogBuffer buffer1 = new LogBuffer(array2, 0, array2.length);
@@ -293,8 +255,7 @@ public class LogBufferTest extends TestCase
long tt1 = 0; long tt1 = 0;
BigDecimal bd1 = null; BigDecimal bd1 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t1 = System.nanoTime(); final long t1 = System.nanoTime();
bd1 = buffer1.getDecimal(0, 19, 10); bd1 = buffer1.getDecimal(0, 19, 10);
tt1 += System.nanoTime() - t1; tt1 += System.nanoTime() - t1;
@@ -305,8 +266,7 @@ public class LogBufferTest extends TestCase
long tt2 = 0; long tt2 = 0;
BigDecimal bd2 = null; BigDecimal bd2 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t2 = System.nanoTime(); final long t2 = System.nanoTime();
bd2 = buffer2.getDecimal(0, 19, 10); bd2 = buffer2.getDecimal(0, 19, 10);
tt2 += System.nanoTime() - t2; tt2 += System.nanoTime() - t2;
@@ -317,8 +277,7 @@ public class LogBufferTest extends TestCase
long tt3 = 0; long tt3 = 0;
BigDecimal bd3 = null; BigDecimal bd3 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t3 = System.nanoTime(); final long t3 = System.nanoTime();
bd3 = buffer3.getDecimal(0, 18, 6); bd3 = buffer3.getDecimal(0, 18, 6);
tt3 += System.nanoTime() - t3; tt3 += System.nanoTime() - t3;
@@ -329,8 +288,7 @@ public class LogBufferTest extends TestCase
long tt4 = 0; long tt4 = 0;
BigDecimal bd4 = null; BigDecimal bd4 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t4 = System.nanoTime(); final long t4 = System.nanoTime();
bd4 = buffer4.getDecimal(0, 18, 6); bd4 = buffer4.getDecimal(0, 18, 6);
tt4 += System.nanoTime() - t4; tt4 += System.nanoTime() - t4;
@@ -341,8 +299,7 @@ public class LogBufferTest extends TestCase
long tt5 = 0; long tt5 = 0;
BigDecimal bd5 = null; BigDecimal bd5 = null;
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++) {
{
final long t5 = System.nanoTime(); final long t5 = System.nanoTime();
bd5 = buffer5.getDecimal(0, 18, 6); bd5 = buffer5.getDecimal(0, 18, 6);
tt5 += System.nanoTime() - t5; tt5 += System.nanoTime() - t5;
@@ -350,7 +307,6 @@ public class LogBufferTest extends TestCase
System.out.print(tt5 / LOOP); System.out.print(tt5 / LOOP);
System.out.print("ns >> "); System.out.print("ns >> ");
System.out.println(bd5); System.out.println(bd5);
} } while (false);
while (false);
} }
} }

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -1,10 +1,14 @@
#!/bin/bash #!/bin/bash
cygwin=false; cygwin=false;
linux=false;
case "`uname`" in case "`uname`" in
CYGWIN*) CYGWIN*)
cygwin=true cygwin=true
;; ;;
Linux*)
linux=true
;;
esac esac
get_pid() { get_pid() {
@@ -15,11 +19,19 @@ get_pid() {
JAVA_CMD=`cygpath --path --unix $JAVA_CMD` JAVA_CMD=`cygpath --path --unix $JAVA_CMD`
JAVA_PID=`ps |grep $JAVA_CMD |awk '{print $1}'` JAVA_PID=`ps |grep $JAVA_CMD |awk '{print $1}'`
else else
if [ ! -z "$PID" ]; then if $linux; then
JAVA_PID=`ps -C java -f --width 1000|grep "$STR"|grep "$PID"|grep -v grep|awk '{print $2}'` if [ ! -z "$PID" ]; then
else JAVA_PID=`ps -C java -f --width 1000|grep "$STR"|grep "$PID"|grep -v grep|awk '{print $2}'`
JAVA_PID=`ps -C java -f --width 1000|grep "$STR"|grep -v grep|awk '{print $2}'` else
fi JAVA_PID=`ps -C java -f --width 1000|grep "$STR"|grep -v grep|awk '{print $2}'`
fi
else
if [ ! -z "$PID" ]; then
JAVA_PID=`ps aux |grep "$STR"|grep "$PID"|grep -v grep|awk '{print $2}'`
else
JAVA_PID=`ps aux |grep "$STR"|grep -v grep|awk '{print $2}'`
fi
fi
fi fi
echo $JAVA_PID; echo $JAVA_PID;
} }

View File

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.otter.canal.common.CanalException;
import com.alibaba.otter.canal.common.utils.AddressUtils; import com.alibaba.otter.canal.common.utils.AddressUtils;
import com.alibaba.otter.canal.common.zookeeper.ZkClientx; import com.alibaba.otter.canal.common.zookeeper.ZkClientx;
import com.alibaba.otter.canal.common.zookeeper.ZookeeperPathUtils; import com.alibaba.otter.canal.common.zookeeper.ZookeeperPathUtils;
@@ -32,11 +33,12 @@ import com.alibaba.otter.canal.instance.core.CanalInstanceGenerator;
import com.alibaba.otter.canal.instance.manager.CanalConfigClient; import com.alibaba.otter.canal.instance.manager.CanalConfigClient;
import com.alibaba.otter.canal.instance.manager.ManagerCanalInstanceGenerator; import com.alibaba.otter.canal.instance.manager.ManagerCanalInstanceGenerator;
import com.alibaba.otter.canal.instance.spring.SpringCanalInstanceGenerator; import com.alibaba.otter.canal.instance.spring.SpringCanalInstanceGenerator;
import com.alibaba.otter.canal.server.embeded.CanalServerWithEmbeded; import com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded;
import com.alibaba.otter.canal.server.exception.CanalServerException; import com.alibaba.otter.canal.server.exception.CanalServerException;
import com.alibaba.otter.canal.server.netty.CanalServerWithNetty; import com.alibaba.otter.canal.server.netty.CanalServerWithNetty;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.google.common.collect.MigrateMap;
/** /**
* canal调度控制器 * canal调度控制器
@@ -58,7 +60,7 @@ public class CanalController {
private boolean autoScan = true; private boolean autoScan = true;
private InstanceAction defaultAction; private InstanceAction defaultAction;
private Map<InstanceMode, InstanceConfigMonitor> instanceConfigMonitors; private Map<InstanceMode, InstanceConfigMonitor> instanceConfigMonitors;
private CanalServerWithEmbeded embededCanalServer; private CanalServerWithEmbedded embededCanalServer;
private CanalServerWithNetty canalServer; private CanalServerWithNetty canalServer;
private CanalInstanceGenerator instanceGenerator; private CanalInstanceGenerator instanceGenerator;
@@ -69,7 +71,7 @@ public class CanalController {
} }
public CanalController(final Properties properties){ public CanalController(final Properties properties){
managerClients = new MapMaker().makeComputingMap(new Function<String, CanalConfigClient>() { managerClients = MigrateMap.makeComputingMap(new Function<String, CanalConfigClient>() {
public CanalConfigClient apply(String managerAddress) { public CanalConfigClient apply(String managerAddress) {
return getManagerClient(managerAddress); return getManagerClient(managerAddress);
@@ -86,7 +88,7 @@ public class CanalController {
cid = Long.valueOf(getProperty(properties, CanalConstants.CANAL_ID)); cid = Long.valueOf(getProperty(properties, CanalConstants.CANAL_ID));
ip = getProperty(properties, CanalConstants.CANAL_IP); ip = getProperty(properties, CanalConstants.CANAL_IP);
port = Integer.valueOf(getProperty(properties, CanalConstants.CANAL_PORT)); port = Integer.valueOf(getProperty(properties, CanalConstants.CANAL_PORT));
embededCanalServer = new CanalServerWithEmbeded(); embededCanalServer = new CanalServerWithEmbedded();
embededCanalServer.setCanalInstanceGenerator(instanceGenerator);// 设置自定义的instanceGenerator embededCanalServer.setCanalInstanceGenerator(instanceGenerator);// 设置自定义的instanceGenerator
canalServer = new CanalServerWithNetty(embededCanalServer); canalServer = new CanalServerWithNetty(embededCanalServer);
canalServer.setIp(ip); canalServer.setIp(ip);
@@ -106,7 +108,7 @@ public class CanalController {
final ServerRunningData serverData = new ServerRunningData(cid, ip + ":" + port); final ServerRunningData serverData = new ServerRunningData(cid, ip + ":" + port);
ServerRunningMonitors.setServerData(serverData); ServerRunningMonitors.setServerData(serverData);
ServerRunningMonitors.setRunningMonitors(new MapMaker().makeComputingMap(new Function<String, ServerRunningMonitor>() { ServerRunningMonitors.setRunningMonitors(MigrateMap.makeComputingMap(new Function<String, ServerRunningMonitor>() {
public ServerRunningMonitor apply(final String destination) { public ServerRunningMonitor apply(final String destination) {
ServerRunningMonitor runningMonitor = new ServerRunningMonitor(serverData); ServerRunningMonitor runningMonitor = new ServerRunningMonitor(serverData);
@@ -182,7 +184,8 @@ public class CanalController {
public void start(String destination) { public void start(String destination) {
InstanceConfig config = instanceConfigs.get(destination); InstanceConfig config = instanceConfigs.get(destination);
if (config == null) { if (config == null) {
config = new InstanceConfig(globalInstanceConfig); // 重新读取一下instance config
config = parseInstanceConfig(properties, destination);
instanceConfigs.put(destination, config); instanceConfigs.put(destination, config);
} }
@@ -214,7 +217,7 @@ public class CanalController {
} }
}; };
instanceConfigMonitors = new MapMaker().makeComputingMap(new Function<InstanceMode, InstanceConfigMonitor>() { instanceConfigMonitors = MigrateMap.makeComputingMap(new Function<InstanceMode, InstanceConfigMonitor>() {
public InstanceConfigMonitor apply(InstanceMode mode) { public InstanceConfigMonitor apply(InstanceMode mode) {
int scanInterval = Integer.valueOf(getProperty(properties, CanalConstants.CANAL_AUTO_SCAN_INTERVAL)); int scanInterval = Integer.valueOf(getProperty(properties, CanalConstants.CANAL_AUTO_SCAN_INTERVAL));
@@ -283,6 +286,9 @@ public class CanalController {
System.setProperty(CanalConstants.CANAL_DESTINATION_PROPERTY, destination); System.setProperty(CanalConstants.CANAL_DESTINATION_PROPERTY, destination);
instanceGenerator.setBeanFactory(getBeanFactory(config.getSpringXml())); instanceGenerator.setBeanFactory(getBeanFactory(config.getSpringXml()));
return instanceGenerator.generate(destination); return instanceGenerator.generate(destination);
} catch (Throwable e) {
logger.error("generator instance failed.", e);
throw new CanalException(e);
} finally { } finally {
System.setProperty(CanalConstants.CANAL_DESTINATION_PROPERTY, ""); System.setProperty(CanalConstants.CANAL_DESTINATION_PROPERTY, "");
} }
@@ -386,7 +392,7 @@ public class CanalController {
} }
if (autoScan) { if (autoScan) {
instanceConfigMonitors.get(config.getMode()).regeister(destination, defaultAction); instanceConfigMonitors.get(config.getMode()).register(destination, defaultAction);
} }
} }

View File

@@ -42,7 +42,7 @@ public class CanalLauncher {
controller.stop(); controller.stop();
} catch (Throwable e) { } catch (Throwable e) {
logger.warn("##something goes wrong when stopping canal Server:\n{}", logger.warn("##something goes wrong when stopping canal Server:\n{}",
ExceptionUtils.getFullStackTrace(e)); ExceptionUtils.getFullStackTrace(e));
} finally { } finally {
logger.info("## canal server is down."); logger.info("## canal server is down.");
} }
@@ -51,7 +51,7 @@ public class CanalLauncher {
}); });
} catch (Throwable e) { } catch (Throwable e) {
logger.error("## Something goes wrong when starting up the canal Server:\n{}", logger.error("## Something goes wrong when starting up the canal Server:\n{}",
ExceptionUtils.getFullStackTrace(e)); ExceptionUtils.getFullStackTrace(e));
System.exit(0); System.exit(0);
} }
} }

View File

@@ -11,15 +11,15 @@ public interface InstanceAction {
/** /**
* 启动destination * 启动destination
*/ */
public void start(String destination); void start(String destination);
/** /**
* 停止destination * 停止destination
*/ */
public void stop(String destination); void stop(String destination);
/** /**
* 重载destination,可能需要stop,start操作,或者只是更新下内存配置 * 重载destination,可能需要stop,start操作,或者只是更新下内存配置
*/ */
public void reload(String destination); void reload(String destination);
} }

View File

@@ -10,7 +10,7 @@ import com.alibaba.otter.canal.common.CanalLifeCycle;
*/ */
public interface InstanceConfigMonitor extends CanalLifeCycle { public interface InstanceConfigMonitor extends CanalLifeCycle {
public void regeister(String destination, InstanceAction action); void register(String destination, InstanceAction action);
public void unRegeister(String destination); void unregister(String destination);
} }

View File

@@ -9,11 +9,11 @@ import com.alibaba.otter.canal.common.CanalLifeCycle;
*/ */
public class ManagerInstanceConfigMonitor extends AbstractCanalLifeCycle implements InstanceConfigMonitor, CanalLifeCycle { public class ManagerInstanceConfigMonitor extends AbstractCanalLifeCycle implements InstanceConfigMonitor, CanalLifeCycle {
public void regeister(String destination, InstanceAction action) { public void register(String destination, InstanceAction action) {
} }
public void unRegeister(String destination) { public void unregister(String destination) {
} }

View File

@@ -24,6 +24,7 @@ import com.alibaba.otter.canal.common.CanalLifeCycle;
import com.alibaba.otter.canal.common.utils.NamedThreadFactory; import com.alibaba.otter.canal.common.utils.NamedThreadFactory;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.google.common.collect.MigrateMap;
/** /**
* 监听基于spring配置的instance变化 * 监听基于spring配置的instance变化
@@ -39,7 +40,7 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
private long scanIntervalInSecond = 5; private long scanIntervalInSecond = 5;
private InstanceAction defaultAction = null; private InstanceAction defaultAction = null;
private Map<String, InstanceAction> actions = new MapMaker().makeMap(); private Map<String, InstanceAction> actions = new MapMaker().makeMap();
private Map<String, InstanceConfigFiles> lastFiles = new MapMaker().makeComputingMap(new Function<String, InstanceConfigFiles>() { private Map<String, InstanceConfigFiles> lastFiles = MigrateMap.makeComputingMap(new Function<String, InstanceConfigFiles>() {
public InstanceConfigFiles apply(String destination) { public InstanceConfigFiles apply(String destination) {
return new InstanceConfigFiles(destination); return new InstanceConfigFiles(destination);
@@ -72,7 +73,7 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
lastFiles.clear(); lastFiles.clear();
} }
public void regeister(String destination, InstanceAction action) { public void register(String destination, InstanceAction action) {
if (action != null) { if (action != null) {
actions.put(destination, action); actions.put(destination, action);
} else { } else {
@@ -80,7 +81,7 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
} }
} }
public void unRegeister(String destination) { public void unregister(String destination) {
actions.remove(destination); actions.remove(destination);
} }

View File

@@ -41,6 +41,10 @@ canal.instance.filter.query.dml = false
canal.instance.filter.query.ddl = false canal.instance.filter.query.ddl = false
canal.instance.filter.table.error = false canal.instance.filter.table.error = false
# binlog format/image check
canal.instance.binlog.format = ROW,STATEMENT,MIXED
canal.instance.binlog.image = FULL,MINIMAL,NOBLOB
# binlog ddl isolation # binlog ddl isolation
canal.instance.get.ddl.isolation = false canal.instance.get.ddl.isolation = false

View File

@@ -179,5 +179,7 @@
<property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" /> <property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" />
<property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" /> <property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" />
<property name="filterTableError" value="${canal.instance.filter.table.error:false}" /> <property name="filterTableError" value="${canal.instance.filter.table.error:false}" />
<property name="supportBinlogFormats" value="${canal.instance.binlog.format}" />
<property name="supportBinlogImages" value="${canal.instance.binlog.image}" />
</bean> </bean>
</beans> </beans>

View File

@@ -164,5 +164,7 @@
<property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" /> <property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" />
<property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" /> <property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" />
<property name="filterTableError" value="${canal.instance.filter.table.error:false}" /> <property name="filterTableError" value="${canal.instance.filter.table.error:false}" />
<property name="supportBinlogFormats" value="${canal.instance.binlog.format}" />
<property name="supportBinlogImages" value="${canal.instance.binlog.image}" />
</bean> </bean>
</beans> </beans>

View File

@@ -161,6 +161,8 @@
<property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" /> <property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" />
<property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" /> <property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" />
<property name="filterTableError" value="${canal.instance.filter.table.error:false}" /> <property name="filterTableError" value="${canal.instance.filter.table.error:false}" />
<property name="supportBinlogFormats" value="${canal.instance.binlog.format}" />
<property name="supportBinlogImages" value="${canal.instance.binlog.image}" />
</bean> </bean>
<bean id="eventParser2" class="com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser"> <bean id="eventParser2" class="com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser">
@@ -249,5 +251,7 @@
<property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" /> <property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" />
<property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" /> <property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" />
<property name="filterTableError" value="${canal.instance.filter.table.error:false}" /> <property name="filterTableError" value="${canal.instance.filter.table.error:false}" />
<property name="supportBinlogFormats" value="${canal.instance.binlog.format}" />
<property name="supportBinlogImages" value="${canal.instance.binlog.image}" />
</bean> </bean>
</beans> </beans>

View File

@@ -152,5 +152,7 @@
<property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" /> <property name="filterQueryDcl" value="${canal.instance.filter.query.dcl:false}" />
<property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" /> <property name="filterQueryDdl" value="${canal.instance.filter.query.ddl:false}" />
<property name="filterTableError" value="${canal.instance.filter.table.error:false}" /> <property name="filterTableError" value="${canal.instance.filter.table.error:false}" />
<property name="supportBinlogFormats" value="${canal.instance.binlog.format}" />
<property name="supportBinlogImages" value="${canal.instance.binlog.image}" />
</bean> </bean>
</beans> </beans>

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -14,15 +14,17 @@ import com.alibaba.otter.canal.common.utils.CanalToStringStyle;
* </pre> * </pre>
* *
* <br> * <br>
* The Packet Header will not be shown in the descriptions of packets that follow this section. Think of it as always * The Packet Header will not be shown in the descriptions of packets that
* there. But logically, it "precedes the packet" rather than "is included in the packet".<br> * follow this section. Think of it as always there. But logically, it
* "precedes the packet" rather than "is included in the packet".<br>
* *
* @author fujohnwang * @author fujohnwang
*/ */
public class HeaderPacket implements IPacket { public class HeaderPacket implements IPacket {
/** /**
* this field indicates the packet length that follows the header, with header packet's 4 bytes excluded. * this field indicates the packet length that follows the header, with
* header packet's 4 bytes excluded.
*/ */
private int packetBodyLength; private int packetBodyLength;
private byte packetSequenceNumber; private byte packetSequenceNumber;

View File

@@ -12,6 +12,7 @@ import java.io.IOException;
* @see 1.0 * @see 1.0
*/ */
public interface IPacket { public interface IPacket {
/** /**
* un-marshal raw bytes into {@link IPacket} state for application usage.<br> * un-marshal raw bytes into {@link IPacket} state for application usage.<br>
* *

View File

@@ -56,24 +56,24 @@ public class FieldPacket extends PacketWithHeaderPacket {
this.name = reader.readLengthCodedString(data); this.name = reader.readLengthCodedString(data);
this.originalName = reader.readLengthCodedString(data); this.originalName = reader.readLengthCodedString(data);
index = reader.getIndex(); index = reader.getIndex();
// //
index++; index++;
// //
this.character = ByteHelper.readUnsignedShortLittleEndian(data, index); this.character = ByteHelper.readUnsignedShortLittleEndian(data, index);
index += 2; index += 2;
// //
this.length = ByteHelper.readUnsignedIntLittleEndian(data, index); this.length = ByteHelper.readUnsignedIntLittleEndian(data, index);
index += 4; index += 4;
// //
this.type = data[index]; this.type = data[index];
index++; index++;
// //
this.flags = ByteHelper.readUnsignedShortLittleEndian(data, index); this.flags = ByteHelper.readUnsignedShortLittleEndian(data, index);
index += 2; index += 2;
// //
this.decimals = data[index]; this.decimals = data[index];
index++; index++;
// //
if (index < data.length) { if (index < data.length) {
reader.setIndex(index); reader.setIndex(index);
this.definition = reader.readLengthCodedString(data); this.definition = reader.readLengthCodedString(data);

View File

@@ -75,7 +75,8 @@ public class HandshakeInitializationPacket extends PacketWithHeaderPacket {
// 8. bypass filtered bytes // 8. bypass filtered bytes
index += 13; index += 13;
// 9. read rest of scramble_buff // 9. read rest of scramble_buff
this.restOfScrambleBuff = ByteHelper.readFixedLengthBytes(data, index, 12); // 虽然Handshake Initialization this.restOfScrambleBuff = ByteHelper.readFixedLengthBytes(data, index, 12); // 虽然Handshake
// Initialization
// Packet规定最后13个byte是剩下的scrumble, // Packet规定最后13个byte是剩下的scrumble,
// 但实际上最后一个字节是0, 不应该包含在scrumble中. // 但实际上最后一个字节是0, 不应该包含在scrumble中.
// end read // end read

View File

@@ -23,7 +23,7 @@ public abstract class ByteHelper {
out.write(str.getBytes()); out.write(str.getBytes());
out.write(MSC.NULL_TERMINATED_STRING_DELIMITER); out.write(MSC.NULL_TERMINATED_STRING_DELIMITER);
} }
public static void writeNullTerminated(byte[] data, ByteArrayOutputStream out) throws IOException { public static void writeNullTerminated(byte[] data, ByteArrayOutputStream out) throws IOException {
out.write(data); out.write(data);
out.write(MSC.NULL_TERMINATED_STRING_DELIMITER); out.write(MSC.NULL_TERMINATED_STRING_DELIMITER);

View File

@@ -26,7 +26,7 @@ public class LengthCodedStringReader {
try { try {
return new String(ArrayUtils.subarray(data, getIndex(), (int) (getIndex() + length)), return new String(ArrayUtils.subarray(data, getIndex(), (int) (getIndex() + length)),
encoding == null ? CODE_PAGE_1252 : encoding); encoding == null ? CODE_PAGE_1252 : encoding);
} finally { } finally {
setIndex((int) (getIndex() + length)); setIndex((int) (getIndex() + length));
} }

View File

@@ -30,8 +30,10 @@ public abstract class PacketManager {
} }
/** /**
* Since We r using blocking IO, so we will just write once and assert the length to simplify the read operation.<br> * Since We r using blocking IO, so we will just write once and assert the
* If the block write doesn't work as we expected, we will change this implementation as per the result. * length to simplify the read operation.<br>
* If the block write doesn't work as we expected, we will change this
* implementation as per the result.
* *
* @param ch * @param ch
* @param len * @param len

View File

@@ -3,7 +3,7 @@ package com.alibaba.otter.canal.parse.driver.mysql;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import junit.framework.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>
@@ -33,7 +33,9 @@
<plugins> <plugins>
<!-- deploy模块的packaging通常是jar,如果项目中没有java 源代码或资源文件,加上这一段配置使项目能通过构建 --> <!-- deploy模块的packaging通常是jar,如果项目中没有java 源代码或资源文件,加上这一段配置使项目能通过构建 -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration> <configuration>
<archive> <archive>
<addMavenDescriptor>true</addMavenDescriptor> <addMavenDescriptor>true</addMavenDescriptor>

View File

@@ -24,7 +24,7 @@ public class SimpleCanalClientTest extends AbstractCanalClientTest {
// 根据ip,直接创建链接,无HA的功能 // 根据ip,直接创建链接,无HA的功能
String destination = "example"; String destination = "example";
CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(AddressUtils.getHostIp(), CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(AddressUtils.getHostIp(),
11111), destination, "", ""); 11111), destination, "", "");
final SimpleCanalClientTest clientTest = new SimpleCanalClientTest(destination); final SimpleCanalClientTest clientTest = new SimpleCanalClientTest(destination);
clientTest.setConnector(connector); clientTest.setConnector(connector);

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -10,33 +10,32 @@ import org.apache.oro.text.regex.Perl5Compiler;
import com.alibaba.otter.canal.filter.exception.CanalFilterException; import com.alibaba.otter.canal.filter.exception.CanalFilterException;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.google.common.collect.MigrateMap;
/** /**
* 提供{@linkplain Pattern}的lazy get处理 * 提供{@linkplain Pattern}的lazy get处理
* *
* @author jianghang 2013-1-22 下午09:36:44 * @author jianghang 2013-1-22 下午09:36:44
* @version 1.0.0 * @version 1.0.0
*/ */
public class PatternUtils { public class PatternUtils {
private static Map<String, Pattern> patterns = new MapMaker().softValues().makeComputingMap( @SuppressWarnings("deprecation")
new Function<String, Pattern>() { private static Map<String, Pattern> patterns = MigrateMap.makeComputingMap(new MapMaker().softValues(),
new Function<String, Pattern>() {
public Pattern apply( public Pattern apply(String pattern) {
String pattern) { try {
try { PatternCompiler pc = new Perl5Compiler();
PatternCompiler pc = new Perl5Compiler(); return pc.compile(pattern,
return pc.compile( Perl5Compiler.CASE_INSENSITIVE_MASK
pattern, | Perl5Compiler.READ_ONLY_MASK
Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK);
| Perl5Compiler.READ_ONLY_MASK } catch (MalformedPatternException e) {
| Perl5Compiler.SINGLELINE_MASK); throw new CanalFilterException(e);
} catch (MalformedPatternException e) { }
throw new CanalFilterException( }
e); });
}
}
});
public static Pattern getPattern(String pattern) { public static Pattern getPattern(String pattern) {
return patterns.get(pattern); return patterns.get(pattern);

View File

@@ -1,6 +1,6 @@
package com.alibaba.otter.canal.filter; package com.alibaba.otter.canal.filter;
import junit.framework.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@@ -67,16 +67,14 @@ public class AviaterFilterTest {
result = filter3.filter("fooooot"); result = filter3.filter("fooooot");
Assert.assertEquals(true, result); Assert.assertEquals(true, result);
AviaterRegexFilter filter4 = new AviaterRegexFilter( AviaterRegexFilter filter4 = new AviaterRegexFilter("otter2.otter_stability1|otter1.otter_stability1|retl.retl_mark|retl.retl_buffer|retl.xdual");
"otter2.otter_stability1|otter1.otter_stability1|retl.retl_mark|retl.retl_buffer|retl.xdual");
result = filter4.filter("otter1.otter_stability1"); result = filter4.filter("otter1.otter_stability1");
Assert.assertEquals(true, result); Assert.assertEquals(true, result);
} }
@Test @Test
public void testDisordered() { public void testDisordered() {
AviaterRegexFilter filter = new AviaterRegexFilter( AviaterRegexFilter filter = new AviaterRegexFilter("u\\..*,uvw\\..*,uv\\..*,a\\.x,a\\.xyz,a\\.xy,abc\\.x,abc\\.xyz,abc\\.xy,ab\\.x,ab\\.xyz,ab\\.xy");
"u\\..*,uvw\\..*,uv\\..*,a\\.x,a\\.xyz,a\\.xy,abc\\.x,abc\\.xyz,abc\\.xy,ab\\.x,ab\\.xyz,ab\\.xy");
boolean result = filter.filter("u.abc"); boolean result = filter.filter("u.abc");
Assert.assertEquals(true, result); Assert.assertEquals(true, result);

View File

@@ -5,7 +5,7 @@ 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 junit.framework.Assert; import org.junit.Assert;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.junit.Test; import org.junit.Test;

View File

@@ -3,10 +3,9 @@
<parent> <parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>
<artifactId>canal</artifactId> <artifactId>canal</artifactId>
<version>1.0.19</version> <version>1.0.20</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId>
<artifactId>canal.instance.core</artifactId> <artifactId>canal.instance.core</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>canal instance core module for otter ${project.version}</name> <name>canal instance core module for otter ${project.version}</name>

View File

@@ -16,20 +16,20 @@ import com.alibaba.otter.canal.store.CanalEventStore;
*/ */
public interface CanalInstance extends CanalLifeCycle { public interface CanalInstance extends CanalLifeCycle {
public String getDestination(); String getDestination();
public CanalEventParser getEventParser(); CanalEventParser getEventParser();
public CanalEventSink getEventSink(); CanalEventSink getEventSink();
public CanalEventStore getEventStore(); CanalEventStore getEventStore();
public CanalMetaManager getMetaManager(); CanalMetaManager getMetaManager();
public CanalAlarmHandler getAlarmHandler(); CanalAlarmHandler getAlarmHandler();
/** /**
* 客户端发生订阅/取消订阅行为 * 客户端发生订阅/取消订阅行为
*/ */
public boolean subscribeChange(ClientIdentity identity); boolean subscribeChange(ClientIdentity identity);
} }

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -89,8 +89,7 @@ public class CanalInstanceWithManager extends CanalInstanceSupport implements Ca
this.destination = canal.getName(); this.destination = canal.getName();
this.filter = filter; this.filter = filter;
logger.info("init CannalInstance for {}-{} with parameters:{}", logger.info("init CannalInstance for {}-{} with parameters:{}", canalId, destination, parameters);
new Object[] { canalId, destination, parameters });
// 初始化报警机制 // 初始化报警机制
initAlarmHandler(); initAlarmHandler();
// 初始化metaManager // 初始化metaManager
@@ -116,8 +115,7 @@ public class CanalInstanceWithManager extends CanalInstanceSupport implements Ca
public void start() { public void start() {
super.start(); super.start();
// 初始化metaManager // 初始化metaManager
logger.info("start CannalInstance for {}-{} with parameters:{}", new Object[] { canalId, destination, logger.info("start CannalInstance for {}-{} with parameters:{}", canalId, destination, parameters);
parameters });
if (!metaManager.isStart()) { if (!metaManager.isStart()) {
metaManager.start(); metaManager.start();
@@ -336,7 +334,7 @@ public class CanalInstanceWithManager extends CanalInstanceSupport implements Ca
} }
private CanalEventParser doInitEventParser(SourcingType type, List<InetSocketAddress> dbAddresses) { private CanalEventParser doInitEventParser(SourcingType type, List<InetSocketAddress> dbAddresses) {
CanalEventParser eventParser = null; CanalEventParser eventParser;
if (type.isMysql()) { if (type.isMysql()) {
MysqlEventParser mysqlEventParser = new MysqlEventParser(); MysqlEventParser mysqlEventParser = new MysqlEventParser();
mysqlEventParser.setDestination(destination); mysqlEventParser.setDestination(destination);

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -63,6 +63,7 @@ public class CanalInstanceWithSpring extends CanalInstanceSupport implements Can
public boolean subscribeChange(ClientIdentity identity) { public boolean subscribeChange(ClientIdentity identity) {
if (StringUtils.isNotEmpty(identity.getFilter())) { if (StringUtils.isNotEmpty(identity.getFilter())) {
logger.info("subscribe filter change to " + identity.getFilter());
AviaterRegexFilter aviaterFilter = new AviaterRegexFilter(identity.getFilter()); AviaterRegexFilter aviaterFilter = new AviaterRegexFilter(identity.getFilter());
boolean isGroup = (eventParser instanceof GroupEventParser); boolean isGroup = (eventParser instanceof GroupEventParser);

View File

@@ -11,8 +11,10 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* 扩展Spring的{@linkplain org.springframework.beans.factory.config.PropertyPlaceholderConfigurer} ,增加默认值的功能。 * 扩展Spring的
* 例如:${placeholder:defaultValue},假如placeholder的值不存在,则默认取得 defaultValue。 * {@linkplain org.springframework.beans.factory.config.PropertyPlaceholderConfigurer}
* ,增加默认值的功能。 例如:${placeholder:defaultValue},假如placeholder的值不存在,则默认取得
* defaultValue。
* *
* @author jianghang 2013-1-24 下午03:37:56 * @author jianghang 2013-1-24 下午03:37:56
* @version 1.0.0 * @version 1.0.0

View File

@@ -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.19</version> <version>1.0.20</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>com.alibaba.otter</groupId> <groupId>com.alibaba.otter</groupId>

View File

@@ -35,12 +35,12 @@ public interface CanalMetaManager extends CanalLifeCycle {
void unsubscribe(ClientIdentity clientIdentity) throws CanalMetaManagerException; void unsubscribe(ClientIdentity clientIdentity) throws CanalMetaManagerException;
/** /**
* 获取cuosr游标 * 获取 cursor 游标
*/ */
Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException; Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException;
/** /**
* 更新cuosr游标 * 更新 cursor 游标
*/ */
void updateCursor(ClientIdentity clientIdentity, Position position) throws CanalMetaManagerException; void updateCursor(ClientIdentity clientIdentity, Position position) throws CanalMetaManagerException;

View File

@@ -26,7 +26,7 @@ import com.alibaba.otter.canal.protocol.position.LogPosition;
import com.alibaba.otter.canal.protocol.position.Position; import com.alibaba.otter.canal.protocol.position.Position;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker; import com.google.common.collect.MigrateMap;
/** /**
* 基于文件刷新的metaManager实现 * 基于文件刷新的metaManager实现
@@ -69,7 +69,7 @@ public class FileMixedMetaManager extends MemoryMetaManager implements CanalMeta
throw new CanalMetaManagerException("dir[" + dataDir.getPath() + "] can not read/write"); throw new CanalMetaManagerException("dir[" + dataDir.getPath() + "] can not read/write");
} }
dataFileCaches = new MapMaker().makeComputingMap(new Function<String, File>() { dataFileCaches = MigrateMap.makeComputingMap(new Function<String, File>() {
public File apply(String destination) { public File apply(String destination) {
return getDataFile(destination); return getDataFile(destination);
@@ -77,14 +77,14 @@ public class FileMixedMetaManager extends MemoryMetaManager implements CanalMeta
}); });
executor = Executors.newScheduledThreadPool(1); executor = Executors.newScheduledThreadPool(1);
destinations = new MapMaker().makeComputingMap(new Function<String, List<ClientIdentity>>() { destinations = MigrateMap.makeComputingMap(new Function<String, List<ClientIdentity>>() {
public List<ClientIdentity> apply(String destination) { public List<ClientIdentity> apply(String destination) {
return loadClientIdentity(destination); return loadClientIdentity(destination);
} }
}); });
cursors = new MapMaker().makeComputingMap(new Function<ClientIdentity, Position>() { cursors = MigrateMap.makeComputingMap(new Function<ClientIdentity, Position>() {
public Position apply(ClientIdentity clientIdentity) { public Position apply(ClientIdentity clientIdentity) {
Position position = loadCursor(clientIdentity.getDestination(), clientIdentity); Position position = loadCursor(clientIdentity.getDestination(), clientIdentity);
@@ -109,10 +109,10 @@ public class FileMixedMetaManager extends MemoryMetaManager implements CanalMeta
// 定时将内存中的最新值刷到file中,多次变更只刷一次 // 定时将内存中的最新值刷到file中,多次变更只刷一次
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
LogPosition cursor = (LogPosition) getCursor(clientIdentity); LogPosition cursor = (LogPosition) getCursor(clientIdentity);
logger.info("clientId:{} cursor:[{},{},{}] address[{}]", new Object[] { logger.info("clientId:{} cursor:[{},{},{}] address[{}]",
clientIdentity.getClientId(), cursor.getPostion().getJournalName(), new Object[] { clientIdentity.getClientId(), cursor.getPostion().getJournalName(),
cursor.getPostion().getPosition(), cursor.getPostion().getTimestamp(), cursor.getPostion().getPosition(), cursor.getPostion().getTimestamp(),
cursor.getIdentity().getSourceAddress().toString() }); cursor.getIdentity().getSourceAddress().toString() });
} }
flushDataToFile(clientIdentity.getDestination()); flushDataToFile(clientIdentity.getDestination());
updateCursorTasks.remove(clientIdentity); updateCursorTasks.remove(clientIdentity);
@@ -122,7 +122,10 @@ public class FileMixedMetaManager extends MemoryMetaManager implements CanalMeta
} }
} }
} }
}, period, period, TimeUnit.MILLISECONDS); },
period,
period,
TimeUnit.MILLISECONDS);
} }
public void stop() { public void stop() {

View File

@@ -15,6 +15,7 @@ import com.google.common.base.Function;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.MigrateMap;
/** /**
* 内存版实现 * 内存版实现
@@ -31,7 +32,7 @@ public class MemoryMetaManager extends AbstractCanalLifeCycle implements CanalMe
public void start() { public void start() {
super.start(); super.start();
batches = new MapMaker().makeComputingMap(new Function<ClientIdentity, MemoryClientIdentityBatch>() { batches = MigrateMap.makeComputingMap(new Function<ClientIdentity, MemoryClientIdentityBatch>() {
public MemoryClientIdentityBatch apply(ClientIdentity clientIdentity) { public MemoryClientIdentityBatch apply(ClientIdentity clientIdentity) {
return MemoryClientIdentityBatch.create(clientIdentity); return MemoryClientIdentityBatch.create(clientIdentity);
@@ -41,7 +42,7 @@ public class MemoryMetaManager extends AbstractCanalLifeCycle implements CanalMe
cursors = new MapMaker().makeMap(); cursors = new MapMaker().makeMap();
destinations = new MapMaker().makeComputingMap(new Function<String, List<ClientIdentity>>() { destinations = MigrateMap.makeComputingMap(new Function<String, List<ClientIdentity>>() {
public List<ClientIdentity> apply(String destination) { public List<ClientIdentity> apply(String destination) {
return Lists.newArrayList(); return Lists.newArrayList();
@@ -65,7 +66,7 @@ public class MemoryMetaManager extends AbstractCanalLifeCycle implements CanalMe
if (clientIdentitys.contains(clientIdentity)) { if (clientIdentitys.contains(clientIdentity)) {
clientIdentitys.remove(clientIdentity); clientIdentitys.remove(clientIdentity);
} }
clientIdentitys.add(clientIdentity); clientIdentitys.add(clientIdentity);
} }
@@ -162,8 +163,9 @@ public class MemoryMetaManager extends AbstractCanalLifeCycle implements CanalMe
Long minBatchId = Collections.min(batches.keySet()); Long minBatchId = Collections.min(batches.keySet());
if (!minBatchId.equals(batchId)) { if (!minBatchId.equals(batchId)) {
// 检查一下提交的ack/rollback,必须按batchId分出去的顺序提交,否则容易出现丢数据 // 检查一下提交的ack/rollback,必须按batchId分出去的顺序提交,否则容易出现丢数据
throw new CanalMetaManagerException(String.format("batchId:%d is not the firstly:%d", batchId, throw new CanalMetaManagerException(String.format("batchId:%d is not the firstly:%d",
minBatchId)); batchId,
minBatchId));
} }
return batches.remove(batchId); return batches.remove(batchId);
} else { } else {

View File

@@ -12,11 +12,11 @@ import com.alibaba.otter.canal.protocol.ClientIdentity;
import com.alibaba.otter.canal.protocol.position.Position; import com.alibaba.otter.canal.protocol.position.Position;
import com.alibaba.otter.canal.protocol.position.PositionRange; import com.alibaba.otter.canal.protocol.position.PositionRange;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.MapMaker; import com.google.common.collect.MigrateMap;
/** /**
* 组合memory + zookeeper的使用模式 * 组合memory + zookeeper的使用模式
* *
* @author jianghang 2012-7-11 下午03:58:00 * @author jianghang 2012-7-11 下午03:58:00
* @version 1.0.0 * @version 1.0.0
*/ */
@@ -37,14 +37,14 @@ public class MixedMetaManager extends MemoryMetaManager implements CanalMetaMana
} }
executor = Executors.newFixedThreadPool(1); executor = Executors.newFixedThreadPool(1);
destinations = new MapMaker().makeComputingMap(new Function<String, List<ClientIdentity>>() { destinations = MigrateMap.makeComputingMap(new Function<String, List<ClientIdentity>>() {
public List<ClientIdentity> apply(String destination) { public List<ClientIdentity> apply(String destination) {
return zooKeeperMetaManager.listAllSubscribeInfo(destination); return zooKeeperMetaManager.listAllSubscribeInfo(destination);
} }
}); });
cursors = new MapMaker().makeComputingMap(new Function<ClientIdentity, Position>() { cursors = MigrateMap.makeComputingMap(new Function<ClientIdentity, Position>() {
public Position apply(ClientIdentity clientIdentity) { public Position apply(ClientIdentity clientIdentity) {
Position position = zooKeeperMetaManager.getCursor(clientIdentity); Position position = zooKeeperMetaManager.getCursor(clientIdentity);
@@ -56,7 +56,7 @@ public class MixedMetaManager extends MemoryMetaManager implements CanalMetaMana
} }
}); });
batches = new MapMaker().makeComputingMap(new Function<ClientIdentity, MemoryClientIdentityBatch>() { batches = MigrateMap.makeComputingMap(new Function<ClientIdentity, MemoryClientIdentityBatch>() {
public MemoryClientIdentityBatch apply(ClientIdentity clientIdentity) { public MemoryClientIdentityBatch apply(ClientIdentity clientIdentity) {
// 读取一下zookeeper信息,初始化一次 // 读取一下zookeeper信息,初始化一次

View File

@@ -19,7 +19,7 @@ import com.alibaba.otter.canal.protocol.ClientIdentity;
import com.alibaba.otter.canal.protocol.position.Position; import com.alibaba.otter.canal.protocol.position.Position;
import com.alibaba.otter.canal.protocol.position.PositionRange; import com.alibaba.otter.canal.protocol.position.PositionRange;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.MapMaker; import com.google.common.collect.MigrateMap;
/** /**
* 基于定时刷新的策略的mixed实现 * 基于定时刷新的策略的mixed实现
@@ -52,14 +52,14 @@ public class PeriodMixedMetaManager extends MemoryMetaManager implements CanalMe
} }
executor = Executors.newScheduledThreadPool(1); executor = Executors.newScheduledThreadPool(1);
destinations = new MapMaker().makeComputingMap(new Function<String, List<ClientIdentity>>() { destinations = MigrateMap.makeComputingMap(new Function<String, List<ClientIdentity>>() {
public List<ClientIdentity> apply(String destination) { public List<ClientIdentity> apply(String destination) {
return zooKeeperMetaManager.listAllSubscribeInfo(destination); return zooKeeperMetaManager.listAllSubscribeInfo(destination);
} }
}); });
cursors = new MapMaker().makeComputingMap(new Function<ClientIdentity, Position>() { cursors = MigrateMap.makeComputingMap(new Function<ClientIdentity, Position>() {
public Position apply(ClientIdentity clientIdentity) { public Position apply(ClientIdentity clientIdentity) {
Position position = zooKeeperMetaManager.getCursor(clientIdentity); Position position = zooKeeperMetaManager.getCursor(clientIdentity);
@@ -71,7 +71,7 @@ public class PeriodMixedMetaManager extends MemoryMetaManager implements CanalMe
} }
}); });
batches = new MapMaker().makeComputingMap(new Function<ClientIdentity, MemoryClientIdentityBatch>() { batches = MigrateMap.makeComputingMap(new Function<ClientIdentity, MemoryClientIdentityBatch>() {
public MemoryClientIdentityBatch apply(ClientIdentity clientIdentity) { public MemoryClientIdentityBatch apply(ClientIdentity clientIdentity) {
// 读取一下zookeeper信息,初始化一次 // 读取一下zookeeper信息,初始化一次

Some files were not shown because too many files have changed in this diff Show More