2

I'm using this query to delete a lot of nodes, and it works fine in 4.0.0 but using 4.1.1 it doesn't seem to work

CALL apoc.periodic.iterate('
MATCH (s:Thing{id:$thingId})
  CALL apoc.path.subgraphNodes(s, {}) YIELD node
  RETURN node',
'DETACH DELETE node',
{batchSize:2000, iterateList:true, parallel:false, params: { thingId: $idOfThingToDelete}}) YIELD total, batches, errorMessages
RETURN total

It errors with the following

Failed to invoke procedure apoc.periodic.iterate: Caused by: org.neo4j.graphdb.NotFoundException: Node 78063 not found

And then further down in the log, we get this

Failed to invoke procedure apoc.periodic.iterate: Caused by: java.lang.IllegalStateException: NOT PART OF CHAIN! RelationshipTraversalCursor[id=64250, open state with: denseNode=false, next=64250, mode=regular, underlying record=Relationship[64250,used=true,source=86327,target=86330,type=7,sPrev=64238,sNext=-1,tCount=1,tNext=-1,prop=478773,secondaryUnitId=-1,!sFirst, tFirst]]

I can see the node with id 78063 and it looks fine, so I don't understand why it's saying it can't find it.

Any help appreciated, thanks!

Update

This is the second query I tried, which uses distinct, but it still gives me a Node 12345 not found error

CALL apoc.periodic.iterate(
    'MATCH (t:Thing{id:$thingId})
    CALL apoc.path.subgraphNodes(s, {}) YIELD node
    RETURN DISTINCT node',
    'DETACH DELETE n',
    {batchSize:2000, iterateList:true, parallel:false, params: { thingId: $idOfThingToDelete}}) YIELD total, batches, errorMessages
RETURN total
Richard
  • 1,731
  • 2
  • 23
  • 54
  • After migrating from Neo4j 3.5 to 4.2.6 (both Enterprise Edition) we also have the phenomenon `java.lang.IllegalStateException: NOT PART OF CHAIN!` in unchanged code. Also with us it is to be narrowed down to `apoc.path.subgraphNodes` in an `apoc.periodic.iterate` fragment, a `DISTINCT` or heap size extension unfortunately does not help. – ThirstForKnowledge May 22 '21 at 21:38

1 Answers1

0

The apoc.path.subgraphNodes procedure can return the same node multiple times, so it should use RETURN DISTINCT node to ensure that each node is only returned once.

For instance:

CALL apoc.periodic.iterate(
  'MATCH (s:Thing{id:$thingId})
   CALL apoc.path.subgraphNodes(s, {}) YIELD node
   RETURN DISTINCT node',
  'DETACH DELETE node',
  {batchSize:2000, iterateList:true, parallel:false,
   params: {thingId: $idOfThingToDelete}}) YIELD total, batches, errorMessages
RETURN total
cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Hey thanks for this reply! We put this change in and it seems to work perfectly for us on 4.0.0, but while it seems to reduce memory usage (possibly) on 4.1.1, it does still give us the "Node not found" error. We are returning the node Id distinct rather than the node itself (RETURN DISTINCT ID(node) AS nodeId). Could that be part of the problem? – Richard Nov 10 '20 at 21:10
  • I will as soon as I can (hopefully in the next hour or two), thanks again. – Richard Nov 10 '20 at 22:09
  • Same problem unfortunately, using this query (below) – Richard Nov 11 '20 at 09:27
  • Actually, posted the new query as an update to my original question for formatting reasons – Richard Nov 11 '20 at 09:36
  • Increasing the batch size helps but with larger amounts of data we just have to keep upping the value otherwise I just keep running into the same issue – Richard Nov 11 '20 at 13:44