Skip to content
This repository

Neo4j write support for rails console and IRB console #99

Closed
dnagir opened this Issue · 6 comments

3 participants

Dmytrii Nagirniak Andreas Ronge Cyprian Kowalczyk
Dmytrii Nagirniak
Collaborator

Since only one process can access the database in write mode we must have some kind of socket connection from IRB to the server instead.

There is no need to replicate the embedded API to the socket client. We could maybe start the irb from the server and capture the stdin and stdout out.
Or just eval the input we get and set the output over the socket.

http://neo4j.lighthouseapp.com/projects/15548/tickets/206-neo4j-write-support-for-rails-console-and-irb-console

Dmytrii Nagirniak
Collaborator

Dmytrii Nagirniak

December 7th, 2011 @ 10:29 PM
Maybe we can just start an IRB/Pry session in the new thread somehow?
I am not sure that stdin/out redirects would work well taking into account all the different terminals, encoding and even color codes etc.

Andreas Ronge

December 7th, 2011 @ 10:53 PM
Yes, maybe something like that, start with plain socket and a thread.
And then we can telnet to the application, as a first step.
It would also be nice to allow all kind of different terminals.
My favorite protocol is XMPP which would enable talking to the rails server using a standard chat client.

Andreas Ronge

December 7th, 2011 @ 10:59 PM
Maybe this could be useful:
https://github.com/nicksieger/drbirb

Cyprian Kowalczyk

If I get your problem right (trying to access neo4j from multiple clients - say, rails app and its console), one potential resolution is using Neo4J in HA Cluster mode.

So far I've got up to the following point:

````11:59:06,867 INFO org.apache.zookeeper.ClientCnxn Socket connection established to localhost/127.0.0.1:2181, initiating session
11:59:06,985 INFO org.apache.zookeeper.ClientCnxn Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1361b20a8df0002, negotiated timeout = 6000
java.lang.RuntimeException: There's already an HA cluster managed by this ZooKeeper cluster

Cyprian Kowalczyk

Here is my temporary solution for simultaneous write access to Neo4j HA cluster from two clients - I tested it with two instances of rails console.

1. Start ZooKeeper from ha-cluster example (https://github.com/andreasronge/neo4j/tree/master/example/ha-cluster),
2. Start rails console,
3. Manipulate config.neo4j in application.rb to get new rails console to start a new instance of neo4j that uses different storage dir and works as a slave:

config.neo4j['storage_path'] = 'db/serv_1'
config.neo4j['ha.db'] = true
config.neo4j['ha.server_id'] = 1
config.neo4j['ha.server'] = 'localhost:6001'

I reckon this could be parametrized and quite easy to use, though would be nice to, say, get the new instance of the app to recognize if this should be done automatically, or something. This could be achieved by checking for the lock file in, say, "db/neo4j-development-#{neo4j_server_id}". Slave storage dirs could be cleaned up on exit for dev env.

Andreas Ronge
Owner

Great. Maybe this is the easiest solution for this issue. There is code for checking the the database is locked in the Neo4j::Database. Yes, a little script for starting and configure this would be nice.

Andreas Ronge andreasronge referenced this issue from a commit
Andreas Ronge Added support to access the rails console with write access at the sa…
…me time as the rails application is running #99

Looks like it works !
You need to include the neo4j-enterprise and neo4j-advanced gem as development deps (see license)
Then you include the ha_console railitie in your application.rb.
This is all that is needed to get the rails console working using a Neo4j HA cluster.
de03537
Andreas Ronge andreasronge referenced this issue from a commit
Andreas Ronge Support for HA cluster with neo4j, 1.9.X, #228, #99, #223
* Fixed for IRB/Pry console using HA to concurrently access the database
* Updated the HA examples
* Removed ZooKeeper and its configuration
5895b86
Andreas Ronge

Zookeeper is gone since we use Neo4j 1.9.M03 :)
see https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3Aha-cluster

Use Rails console with ha enabled

Andreas Ronge andreasronge closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.