Server won't start after upgrade to 4.0 from 3.17

rjk6 years ago

I'm unable to get the server to work correctly after trying to upgrade to version 4.0. The log doesn't show any errors, here's what it shows:

2018-08-24 19:54:07  INFO: Operating system name: Linux version: 4.15.0-33-generic architecture: amd64
2018-08-24 19:54:07  INFO: Java runtime name: OpenJDK 64-Bit Server VM vendor: Oracle Corporation version: 10.0.2+13-Ubuntu-1ubuntu0.18.04.1
2018-08-24 19:54:07  INFO: Memory limit heap: 237mb non-heap: 0mb
2018-08-24 19:54:07  INFO: Character encoding: UTF-8 charset: UTF-8
2018-08-24 19:54:07  INFO: Version: 4.0-SNAPSHOT
Anton Tananaev6 years ago

What about wrapper log file?

rjk6 years ago

How much of it do you want? I found this error in there:

INFO|1229/0|Service traccar|18-08-24 20:17:25|Caused by: org.h2.jdbc.JdbcSQLException: Constraint "FK_POSITION_DEVICEID" already exists; SQL statement:
INFO|1229/0|Service traccar|18-08-24 20:17:25|ALTER TABLE PUBLIC.POSITIONS ADD CONSTRAINT PUBLIC.FK_POSITION_DEVICEID FOREIGN KEY(DEVICEID) INDEX PUBLIC.FK_POSITION_DEVICEID_INDEX_B REFERENCES PUBLIC.DEVICES(ID) ON DELETE CASCADE NOCHECK [90045-197]
Anton Tananaev6 years ago

I don't want any of it. I'm just giving you suggestions where to look for the problem.

rjk6 years ago

Well, I don't know how to fix that error which was caused after the upgrade. Is it a bug?

Anton Tananaev6 years ago

We upgraded more than 10 servers so far without any issues. More likely you are doing something wrong, but of course there is a tiny possibility that it could be some bug.

rjk6 years ago

Well, I took a backup and then ran the new ./traccar.run file to do the upgrade, like I always do. There's not really anything to get wrong. What can I check, or should I just revert back to 3.17 and never upgrade again?

Anton Tananaev6 years ago

Sounds like you haven't read official documentation about upgrading Traccar. I would recommend you start from that, if you are interested in upgrade.

rjk6 years ago

OK. After reverting back to the old version, and still having the issue happen again, I think the problem is that my JVM went from version 1.8.0_181 (Java 8) to version 10.0.2 (Java 11) after an OS upgrade. I will see about downgrading the JVM and then try the new traccar version.

Lucas B.6 years ago

Hi Anton, rjk could have right. I have just updated my traccar successfully from version 3.15 (previous updates: 3.7 -> 3.11 -> 3.15) to 4.2 and encountered the same error in scenario: 3.15 -> 3.17 -> 4.0. Directly updated traccar from 3.15 to 4.2 throws errors about not existing user table when trying to log in. Proper upgrade path was 3.15 -> 4.0 -> 4.2. Hope it will help someone with an update.

Anton Tananaev6 years ago

What do you mean by "the same error" exactly? Please provide error logs.

Lucas B.6 years ago

Hi Anton,

I meant this:


root@server:/opt/traccar# java -jar tracker-server.jar conf/traccar.xml
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/traccar/lib/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/traccar/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
[main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
org.h2.jdbc.JdbcSQLException: Constraint "FK_POSITION_DEVICEID" already exists; SQL statement:
ALTER TABLE PUBLIC.POSITIONS ADD CONSTRAINT PUBLIC.FK_POSITION_DEVICEID FOREIGN KEY(DEVICEID) INDEX PUBLIC.FK_POSITION_DEVICEID_INDEX_B REFERENCES PUBLIC.DEVICES(ID) ON DELETE CASCADE NOCHECK [90045-197]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
        at org.h2.message.DbException.get(DbException.java:179)
        at org.h2.message.DbException.get(DbException.java:155)
        at org.h2.command.ddl.AlterTableAddConstraint.tryUpdate(AlterTableAddConstraint.java:110)
        at org.h2.command.ddl.AlterTableAddConstraint.update(AlterTableAddConstraint.java:78)
        at org.h2.engine.MetaRecord.execute(MetaRecord.java:58)
        at org.h2.engine.Database.open(Database.java:775)
        at org.h2.engine.Database.openDatabase(Database.java:286)
        at org.h2.engine.Database.<init>(Database.java:280)
        at org.h2.engine.Engine.openSession(Engine.java:66)
        at org.h2.engine.Engine.openSession(Engine.java:179)
        at org.h2.engine.Engine.createSessionAndValidate(Engine.java:157)
        at org.h2.engine.Engine.createSession(Engine.java:140)
        at org.h2.engine.Engine.createSession(Engine.java:28)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:351)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:124)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:103)
        at org.h2.Driver.connect(Driver.java:69)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:112)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:118)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:341)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:193)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:428)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:499)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:112)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:72)
        at org.traccar.database.DataManager.initDatabase(DataManager.java:134)
        at org.traccar.database.DataManager.<init>(DataManager.java:87)
        at org.traccar.Context.init(Context.java:361)
        at org.traccar.Main.main(Main.java:35)
