Transaction isolation

We have a tree like structure stored in Realm and want to export it all. But other processes may change it during the export, so the consistency (the business consistency, not the Realm consistency) may be corrupted. Does Realm.write(callback) transaction ensures the callback code has a kind or serializability, e.g. the callback has it’s own snapshot, even if it does read only?

Yes, Realm transactions are locking, so once you acquire the write lock (by doing Realm.write), no other transaction will begin until you’ve committed (or exited the callback without throwing).

1 Like

@nirinchev Thanks for the answer. Is a listener also locked? E.g. I would make some counter property and increment it after each write. Other process is listening on the counter change (by addListener) and may read tree like structure data inside the listener. Is it consistency ensured or do I have to call Realm.write(callback) lock?