Reference Node (again...)

353 views
Skip to first unread message

tcb

unread,
Jan 24, 2012, 6:49:46 PM1/24/12
to ne...@googlegroups.com
Hi,

Just starting to use neo4j for working with large graphs (mostly social networks) and it looks very promising. After getting some mysterious results I discovered the reference node (ok, I should have read the docs more carefully...). Browsing the discussion lists, it has come up before [1] and I'm in agreement that it should be removed, although I couldn't see any decision on what was to be done or any outstanding issue. I have my own graph data which I load into neo4j, creating the nodes and relationships as I go- I don't want or need the reference node and it's really an inconvenience. I decided the best thing to do was just delete it when I create the database:

graphdb = neo4j.GraphDatabase(path)

with graphdb.transaction:

    graphdb.getReferenceNode().delete()  


but I'm not sure now if this might cause problems later on. I can work around it, but it is sometimes handy to have a 0-referenced (by id) list of nodes.

The notion of a fixed reference node is flawed in several ways. The database is creating data you didn't ask it to- how do you start with a clean database (first node with id=0?). If you delete the reference node, and then try to access it later you get a NotFoundException- but adding and removing nodes are fairly fundamental uses of such graph databases. It seems the idea behind the reference node is to give you a starting point for traversals- but why not just choose the first node 

 referenceNode = graphdb.nodes[0]

or a random one:

referenceNode = graphdb.getRandomNode()

In general, one would not expect the reference node to be the root node of your graph from which all other nodes are reachable- this assumes your graph is fully connected. If you know this is the case (its not for any of my datasets), then why not just set the reference yourself in your own code- is it really that difficult to track a reference to one node?

myReferenceNode = node0

or if its really easier, then the graph db could store the reference for you:

graphdb.setReferenceNode(myRootNode)

- at least this would allow you to set a specific node as the reference node after you had created it, and change it if required.

Obviously, since some people have already come to depend on the presence of the referenceNode, perhaps there could be some option to create it or not when the database is created:

graphdb = neo4j.GraphDatabase(path, withReferenceNode=False)

and I think this would solve most of the problems, without too much inconvenience.



Jim Webber

unread,
Jan 27, 2012, 5:08:33 AM1/27/12
to ne...@googlegroups.com
Hello,

I concur with you - I almost always remove the reference node before writing to my database with actual data from my domain.

I don't see SQL databases giving us a "reference table" so I'd be in favour of nuking it and its corresponding API calls.

Jim

Johnny Weng Luu

unread,
Jan 27, 2012, 8:03:15 AM1/27/12
to ne...@googlegroups.com
I totally agree with you. Let the user decide instead.

Pablo Pareja

unread,
Jan 27, 2012, 8:08:35 AM1/27/12
to ne...@googlegroups.com
+ 1 to get rid of the reference node


On Fri, Jan 27, 2012 at 2:03 PM, Johnny Weng Luu <johnny....@gmail.com> wrote:
I totally agree with you. Let the user decide instead.



--
Pablo Pareja Tobes 

Peter Neubauer

unread,
Jan 27, 2012, 4:45:09 PM1/27/12
to ne...@googlegroups.com
Done,

https://github.com/neo4j/community/issues/203

Now there is a number of projects and code depending on the reference
node, but we could start with deprecating it if there is enough
opinion behind it. Will check with the others.

Thanks for picking this up!

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Paul Jackson

unread,
May 3, 2012, 3:05:17 PM5/3/12
to ne...@googlegroups.com
I am not sure where this stands. I run into issues if I create an empty graph, remove the reverence node, shut down, start up, and add new nodes. The first new node added is given an id of 0. This was OK until I started working in a High Availability environment, because I would know if I am creating a new graph or opening an existing one. In HA, if I create a "new" graph, I am in the dark as to whether I am the actual creator or if it already exists in the system and updates will be injected into my graph (including reference node removal) under the covers. If I then remove the reference node, I can get exceptions if it was already removed by another instance, or I can end up removing a non-reference node if id 0 was reused as can happen.

I suggest two improvements:
1) Never reuse id 0, unless the method used to do so is explicitly called "createReferenceNode" or the like.
2) Allow a user to create a graph with no reference node. I saw comments in another thread (dated 2010) about making the creation lazy - was this done? If so, in what release?

Many thanks,
-Paul

Mattias Persson

unread,
May 5, 2012, 5:00:37 AM5/5/12
to ne...@googlegroups.com
Hi Paul,

basically Neo4j doesn't handle deletion of the reference node very well and nowadays it makes much sense to have it created on demand and that all dbs are created without it. Also, would named reference nodes be of any use, in that by default there are none but you can get or create reference nodes by name when needed? It's a slightly redundant feature though (there are indexes of course).

2012/5/3 Paul Jackson <paul_j...@g1.com>



