gpt4 book ai didi

liquibase - Liquibase 应该处理并发初始化吗?

转载 作者:行者123 更新时间:2023-12-01 02:04:17 33 4
gpt4 key购买 nike

我正在针对一个干净的 HSQLDB 实例同时运行 Liquibase 迁移,当其中一个更新成功时,另一个失败,如下所示:

Exception in thread "Thread-7" liquibase.exception.LockException: liquibase.exception.DatabaseException: object name already exists: DATABASECHANGELOGLOCK in statement [CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))] [Failed SQL: CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]
at liquibase.lockservice.StandardLockService.acquireLock(StandardLockService.java:216)
at liquibase.lockservice.StandardLockService.waitForLock(StandardLockService.java:155)
at liquibase.Liquibase.update(Liquibase.java:194)
at liquibase.Liquibase.update(Liquibase.java:190)
at liquibase.Liquibase.update(Liquibase.java:186)
at liquibase.Liquibase.update(Liquibase.java:179)
Caused by: liquibase.exception.DatabaseException: object name already exists: DATABASECHANGELOGLOCK in statement [CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))] [Failed SQL: CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:316)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:122)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:112)
at liquibase.lockservice.StandardLockService.init(StandardLockService.java:87)
at liquibase.lockservice.StandardLockService.acquireLock(StandardLockService.java:189)

这是预期的行为吗?使用 Liquibase 3.4.1。

(原因是它是一个自动化测试,启动一个带有两个应用程序节点的干净环境以强制代码处理多个节点,我在应用程序节点启动时运行 Liquibase。)

最佳答案

感谢您指出问题。目标是安全并发运行,如果 DATABASECHANGELOGLOCK 表存在应该是好的,但是检查表是否存在和尝试创建它之间存在时间间隔,如果它不存在会导致您看到的错误如果时机恰到好处/错误。

我创建了 https://liquibase.jira.com/browse/CORE-2596跟踪问题并添加了 3.4.2 的修复程序,这将使 Liquibase 从“表已存在”异常中恢复。这将避免您的问题,并且稍后插入到表中的代码才是分布式锁定的真正作用,因此您仍然可以免受并发更新的影响。

关于liquibase - Liquibase 应该处理并发初始化吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33767681/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com