我有一个使用mysql数据库的quarkus应用程序(包含容器的Web服务)。数据库中的一个表(问题)具有一个外键,该外键指向评估的主键(给定评估可能有0,1,n个问题)。您可以在此处找到执行的SQL:https://gitlab.com/connorbutch/reading-comprehension/-/tree/9-list-all-assessments/reading-comprehension-server-quarkus-impl/src/main/resources/db/migration
我的应用程序具有(准备)运行状况检查。这些工作的流程如下:
我要执行的两个运行状况检查是综合插入/选择,以确保数据库的连接/权限正确。这些健康检查有两个要求:
当我只有插入插入评估然后回滚的运行状况检查时,以上逻辑才起作用(请参见此文件:https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/reading-comprehension-server-quarkus-impl/src/main/java/com/connor/reading/health/AbstractBaseHealthChecker.java)。我可以根据需要运行任意多次,直到通过。
为了完成此任务,我做了以下工作:
如上所述,这可以正常进行一次健康检查,随后的检索显示这可以正确回滚。但是,一旦我添加了运行状况相同的插入的第二次运行状况检查,但应在回滚后执行,我得到了重复的密钥异常(Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '1234' for key 'PRIMARY' -- see below for more complete stack trace)
,这使我认为事务未在滚动在另一个开始之前返回。您能建议如何解决此问题吗?如果情况变得更糟,我总是可以向这些容器添加随机数,并确保99.99999999%不会发生冲突,但是我想知道是什么原因导致了此问题。
(GET)请求:http://localhost:8080/health/readiness
响应(正文):
{
"isAvailable": false,
"availableDependencies": [
{
"name": "MemoryChecker",
"isAvailable": true
},
{
"name": "QueryForErrorById",
"isAvailable": true
},
{
"name": "QueryQuestions",
"isAvailable": true
},
{
"name": "ReadFromDatabaseChecker",
"isAvailable": true
},
{
"name": "SystemPropertyChecker",
"isAvailable": true
}
],
"unavailableDependencies": [
{
"name": "InsertAssessmentChecker",
"isAvailable": false
},
{
"name": "InsertQuestionChecker",
"isAvailable": false
}
]
}
2020-09-22 21:53:16,969 INFO [com.con.rea.hea.HealthCheckerInsertAssessmentImpl] (executor-thread-1) Got exception when performing health check on downstream dependency: com.connor.reading.exception.ReadingSystemException: There was an error when inserting an assessment count. The sql ran was INSERT INTO ASSESSMENT(ISBN,AUTHOR_FIRST_NAME,AUTHOR_LAST_NAME,TITLE,NUMBER_OF_POINTS,READING_LEVEL,CREATED_TEACHER_ID) VALUES(:ISBN,:AUTHOR_FIRST_NAME,:AUTHOR_LAST_NAME,:TITLE,:NUMBER_OF_POINTS,:READING_LEVEL,:CREATED_TEACHER_ID) and the parameter map was CREATED_TEACHER_ID: 2, AUTHOR_FIRST_NAME: First, NUMBER_OF_POINTS: 8.0, AUTHOR_LAST_NAME: Last, READING_LEVEL: 8.0, TITLE: Title, ISBN: 1234
reading-comprehension | at com.connor.reading.dao.AssessmentDao.addAssessment(AssessmentDao.java:104)
reading-comprehension | at com.connor.reading.dao.AssessmentDao_Subclass.addAssessment$$superaccessor7(AssessmentDao_Subclass.zig:1271)
reading-comprehension | at com.connor.reading.dao.AssessmentDao_Subclass$$function$$7.apply(AssessmentDao_Subclass$$function$$7.zig:33)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:32)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
reading-comprehension | at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
reading-comprehension | at com.connor.reading.dao.AssessmentDao_Subclass.addAssessment(AssessmentDao_Subclass.zig:1228)
reading-comprehension | at com.connor.reading.service.AssessmentService.addAssessment(AssessmentService.java:60)
reading-comprehension | at com.connor.reading.service.AssessmentService_Subclass.addAssessment$$superaccessor7(AssessmentService_Subclass.zig:1262)
reading-comprehension | at com.connor.reading.service.AssessmentService_Subclass$$function$$7.apply(AssessmentService_Subclass$$function$$7.zig:33)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInCallerTx(TransactionalInterceptorBase.java:252)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:34)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:53)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:26)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired_Bean.intercept(TransactionalInterceptorRequired_Bean.zig:339)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:50)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:32)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
reading-comprehension | at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
reading-comprehension | at com.connor.reading.service.AssessmentService_Subclass.addAssessment(AssessmentService_Subclass.zig:1219)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl.getValue(HealthCheckerInsertAssessmentImpl.java:37)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl_Subclass.getValue$$superaccessor9(HealthCheckerInsertAssessmentImpl_Subclass.zig:1348)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl_Subclass$$function$$9.apply(HealthCheckerInsertAssessmentImpl_Subclass$$function$$9.zig:29)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:127)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:100)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequiresNew.doIntercept(TransactionalInterceptorRequiresNew.java:35)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:53)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequiresNew.intercept(TransactionalInterceptorRequiresNew.java:26)
reading-comprehension | at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequiresNew_Bean.intercept(TransactionalInterceptorRequiresNew_Bean.zig:339)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:50)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:32)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
reading-comprehension | at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl_Subclass.getValue(HealthCheckerInsertAssessmentImpl_Subclass.zig:1306)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl.getValue(HealthCheckerInsertAssessmentImpl.java:13)
reading-comprehension | at com.connor.reading.health.AbstractBaseHealthChecker.get(AbstractBaseHealthChecker.java:18)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl_Subclass.get$$superaccessor1(HealthCheckerInsertAssessmentImpl_Subclass.zig:474)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl_Subclass$$function$$1.apply(HealthCheckerInsertAssessmentImpl_Subclass$$function$$1.zig:29)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:32)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
reading-comprehension | at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
reading-comprehension | at com.connor.reading.health.HealthCheckerInsertAssessmentImpl_Subclass.get(HealthCheckerInsertAssessmentImpl_Subclass.zig:432)
reading-comprehension | at com.connor.reading.health.AbstractBaseHealthChecker.get(AbstractBaseHealthChecker.java:5)
reading-comprehension | at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
reading-comprehension | at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
reading-comprehension | at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
reading-comprehension | at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
reading-comprehension | at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
reading-comprehension | at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
reading-comprehension | at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
reading-comprehension | at com.connor.reading.service.HealthService.runHealthChecksInParallel(HealthService.java:93)
reading-comprehension | at com.connor.reading.service.HealthService_Subclass.runHealthChecksInParallel$$superaccessor5(HealthService_Subclass.zig:981)
reading-comprehension | at com.connor.reading.service.HealthService_Subclass$$function$$5.apply(HealthService_Subclass$$function$$5.zig:35)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:32)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
reading-comprehension | at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
reading-comprehension | at com.connor.reading.service.HealthService_Subclass.runHealthChecksInParallel(HealthService_Subclass.zig:938)
reading-comprehension | at com.connor.reading.service.HealthService.checkDownstreamDependencies(HealthService.java:41)
reading-comprehension | at com.connor.reading.service.HealthService_Subclass.checkDownstreamDependencies$$superaccessor2(HealthService_Subclass.zig:636)
reading-comprehension | at com.connor.reading.service.HealthService_Subclass$$function$$2.apply(HealthService_Subclass$$function$$2.zig:33)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:32)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
reading-comprehension | at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
reading-comprehension | at com.connor.reading.service.HealthService_Subclass.checkDownstreamDependencies(HealthService_Subclass.zig:593)
reading-comprehension | at com.connor.reading.controller.HealthApiImpl.readinessCheck(HealthApiImpl.java:36)
reading-comprehension | at com.connor.reading.controller.HealthApiImpl_Subclass.readinessCheck$$superaccessor1(HealthApiImpl_Subclass.zig:223)
reading-comprehension | at com.connor.reading.controller.HealthApiImpl_Subclass$$function$$1.apply(HealthApiImpl_Subclass$$function$$1.zig:33)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:32)
reading-comprehension | at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
reading-comprehension | at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
reading-comprehension | at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
reading-comprehension | at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
reading-comprehension | at com.connor.reading.controller.HealthApiImpl_Subclass.readinessCheck(HealthApiImpl_Subclass.zig:180)
reading-comprehension | at java.lang.reflect.Method.invoke(Method.java:566)
reading-comprehension | at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
reading-comprehension | at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
reading-comprehension | at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
reading-comprehension | at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
reading-comprehension | at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
reading-comprehension | at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
reading-comprehension | at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
reading-comprehension | at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
reading-comprehension | at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
reading-comprehension | at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
reading-comprehension | at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
reading-comprehension | at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
reading-comprehension | at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
reading-comprehension | at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
reading-comprehension | at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
reading-comprehension | at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
reading-comprehension | at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
reading-comprehension | at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:132)
reading-comprehension | at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:37)
reading-comprehension | at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:94)
reading-comprehension | at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
reading-comprehension | at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
reading-comprehension | at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
reading-comprehension | at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
reading-comprehension | at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
reading-comprehension | at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
reading-comprehension | at java.lang.Thread.run(Thread.java:834)
reading-comprehension | at org.jboss.threads.JBossThread.run(JBossThread.java:479)
reading-comprehension | at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
reading-comprehension | at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
reading-comprehension | Caused by: com.connor.quarkus.jdbc.QuarkusDataAccessException: There was an error when executing sql and finding how many rows are updated
reading-comprehension | at com.connor.quarkus.jdbc.QuarkusJdbcTemplate.update(QuarkusJdbcTemplate.java:67)
reading-comprehension | at com.connor.quarkus.jdbc.QuarkusNamedJdbcTemplate.update(QuarkusNamedJdbcTemplate.java:33)
reading-comprehension | at com.connor.reading.dao.AssessmentDao.addAssessment(AssessmentDao.java:101)
reading-comprehension | ... 124 more
reading-comprehension | Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '1234' for key 'PRIMARY'
reading-comprehension | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)
reading-comprehension | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
reading-comprehension | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
reading-comprehension | at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
reading-comprehension | at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
reading-comprehension | at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
reading-comprehension | at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)
reading-comprehension | at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
reading-comprehension | at io.agroal.pool.wrapper.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:85)
reading-comprehension | at com.connor.quarkus.jdbc.QuarkusJdbcTemplate.update(QuarkusJdbcTemplate.java:65)
reading-comprehension | ... 126 more
请注意,我们不能为此使用多个线程/执行程序,因为这会混淆事务管理器