Is it possible to get/insert/replace multiple documents within transaction concurrently?

Hi,

We use gocb and open a transaction to insert/replace around 100 documents.
We use goroutines and operate the documents concurrently since timing is important for us.
So, we create the transaction, then we create goroutines and concurrently insert/replace within the transaction.

However, we noticed that we get error in that kind of structure.

deadline expired before WWC was resolved on BucketName._default._default._txn:atr-790-#822

Is this normal?

I’m not the go transactions expert, but I think you should be able to do that without issue - provided that you adhere to the transactions mechanics. Specifically - whenever a document is replaced, the original get result that was fed into the replace will no longer be valid and another get will need to be issued if there is another replace on the same document in the same transactions.

i.e.

txGetResult1 = ctx.get(docId)
// modify document
ctx.replace(txGetResult1)

txGetResult2 = ctx.get(docId)
// modified document
ctx.replace(txGetResult2)

Thank you for your response.
I understand the concerns regarding the docId and the data consistency during get/replace scenarios.
However in my case, I don’t have such situations where I can have conflicts regarding the same docId usage.

In my case, I just have a single transaction where I have lots of concurrent threads that tries to insert/replace within this transaction with different Ids when it comes to get/replace.

If you don’t have any conflicts, then there should be no issue. You just might need to specify a longer transaction timeout. gocb package - github.com/couchbase/gocb/v2 - Go Packages

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.