elnino
elnino

Reputation: 245

Realm - write from different threads - RxJava

I want to use Realm and I need to write data from different threads. I read post about Realm. Realm is similar as Git. Can you explain how merge of data with conflicts works in Realm? Thanks

Upvotes: 0

Views: 288

Answers (1)

EpicPandaForce
EpicPandaForce

Reputation: 81588

Can you explain how merge of data with conflicts works in Realm?

If we are talking about the Realm local database (Realm Mobile Database), and NOT about the Realm Mobile Platform:

  • Transactions are blocking across threads and processes, so there can only be one write transaction at a time. Therefore when that is committed, that will become the new version. Merge scenario is impossible. When a write transaction is open, then in the transaction, you see the latest state of the database at all times, and it is impossible to see an older version.

If we are talking about the Realm Mobile Platform:

  • When multiple offline transactions occur on the same data where they only get synced later, the conflict resolution happens based on rules of the operational transform:

    • Deletes always win: If one side deletes an object it will always stay deleted, even if the other side has made changes to it later on.

    • Last update wins. If two sides update the same property, the value will end up as the last updated.

    • Inserts in lists are ordered by time. If two items are inserted at the same position, the item that was inserted first will end up before the other item.

Upvotes: 1

Related Questions