diff options
author | Anton Tananaev <anton@traccar.org> | 2024-04-27 07:46:24 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-04-27 07:46:24 -0700 |
commit | 8da81efe902ceb9a106dff15ce44638c6be1eecc (patch) | |
tree | caf73fa775dda8ba7f6a1d8d68f41b4ae8ad7ffb /src/main/java/org/traccar/storage | |
parent | 3b739942dafea3c9d2bb3f061fb6ee98a33c747a (diff) | |
download | trackermap-server-8da81efe902ceb9a106dff15ce44638c6be1eecc.tar.gz trackermap-server-8da81efe902ceb9a106dff15ce44638c6be1eecc.tar.bz2 trackermap-server-8da81efe902ceb9a106dff15ce44638c6be1eecc.zip |
Better DB lock error message
Diffstat (limited to 'src/main/java/org/traccar/storage')
-rw-r--r-- | src/main/java/org/traccar/storage/DatabaseModule.java | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/storage/DatabaseModule.java b/src/main/java/org/traccar/storage/DatabaseModule.java index 9898a2fca..86e5267d4 100644 --- a/src/main/java/org/traccar/storage/DatabaseModule.java +++ b/src/main/java/org/traccar/storage/DatabaseModule.java @@ -20,10 +20,12 @@ import com.google.inject.Provides; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import liquibase.Contexts; +import liquibase.GlobalConfiguration; import liquibase.Liquibase; import liquibase.database.Database; import liquibase.database.DatabaseFactory; import liquibase.exception.LiquibaseException; +import liquibase.exception.LockException; import liquibase.resource.DirectoryResourceAccessor; import liquibase.resource.ResourceAccessor; import org.traccar.config.Config; @@ -83,16 +85,22 @@ public class DatabaseModule extends AbstractModule { ResourceAccessor resourceAccessor = new DirectoryResourceAccessor(new File(".")); - Database database = DatabaseFactory.getInstance().openDatabase( - config.getString(Keys.DATABASE_URL), - config.getString(Keys.DATABASE_USER), - config.getString(Keys.DATABASE_PASSWORD), - config.getString(Keys.DATABASE_DRIVER), - null, null, null, resourceAccessor); + System.setProperty("liquibase.changelogLockWaitTimeInMinutes", "1"); - try (Liquibase liquibase = new Liquibase(changelog, resourceAccessor, database)) { - liquibase.clearCheckSums(); - liquibase.update(new Contexts()); + try { + Database database = DatabaseFactory.getInstance().openDatabase( + config.getString(Keys.DATABASE_URL), + config.getString(Keys.DATABASE_USER), + config.getString(Keys.DATABASE_PASSWORD), + config.getString(Keys.DATABASE_DRIVER), + null, null, null, resourceAccessor); + + try (Liquibase liquibase = new Liquibase(changelog, resourceAccessor, database)) { + liquibase.clearCheckSums(); + liquibase.update(new Contexts()); + } + } catch (LockException e) { + throw new DatabaseLockException(); } } @@ -100,3 +108,12 @@ public class DatabaseModule extends AbstractModule { } } + +class DatabaseLockException extends RuntimeException { + DatabaseLockException() { + super("Database is in a locked state. " + + "It could be due to early service termination on a previous launch. " + + "To unlock you can run this query: 'UPDATE DATABASECHANGELOGLOCK SET locked = 0'. " + + "Make sure the schema is up to date before unlocking the database."); + } +} |