cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Duplicate relationships

Neo v4.4

I have a stream of data that is rapidly inserting arrival relationships with the following query:

MATCH (s:station), (t:train) WHERE s.locationid=$arrLoc AND t.trainid=$trainID
MERGE (t)-[a:arrival { planneddeparturetime:$planDepTime }]->(s)
ON CREATE SET a += {departuretime:$depTime, planneddeparturetime:$planDepTime, fromtimetable:$fromtt}
ON MATCH SET a += {departuretime:$depTime, planneddeparturetime:$planDepTime, fromtimetable:$fromtt}
RETURN a, s.locationid as sourcelocid

However i'm seeing duplicate arrival relationships between the train and station which have been created very close together. The service inserting the records is single threaded and I have an index on planneddeparturetime.

Is the issue that the match is using the index but the insertion is asynchronous and therefore the second insert a few ms later won't see the just created arrival in the index?

2 REPLIES 2

As I understand it, merge is not threadsafe, as you can create the same node relationship it the happen close together.  You state you are using one thread to processing the incoming data, so that is not the issue.  Are you using a blocking write or an async write in this thread?  Async would be like multi threading. 

Yes we're blocking on the write and reading the returned locationid before continuing in the single thread.

On an insertion, does Neo block until a record is propagated to all secondary indexes?