You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With lots of operations coming in from multiple sites, it is possible in this adapter to commit an operation with a version that has already been committed.
Given a scenario where User A and User B concurrently submit operation version 2, the max version check here will pass for both operations, and one operation will not be rebased against the one before it.
In order to resolve this, you can move the max version check inside of your transaction and append FOR UPDATE to the max version query:
SELECTmax(version) AS max_version FROM ops WHERE collection = $1AND doc_id = $2 FOR UPDATE
This will create a lock on this row for the duration of the transaction, ensuring that the later operation's max version check query blocks until the previous operation is fully committed.
I'm not actually using this adapter because my schema is different from what sharedb-postgres assumes, but I just spent a lot of time debugging this, and hopefully it can help you, too!
The text was updated successfully, but these errors were encountered:
@jclem I implemented row-locking in a knex port here (https://github.com/brainkim/sharedb-knex/blob/master/index.js#L35-L70). You can’t use for update in queries with aggregate functions (in postgres at least) so I moved the for update to a separate select. I have no idea what I'm doing when it comes to databases but it feels like this should fix the issue you describe, right?
:3
With lots of operations coming in from multiple sites, it is possible in this adapter to commit an operation with a version that has already been committed.
Given a scenario where User A and User B concurrently submit operation version 2, the max version check here will pass for both operations, and one operation will not be rebased against the one before it.
In order to resolve this, you can move the max version check inside of your transaction and append
FOR UPDATE
to the max version query:This will create a lock on this row for the duration of the transaction, ensuring that the later operation's max version check query blocks until the previous operation is fully committed.
I'm not actually using this adapter because my schema is different from what sharedb-postgres assumes, but I just spent a lot of time debugging this, and hopefully it can help you, too!
The text was updated successfully, but these errors were encountered: