Multitenancy, Upgrade, Admin, Configuration and Backup

1 The Admin Console and Visualization

If you want to have the same admin console as in the neo4j server you can use the neo4j-admin gem. Check the neo4j-admin gem

Here is another console the neo-viz gem

2 Multitenancy

You can split the graph database (and the lucene database) into separated parts by setting the reference node.


a = User.all[0] # could be any Neo4j node object
b = User.all[1]
Neo4j.threadlocal_ref_node = a  # store this in the current thread
Product.all.size #=> 1
Product.find('name: p') #=> the product p

Neo4j.threadlocal_ref_node = b
Product.all.size #=> 0
Product.find('name: p') #=> nil

If you want to share data between different users, example:

class Shared < Neo4j::Rails::Model
  property :foo
  ref_node { Neo4j.default_ref_node }

When used from rails the thread context variable Neo4j.threadlocal_ref_node is automtically reset after each request (Rack Middleware). The same is true for lucene connections.

Multitenency is supported for both Neo4j::NodeMixin and Neo4j::Rails::Model.

For more information –

In Neo4j there is just one reference node. Neo4j.rb has support for having more than one reference node. Instead of returning the reference node from the Java API, neo4j.rb uses the thread local storage where the user can have his own node as a reference node. By doing that the lucene files will also be prefixed so that the lucene database is also split.

3 Upgrade to a new Neo4j version

Some of the neo4j.rb releases includes a new version of the java neo4j library which requires a upgrade of the database since it has a different format.

  • Version 1.3.1 uses Neo4j java library 1.6.0.M01
  • Version 1.3.0 uses Neo4j java library 1.5.0
  • Version 1.2.x uses Neo4j java library 1.4.1
  • Version 1.1.x uses Neo4j java library 1.3
  • Version 1.0.x uses Neo4j java library 1.3.M03

Also, see Upgrade Neo4j

3.1 How to upgrade for rails application

Make sure that you have shutdown the server cleanly. If not sure do this:

  1. Make sure the server is not running
  2. type rails console
  3. type in the console: Neo4j.shutdown

Run the script (after installing the new version of neo4j, gem install neo4j)


If you rather do this manually:

  1. Change your dependency to Neo4j in the Gemfile, e.g. gem 'neo4j', '1.3.0'
  2. type: bundle update neo4j
  3. type: rails console
  4. In the rails console: Neo4j::Config[:allow_store_upgrade] = 'true'
  5. In the rails console: Neo4j.start

Notice, in the neo4j.rb release 1.3.0 the filenames of the lucene indices was changed. The neo4j-upgrade script will handle this and rename the lucene files.

4 Backup

This feature is only available in the neo4j-enterprise edition. Please add a dependency to the neo4j-enteprise gem and require it (in upcoming neo4j 2.0.0 release).

By setting the configuration enable_online_backup to true (as a String) For more info check this

IRB Example:

> require 'neo4j'
> Neo4j.config[:enable_online_backup] = 'true'                   
> { Neo4j.ref_node[:ko] = 'fo'}          
I, [2011-02-16T12:36:47.196000 #28375]  INFO -- : Enable remote shell at port port=9332
I, [2011-02-16T12:36:47.207000 #28375]  INFO -- : Starting local Neo4j using db /home/andreas/projects/neo4j/lib/db
Wed Feb 16 12:36:48 CET 2011: BackupServer communication server started and bound to 6362
> org.neo4j.backup.OnlineBackup.from('localhost').full('/tmp/mynewbackup')
Wed Feb 16 12:36:52 CET 2011: Client connected to localhost:6362
Wed Feb 16 12:36:52 CET 2011: Opened a new channel to localhost/
 => #<Java::OrgNeo4jBackup::OnlineBackup:0x1bd5f28> 

5 Neo4j.rb configuration

The Neo4j::Config class is used to configure neo4j. It uses this file as default. You can change or add any configuration property by using Neo4j::Config[key]=value.

You can also load configuration from your own file, example:


5.1 Neo4j Java Configuration

The same YAML file is also used for the Java Neo4j configuration. See here

6 Config Neo4j from Rails

When using Neo4j.rb from rails you can use the normal rails configuration to set Neo4j configuration.

Example config/application.rb

module Neo4jRailsExample
  class Application < Rails::Application
    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]
    # Neo4j configuration
    config.neo4j.storage_path = "#{config.root}/db/neo4j-#{Rails.env}"

7 JRuby Configuration

See PerformanceTuning

8 Development and Testing configuration

8.1 Travis

Neo4j.rb is using the travis CI

8.2 Faster RSpecs

8.2.1 Linux

You can create a RAM disk with 500MB like this: (the mount command needs to be issued as root)

mkdir -p /tmp/neo4j_testing
mount -t tmpfs -o size=500M tmpfs /tmp/neo4j_testing
8.2.2 Mac

You can create a 550MB RAM disk like this:

diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://1165430`

This will create a RAM disk under /Volumes/ramdisk

For both of these, in your spec_helper, you’ll have to change the Neo4j config to use the RAM disk.

Neo4j::Config[:storage_path] = /path/to/ram/disk
You can use umount to unmount the ram disk on both platforms.

For more info, check this

8.3 Using RSpec and Guard

The flow for testing with this PR would be:

  1. Start the guard: bundle exec guard
  2. It’ll run all specs.
  3. Got to you spec and start adding/changing.
  4. Save spec/related implementation file.
  5. The spec will be executed automatically.

If you want to concentrate on a single spec/example group, just add the :focus tag and only this spec will be executed by guard:

it "should do something", :focus do

Additionally the following are included:

default .rspec config is added to make it easier to see the spec results with colours. Growl 1.3 notifications (Mac only for now).

For more info, check this pull request