问题描述
我正在使用Spring Boot和Flyway(6.5.5)的集成来运行CockroachDB集群的更新。当几个服务实例同时启动时,它们都试图锁定flyway_schema_history
表以验证迁移。但是,发生以下异常:
2020-09-09 00:00:00.013 ERROR 1 --- [ main] o.s.boot.SpringApplication :
Application run Failed org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method Failed; nested exception is org.flywaydb.core.api.FlywayException:
Unable to obtain table lock - another Flyway instance may be running
我找不到任何配置属性来对此进行调整。也许有人面对相同的问题并以某种方式解决了这个问题?
解决方法:重新启动服务。
解决方法
调试问题后,它以非常奇怪的Flyway行为出现: org.flywaydb.core.internal.database.cockroachdb.CockroachDBTable
CockroachDB-specific table.
Note that CockroachDB doesn't support table locks. We therefore use a row in the schema history as a lock indicator;
if another process ahs inserted such a row we wait (potentially indefinitely) for it to be removed before
carrying out a migration.
*/
因此,在我的情况下,在应用迁移期间,服务重新启动,并且该伪锁记录永远保留了。
解决方法是手动删除“锁定”:
installed_rank | version | description | type | script | checksum | installed_by | installed_on | execution_time | success
-----------------+----------------------------------+------------------------------------------+------+--------------------------------------------------+-------------+--------------------+----------------------------------+----------------+----------
-100 | d9ab17626a4d66a4d8a89fe9bdca98e9 | flyway-lock | | | 0 | | 2020-09-14 11:25:02.874838+00:00 | 0 | true
希望,它将对某人有所帮助。