Skip to content

Commit

Permalink
Do not use traversal API to delete nodes
Browse files Browse the repository at this point in the history
This can cause the traversal to fail on an already deleted node
  • Loading branch information
craigtaverner committed Oct 14, 2017
1 parent 26c04c0 commit 3217403
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/main/java/org/neo4j/gis/spatial/rtree/RTreeIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ public void add(List<Node> geomNodes) {
nodesToAdd.add(n);
}
nodesToAdd.addAll(geomNodes);
for (Node n : getAllIndexInternalNodes()) {
if (!n.equals(getIndexRoot())) {
deleteNode(n);
}
}
detachGeometryNodes( false, getIndexRoot(), new NullListener() );
deleteTreeBelow( getIndexRoot() );
buildRtreeFromScratch(getIndexRoot(), decodeGeometryNodeEnvelopes(nodesToAdd), 0.7);
countSaved = false;
totalGeometryCount = nodesToAdd.size();
Expand Down Expand Up @@ -601,10 +598,7 @@ private Node deleteEmptyTreeNodes(Node indexNode, RelationshipType relType) {
}
}

@Override
public void removeAll(final boolean deleteGeomNodes, final Listener monitor) {
Node indexRoot = getIndexRoot();

private void detachGeometryNodes(final boolean deleteGeomNodes, Node indexRoot, final Listener monitor) {
monitor.begin(count());
try {
// delete all geometry nodes
Expand All @@ -625,6 +619,13 @@ public void onIndexReference(Node geomNode) {
} finally {
monitor.done();
}
}

@Override
public void removeAll(final boolean deleteGeomNodes, final Listener monitor) {
Node indexRoot = getIndexRoot();

detachGeometryNodes( deleteGeomNodes, indexRoot, monitor );

try (Transaction tx = database.beginTx()) {
// delete index root relationship
Expand Down Expand Up @@ -1346,6 +1347,12 @@ private double getArea(Envelope e) {
// TODO why not e.getArea(); ?
}

private void deleteTreeBelow( Node rootNode ) {
for ( Relationship relationship : rootNode.getRelationships( RTreeRelationshipTypes.RTREE_CHILD, Direction.OUTGOING )) {
deleteRecursivelySubtree( relationship.getEndNode(), relationship );
}
}

private void deleteRecursivelySubtree(Node node, Relationship incoming) {
for (Relationship relationship : node.getRelationships(RTreeRelationshipTypes.RTREE_CHILD, Direction.OUTGOING)) {
deleteRecursivelySubtree(relationship.getEndNode(),relationship);
Expand Down

0 comments on commit 3217403

Please sign in to comment.