class TwoPhaseNodeForRelationshipLocking {

    void lockAllNodesAndConsumeRelationships( long nodeId, final Transaction transaction, NodeCursor nodes ) throws KernelException
    {
        boolean retry;
        do
        {
            retry = false;
            relIds = new LongHashSet();

            collectAndSortNodeIds( nodeId, transaction, nodes );
            // lock all the nodes involved by following the node id ordering
            lockAllNodes( sortedNodeIds );

            // perform the action on each relationship, we will retry if the the relationship iterator contains
            // new relationships
            transaction.dataRead().singleNode( nodeId, nodes );
            //if the node is not there, someone else probably deleted it, just ignore
            if ( nodes.next() )
            {
                try ( RelationshipSelectionCursor rels =
                              RelationshipSelections.allCursor( transaction.cursors(), nodes, null ) )
                {
                    while ( rels.next() && !retry )
                    {
                        if ( !relIds.contains( rels.relationshipReference() ) )
                        {
                            retry = true;
                            unlockAllNodes( sortedNodeIds );
                            sortedNodeIds = null;
                        }
                    }
                }
            }
        }
        while ( retry );
        long[] sortedRelIds = relIds.toSortedArray();
        if ( sortedRelIds.length > 0 )
        {
            locks.acquireExclusive( lockTracer, ResourceTypes.RELATIONSHIP, sortedRelIds );
            for ( long relId : sortedRelIds )
            {
                relIdAction.accept( relId );
            }
        }
    }

      TwoPhaseNodeForRelationshipLocking(
            ThrowingConsumer<Long,KernelException> relIdAction, Locks.Client locks,
            LockTracer lockTracer );

}