DemocracyDevelopers / colorado-rla

Colorado Risk-Limiting Audit (RLA) software – developed to support risk-limiting post-election audits of election outcomes.
Other
0 stars 0 forks source link

Investigate constraint violation exception #201

Open vteague opened 2 weeks ago

vteague commented 2 weeks ago

A constraint violation exception is occasionally thrown when generating assertions. It's not clear whether this only happens when we've gone partway through the process (e.g. tried to generate assertions but forgotten to turn the raire service on).

Exception: 2024-09-14-20:55:03 INFO corla:522 - successful /set-contest-names by stateadmin1 from localhost:8888 2024-09-14-20:55:06 INFO corla:420 - endpoint /generate-assertions hit by localhost:8888 2024-09-14-20:55:06 INFO AbstractBatchImpl:213 - HHH000010: On release of batch it still contained JDBC statements 2024-09-14-20:55:06 ERROR BatchingBatch:134 - HHH000315: Exception executing batch [java.sql.BatchUpdateException: Batch entry 0 insert into contests_to_contest_results (contest_result_id, contest_id) values (1951233, 1794238) was aborted: ERROR: duplicate key value violates unique constraint "uk_t1qahmm5y32ovxtqxne8i7ou0" Detail: Key (contest_id)=(1794238) already exists. Call getNextException to see other errors in the batch.], SQL: insert into contests_to_contest_results (contest_result_id, contest_id) values (?, ?) 2024-09-14-20:55:06 WARN SqlExceptionHelper:137 - SQL Error: 0, SQLState: 23505 2024-09-14-20:55:06 ERROR SqlExceptionHelper:142 - Batch entry 0 insert into contests_to_contest_results (contest_result_id, contest_id) values (1951233, 1794238) was aborted: ERROR: duplicate key value violates unique constraint "uk_t1qahmm5y32ovxtqxne8i7ou0" Detail: Key (contest_id)=(1794238) already exists. Call getNextException to see other errors in the batch. 2024-09-14-20:55:06 ERROR SqlExceptionHelper:142 - ERROR: duplicate key value violates unique constraint "uk_t1qahmm5y32ovxtqxne8i7ou0" Detail: Key (contest_id)=(1794238) already exists. 2024-09-14-20:55:06 ERROR corla:483 - uncaught exception in endpoint /generate-assertions: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute batch at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1626) at org.hibernate.query.internal.AbstractProducedQuery.uniqueResult(AbstractProducedQuery.java:1659) at org.hibernate.query.internal.AbstractProducedQuery.uniqueResultOptional(AbstractProducedQuery.java:1610) at us.freeandfair.corla.query.ContestResultQueries.findOrCreate(ContestResultQueries.java:30) at us.freeandfair.corla.controller.ContestCounter.countContest(ContestCounter.java:92) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) at java.base/java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1850) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) at us.freeandfair.corla.controller.ContestCounter.countAllContests(ContestCounter.java:52) at au.org.democracydevelopers.corla.endpoint.AbstractAllIrvEndpoint.getIRVContestResults(AbstractAllIrvEndpoint.java:100) at au.org.democracydevelopers.corla.endpoint.GenerateAssertions.endpointBody(GenerateAssertions.java:147) at us.freeandfair.corla.endpoint.AbstractEndpoint.endpoint(AbstractEndpoint.java:468) at us.freeandfair.corla.Main.lambda$activateEndpoints$3(Main.java:365) at spark.RouteImpl$1.handle(RouteImpl.java:72) at spark.http.matching.Routes.execute(Routes.java:61) at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:130) at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.Server.handle(Server.java:564) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128) at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590) at java.base/java.lang.Thread.run(Thread.java:840) Caused by: org.hibernate.exception.ConstraintViolationException: could not execute batch at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:109) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:37) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:135) at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.doExecuteBatch(BatchingBatch.java:110) at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.execute(AbstractBatchImpl.java:153) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.getBatch(JdbcCoordinatorImpl.java:187) at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1327) at org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:50) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604) at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478) at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:344) at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:57) at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107) at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1372) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1452) at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1649) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617) ... 36 more

vteague commented 1 week ago

I suspect this is not a real problem, just something that happens in dev when the database isn't emptied properly between runs.