maps: download planet4.mamaps; move planet3 installs across bases (#planet4)
- Commit
868294a064188b91492c4927c141f55220762ae4- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-11 21:10 UTC (24 days ago)
- Parents
96f24ba
- MapTileCache.BASEMAP_ARCHIVE_URL / BASEMAP_MANIFEST_URL and MapOverlay.MANIFEST_URL point at planet4.mamaps and planet4.manifest.json (live: 81,331,811,296 B, build 0x2ab5ba5833e54438, rebase manifest seq 0, no segments). - Migration of existing installs: the startup gate only checks that basemap.mamaps exists, so a planet3 install keeps its file and is moved by the overlay worker's rebase path (background download to basemap.mamaps.next, verify length + header build id, atomic swap, delete the old base and overlays). The worker compared overlay_seq across bases: a device pinned to planet3's stack at seq N would have treated planet4's seq-0 rebase as "already applied" forever. Sequence numbers now only order overlays of the same base, and a seq-0 manifest for a different base is a rebase signal (isRebaseSignal). planet3 never published a manifest, so today every install has nothing pinned and takes the rebase on its first daily check (unmetered, auto-update on by default) or a manual check in Settings. - tile_build manifest docs name planet4. upload_planet.py is untouched here (main's --key/--manifest-key handles planetN stacks). Tests: MapOverlay(*)Test URLs updated; new worker test for a planet3- pinned device receiving planet4's seq-0 rebase; MapOverlayLiveTest (MAMAPS_LIVE=1) fetches the live planet4 manifest, parses it with MapOverlay and checks it pins the archive the app downloads. User-visible: a planet3 device downloads planet4 once in the background (about 81 GB, old + new coexist until the swap); fresh installs get planet4 at the startup gate.
Diff
maps/src/main/java/com/vayunmathur/maps/util/MapOverlay.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapOverlay.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapOverlay.ktindex 53ae377381..52f8e09159 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapOverlay.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapOverlay.kt@@ -11,7 +11,7 @@ import kotlinx.serialization.json.long import kotlinx.serialization.json.int /**- * The client half of incremental map updates: the `planet3.manifest.json`+ * The client half of incremental map updates: the `planet4.manifest.json` * model, the on-disk overlay layout, and the queries the Settings UI and the * check worker drive. *@@ -32,7 +32,7 @@ import kotlinx.serialization.json.int */ object MapOverlay { /** Where [MapTileCache.BASEMAP_ARCHIVE_FILE] is checked for updates. */- const val MANIFEST_URL = "https://data.maproj.org/planet3.manifest.json"+ const val MANIFEST_URL = "https://data.maproj.org/planet4.manifest.json" /** Pinned manifest filename (under [OVERLAY_ROOT]). */ const val MANIFEST_FILE = "manifest.json"
maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.ktindex fa8ae76739..a1b46dba47 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt@@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit /** * Checks for and fetches incremental map updates (Phase 2: download + store). *- * One run: fetch `planet3.manifest.json` (kilobytes, any network), compare+ * One run: fetch `planet4.manifest.json` (kilobytes, any network), compare * its overlay sequence against the pinned manifest, and — when newer — * download the missing segments sequentially through the shared * [downloadModels] path (`.part` + Range resume, per-segment SHA-256, atomic@@ -72,17 +72,20 @@ class MapOverlayWorker(context: Context, params: WorkerParameters) : text: String, ): Result { val pinned = MapOverlay.pinned(root)- if (pinned != null && pinned.overlaySeq >= manifest.overlaySeq) {+ // Sequence numbers only order overlays of ONE base: a manifest for a new+ // base (planet3 -> planet4 restarts its sequence) is never "already+ // applied" just because the old base's stack reached a higher seq.+ val sameBase = pinned != null && pinned.baseBuildId == manifest.baseBuildId+ if (pinned != null && sameBase && pinned.overlaySeq >= manifest.overlaySeq) { Log.status(TAG, "overlay seq ${manifest.overlaySeq} already applied") return Result.success() } // Base mismatch: either a foreign overlay (refuse) or a server // rebase (refresh the base once, then drop the old stack). An empty- // segment list with a newer seq is the rebase signal.+ // segment list with a newer seq, or for a different base than the+ // pinned one, is the rebase signal. if (!baseMatches(root, manifest)) {- if (manifest.segments.isEmpty() &&- (pinned == null || manifest.overlaySeq > pinned.overlaySeq)- ) {+ if (isRebaseSignal(manifest, pinned)) { return refreshBase(root, ds, manifest, text) } Log.status(TAG, "overlay seq ${manifest.overlaySeq} is for another base; skipping")@@ -101,6 +104,17 @@ class MapOverlayWorker(context: Context, params: WorkerParameters) : return Result.success() } + /**+ * An empty segment list is the rebase signal when nothing is pinned yet, when the pinned+ * manifest is for another base (planet3 → planet4 restarts the sequence), or when its+ * sequence moved past the pinned one.+ */+ private fun isRebaseSignal(manifest: MapOverlay.Manifest, pinned: MapOverlay.Manifest?): Boolean {+ if (manifest.segments.isNotEmpty()) return false+ if (pinned == null || pinned.baseBuildId != manifest.baseBuildId) return true+ return manifest.overlaySeq > pinned.overlaySeq+ }+ /** Download [missing] sequentially, one segment at a time: peak transient is one segment. */ private suspend fun downloadSegments( root: File,
maps/src/main/java/com/vayunmathur/maps/util/MapTileCache.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapTileCache.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapTileCache.ktindex fb4f5cd45e..127b8f9540 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapTileCache.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapTileCache.kt@@ -19,11 +19,11 @@ object MapTileCache { /** Where [BASEMAP_ARCHIVE_FILE] is fetched from on a first launch that has no copy yet. */ const val BASEMAP_ARCHIVE_URL =- "https://data.maproj.org/planet3.mamaps"+ "https://data.maproj.org/planet4.mamaps" /** Where the incremental-update manifest lives (see `util/MapOverlay`). */ const val BASEMAP_MANIFEST_URL =- "https://data.maproj.org/planet3.manifest.json"+ "https://data.maproj.org/planet4.manifest.json" /** * The single source of truth for the streamed basemap PMTiles URL.
maps/src/test/java/com/vayunmathur/maps/util/MapOverlayLiveTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayLiveTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayLiveTest.ktnew file mode 100644index 0000000000..4a7cc09d4d--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayLiveTest.kt@@ -0,0 +1,39 @@+package com.vayunmathur.maps.util++import java.net.URI+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertTrue+import org.junit.Assume++/**+ * The LIVE `planet4.manifest.json` through [MapOverlay.parse], checked against what the app+ * downloads ([MapTileCache.BASEMAP_ARCHIVE_URL]) and what a planet3 install will do with it.+ * Skipped unless `MAMAPS_LIVE=1` (network to data.maproj.org).+ */+class MapOverlayLiveTest {++ @Test+ fun `live planet4 manifest parses and pins the archive the app downloads`() {+ Assume.assumeTrue("MAMAPS_LIVE not set; live test skipped", System.getenv("MAMAPS_LIVE") == "1")+ val text = URI(MapOverlay.MANIFEST_URL).toURL().readText()+ println("live manifest (${text.length} B): $text")+ val m = assertNotNull(MapOverlay.parse(text), "the client refuses the live manifest")+ assertEquals(MapTileCache.BASEMAP_MANIFEST_URL, MapOverlay.MANIFEST_URL)+ assertEquals(MapTileCache.BASEMAP_ARCHIVE_URL, m.baseUrl)+ assertEquals(PLANET4_BUILD_ID, m.baseBuildId)+ assertEquals(PLANET4_LEN, m.baseLen)+ // A fresh base with an empty stack: the rebase signal. A planet3 install (no pinned+ // manifest, or one pinned to planet3's build) downloads planet4 once in the+ // background and swaps it in; a fresh install fetches planet4 at the startup gate.+ assertTrue(m.segments.isEmpty(), "a rebase manifest carries no segments")+ assertEquals(0L, m.overlaySeq)+ assertTrue(m.tombstones.isEmpty())+ }++ private companion object {+ const val PLANET4_BUILD_ID = 0x2ab5ba5833e54438L+ const val PLANET4_LEN = 81_331_811_296L+ }+}
maps/src/test/java/com/vayunmathur/maps/util/MapOverlaySlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/MapOverlaySlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlaySlice3ExtraTest.ktindex d6dfa3ef1e..e7646c92c4 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/MapOverlaySlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlaySlice3ExtraTest.kt@@ -141,7 +141,7 @@ class MapOverlaySlice3ExtraTest { } } @Test fun workerConstants() {- assertEquals("https://data.maproj.org/planet3.manifest.json", MapOverlay.MANIFEST_URL)+ assertEquals("https://data.maproj.org/planet4.manifest.json", MapOverlay.MANIFEST_URL) assertEquals(1, MapOverlay.MANIFEST_VERSION) } }
maps/src/test/java/com/vayunmathur/maps/util/MapOverlayTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayTest.ktindex 8a2e790ee8..3e72d1da40 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayTest.kt@@ -33,13 +33,13 @@ class MapOverlayTest { } private fun manifestJson(seq: Long = 7): String =- """{"version":1,"base":{"url":"https://data.maproj.org/planet3.mamaps","build_id":"0x0000000000001234","len":78017648928},"overlay_seq":$seq,"overlay_build_id":"0x000000000000abcd","segments":[{"url":"https://data.maproj.org/overlays/0007/overlay-0000.mamaps","len":11,"sha256":"abc","seq":0}],"sections":[],"min_client":1}"""+ """{"version":1,"base":{"url":"https://data.maproj.org/planet4.mamaps","build_id":"0x0000000000001234","len":78017648928},"overlay_seq":$seq,"overlay_build_id":"0x000000000000abcd","segments":[{"url":"https://data.maproj.org/overlays/0007/overlay-0000.mamaps","len":11,"sha256":"abc","seq":0}],"sections":[],"min_client":1}""" @Test fun parses_the_published_schema() { val m = MapOverlay.parse(manifestJson())!! assertEquals(1, m.version)- assertEquals("https://data.maproj.org/planet3.mamaps", m.baseUrl)+ assertEquals("https://data.maproj.org/planet4.mamaps", m.baseUrl) assertEquals(0x1234L, m.baseBuildId) assertEquals(78017648928L, m.baseLen) assertEquals(7L, m.overlaySeq)
maps/src/test/java/com/vayunmathur/maps/util/MapOverlayWorkerSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayWorkerSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayWorkerSlice3ExtraTest.ktindex 7138701691..31f3eb8e0f 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayWorkerSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/MapOverlayWorkerSlice3ExtraTest.kt@@ -107,6 +107,20 @@ class MapOverlayWorkerSlice3ExtraTest { Unit } } + @Test fun newBaseRebasesEvenWhenItsSeqRestartsBelowThePinnedOne() { runBlocking {+ // planet3 -> planet4: the device pinned the old base's stack at seq 5;+ // the new base's manifest restarts at seq 0 with no segments. That is a+ // rebase (download attempted -> retry against example.invalid), never+ // "already applied", or the device would sit on the old base forever.+ cleanRoot(); plantBase(buildId = 0x99)+ MapOverlay.pin(root, manifest(5, "", baseBuild = "0x99", baseLen = 64))+ MapOverlayWorker.manifestFetcher = { manifest(0, "", baseBuild = "0x10", baseLen = 64) }+ try {+ assertEquals(ListenableWorker.Result.retry(), runWorker())+ } finally { restoreFetcher(); cleanRoot() }+ Unit+ } }+ @Test fun missingSegmentsRetryWhenDownloadsFail() { runBlocking { cleanRoot(); plantBase() val text = manifest(11, """{"url": "https://example.invalid/s0", "len": 4, "sha256": "aa", "seq": 0}""", baseLen = 64)
scripts/maps/tile_build/src/bin/mamaps_overlay.rs
diff --git a/scripts/maps/tile_build/src/bin/mamaps_overlay.rs b/scripts/maps/tile_build/src/bin/mamaps_overlay.rsindex e64b353f73..8aa2f22c49 100644--- a/scripts/maps/tile_build/src/bin/mamaps_overlay.rs+++ b/scripts/maps/tile_build/src/bin/mamaps_overlay.rs@@ -5,7 +5,7 @@ //! [--base-url URL] //! //! Emits `overlay-0000.mamaps`, `overlay-0001.mamaps`, … plus `overlay.json`-//! (the per-overlay half of `planet3.manifest.json`: overlay seq/build id,+//! (the per-overlay half of `planet4.manifest.json`: overlay seq/build id, //! segment list with lengths and SHA-256). Each segment is a small //! self-contained `.mamaps` holding only changed/added tile bodies with //! overlay-relative offsets; the base is never touched.
scripts/maps/tile_build/src/manifest.rs
diff --git a/scripts/maps/tile_build/src/manifest.rs b/scripts/maps/tile_build/src/manifest.rsindex edd4d210cd..1d689638cd 100644--- a/scripts/maps/tile_build/src/manifest.rs+++ b/scripts/maps/tile_build/src/manifest.rs@@ -1,4 +1,4 @@-//! `manifest` — the `planet3.manifest.json` schema for incremental updates.+//! `manifest` — the `planet4.manifest.json` schema for incremental updates. //! //! The manifest is the only versioned thing the client fetches on a check //! (bytes, not gigabytes): it pins the base archive, names the overlay@@ -27,7 +27,7 @@ pub const SECTION_CHUNK_BYTES: u64 = 32 * 1024 * 1024; /// The base archive this overlay applies to. pub struct BaseRef {- /// Download URL of the base `.mamaps` (today `planet3.mamaps`).+ /// Download URL of the base `.mamaps` (today `planet4.mamaps`). pub url: String, /// `build_id` from the base header: the overlay refuses a mismatched base. pub build_id: u64,
scripts/maps/tile_build/tests/overlay_phase1.rs
diff --git a/scripts/maps/tile_build/tests/overlay_phase1.rs b/scripts/maps/tile_build/tests/overlay_phase1.rsindex 08acb507f5..a6700bc541 100644--- a/scripts/maps/tile_build/tests/overlay_phase1.rs+++ b/scripts/maps/tile_build/tests/overlay_phase1.rs@@ -148,7 +148,7 @@ mod tests { let manifest = tile_build::manifest::Manifest { version: tile_build::manifest::MANIFEST_VERSION, base: tile_build::manifest::BaseRef {- url: "https://data.maproj.org/planet3.mamaps".to_string(),+ url: "https://data.maproj.org/planet4.mamaps".to_string(), build_id: 0x1234, len: 78017648928, },