将 Spring 批处理 MyISAM 序列表迁移到 InnoDB

Migrating Spring Batch MyISAM Sequence Tables to InnoDB

Spring 批处理使用了一些序列表,在 MySQL 的情况下使用了 MyISAM 存储引擎。我面临的问题是我使用的是 Amazon Web Services RDS 数据库,它们的 "Point in Time" 数据库恢复功能不能很好地处理包含 MyISAM 表的数据库。

我正在寻找一种解决方案,可以让我切换这些 Spring 批处理 MyISAM 序列表并用 InnoDB 表替换它们,目标是启用 AWS RDS "Point in Time" 数据库修复功能。

编辑:

根据@Michael 的回复,这是来自 Java class 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.

所以我的具体问题是 "what is the simplest possible way to remove the MyISAM sequence table" 并保持 Spring 批量运行?

我确认仅将 MyISAM 序列表更改为 InnoDB 会导致在 update...set...=last_insert_id() 语句之后但在提交事务之前在序列表上创建更新锁。使用 MyISAM 序列时不会创建这些锁。因此 "easy" 方法可能会对性能产生负面影响。

这是我想出的。不确定这是最简单的方法,但它确实有效。

  1. 根据 this 的回答,删除现有序列表并使用单列重新定义它们 uid BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY auto_increment
  2. 创建一个存储过程:a) 将序列名称作为参数,b) 插入到序列中,以及 c) returns LAST_INSERT_ID()
  3. 写一个java class扩展MySQLMaxValueIncrementer,调用getNextKey()方法中的存储过程。我正在使用 SimpleJdbcCall 实例来执行此操作。
  4. 写一个 java class 来实现 DataFieldMaxValueIncrementerFactory 和 returns 来自 getIncrementer() 方法
  5. 步骤 #3 的实例
  6. 在批处理配置中,更新 org.springframework.batch.core.repository.support.JobRepositoryFactoryBean 配置以使用步骤 #4 中的增量器工厂