英文:
HSLQDB + JPA2 (with Hibernate) - The app gets stuck when trying a TRUNCATE SCHEMA
问题
我的应用程序实现了Deltaspike v1.6,并使用了Hibernate v4.3.8。还使用了C3P0 v0.9.5.4。
我的回归测试使用了TestNG v7和HSQLDB v2.4。
情况:
我正在使用TestNG为测试本身编写一些回归测试,并将HSQLDB作为内存数据库(实际上是文件上的)。我还使用了testng的数据提供程序(dataproviders)。
问题:
在数据提供程序中的每个场景之后,必须清除数据库。因此,我尝试在@AfterMethod方法中以以下方式清除数据库:
public void resetDb() {
em.getTransaction().begin();
em.createNativeQuery("TRUNCATE SCHEMA PUBLIC RESTART IDENTITY AND COMMIT NO CHECK").executeUpdate();
em.getTransaction().commit();
}
运行在*em.createNativeQuery...*这一行卡住了。我逐步调试了这一步,并启用了各种日志记录,它就是停在那里。
这是Hibernate在控制台中记录的最后一条日志:
Hibernate:
TRUNCATE SCHEMA PUBLIC RESTART IDENTITY
AND COMMIT NO CHECK
在我的日志文件中,我一直收到这些日志,我认为这是正常的?
2020-10-22 14:15:43 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730:将任务添加到队列中 - com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@284e5784
2020-10-22 14:15:43 TRACE BasicResourcePool:196 - 跟踪 com.mchange.v2.resourcepool.BasicResourcePool@31f9f9b3 [已管理:50,未使用:47,已排除:0](例如 com.mchange.v2.c3p0.impl.NewPooledConnection@12f66dd1)
2020-10-22 14:15:49 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1677180d - 运行 DeadlockDetector[退出。没有待处理任务。]
2020-10-22 14:15:59 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1677180d - 运行 DeadlockDetector[退出。没有待处理任务。]
...
2020-10-22 14:17:09 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730:将任务添加到队列中 - com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@246b9ea4
2020-10-22 14:17:09 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730:将任务添加到队列中 - com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@7f791d48
2020-10-22 14:17:09 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730:将任务添加到队列中 - com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@162d1ed8
2020-10-22 14:17:09 TRACE BasicResourcePool:196 - 跟踪 com.mchange.v2.resourcepool.BasicResourcePool@31f9f9b3 [已管理:50,未使用:48,已排除:0](例如 com.mchange.v2.c3p0.impl.NewPooledConnection@12f66dd1)
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - 正在对 IDLE CHECK 上的 PooledConnection 进行测试 [com.mchange.v2.c3p0.impl.NewPooledConnection@79c8cd43]。
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - 正在对 IDLE CHECK 上的 PooledConnection 进行测试 [com.mchange.v2.c3p0.impl.NewPooledConnection@6c2c47fe]。
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - 正在对 IDLE CHECK 上的 PooledConnection 进行测试 [com.mchange.v2.c3p0.impl.NewPooledConnection@723253a6]。
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - 正在对 IDLE CHECK 上的 PooledConnection 进行测试 [com.mchange.v2.c3p0.impl.NewPooledConnection@723253a6] 已成功。
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - 正在对 IDLE CHECK 上的 PooledConnection 进行测试 [com.mchange.v2.c3p0.impl.NewPooledConnection@6c2c47fe] 已成功。
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - 正在对 IDLE CHECK 上的 PooledConnection 进行测试 [com.mchange.v2.c3p0.impl.NewPooledConnection@79c8cd43] 已成功。
另外,我尝试过这样截断一个表:
TRUNCATE TABLE [table_name] RESTART IDENTITY
这个是可以工作的,但是当我尝试这样:
TRUNCATE TABLE "+table+" RESTART IDENTITY AND COMMIT NO CHECK
它无法工作,也被卡住了。我认为"AND COMMIT"部分可能会导致某种死锁。
英文:
My app implements Deltaspike v1.6 and uses Hibernate v4.3.8. It also uses C3P0 v0.9.5.4
My regression tests use TestNG v7 and HSQLDB v2.4
Situation:
I'm coding some regression tests using TestNG for tests themselves, and HSQLDB as an on-mem db (on-file actually). I also use testng's dataproviders
The issue:
After each scenario in the dataprovider database must be cleaned. Therefore, I attempt to clean the database in the @AfterMethod method in this way:
public void resetDb() {
em.getTransaction().begin();
em.createNativeQuery("TRUNCATE SCHEMA PUBLIC RESTART IDENTITY AND COMMIT NO CHECK").executeUpdate();
em.getTransaction().commit();
}
The running gets stuck at em.createNativeQuery... line. I debugged this step by step and have enabled all kind of loging, It just stops there.
This is the last thing hibnernate logs in the console:
Hibernate:
TRUNCATE SCHEMA PUBLIC RESTART IDENTITY
AND COMMIT NO CHECK
In my log file I keep getting these logs, which I think are normal?
2020-10-22 14:15:43 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@284e5784
2020-10-22 14:15:43 TRACE BasicResourcePool:196 - trace com.mchange.v2.resourcepool.BasicResourcePool@31f9f9b3 [managed: 50, unused: 47, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@12f66dd1)
2020-10-22 14:15:49 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1677180d -- Running DeadlockDetector[Exiting. No pending tasks.]
2020-10-22 14:15:59 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1677180d -- Running DeadlockDetector[Exiting. No pending tasks.]
...
2020-10-22 14:17:09 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@246b9ea4
2020-10-22 14:17:09 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@7f791d48
2020-10-22 14:17:09 TRACE ThreadPoolAsynchronousRunner:196 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@7dbbf730: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@162d1ed8
2020-10-22 14:17:09 TRACE BasicResourcePool:196 - trace com.mchange.v2.resourcepool.BasicResourcePool@31f9f9b3 [managed: 50, unused: 48, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@12f66dd1)
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@79c8cd43] on IDLE CHECK.
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@6c2c47fe] on IDLE CHECK.
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@723253a6] on IDLE CHECK.
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@723253a6] on IDLE CHECK has SUCCEEDED.
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@6c2c47fe] on IDLE CHECK has SUCCEEDED.
2020-10-22 14:17:09 DEBUG C3P0PooledConnectionPool:204 - Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@79c8cd43] on IDLE CHECK has SUCCEEDED.
On a SIDE NOTE, I've tried truncating a table like this:
TRUNCATE TABLE [table_name] RESTART IDENTITY
It works, but when I try this one:
TRUNCATE TABLE "+table+" RESTART IDENTITY AND COMMIT NO CHECK
It DOESN't WORK, it gets stuck too. I think the "AND COMMIT" part is causing some kind of deadlock
答案1
得分: 1
"TRUNCATE .. AND COMMIT
"语句需要在数据库上获取独占锁。似乎另一个会话正在活动,并且已经启动了一个尚未提交的事务。
英文:
The TRUNCATE .. AND COMMIT
statement needs to obtain an exclusive lock on the database. It seems another session is active and has started a transaction that is not committed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论