Neo4j - inconsistencies in accessing auto index
===

I've been playing around with Neo4j auto indexing and I'm quite confused...

What I'm using:

 - neo4j-community-1.8.M05
 - ruby1.9.3p194

My intention is to create nodes which have unique 'uuid' values (generated by me). To ensure that they are unique, my thinking was to check against an index, and if the uuid value already exists, then I'd generate a new uuid value.

What I see is that for one of my uuids ('blahblahuuid') this works, but for the other it doesn't... and I don't know why (check in the Neo4j Monitoring tool console).

If you try the code below on a clean install of neo4j on ruby1.9.3 (no changes to properties etc) then hopefully you'll see the behaviour that I'm seeing!

Here's my code:

Gemfile:

    source "http://rubygems.org"
    source "http://gems.rubyforge.org"
    source "http://gemcutter.org"
    
    #gem install bundler -v 1.2.0.pre --pre
    
    ruby '1.9.3'
    gem 'bundler', '1.2.0.pre'
    gem 'neography', :git => 'https://github.com/maxdemarzi/neography'

test.rb:

    require "rubygems"
    require "bundler"
    require 'digest/sha1'
    require 'securerandom'
    Bundler.setup(:default)
    
    require 'neography'
    
    $neo = Neography::Rest.new("http://localhost:7474")
    $neo.create_node_index("node_auto_index")
    $neo.set_node_auto_index_status(true)
    
    $neo.execute_script("g.clear()")
    
    def generate_uuid(deviceUUID)
      uuid = Digest::SHA1.base64digest deviceUUID
      existing_node_with_uuid = $neo.get_node_auto_index('uuid', uuid)
    
      until existing_node_with_uuid.nil?
        uuid = Digest::SHA1.base64digest (deviceUUID.to_s + SecureRandom.base64(8))
        existing_node_with_uuid = $neo.get_node_auto_index('uuid', uuid)
      end
      uuid
    end
    
    
    def generate_node(deviceUUID)
      uuid = generate_uuid(deviceUUID)
      secret = SecureRandom.base64(256)
      currentTime = DateTime.now
    
      $neo.create_node("uuid" => uuid, "deviceUUID" => deviceUUID,
                       "secret" => secret, "currentTime" => currentTime)
    end
    
    generate_node('blahblahuuid')
    generate_node('blahblahuuid')
    generate_node('4edb096b479588f6')
    generate_node('4edb096b479588f6')

To run the code:

    ruby test.rb

Listing results in the neo4j console:

    start all = node(*)
    return all;

If you have any idea what's going on, or what I'm doing wrong, I'd love to know!


Thanks,

Louis