--
Mattias Persson, [mat...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com

Paul Jackson

unread,
May 6, 2012, 10:01:58 PM5/6/12
to ne...@googlegroups.com
Hi Mattias,

Thanks for the reply. This is good to know.

I can't offer an opinion on the named reference node because I wouldn't use them - index nodes throw off the SNA metrics.

-Paul


On Saturday, May 5, 2012 5:00:37 AM UTC-4, Mattias Persson wrote:
Hi Paul,

basically Neo4j doesn't handle deletion of the reference node very well and nowadays it makes much sense to have it created on demand and that all dbs are created without it. Also, would named reference nodes be of any use, in that by default there are none but you can get or create reference nodes by name when needed? It's a slightly redundant feature though (there are indexes of course).

2012/5/3 Paul Jackson
I am not sure where this stands. I run into issues if I create an empty graph, remove the reverence node, shut down, start up, and add new nodes. The first new node added is given an id of 0. This was OK until I started working in a High Availability environment, because I would know if I am creating a new graph or opening an existing one. In HA, if I create a "new" graph, I am in the dark as to whether I am the actual creator or if it already exists in the system and updates will be injected into my graph (including reference node removal) under the covers. If I then remove the reference node, I can get exceptions if it was already removed by another instance, or I can end up removing a non-reference node if id 0 was reused as can happen.

Niranjan U

unread,
Aug 9, 2013, 4:07:33 AM8/9/13
to ne...@googlegroups.com
Hi,

I am just getting started on Neo4J Spatial and I am running into issues while creating a pointlayer:

{ "message" : "Node 0 not found", "exception" : "NotFoundException", "fullname" : "org.neo4j.graphdb.NotFoundException", ............... }

How do I recreate the reference node? 

Regards,
Niranjan

Michael Hunger

unread,
Aug 9, 2013, 4:52:19 AM8/9/13
to ne...@googlegroups.com
Can you share all your code that you use to interact with spatial? Also if you use the spatial plugin or the spatial APIs …

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Niranjan U

unread,
Aug 9, 2013, 5:35:05 AM8/9/13
to ne...@googlegroups.com
Hi,

I installed the spatial plugin and am using the REST APIs given in this link: http://neo4j.github.io/spatial/#rest-api-finding-the-plugin

Here is my code for creating the point layer:


                $data = array("layer" => "geom", "lat" => "lat", "lon" => "lon");
                $content = json_encode($data);

                $curl = curl_init($url);
                curl_setopt($curl, CURLOPT_HEADER, false);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_HTTPHEADER,
                                array("Content-type: application/json"));
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

                $json_response = curl_exec($curl);

                $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

                if ( $status != 201 ) {
                        die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
                }


                curl_close($curl);

                $response = json_decode($json_response, true);
                echo $response;




And the response I get is:


Error: call to URL http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer failed with status 500, response { "message" : "Node 0 not found", "exception" : "NotFoundException", "fullname" : "org.neo4j.graphdb.NotFoundException", "stacktrace" : [ "org.neo4j.kernel.impl.core.NodeManager.getNodeById(NodeManager.java:339)", "org.neo4j.kernel.impl.core.NodeManager.getReferenceNode(NodeManager.java:489)", "org.neo4j.kernel.InternalAbstractGraphDatabase.getReferenceNode(InternalAbstractGraphDatabase.java:931)", "org.neo4j.gis.spatial.SpatialDatabaseService.getSpatialRoot(SpatialDatabaseService.java:86)", "org.neo4j.gis.spatial.SpatialDatabaseService.getLayer(SpatialDatabaseService.java:107)", "org.neo4j.gis.spatial.SpatialDatabaseService.getOrCreatePointLayer(SpatialDatabaseService.java:181)", "org.neo4j.gis.spatial.server.plugin.SpatialPlugin.addSimplePointLayer(SpatialPlugin.java:57)", "java.lang.reflect.Method.invoke(Method.java:606)", "org.neo4j.server.plugins.PluginMethod.invoke(PluginMethod.java:57)", "org.neo4j.server.plugins.PluginManager.invoke(PluginManager.java:168)", "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:300)", "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:122)", "java.lang.reflect.Method.invoke(Method.java:606)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)" ] }, curl_error , curl_errno 0

Thanks,
Niranjan

--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/1nwZk_Z4Ie0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

Michael Hunger

unread,
Aug 9, 2013, 5:42:54 AM8/9/13
to ne...@googlegroups.com
It seems that you deleted the node 0 which is the reference node that neo4j spatial connects its geo-trees to.

Stop your database, start it again and create a new node, that one should get the id=0

Michael

Niranjan U

unread,
Aug 9, 2013, 7:01:53 AM8/9/13
to ne...@googlegroups.com
That worked! Thanks a lot.

Niranjan
Reply all
Reply to author
Forward
0 new messages