Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RethinkDB Transaction to multiple documents/tables

I need to update 2 tables in one transaction.

In current version RethinkDB doesn't support transactions from the box. So, how can I achieve this?

I can make update in 2 ways:

  1. Update 1st table. If success -> update second table.
  2. Update 2nd tables async.

But how can I resolve case, when 1 of 2 updates was completed well, but another no? Yes, I can check result of update and revert update if error occured. But anyway, there can be case, when something happens with application (lost connection to Rethink, or just crash of script), but one of two updates was completed. So, my data base will be in inconsistent state. And no way to resolve this.

So, is it possible to simulate transaction behavior in nodejs for RethinkDB?

like image 904
Suvitruf - Andrei Apanasik Avatar asked Mar 01 '26 01:03

Suvitruf - Andrei Apanasik


1 Answers

The best you can do is two-phase commit. (MongoDB has a good document on how to do this, and the exact same technique should work in RethinkDB: http://docs.mongodb.org/master/tutorial/perform-two-phase-commits/ .)

like image 57
mlucy Avatar answered Mar 03 '26 16:03

mlucy