Exception when inserting WKT point

Hi,

I keep getting the following error when updating a graph through the Jena API

ERROR 2017-06-25 14:21:56,617 [XNIO-1 task-5] com.complexible.tx.api.impl.DefaultTransaction:computePrepareResult(496): There was a fatal failure during preparation of 89a90ede-9275-4397-8a40-57092f104ce9
com.complexible.tx.api.ResourceTransactionException: 
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection$GeoTransaction.prepare(GeospatialConnectableConnection.java:275) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.tx.api.BaseResourceTransaction.prepare(BaseResourceTransaction.java:187) ~[stardog-5.0.jar:?]
	at com.complexible.tx.api.impl.DefaultTransaction.computePrepareResult(DefaultTransaction.java:480) ~[stardog-5.0.jar:?]
	at com.complexible.tx.api.impl.DefaultTransaction.runPreparePhase(DefaultTransaction.java:446) ~[stardog-5.0.jar:?]
	at com.complexible.tx.api.impl.DefaultTransaction.commit(DefaultTransaction.java:333) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.db.index.ConnectableIndexRWConnectionImpl.commit(ConnectableIndexRWConnectionImpl.java:533) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.db.DatabaseConnectionImpl.commit(DatabaseConnectionImpl.java:447) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.db.DelegatingDatabaseConnection.commit(DelegatingDatabaseConnection.java:282) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.db.DatabaseImpl$MonitoredDbConnection.commit(DatabaseImpl.java:1664) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.db.DatabaseImpl$DBConnectionWrapper.commit(DatabaseImpl.java:1433) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.db.DelegatingDatabaseConnection.commit(DelegatingDatabaseConnection.java:282) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.StardogKernel$KernelDbConnection.commit(StardogKernel.java:3106) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.db.DelegatingDatabaseConnection.commit(DelegatingDatabaseConnection.java:282) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.StardogKernel$NotifyingDatabaseConnection.commit(StardogKernel.java:3374) ~[stardog-5.0.jar:?]
	at com.complexible.stardog.protocols.http.server.ProtocolUtils.executeCommit(ProtocolUtils.java:557) ~[stardog-protocols-http-server-5.0.jar:?]
	at com.complexible.stardog.protocols.http.server.TransactionService.commit(TransactionService.java:127) ~[stardog-protocols-http-server-5.0.jar:?]
	at com.stardog.http.server.undertow.jaxrs.ExtractRoutes.lambda$handleIt$91(ExtractRoutes.java:186) ~[stardog-protocols-http-server-5.0.jar:?]
	at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120) ~[shiro-core-1.2.3.jar:1.2.3]
	at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108) ~[shiro-core-1.2.3.jar:1.2.3]
	at com.stardog.http.server.undertow.ErrorHandling.lambda$safeDispatch$46(ErrorHandling.java:70) ~[stardog-protocols-http-server-5.0.jar:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Caused by: com.complexible.stardog.spatial.GeoException: com.complexible.stardog.spatial.GeoException: java.lang.RuntimeException: org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: /home/stardog/test/spatial/write.lock
	at com.complexible.stardog.spatial.io.StatementSourceGeospatialSource.parse(StatementSourceGeospatialSource.java:146) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectable.reindex(GeospatialConnectable.java:157) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection.reindex(GeospatialConnectableConnection.java:170) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection$GeoTransaction.prepare(GeospatialConnectableConnection.java:267) ~[stardog-spatial-core-5.0.jar:?]
	... 22 more
Caused by: com.complexible.stardog.spatial.GeoException: java.lang.RuntimeException: org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: /home/stardog/test/spatial/write.lock
	at com.complexible.stardog.spatial.impl.LuceneGeospatialIndexConnection.add(LuceneGeospatialIndexConnection.java:380) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectable.lambda$reindex$1(GeospatialConnectable.java:159) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.io.StatementSourceGeospatialSource.parse(StatementSourceGeospatialSource.java:137) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectable.reindex(GeospatialConnectable.java:157) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection.reindex(GeospatialConnectableConnection.java:170) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection$GeoTransaction.prepare(GeospatialConnectableConnection.java:267) ~[stardog-spatial-core-5.0.jar:?]
	... 22 more
Caused by: java.lang.RuntimeException: org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: /home/stardog/test/spatial/write.lock
	at com.complexible.stardog.spatial.impl.LuceneGeospatialIndexConnection.acquireIndexWriter(LuceneGeospatialIndexConnection.java:501) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.impl.LuceneGeospatialIndexConnection.add(LuceneGeospatialIndexConnection.java:376) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectable.lambda$reindex$1(GeospatialConnectable.java:159) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.io.StatementSourceGeospatialSource.parse(StatementSourceGeospatialSource.java:137) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectable.reindex(GeospatialConnectable.java:157) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection.reindex(GeospatialConnectableConnection.java:170) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection$GeoTransaction.prepare(GeospatialConnectableConnection.java:267) ~[stardog-spatial-core-5.0.jar:?]
	... 22 more
Caused by: org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: /home/stardog/test/spatial/write.lock
	at org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:127) ~[lucene-core-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:38:09]
	at org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41) ~[lucene-core-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:38:09]
	at org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45) ~[lucene-core-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:38:09]
	at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:775) ~[lucene-core-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:38:09]
	at com.complexible.stardog.search.waldo.IndexWriterManager.getWriter(IndexWriterManager.java:79) ~[stardog-search-waldo-5.0.jar:?]
	at com.complexible.stardog.search.waldo.IndexWriterManager.acquire(IndexWriterManager.java:43) ~[stardog-search-waldo-5.0.jar:?]
	at com.complexible.stardog.spatial.impl.LuceneGeospatialIndexConnection.acquireIndexWriter(LuceneGeospatialIndexConnection.java:497) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.impl.LuceneGeospatialIndexConnection.add(LuceneGeospatialIndexConnection.java:376) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectable.lambda$reindex$1(GeospatialConnectable.java:159) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.io.StatementSourceGeospatialSource.parse(StatementSourceGeospatialSource.java:137) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectable.reindex(GeospatialConnectable.java:157) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection.reindex(GeospatialConnectableConnection.java:170) ~[stardog-spatial-core-5.0.jar:?]
	at com.complexible.stardog.spatial.db.GeospatialConnectableConnection$GeoTransaction.prepare(GeospatialConnectableConnection.java:267) ~[stardog-spatial-core-5.0.jar:?]
	... 22 more

