Search code examples
grails-ormgrails-pluginliquibase

What happens when two app servers in cluster start LiquiBase update (via Grails)?


I am planning to use LiquiBase via grails database-migration plugin. When I start a cluster of two servers with a new version of the DB schema, and both servers attempt to start schema upgrade, what will happen?

Does either grails database-migration plugin or LiquiBase itself has protection against concurrent upgrade attempt?


Solution

  • In addition to your database tables, Liquibase creates a databasechangelog and a databasechangeloglock table to manage its state. databasechangelog contains information about the migrations that you've already run, and databasechangeloglock is there to guard against concurrent attempts at running migrations.

    When the first cluster instance starts up it will obtain a lock by inserting a row in the databasechangeloglock table, and run any missing migrations. When the second one starts it'll be blocked until the lock is freed, then it'll obtain a lock and since there won't be any un-run migrations, it won't do anything.