Hi folks,

we're working with spatial queries on databases with 6 million entries and 
more on Windows machines.

However we still experience constantly internal ClosedChannelExceptions 
that usually look like  this:

General error: "java.lang.IllegalStateException: Reading from 
cache:nio:C:/temp/h2/xxx.mv.db failed; file length -1 read length 512 at 
952348402 [1.3.176/1]"; SQL statement:
SELECT FID,SHAPE,FS,FZ_FN,FL_FZ_FN,KREIS,CD,MSG FROM xxx WHERE  INTERSECTS 
(SHAPE, 'POLYGON ((3496159.5592107037 5597032.982892634, 3496159.5592107037 
5601139.071733489, 3502562.0416436885 5601139.071733489, 3502562.0416436885 
5597032.982892634, 3496159.5592107037 5597032.982892634))'::Geometry); 
[50000-176]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.message.DbException.convert(DbException.java:294)
at org.h2.command.Command.executeQuery(Command.java:209)
at 
org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:109)
         (....)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalStateException: Reading from 
cache:nio:C:/temp/h2/alk_r-file-databaseeventlistener-2014-05-14-002.mv.db 
failed; file length -1 read length 512 at 952348402 [1.3.176/1]
at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:757)
at org.h2.mvstore.DataUtils.readFully(DataUtils.java:427)
at org.h2.mvstore.FileStore.readFully(FileStore.java:99)
at org.h2.mvstore.Page.read(Page.java:195)
at org.h2.mvstore.MVStore.readPage(MVStore.java:1613)
at org.h2.mvstore.MVMap.readPage(MVMap.java:733)
at org.h2.mvstore.Page.getChildPage(Page.java:222)
at org.h2.mvstore.MVMap.binarySearch(MVMap.java:446)
at org.h2.mvstore.MVMap.binarySearch(MVMap.java:447)
at org.h2.mvstore.MVMap.binarySearch(MVMap.java:447)
at org.h2.mvstore.MVMap.get(MVMap.java:428)
at 
org.h2.mvstore.db.TransactionStore$TransactionMap.getValue(TransactionStore.java:1186)
at 
org.h2.mvstore.db.TransactionStore$TransactionMap.get(TransactionStore.java:1164)
at 
org.h2.mvstore.db.TransactionStore$TransactionMap.get(TransactionStore.java:1131)
at org.h2.mvstore.db.MVPrimaryIndex.getRow(MVPrimaryIndex.java:207)
at org.h2.mvstore.db.MVTable.getRow(MVTable.java:367)
at 
org.h2.mvstore.db.MVSpatialIndex$MVStoreCursor.get(MVSpatialIndex.java:374)
at org.h2.index.IndexCursor.get(IndexCursor.java:261)
at org.h2.table.TableFilter.getValue(TableFilter.java:898)
at org.h2.expression.ExpressionColumn.getValue(ExpressionColumn.java:187)
at org.h2.expression.Comparison.getValue(Comparison.java:229)
at org.h2.expression.Expression.getBooleanValue(Expression.java:179)
at org.h2.command.dml.Select.queryFlat(Select.java:535)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:646)
at org.h2.command.dml.Query.query(Query.java:323)
at org.h2.command.dml.Query.query(Query.java:291)
at org.h2.command.dml.Query.query(Query.java:37)
at org.h2.command.CommandContainer.query(CommandContainer.java:91)
at org.h2.command.Command.executeQuery(Command.java:197)
... 16 more
Caused by: java.nio.channels.ClosedChannelException
at sun.nio.ch.FileChannelImpl.ensureOpen(FileChannelImpl.java:88)
at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:603)
at org.h2.store.fs.FileNio.read(FilePathNio.java:75)
at org.h2.mvstore.cache.FilePathCache$FileCache.read(FilePathCache.java:82)
at org.h2.mvstore.DataUtils.readFully(DataUtils.java:413)
... 43 more


We use straight SQL queries and our spatial query statement looks like 

SELECT FID,SHAPE,FS,FZ_FN,FL_FZ_FN,KREIS,CD,MSG FROM xxx WHERE  INTERSECTS 
(SHAPE, 'POLYGON ((3496159.5592107037 5597032.982892634, 3496159.5592107037 
5601139.071733489, 3502562.0416436885 5601139.071733489, 3502562.0416436885 
5597032.982892634, 3496159.5592107037 5597032.982892634))'::Geometry) 

to retrieve spatial features using a bounding box.

The spatial index was actually created like in the H2 query sample code 
seen in *TestSpatial.java* and is managed using the MVStore engine, because 
of its R-Tree implementation.

We've tested a lot of different setups and H2 settings (different internal 
file sub-systems like *file*, *nio *and *nioMapped *as well). In the end 
we've figured out that the culprit might be somewhere in the internal file 
handling and that a delay between the queries might be helpful against 
these *ClosedChannelExceptions*. But this would actually vanish the 
performance benefits of H2 away. Memory-tables-only on small data sets work 
without any problems.

These *ClosedChannelExceptions *happen very randomly, but will happen more 
frequently the larger the data sets are. And it seems like H2 doesn't wait 
internally for the operating system to let an assumed file flush settle, 
before a new query is made.

The question: Is there a known workaround against these curious 
*ClosedChannelExceptions 
*? Or does anyone experience similar behavior when using spatial queries ? 
Is it a known H2 issue atm?

(PS: This happens to H2 1.3.176 and 1.3.175 as well)

Best regards,
Enrico

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to