Graphs which contained WKT POINT geometries are not inserted into the database, the spatial index is on

We are running Stardog 5.

Bart

Disabling the spatial index prevents the error.

You might want to check that the user that you’re running Stardog with has
write access to

/home/stardog/test/spatial

That directory would have been created by the Stardog user but if you
started stardog, created the databse, shutdown and then restarted with a
different user you might not.

interesting thought, but all owned by respective user

I have one last thing you might try. Try shutting down Stardog and removing the lock /home/stardog/test/spatial/write.lock and then start back up and see if that fixes things up.

Hi Bart,

Thanks for your bug report. We are currently investigating a similar error reported by other user.
Could you share with us the code you’re using? We haven’t been able to replicate this behaviour locally.

Thanks,
-pedro

Hi Pedro,

The full code is rather complex, essentially what I do is:
Get a Jena model and add a litteral.

location.addLiteral(Geosparql.asWKT,
		    ResourceFactory.createTypedLiteral("POINT(" + anonSet.getString("anon_x") + " " + znonSet.getString("anon_y") + ")",
		    WktLiteral.wktLiteralType));

This model is then stored in a named graph and generates the error. The triple it tries to insert:

<http://ri-test/data/incident/2017/225227/deployment/201706251942500#location> <http://www.opengis.net/ont/geosparql#asWKT> "POINT(4.862342177035991 52.34820977059975)"

disabling the spatial index solves the problem.

Do you need more info?

Bart

Thanks Bart. Just one more question: is the insertion code being called in
parallel, e.g., multiple threads?

Yes, we use a MDB to offload interaction with the graph store so on higher loads it will be mutli threaded

Thanks for your input. We are currently working on this issue, a fix should
be available with the next release.

okay, let me know if we need to test anything, would be happy too

Hi Bart,

We just released Stardog 5.0.1, which contains a fix that might solve this issue. Let us know if you encounter this error again.

-pedro