RestoreResult

sealed interface RestoreResult

What LocalHeddle.decode found in a stored snapshot.

Samples

val tree = twoLanes()
val heavy = tree.groupId("heavy")
val light = tree.groupId("light")
val policy = LocalPolicy(defaultReservation = 3L)
val (heddle, booted) = LocalHeddle.fromTopology(tree, policy, epoch = 0L)
check(booted.refusals.isEmpty())
heddle.reconcileCapacity(totalSlots = 2L)
val queued = setOf(heavy, light)
val running = (heddle.acquire(queued, queued, startedAt = 100L) as AcquireOutcome.Acquired).lease

// Under your scheduling lock: take the snapshot. Encoding and storing it can happen off the lock.
val stored = Json.encodeToString(LocalHeddleSnapshot.serializer(), heddle.persist())

// After the restart: decode, then restore under a later epoch, your persisted boot counter.
val decoded = LocalHeddle.decode(stored, Json)
check(decoded is RestoreResult.Restored)
val restarted = LocalHeddle.restore(decoded.snapshot, policy, epoch = decoded.snapshot.epoch + 1)

// The lease that was running is still open, and settles as it would have.
check(restarted.complete(running.id, actualCost = 3L, waiting = queued) == LeaseOutcome.Done(charged = 3L, overrun = 0L, unrecorded = 0L))
// New leases are named under the new epoch, so none can repeat an old id.
check((restarted.acquire(queued, queued, startedAt = 120L) as AcquireOutcome.Acquired).lease.id.epoch == 1L)

Inheritors

Types

Link copied to clipboard
data class Corrupt(val reason: String) : RestoreResult

The bytes are not a snapshot of a supported format, or hold one that is inconsistent: reason says which.

Link copied to clipboard
data class Restored(val snapshot: LocalHeddleSnapshot) : RestoreResult

The bytes held a snapshot this release reads. Start an engine from it with LocalHeddle.restore.

Link copied to clipboard
data class UnsupportedVersion(val found: Int, val supported: List<Int>) : RestoreResult

The bytes say they are format found, which this release does not read; supported lists the ones it does. Nothing past the version was read. A format newer than this release's own is from a later release, or, for format 2, from a development build of 0.7.5.