There’s a some sort of race condition / thread safety issue either with neo4j-spatial and/or Spring Data for Neo4j that causes the data kept by the Spatial Index Provider to get corrupted.

Specifically, a spatial node is only supposed to have one incoming relationship of type RTREE_REFERENCE. However, under some circumstances more than one relationship of this type gets created, and any attempt to set values on properties indexed with the Spatial Index Provider on these nodes will fail with the following exception:

I have been unable to reproduce the conditions by which this issue occurs in a test case of any sorts, so finding a cause or solution has been difficult.

While the issue continues to get debugged I put in a temporary solution that at least removes the failures when setting the spatial properties on the node entities.

I implemented a simple monitor that searches for nodes with more than one incoming RTREE_REFERENCE relationship, then deletes all but one of those relationships from the node. I’m using Spring Framework’s task scheduler functionality.

I created a simple Java bean for the monitor:

I then created the task scheduler and the scheduled tasks it executes in a Spring Framework configuration file as follows:

graphDatabaseService refers to the Neo4j GraphDatabaseService interface implementation, in my case org.neo4j.kernel.EmbeddedGraphDatabase.

Spring Framework takes care of the execution of the scheduled tasks automatically. I’ve set the monitor to run every 20 minutes, as we’re importing data into the database every 30 minutes or so.

Share →

Leave a Reply

Your email address will not be published. Required fields are marked *