Re: RuntimeException in a Select max() query

158 views
Skip to first unread message

Thomas Mueller

unread,
Sep 28, 2012, 7:26:36 PM9/28/12
to h2-da...@googlegroups.com

Hi

Could you post the rest of the stack tragen please?

Regards, Thomas

Am 28.09.2012 09:11 schrieb "Ignasi Marimon-Clos i Sunyol" <igna...@gmail.com>:
Hi all,

we are long time users of H2 and have come to love it's versatility. This love is not free of bumps though.

We've just faced the most strange one: 

(excerpt stack trace, full stack trace at bottom)

General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:158)
at org.h2.message.DbException.convert(DbException.java:281)
at org.h2.command.Command.executeQuery(Command.java:189)
                  .... 

We are using  com.h2database:h2:1.3.160 and at this stage of the development we can't afford upgrading the version.

We connect to the DB using the URL:

jdbc:h2:C:\path\to\db;MAX_MEMORY_UNDO=20000;MAX_OPERATION_MEMORY=20000;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=100000;IFEXISTS=TRUE;MVCC=TRUE;CIPHER=AES;DB_CLOSE_ON_EXIT=FALSE 


All the information (symptoms) we have are :

* We can't reproduce the error in a single threaded application with high DB load.
* We can't reproduce the error in a multi threaded application with low DB load.
* We can reproduce the error in a multi threaded application with high DB load.


Any help/feedback will be welcome. Thanks in advance,

Ignasi


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/AyAAqx58VuMJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Ignasi Marimon-Clos i Sunyol

unread,
Oct 1, 2012, 4:02:38 AM10/1/12
to h2-da...@googlegroups.com
Sorry, 

I mentioned that in my previous e-mail but forgot the attachment:


2012-09-27 18:22:50,434 ERROR [Thread-1] (Context.java:282) Calling onError of com.myBizz.edmpb.addressbook.sm.UserDetailsState@1d56250 for org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_]; SQL state [HY000]; error code [50000]; General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160]; nested exception is org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160] 
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_]; SQL state [HY000]; error code [50000]; General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160]; nested exception is org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1046)
at com.myBizz.edmpb.dao.ExtendedEntityDaoImpl.get(ExtendedEntityDaoImpl.java:213)
at com.myBizz.edmpb.dao.ExtendedEntityDaoImpl.getUnique(ExtendedEntityDaoImpl.java:231)
at com.myBizz.edmpb.dao.ExtendedEntityDaoImpl.getUnique(ExtendedEntityDaoImpl.java:222)
at com.myBizz.edmpb.services.communication.queueing.repositories.AbstractQueueRepository.lastQueuePosition(AbstractQueueRepository.java:538)
at com.myBizz.edmpb.services.communication.queueing.repositories.AbstractQueueRepository.findTailPackageId(AbstractQueueRepository.java:508)
at com.myBizz.edmpb.communication.queueing.Queue.findTailPackageId(Queue.java:95)
at com.myBizz.edmpb.communication.translation.builder.RawPackageBuilderImpl.buildPackage(RawPackageBuilderImpl.java:53)
at com.myBizz.edmpb.services.communication.translation.builder.SynchronizationPackageBuilderImpl.buildPackageOperation(SynchronizationPackageBuilderImpl.java:90)
[...]
Caused by: org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:158)
at org.h2.message.DbException.convert(DbException.java:281)
at org.h2.command.Command.executeQuery(Command.java:189)
at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:96)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2136)
at org.hibernate.loader.Loader.list(Loader.java:2096)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1056)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
... 35 more
Caused by: java.lang.RuntimeException: Unexpected code path
at org.h2.message.DbException.throwInternalError(DbException.java:228)
at org.h2.message.DbException.throwInternalError(DbException.java:241)
at org.h2.index.PageDataCursor.previous(PageDataCursor.java:102)
at org.h2.index.MultiVersionCursor.step(MultiVersionCursor.java:73)
at org.h2.index.MultiVersionCursor.loadNext(MultiVersionCursor.java:57)
at org.h2.index.MultiVersionCursor.next(MultiVersionCursor.java:105)
at org.h2.index.MultiVersionCursor.previous(MultiVersionCursor.java:179)
at org.h2.index.MultiVersionIndex.findFirstOrLast(MultiVersionIndex.java:113)
at org.h2.expression.Aggregate.getValue(Aggregate.java:279)
at org.h2.expression.Alias.getValue(Alias.java:35)
at org.h2.command.dml.Select.queryQuick(Select.java:542)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:607)
at org.h2.command.dml.Query.query(Query.java:298)
at org.h2.command.dml.Query.query(Query.java:268)
at org.h2.command.dml.Query.query(Query.java:37)
at org.h2.command.CommandContainer.query(CommandContainer.java:82)
at org.h2.command.Command.executeQuery(Command.java:185)
... 49 more
2012-09-27 18:22:50,434 ERROR [Thread-1] (EpbaddressbookState.java:77) Hibernate operation: could not execute query; uncategorized SQLException for SQL [select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_]; SQL state [HY000]; error code [50000]; General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160]; nested exception is org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
select max(this_.QUEUE_POSITION) as y0_ from HISTORY_QUEUE this_ limit ? [50000-160] 
2012-09-27 18:22:50,434 INFO  [Thread-1] (UserDetailsState.java:1023) EXITING UserDetailsState STATE 



We finally managed to reproduce the error and we suspect the conditions are:

 - thread 1 opens transaction
 - thread 2 opens transaction
 - thread 2 inserts Item in table Foo
 - thread 1 runs a select max(col) in table Foo

Or similar.
We could only see the error when both Threads were using transactions.


Thanks for the help!

Noel Grandin

unread,
Oct 2, 2012, 2:45:10 AM10/2/12
to h2-da...@googlegroups.com, Ignasi Marimon-Clos i Sunyol, Thomas Mueller
Turn off MVCC.

Thomas, perhaps the MVCC option should be disabled, since it keeps
causing problems ?

On 2012-10-01 10:02, Ignasi Marimon-Clos i Sunyol wrote:

Ignasi Marimon-Clos i Sunyol

unread,
Oct 3, 2012, 5:37:34 AM10/3/12
to h2-da...@googlegroups.com, Ignasi Marimon-Clos i Sunyol, Thomas Mueller
Turning off MVCC is not feasible at this time. And we are not uncomfortable with MVCC.

It's only that we are not aware of MVCC's limitations (like concurrent updates when a select max() is run).



We worked around the issue by denormalizing the data and maintaining that MAX value on a separate table. 



Thanks for all the feedback.
Reply all
Reply to author
Forward
0 new messages