Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- Linked devices: a device no longer gets stuck behind another one that cleaned up a snapshot it hadn't read yet (#1075)
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ class Facts(

private fun acknowledged(link: String?): List<Logged> = manifests.filter { it.manifest.link == link && acked(it.did) >= it.seq }

/** A newer acknowledged snapshot covers [old], and every device read past [old] itself, so its removal leaves no gap. */
private fun superseded(old: Logged): Boolean =
acknowledged(old.manifest.link).any { newer ->
newer != old && old.manifest.vv.all { (did, tip) -> (newer.manifest.vv[did]?.seq ?: -1) >= tip.seq }
}
acked(old.did) >= old.seq &&
acknowledged(old.manifest.link).any { newer ->
newer != old && old.manifest.vv.all { (did, tip) -> (newer.manifest.vv[did]?.seq ?: -1) >= tip.seq }
}

/** How far every link's newest acknowledged snapshot covers [did]'s log. */
private fun covered(did: String): Long =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ class GarbageCollectionTest {
assertTrue(plan(setOf("a", "b"), setOf("a"), mapOf("b" to mapOf("a" to 4L)), listOf(old, new)).manifests.isEmpty())
}

@Test
fun a_snapshot_stays_until_every_device_read_past_it_even_when_another_covers_it() {
// The Mac's manifest 573 is covered by the phone's acknowledged snapshot, but the phone has read the Mac's log only to 572.
val mac = snapshot("mac", 573, "mac" to 572, "phone" to 40)
val phone = snapshot("phone", 41, "mac" to 572, "phone" to 40)
val acks = mapOf("mac" to mapOf("phone" to 41L))
val devices = setOf("mac", "phone")
assertTrue(plan(devices, setOf("mac"), acks + ("phone" to mapOf("mac" to 572L)), listOf(mac, phone)).manifests.isEmpty())
assertEquals(listOf(mac), plan(devices, setOf("mac"), acks + ("phone" to mapOf("mac" to 573L)), listOf(mac, phone)).manifests)
}

@Test
fun every_link_batches_name_needs_an_acknowledged_snapshot() {
val acks = mapOf("b" to mapOf("a" to 9L))
Expand Down
Loading