shf*_*ful 3 java sqlite flyway
我们使用 SQLite (Flyway v3.2.1、SQLite 3.7.13 和 org.xerial:sqlite-jdbc:3.8.7 驱动程序)进行 Flyway迁移。
并行数据库连接的最大数量似乎至关重要。但是由于不同的原因,任何连接池大小的迁移都会失败。
存在与多个并行数据库连接相关的锁定问题。在空的 SQLite 数据库上进行一次迁移,结果是:
o.f.core.internal.command.DbMigrate.(:)() Current version of schema "main": << Empty Schema >>
o.f.core.internal.command.DbMigrate.(:)() Migrating schema "main" to version 1 - initial
o.f.c.i.u.jdbc.TransactionTemplate.(:)() Unable to restore autocommit to original value for connection
java.sql.SQLException: database is locked
at org.sqlite.core.DB.throwex(DB.java:859) ~[sqlite-jdbc-3.8.7.jar:na]
at org.sqlite.core.DB.exec(DB.java:142) ~[sqlite-jdbc-3.8.7.jar:na]
at org.sqlite.jdbc3.JDBC3Connection.setAutoCommit(JDBC3Connection.java:152) ~[sqlite-jdbc-3.8.7.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_71]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_71]
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126) ~[tomcat-jdbc-7.0.56.jar:na]
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109) ~[tomcat-jdbc-7.0.56.jar:na]
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80) ~[tomcat-jdbc-7.0.56.jar:na]
at com.sun.proxy.$Proxy76.setAutoCommit(Unknown Source) ~[na:na]
at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:96) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.command.DbMigrate.applyMigration(DbMigrate.java:282) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.command.DbMigrate.access$800(DbMigrate.java:46) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:207) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:156) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:156) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1059) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1006) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway.execute(Flyway.java:1418) [flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway.migrate(Flyway.java:1006) [flyway-core-3.2.1.jar:na]
...
Run Code Online (Sandbox Code Playgroud)
这似乎是一个普通的SQLite陷阱,如所描述这里。
通常,Flyway 迁移以及我们剩余的应用程序都会遭受这种类型的频繁锁定错误:
java.sql.SQLException: [SQLITE_BUSY] 数据库文件被锁定
当两个或多个连接处于活动状态时。这就是为什么我们尝试...
我们将并行数据库连接的数量减少到一个(通过使用“maxActive=1”配置我们的 Tomcat JDBC 连接池)。
但是现在,Flyway 失败了
... org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
at org.flywaydb.core.Flyway.execute(Flyway.java:1386)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1006)
(...)
Caused by: org.apache.tomcat.jdbc.pool.PoolExhaustedException: [localhost-startStop-1] Timeout: Pool empty. Unable to fetch a connection in 10 seconds, none available[size:1; busy:1; idle:0; lastwait:10000].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:674)
at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:50)
Run Code Online (Sandbox Code Playgroud)
为什么 ?Flyway 迁移似乎需要两个并行连接。 他们在这里遇到了一个相关的问题并指出:“似乎 Flyway 至少使用了两个连接:一个用于锁定 schema_version 表,另一个用于实际运行更改......”
最后,我想知道 Flyway 如何完全支持 SQLite。两个连接是强制性的,但数据库最终被锁定。
但是,官方支持SQLite ,我认为我搞砸了一些事情。
Flyway 如何与 SQLite 配合使用?
| 归档时间: |
|
| 查看次数: |
3664 次 |
| 最近记录: |