Spring batch 使用一些序列表,在 MySQL 的情况下使用 MyISAM 存储引擎。我面临的问题是我使用的是 Amazon Web Services RDS 数据库,它们的“时间点”数据库恢复功能不能很好地处理包含 MyISAM 表的数据库。
我正在寻找一种解决方案,让我可以切换这些 Spring Batch MyISAM 序列表并用 InnoDB 表替换它们,目标是启用 AWS RDS“时间点”数据库恢复功能。
编辑:
根据@Michael 的回复,这是来自读取序列的 Java 类 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 序列表的最简单方法是什么”并让 Spring Batch 继续运行?
最佳答案
我确认仅将 MyISAM 序列表更改为 InnoDB 会导致在 update...set...=last_insert_id()
语句之后但在事务之前在序列表上创建更新锁已 promise 。使用 MyISAM 序列时不会创建这些锁。因此,“简单”的方法可能会对性能产生负面影响。
这是我想出的。不确定这是最简单的方法,但它确实有效。
- 根据 this回答,删除现有的序列表并用单列重新定义它们
uid BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY auto_increment
- 创建一个存储过程:a) 将序列名称作为参数,b) 插入序列,c) 返回 LAST_INSERT_ID()
- 编写一个扩展
MySQLMaxValueIncrementer
的 java 类,并调用getNextKey()
方法中的存储过程。我正在使用SimpleJdbcCall
实例来执行此操作。 - 编写一个实现
DataFieldMaxValueIncrementerFactory
的 java 类,并从getIncrementer()
方法返回第 3 步中的实例 - 在批处理配置中,更新
org.springframework.batch.core.repository.support.JobRepositoryFactoryBean
配置以使用第 4 步中的增量工厂
关于mysql - 将 Spring Batch MyISAM 序列表迁移到 InnoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27970600/