SyncEngine

class SyncEngine(storage: CloudStorage, stateStore: SyncStateStore, policy: SyncPolicy, clock: () -> Long = { Clock.System.now().toEpochMilliseconds() })(source)

Layer 2: ONE reconciliation run per sync. Lists the remote, self-heals the state cache, diffs the snapshot against it, uploads size-compared entries, then hash-compared entries, then the marker, then deletes what is no longer in the snapshot. State is saved after every put, so a killed process resumes exactly where it stopped. See docs/contract.md.

Constructors

Link copied to clipboard
constructor(storage: CloudStorage, stateStore: SyncStateStore, policy: SyncPolicy, clock: () -> Long = { Clock.System.now().toEpochMilliseconds() })

Properties

Link copied to clipboard

The persisted WriteHold; WriteHold.None when the state is absent or holds an unknown value.

Functions

Link copied to clipboard
suspend fun probe(): RemoteProbe

Metadata-only inspection for a restore offer: availability, the listing, and the marker bytes. Never throws for cloud failures; they come back as RemoteProbe.Failed.

Link copied to clipboard
fun setHold(hold: WriteHold)

Persists hold without touching the cached entries. While it is not WriteHold.None, sync writes nothing.

Link copied to clipboard
suspend fun sync(snapshot: SyncSnapshot, onProgress: (done: Int, total: Int) -> Unit = { _, _ -> }): SyncOutcome

Runs on the caller's dispatcher. Never throws for cloud failures; they come back as SyncOutcome.Failed. Concurrent calls are serialised: a second caller waits for the first run. A WriteHold set while a run is in progress stops it before its next put or delete.