Browse Source

fixed issue #440 , optime find position

agapple 7 years ago
parent
commit
c60b04424b

+ 8 - 0
parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/MysqlEventParser.java

@@ -771,6 +771,14 @@ public class MysqlEventParser extends AbstractMysqlEventParser implements CanalE
                             }
                             }
                         }
                         }
 
 
+                        if (entryPosition == null) {
+                            // 如果啥都找不到,就返回第一条Format Event的位点,一般是116位点
+                            entryPosition = new EntryPosition(logfilename, logfileoffset, logposTimestamp, serverId);
+                            logger.debug("set {} to be pending start position before finding another proper one...",
+                                entryPosition);
+                            logPosition.setPostion(entryPosition);
+                        }
+
                         if (StringUtils.equals(endPosition.getJournalName(), logfilename)
                         if (StringUtils.equals(endPosition.getJournalName(), logfilename)
                             && endPosition.getPosition() < logfileoffset) {
                             && endPosition.getPosition() < logfileoffset) {
                             return false;
                             return false;

+ 64 - 23
parse/src/test/resources/ddl/create.sql

@@ -1,23 +1,64 @@
- CREATE TABLE `test` (
-  `id`  bigint(20)  zerofill unsigNed   NOT NULL AUTO_INCREMENT COMMENT 'id',
-  `c_tinyint` tinyint(4) DEFAULT '1' COMMENT 'tinyint',
-  `c_smallint` smallint(6) DEFAULT 0 COMMENT 'smallint',
-  `c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
-  `c_int` int(11) DEFAULT NULL COMMENT 'int',
-  `c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',
-  `c_decimal` decimal(10,3) DEFAULT NULL COMMENT 'decimal',
-  `c_date` date DEFAULT '0000-00-00' COMMENT 'date',
-  `c_datetime` datetime DEFAULT '0000-00-00 00:00:00' COMMENT 'datetime',
-  `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',
-  `c_time` time DEFAULT NULL COMMENT 'time',
-  `c_char` char(10) DEFAULT NULL COMMENT 'char',
-  `c_varchar` varchar(10) DEFAULT 'hello' COMMENT 'varchar',
-  `c_blob` blob COMMENT 'blob',
-  `c_text` text COMMENT 'text',
-  `c_mediumtext` mediumtext COMMENT 'mediumtext',
-  `c_longblob` longblob COMMENT 'longblob',
-  PRIMARY KEY (`id`),
-  UNIQUE KEY `uk_a` (`c_tinyint`),
-  KEY `k_b` (`c_smallint`),
-  KEY `k_c` (`c_mediumint`,`c_int`)
-) ENGINE=InnoDB AUTO_INCREMENT=1769503 DEFAULT CHARSET=utf8mb4 COMMENT='10000000';
+CREATE TABLE `test_all` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `c_bit_1` bit(1) DEFAULT NULL,
+  `c_bit_8` bit(8) DEFAULT NULL,
+  `c_bit_16` bit(16) DEFAULT NULL,
+  `c_bit_32` bit(32) DEFAULT NULL,
+  `c_bit_64` bit(64) DEFAULT NULL,
+  `c_bool` boolean DEFAULT NULL,
+  `c_tinyint_1` tinyint(1) DEFAULT NULL,
+  `c_tinyint_4` tinyint(4) DEFAULT NULL,
+  `c_tinyint_8` tinyint(8) DEFAULT NULL,
+  `c_tinyint_8_un` tinyint(8) unsigned DEFAULT NULL,
+  `c_smallint_1` smallint(1) DEFAULT NULL,
+  `c_smallint_16` smallint(16) DEFAULT NULL,
+  `c_smallint_16_un` smallint(16) unsigned DEFAULT NULL,
+  `c_mediumint_1` mediumint(1) DEFAULT NULL,
+  `c_mediumint_24` mediumint(24) DEFAULT NULL,
+  `c_mediumint_24_un` mediumint(24) unsigned DEFAULT NULL,
+  `c_int_1` int(1) DEFAULT NULL,
+  `c_int_32` int(32) DEFAULT NULL,
+  `c_int_32_un` int(32) unsigned DEFAULT NULL,
+  `c_bigint_1` bigint(1) DEFAULT NULL,
+  `c_bigint_64` bigint(64) DEFAULT NULL,
+  `c_bigint_64_un` bigint(64) unsigned DEFAULT NULL,
+  `c_decimal` decimal(10,3) DEFAULT NULL,
+  `c_decimal_pr` decimal(10,3) DEFAULT NULL,
+  `c_float` float DEFAULT NULL,
+  `c_float_pr` float(10,3) DEFAULT NULL,
+  `c_float_un` float(10,3) unsigned DEFAULT NULL,
+  `c_double` double DEFAULT NULL,
+  `c_double_pr` double(10,3) DEFAULT NULL,
+  `c_double_un` double(10,3) unsigned DEFAULT NULL,
+  `c_date` date DEFAULT NULL COMMENT 'date',
+  `c_datetime` datetime DEFAULT NULL,
+  `c_datetime_1` datetime(1) DEFAULT NULL,
+  `c_datetime_3` datetime(3) DEFAULT NULL,
+  `c_datetime_6` datetime(6) DEFAULT NULL,
+  `c_timestamp` timestamp DEFAULT CURRENT_TIMESTAMP,
+  `c_timestamp_1` timestamp(1) DEFAULT 0,
+  `c_timestamp_3` timestamp(3) DEFAULT 0,
+  `c_timestamp_6` timestamp(6) DEFAULT 0,
+  `c_time` time DEFAULT NULL,
+  `c_time_1` time(1) DEFAULT NULL,
+  `c_time_3` time(3) DEFAULT NULL,
+  `c_time_6` time(6) DEFAULT NULL,
+  `c_year` year DEFAULT NULL,
+  `c_year_4` year(4) DEFAULT NULL,
+  `c_char` char(10) DEFAULT NULL,
+  `c_varchar` varchar(10) DEFAULT NULL,
+  `c_binary` binary(10) DEFAULT NULL,
+  `c_varbinary` varbinary(10) DEFAULT NULL,
+  `c_blob_tiny` tinyblob DEFAULT NULL,
+  `c_blob` blob DEFAULT NULL,
+  `c_blob_medium` mediumblob DEFAULT NULL,
+  `c_blob_long` longblob DEFAULT NULL,
+  `c_text_tiny` tinytext DEFAULT NULL,
+  `c_text` text DEFAULT NULL,
+  `c_text_medium` mediumtext DEFAULT NULL,
+  `c_text_long` longtext DEFAULT NULL,
+  `c_enum` enum('a','b','c') DEFAULT NULL,
+  `c_set` set('a','b','c') DEFAULT NULL,
+  `c_json` json DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='10000000'