Skip to content
Dieter Pisarewski edited this page Apr 28, 2015 · 7 revisions

Multitenancy, Upgrade, Admin, Configuration and Backup

endprologue.

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

Multitenancy

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

Example:

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.create(:name=>'p')
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 }
end

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 – http://blog.vivekprahlad.com/multitenancy-with-neo4jrb.

TIP: 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.

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

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)

neo4j-upgrade

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.

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::Transaction.run { 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/127.0.0.1:6362
 => #<Java::OrgNeo4jBackup::OnlineBackup:0x1bd5f28> 

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:

Neo4j::Config.default_file='/var/neo4j/config.yaml'

Neo4j Java Configuration

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

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}"
  end
end

JRuby Configuration

See PerformanceTuning

Development and Testing configuration

Travis

Neo4j.rb is using the travis CI

Faster RSpecs

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
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

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
  do_something
end

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

Autosave on assignment

If you try to associate a node to a non-persisted node, you will get the Neo4j::ActiveNode::HasN::NonPersistedNodeError: Unable to create relationship with non-persisted nodes error.

In order to make such assignment possible, you can configure Neo4j.rb to automatically save associated nodes upon assignment:

Neo4j::Config[:autosave_on_assignment] = true
Clone this wiki locally