Can't traverse when saving node within a transaction

10 views
Skip to first unread message

Dmytrii Nagirniak

unread,
Dec 9, 2011, 6:30:50 AM12/9/11
to neo4jrb
Hi again,

It's related to my prev post, but deserves a dedicated one.

When I do:

Neo4j::Transaction.run do
  user = User.create(email: 'what...@example.com')
  User.count.should_not == 1
end

it fails (assertion I mean).

It is completely unexpected for me. Why is that?
I expect when I persist an object it is "retrievable" no matter whether it is within a transaction or not.

Vivek Prahlad

unread,
Dec 9, 2011, 6:38:29 AM12/9/11
to neo...@googlegroups.com
Neo4j does not support true nested transactions. So your user object will actually be created in the graph only after the transaction block is executed (of course, your test will fail before that). All operations that modify the graph have to be in a transaction (this is a Neo4j requirement). Operations like create / update_attribute etc. will automatically create a transaction.

I'd suggest you take a look at the Neo4j.rb docs here: http://neo4j.rubyforge.org/guides/rails3.html
 
For more, please take a look at: http://wiki.neo4j.org/content/Transactions

Vivek

--
You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To post to this group, send email to neo...@googlegroups.com.
To unsubscribe from this group, send email to neo4jrb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/neo4jrb?hl=en.

Dmytrii Nagirniak

unread,
Dec 9, 2011, 6:56:27 AM12/9/11
to neo...@googlegroups.com
On 09/12/2011, at 10:38 PM, Vivek Prahlad wrote:

Neo4j does not support true nested transactions. So your user object will actually be created in the graph only after the transaction block is executed.

I see now. So the transaction doesn't work the way it usually does with RDBMSs.
In any DB when you create an object/record, you can query it immediately.


I'd suggest you take a look at the Neo4j.rb docs here: http://neo4j.rubyforge.org/guides/rails3.html

I did read it. The around filter is pretty useful.

For more, please take a look at: http://wiki.neo4j.org/content/Transactions

I could find any mentioning there that objects get saved AFTER the transaction completes only.
And there are no examples of creation and querying in the same transaction.
This is HUGE differentiating factor about the transaction and must be in red colour somewhere at the top :)

Or I just have missed it?

With "normal" transactions the objects created within a transaction are always visible to the owner of the transaction, but not to other clients.
Here the object is not visible to anybody.

Cheers,
D.

Peter Neubauer

unread,
Dec 9, 2011, 7:05:50 AM12/9/11
to neo...@googlegroups.com
Dmytri,
the modified data inside a transaction is query-able and visible to
the owner of that transaction. If not, something is wrong. For more
info and suggestions on wording,
http://docs.neo4j.org/chunked/snapshot/transactions.html (have
forwarded the wiki page there now).

Cheers,

/peter neubauer

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

brew install neo4j && neo4j start
heroku addons:add neo4j

Andreas Ronge

unread,
Dec 9, 2011, 7:24:04 AM12/9/11
to neo...@googlegroups.com
No, you can't query and find newly created nodes using the lucene
index until the transaction is completed since we are using Neo4j
events which are triggered just before the transaction commits.
But you can of course always access with for traversals (for example)
all created nodes in the same transaction, which are only visible for
the current transaction.

@peter The new in graph index that we are planning to develop will not
support this either because it will also use the Neo4j events

Dmytrii Nagirniak

unread,
Dec 9, 2011, 7:42:48 AM12/9/11
to neo...@googlegroups.com

On 09/12/2011, at 11:24 PM, Andreas Ronge wrote:

> No, you can't query and find newly created nodes using the lucene
> index until the transaction is completed since we are using Neo4j
> events which are triggered just before the transaction commits.
> But you can of course always access with for traversals (for example)
> all created nodes in the same transaction, which are only visible for
> the current transaction.

Ok. So the transaction works as in most DBs. That's a relief :)
It is the index that get updated only after transaction commits.
Meaning I can't query by index, but can by ID or traversing from the root or other node.

Right?

I'm kind of ok with this.

But it should be reflected much better in the docs though.

Cheers.

Andreas Ronge

unread,
Dec 9, 2011, 7:46:41 AM12/9/11
to neo...@googlegroups.com
Yes it's correct.
Yes, I agree and I also can't find it in the docs.

Peter Neubauer

unread,
Dec 9, 2011, 7:52:50 AM12/9/11
to neo...@googlegroups.com
Guys,
you not be able to see Lucene changes before the tx is finished is
because Neo4j.rb is not using the Neo4j Index framework, but a totally
separate Lucene instance. In the integrated indexing framework, Lucene
changes ARE visible and searchable before commit as expected inside a
TX. maybe time to change to that if it starts to become a problem?

Cheers,

/peter neubauer

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

brew install neo4j && neo4j start
heroku addons:add neo4j

Andreas Ronge

unread,
Dec 9, 2011, 7:58:19 AM12/9/11
to neo...@googlegroups.com
Yes, we should really look into that since we also can remove some
complex code in neo4j.rb.
However, not sure it has all the features we want, like multitenancy.
Reply all
Reply to author
Forward
0 new messages