RecoverOrDiscardUnsyncedChangesStrategy

Strategy that attempts to automatically recover any unsynced changes during a Client Reset, if the recovery fails the changes would be discarded.

A synced realm may need to be reset because the MongoDB Realm Server encountered an error and had to be restored from a backup or because it has been too long since the client connected to the server so the server has rotated the logs.

The Client Reset thus occurs because the server does not have all the information required to bring the client fully up to date.

The recover or discard unsynced changes process is as follows: when a Client Reset is received by the client the onBeforeReset callback is invoked, after which the client will be reset. Once the reset has concluded the onAfterRecovery callback will be invoked if the changes have been recovered successfully, otherwise the changes will be discarded and onAfterDiscard will be invoked.

In the event that the client reset could not discard the unsynced data onManualResetFallback will be invoked. This allows to manually resolve the reset as it would have been done by ManuallyRecoverUnsyncedChangesStrategy.onClientReset.

Functions

Link copied to clipboard
abstract fun onAfterDiscard(before: TypedRealm, after: MutableRealm)

Callback invoked once the Client Reset has discarded the unsynced changes because it couldn't recover them. It provides two Realm instances, a frozen one displaying the state before the reset and a regular Realm displaying the current state that can be used to recover objects from the reset.

Link copied to clipboard
abstract fun onAfterRecovery(before: TypedRealm, after: MutableRealm)

Callback invoked once the Client Reset has recovered the unsynced changes successfully. It provides two Realm instances, a frozen one displaying the state before the reset and a mutable Realm with the current state.

Link copied to clipboard
abstract fun onBeforeReset(realm: TypedRealm)

Callback that indicates a Client Reset is about to happen. It receives a frozen instance of the realm that will be reset.

Link copied to clipboard

Callback that indicates the Client reset failed to complete. It should be handled as in ManuallyRecoverUnsyncedChangesStrategy.onClientReset.