Exception in thread "main" com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Constraint "FK_POSITION_DEVICEID" already exists; SQL statement:
ALTER TABLE PUBLIC.POSITIONS ADD CONSTRAINT PUBLIC.FK_POSITION_DEVICEID FOREIGN KEY(DEVICEID) INDEX PUBLIC.FK_POSITION_DEVICEID_INDEX_B REFERENCES PUBLIC.DEVICES(ID) ON DELETE CASCADE NOCHECK [90045-197]
        at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:528)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:520)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:112)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:72)
        at org.traccar.database.DataManager.initDatabase(DataManager.java:134)
        at org.traccar.database.DataManager.<init>(DataManager.java:87)
        at org.traccar.Context.init(Context.java:361)
        at org.traccar.Main.main(Main.java:35)
Caused by: org.h2.jdbc.JdbcSQLException: Constraint "FK_POSITION_DEVICEID" already exists; SQL statement:
ALTER TABLE PUBLIC.POSITIONS ADD CONSTRAINT PUBLIC.FK_POSITION_DEVICEID FOREIGN KEY(DEVICEID) INDEX PUBLIC.FK_POSITION_DEVICEID_INDEX_B REFERENCES PUBLIC.DEVICES(ID) ON DELETE CASCADE NOCHECK [90045-197]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
        at org.h2.message.DbException.get(DbException.java:179)
        at org.h2.message.DbException.get(DbException.java:155)
        at org.h2.command.ddl.AlterTableAddConstraint.tryUpdate(AlterTableAddConstraint.java:110)
        at org.h2.command.ddl.AlterTableAddConstraint.update(AlterTableAddConstraint.java:78)
        at org.h2.engine.MetaRecord.execute(MetaRecord.java:58)
        at org.h2.engine.Database.open(Database.java:775)
        at org.h2.engine.Database.openDatabase(Database.java:286)
        at org.h2.engine.Database.<init>(Database.java:280)
        at org.h2.engine.Engine.openSession(Engine.java:66)
        at org.h2.engine.Engine.openSession(Engine.java:179)
        at org.h2.engine.Engine.createSessionAndValidate(Engine.java:157)
        at org.h2.engine.Engine.createSession(Engine.java:140)
        at org.h2.engine.Engine.createSession(Engine.java:28)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:351)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:124)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:103)
        at org.h2.Driver.connect(Driver.java:69)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:112)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:118)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:341)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:193)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:428)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:499)
        ... 6 more

In the log file despite default settings:

    <entry key='logger.enable'>true</entry>
    <entry key='logger.level'>all</entry>
    <entry key='logger.file'>./logs/tracker-server.log</entry>

there is only:

2018-12-03 09:55:35  INFO: Operating system name: Linux version: 4.9.35+ architecture: arm
2018-12-03 09:55:35  INFO: Java runtime name: Java HotSpot(TM) Client VM vendor: Oracle Corporation version: 25.65-b01
2018-12-03 09:55:35  INFO: Memory limit heap: 118mb non-heap: 0mb
2018-12-03 09:55:35  INFO: Character encoding: UTF-8 charset: UTF-8
2018-12-03 09:55:35  INFO: Version: 4.0-SNAPSHOT

Still, I was able to update Traccar, but maybe that's what other users complain about from time to time.

Anton Tananaev6 years ago

Try removing foreign key constraints.

Lucas B.6 years ago

It works, but you need to remove the constraint on the database before starting the new version of Traccar. If you have got the error during the start of Traccar, it throws the same error during connecting to H2 database as well:

root@server:/opt/traccar/lib# java -cp h2*.jar org.h2.tools.Shell

Welcome to H2 Shell 1.4.197 (2018-03-18)
Exit with Ctrl+C
[Enter]   jdbc:h2:~/test
URL       jdbc:h2:/opt/traccar/data/database
[Enter]   org.h2.Driver
Driver
[Enter]
User      user_here
[Enter]   Hide
Password
Password
SQL Exception: Constraint "FK_POSITION_DEVICEID" already exists; SQL statement:
ALTER TABLE PUBLIC.POSITIONS ADD CONSTRAINT PUBLIC.FK_POSITION_DEVICEID FOREIGN KEY(DEVICEID) INDEX PUBLIC.FK_POSITION_DEVICEID_INDEX_B REFERENCES PUBLIC.DEVICES(ID) ON DELETE CASCADE NOCHECK [90045-197]
[Enter]   jdbc:h2:~/test
URL

When I have copied the database and did it before starting Traccar 4.0:

root@server:/opt/traccar/lib# java -cp h2*.jar org.h2.tools.Shell

Welcome to H2 Shell 1.4.197 (2018-03-18)
Exit with Ctrl+C
[Enter]   jdbc:h2:~/test
URL       jdbc:h2:/opt/traccar/data/database
[Enter]   org.h2.Driver
Driver
[Enter]
User      user_here
[Enter]   Hide
Password
Password
Connected
Commands are case insensitive; SQL statements end with ';'
help or ?      Display this help
list           Toggle result list / stack trace mode
maxwidth       Set maximum column width (default is 100)
autocommit     Enable or disable autocommit
history        Show the last 20 statements
quit or exit   Close the connection and exit

sql> alter table PUBLIC.POSITIONS drop constraint PUBLIC.FK_POSITION_DEVICEID;
(Update count: 0, 130 ms)
sql> exit
Connection closed

liquibase was able to update database and Traccar 4.0 has started. Seems like it's some bug in the update procedure of Traccar.

Anton Tananaev6 years ago

Version 4.0 is an old one. Do you get problems with upgrading to 4.2? If yes, I need to know steps to reproduce because it works just fine for me.