geonetwork / core-geonetwork

GeoNetwork is a catalog application to manage spatially referenced resources. It provides powerful metadata editing and search functions as well as an interactive web map viewer. It is currently used in numerous Spatial Data Infrastructure initiatives across the world.
http://geonetwork-opensource.org/
GNU General Public License v2.0
404 stars 481 forks source link

postgis spatialindex lastval exception #1379

Open landryb opened 8 years ago

landryb commented 8 years ago

When storing the spatialindex in postgis, when reindexing all MD a traceback is trigerred for each metadata in the log:

ERROR [geonetwork.index] - Failed to properly index geometry of metadata 2239. Error: Error inserting features
java.io.IOException: Error inserting features
        at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1468)
        at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1401)
        at org.geotools.jdbc.JDBCInsertFeatureWriter.write(JDBCInsertFeatureWriter.java:76)
        at org.geotools.data.InProcessLockingManager$1.write(InProcessLockingManager.java:337)
        at org.geotools.data.store.ContentFeatureStore.addFeature(ContentFeatureStore.java:291)
        at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:245)
        at org.fao.geonet.kernel.search.spatial.SpatialIndexWriter.index(SpatialIndexWriter.java:167)
        at org.fao.geonet.kernel.search.SearchManager.indexGeometry(SearchManager.java:741)
        at org.fao.geonet.kernel.search.SearchManager.index(SearchManager.java:724)
        at org.fao.geonet.kernel.DataManager.indexMetadata(DataManager.java:665)
        at org.fao.geonet.kernel.IndexMetadataTask.run(IndexMetadataTask.java:90)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.postgresql.util.PSQLException: ERROR: lastval is not yet defined in this session
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
        at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
        at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
        at org.geotools.data.postgis.PostGISDialect.getLastAutoGeneratedValue(PostGISDialect.java:574)
        at org.geotools.jdbc.JDBCDataStore.getLastValue(JDBCDataStore.java:1897)
        at org.geotools.jdbc.JDBCDataStore.getLastValues(JDBCDataStore.java:1885)
        at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1457)
        ... 13 more

Afaik, this looks like http://osgeo-org.1560.x6.nabble.com/Postgis-datastore-and-lastval-request-td4978586.html / http://osgeo-org.1560.x6.nabble.com/PostGIS-JDBC-issue-with-sequences-td5190922.html which should be fixed by https://github.com/geotools/geotools/pull/759 but geonetwork uses a wayy too old geotools to try to backport this or update geotools without side-effects.

landryb commented 8 years ago

As a hackish' workaround i tried making the spatialindex table use hibernate_sequence instead of its own spatialindex_fid_seq. hoping that lastval would be 'more' defined within JDBC interactions

alter table spatialindex alter column fid set default nextval('hibernate_sequence');

But that didnt solve the issue, the exception is still trigerred for each MD when reindexing. Weird thing is that spatialindex table still seems correctly populated with features/bbox...

landryb commented 8 years ago

The fix seems to be in geotools since 12.x branch.

landryb commented 8 years ago

unsurprisingly, bumping geotools.version to 12.5 in pom.xml fails to build veeery quickly.

Delawen commented 8 years ago

So, when we update geotools is this going to be fixed?

landryb commented 8 years ago

In an ideal world, maybe