简体   繁体   English

春季批处理MySql序列“无法获取last_insert_id()”以保护引擎类型

[英]Spring batch MySql Sequence “Could not obtain last_insert_id()” reguarding engine type

I am using Spring Batch 3.0.5. 我正在使用Spring Batch 3.0.5。 The same question regarding engine type for the MySql sequence tables. 关于MySql序列表的引擎类型的相同问题。 Almost the same question as spring-batch-storage-engine-as-myisam-than-innodb . spring-batch-storage-engine-as-myisam-than-innodb几乎相同的问题。 However I am getting errors (using ENGINE = InnoDB) such as 但是我遇到了错误(使用ENGINE = InnoDB),例如

org.springframework.dao.DataAccessResourceFailureException: Could not obtain last_insert_id(); nested exception is java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
at org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer.getNextKey(MySQLMaxValueIncrementer.java:118) ~[spring-jdbc-4.1.3.RELEASE.jar:4.1.3.RELEASE]

After looking around I found there is a contradiction between what Spring Batch is doing and what the document says on MySQLMaxValueIncrementer 环顾四周后,我发现Spring Batch所做的事情与MySQLMaxValueIncrementer上的文档说的有矛盾之处

The sequence is kept in a table; 序列保存在表格中; there should be one sequence table per table that needs an auto-generated key. 每个表应该有一个需要自动生成键的序列表。 The table type of the sequence table should be MyISAM so the sequences are allocated without regard to any transactions that might be in progress. 序列表的表类型应为MyISAM,以便在分配序列时不考虑可能正在进行的任何事务。

In order to keep using InnoDB for the sequence tables to support GTID replication, it seems like we have to implement our own strategy like this . 为了保持使用的是InnoDB的序列表,以支持GTID复制,好像我们要实现我们自己的战略就像这样

My question would be if Spring Batch want to be consistent, why doesn't Spring Batch provide a built-in way or an alternative to the default MySQLMaxValueIncrementer? 我的问题是,如果Spring Batch要保持一致,为什么Spring Batch不提供内置方法或默认MySQLMaxValueIncrementer的替代方法?

Or is there something I am missing? 还是我想念的东西?

Hope, this link will give you a idea about your queries. 希望,此链接将使您对查询有所了解。

If you are using MySQL DB, then Sequence table should be in ENGINE=MyISAM DEFAULT CHARSET=utf8; 如果使用的是MySQL DB,则序列表应位于ENGINE=MyISAM DEFAULT CHARSET=utf8; You can have innodb also. 您也可以拥有innodb But MyISAM engine has a built in to increment with different values according to your specific column. 但是MyISAM引擎具有内置功能,可以根据您的特定列以不同的值递增。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM