neo4j/neo4j-go-driver

[Question] In this v4.3 driver, can you run a Read and Write transaction at the same time?

shasaur opened this issue ยท 3 comments

I wasn't sure if I should post this on the community forum since it's very specific to this repo's implementation of the neo4j driver.

I'm currently using v1.8.3 of this driver and from what I can tell, running a read and write transaction at the same returns an error "Already in tx". I assume this is because there is only one lock s.inTx which is set to true regardless of the type of transaction through:

  • either ReadTransaction or WriteTransaction -> runRetriable -> runOneTry -> beginTransaction -> s.inTx = true.

I also notice that in the latest version of this driver (v4.3), this lock is now differentiated into at least txExplicit and txAuto. Neither of these seems to be used by ReadTransaction or WriteTransaction - so am I right in saying that in this latest version of the driver, you can run a read and write transaction at the same time through these functions?

Thanks in advance!

Hi @shasaur, could you elaborate what you mean by "at the same time"?
Do you mean in two different goroutines? If so, the session instances are not meant to be shared across these so you may run into issues if you try.

Thanks for the response @fbiville .

Ah okay I see, I just now read literally the first line of the Java docs about sessions which says "Simple sessions provide a "classic" blocking style API for Cypher execution", woops ๐Ÿ‘€ .

So would you recommend creating several sessions - one per goroutine that wants to access the neo4j db? In which case, if they try to access the same data, will neo4j take care of managing the transactions - therefore not resulting in an error if you run queries from multiple sessions at the same time?

I just refactored to use a separate session per go routine and am no longer having any issues - this is great, thank you! ๐Ÿ‘