maps: pack poi_admin.bin as archive kind 16 (#mapsearch)
- Commit
1993301705f60b11aa989d68da5967109c9995ff- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 20:49 UTC (22 days ago)
- Parents
a671fa2
Follows the previous commit (poi_extract writes poi_admin.bin beside poi_region.bin). This makes it reach the phone: * tilecodec: ARCHIVE_KIND_POI_ADMIN = 16; ARCHIVE_KIND_MAX_KNOWN moves to it. Readers already accept any non-zero kind and skip unknown ones (ArchiveView::parse, PoiArchive.kt), so an archive with kind 16 still opens in every shipped app; only the new app reads it. * mamaps_pack: auto-stages poi_admin.bin from --poi when present and non-empty, after poi_region.bin (kinds must ascend). Validated before anything is written like every other sidecar: PAD1 magic, version 1, and file length == 16 + 32 x entry_count + names_len (it is keyed by boundary id, so there is no index count to cross-check). No new flag. * Build id: the FNV-1a of poi_admin.bin is appended to the POI attributes digest that already feeds derive_build_id, because adding or rebuilding the hierarchy changes the section directory with no tile change and phones cache byte ranges by build id. Without the file the digest โ and every existing archive's id โ is unchanged. * mamaps_probe / mamaps_sizes name kind 16; planet_build.sh logs the sidecar's size beside the region one (no new step: the existing poi_extract + mamaps_pack invocations already carry it). Not done here: no planet rebuild or upload; planet4 stays as is and the app falls back to what it can derive without the section. Tests: mamaps_pack gains "an admin sidecar packs after the region and moves the build id" (round-trip through ArchiveView, digest empty without attrs/admin, non-empty with) and "a truncated admin sidecar fails the pack"; tilecodec's archive tests pin kind 16 and MAX_KNOWN. tile_build `cargo test --release` (all bins) and tilecodec `cargo test --features write --lib archive` pass.
Diff
library/tilecodec/src/main/rust/src/mamaps/archive/consts.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/archive/consts.rs b/library/tilecodec/src/main/rust/src/mamaps/archive/consts.rsindex ac6f52ca6f..14912cff3d 100644--- a/library/tilecodec/src/main/rust/src/mamaps/archive/consts.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/archive/consts.rs@@ -40,9 +40,14 @@ pub const ARCHIVE_KIND_GRAPH_OVERLAY: u8 = 14; /// POI `poi_region.bin` payload: one tagged OSM boundary id per index ordinal /// (`PRG1` + version + count, then `u64` ids; 0 means no boundary). pub const ARCHIVE_KIND_POI_REGION: u8 = 15;+/// POI `poi_admin.bin` payload: the boundary hierarchy behind kind 15 โ per+/// linked boundary and ancestor its name, `name:en`, `admin_level` and parent+/// (`PAD1` + version + count + names_len, 32 B entries, then a name pool; see+/// `osm_ingest/src/poi_admin.rs`). Optional.+pub const ARCHIVE_KIND_POI_ADMIN: u8 = 16; /// Highest kind this build writes. Readers accept any non-zero kind and skip /// the ones they do not know, so a newer archive still opens in an older app.-pub const ARCHIVE_KIND_MAX_KNOWN: u8 = ARCHIVE_KIND_POI_REGION;+pub const ARCHIVE_KIND_MAX_KNOWN: u8 = ARCHIVE_KIND_POI_ADMIN; /// `metadata.bin` (`MARG`) magic, little-endian `u32`. pub const GRAPH_MAGIC: u32 = 0x4752_414D;
library/tilecodec/src/main/rust/src/mamaps/archive/mod.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/archive/mod.rs b/library/tilecodec/src/main/rust/src/mamaps/archive/mod.rsindex 0ff457cc42..007fe80526 100644--- a/library/tilecodec/src/main/rust/src/mamaps/archive/mod.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/archive/mod.rs@@ -102,7 +102,7 @@ pub use consts::{ ARCHIVE_KIND_GRAPH_EDGES, ARCHIVE_KIND_GRAPH_ELEVATION, ARCHIVE_KIND_GRAPH_INTERMEDIATE, ARCHIVE_KIND_GRAPH_LANES, ARCHIVE_KIND_GRAPH_META, ARCHIVE_KIND_GRAPH_NAMES, ARCHIVE_KIND_GRAPH_NODES, ARCHIVE_KIND_GRAPH_OVERLAY, ARCHIVE_KIND_MAX_KNOWN, ARCHIVE_KIND_POI_ATTRS,- ARCHIVE_KIND_POI_INDEX, ARCHIVE_KIND_POI_NAMES, ARCHIVE_KIND_POI_REGION,+ ARCHIVE_KIND_POI_ADMIN, ARCHIVE_KIND_POI_INDEX, ARCHIVE_KIND_POI_NAMES, ARCHIVE_KIND_POI_REGION, ARCHIVE_KIND_POI_SPATIAL, ARCHIVE_KIND_POI_WORDS, ARCHIVE_KIND_TRANSIT, GRAPH_MAGIC, GRAPH_META_LEN, GRAPH_VERSION, GRAPH_VERSION_MIN, POI_RECORD_BYTES, TRANSIT_MAGIC, TRANSIT_VERSION, TRANSIT_VERSION_MIN,
library/tilecodec/src/main/rust/src/mamaps/archive/tests.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/archive/tests.rs b/library/tilecodec/src/main/rust/src/mamaps/archive/tests.rsindex c24bc97643..dae8ceaa87 100644--- a/library/tilecodec/src/main/rust/src/mamaps/archive/tests.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/archive/tests.rs@@ -101,10 +101,13 @@ fn entries_are_32_bytes_and_unknown_kinds_parse() { assert_eq!(ARCHIVE_KIND_TRANSIT, 13, "transit is kind 13"); assert_eq!(ARCHIVE_KIND_GRAPH_OVERLAY, 14, "the highway overlay is kind 14"); assert_eq!(ARCHIVE_KIND_POI_REGION, 15, "the POI region sidecar is kind 15");+ assert_eq!(ARCHIVE_KIND_POI_ADMIN, 16, "the POI admin hierarchy is kind 16");+ assert_eq!(ARCHIVE_KIND_MAX_KNOWN, ARCHIVE_KIND_POI_ADMIN); let mut future = e.serialize(); future[0] = 99; assert_eq!(ArchiveEntry::parse(&future).expect("a future kind parses").kind, 99); assert!(!is_known_kind(99) && is_known_kind(ARCHIVE_KIND_POI_REGION) && !is_known_kind(0));+ assert!(is_known_kind(ARCHIVE_KIND_POI_ADMIN)); let mut zero = e.serialize(); zero[0] = 0; assert!(ArchiveEntry::parse(&zero).is_err(), "kind 0 is never a section");
scripts/maps/osm_ingest/src/bin/poi_extract.rs
diff --git a/scripts/maps/osm_ingest/src/bin/poi_extract.rs b/scripts/maps/osm_ingest/src/bin/poi_extract.rsindex b19f26f014..2e652fb5f0 100644--- a/scripts/maps/osm_ingest/src/bin/poi_extract.rs+++ b/scripts/maps/osm_ingest/src/bin/poi_extract.rs@@ -89,14 +89,15 @@ fn main() -> ExitCode { ); println!("{} POI(s) with a boundary link", stats.with_region); println!(- "Wrote {}, {}, {}, {}, {}, {}, {}",+ "Wrote {}, {}, {}, {}, {}, {}, {}, {}", args.geojson.display(), args.names.display(), args.index.display(), args.attrs.display(), args.spatial.display(), args.name_index.display(),- args.region.display()+ args.region.display(),+ args.region.with_file_name("poi_admin.bin").display() ); ExitCode::SUCCESS }
scripts/maps/planet_build.sh
diff --git a/scripts/maps/planet_build.sh b/scripts/maps/planet_build.shindex f36eeee169..b762d653c1 100755--- a/scripts/maps/planet_build.sh+++ b/scripts/maps/planet_build.sh@@ -415,6 +415,9 @@ poi_job(){ # --index; mamaps_pack auto-stages it as kind 15. No new flags either end. [ -f "$POI/poi_region.bin" ] || bgdie "poi_extract wrote no $POI/poi_region.bin -- fix regressed?" log " poi sidecars done ($(stat -c%s "$POI/poi_region.bin") B region sidecar)"+ # poi_admin.bin (boundary names/levels/parents) rides beside poi_region.bin the same way;+ # mamaps_pack auto-stages it as kind 16. Optional: an older poi_extract simply omits it.+ if [ -f "$POI/poi_admin.bin" ]; then log " admin hierarchy $(stat -c%s "$POI/poi_admin.bin") B"; fi } # --- background job: hold early mamaps_build at Pass 3 while road_graph runs -
scripts/maps/tile_build/src/bin/mamaps_pack.rs
diff --git a/scripts/maps/tile_build/src/bin/mamaps_pack.rs b/scripts/maps/tile_build/src/bin/mamaps_pack.rsindex 7405656ce4..e6d7f198ea 100644--- a/scripts/maps/tile_build/src/bin/mamaps_pack.rs+++ b/scripts/maps/tile_build/src/bin/mamaps_pack.rs@@ -20,7 +20,7 @@ //! graph: metadata.bin nodes.bin edges.bin intermediate.bin road_names.bin //! lanes.bin elevation.bin //! poi: poi_index.bin poi_names.bin poi_attrs.bin poi_spatial.bin-//! poi_name_index.bin poi_region.bin+//! poi_name_index.bin poi_region.bin poi_admin.bin //! transit: world.transit (one TRIX pack; `<feed>.transit` naming is a //! delivery rename, the bytes are what matter) use std::io::{Read, Seek, SeekFrom, Write};@@ -31,7 +31,7 @@ use tile_build::mamaps::archive::{ ARCHIVE_KIND_GRAPH_EDGES, ARCHIVE_KIND_GRAPH_ELEVATION, ARCHIVE_KIND_GRAPH_INTERMEDIATE, ARCHIVE_KIND_GRAPH_LANES, ARCHIVE_KIND_GRAPH_META, ARCHIVE_KIND_GRAPH_NAMES, ARCHIVE_KIND_GRAPH_NODES, ARCHIVE_KIND_GRAPH_OVERLAY, ARCHIVE_KIND_POI_ATTRS, ARCHIVE_KIND_POI_INDEX,- ARCHIVE_KIND_POI_NAMES, ARCHIVE_KIND_POI_REGION,+ ARCHIVE_KIND_POI_ADMIN, ARCHIVE_KIND_POI_NAMES, ARCHIVE_KIND_POI_REGION, ARCHIVE_KIND_POI_SPATIAL, ARCHIVE_KIND_POI_WORDS, ARCHIVE_KIND_TRANSIT, }; use tile_build::mamaps::header::Header;@@ -134,15 +134,21 @@ struct Validated { /// rather than in front of it: the id is only needed for the header and footer, /// which are written last. poi_attrs: Option<PathBuf>,+ /// `poi_admin.bin` when staged non-empty. Its FNV-1a is appended to the attributes digest+ /// for the same reason: adding or rebuilding the hierarchy changes the section directory+ /// with no tile change. Absent, the digest (and so every existing build id) is unchanged.+ poi_admin: Option<PathBuf>, } impl Validated {- /// FNV-1a of `poi_attrs.bin`, or empty without the file.+ /// FNV-1a of `poi_attrs.bin` followed by FNV-1a of `poi_admin.bin`, each only when that+ /// file is staged; empty with neither. fn poi_attrs_digest(&self) -> Result<Vec<u8>, String> {- match &self.poi_attrs {- Some(p) => Ok(fnv64_file(p)?.to_vec()),- None => Ok(Vec::new()),+ let mut out = Vec::new();+ for p in [&self.poi_attrs, &self.poi_admin].into_iter().flatten() {+ out.extend_from_slice(&fnv64_file(p)?); }+ Ok(out) } } @@ -237,6 +243,18 @@ fn load_sidecars_impl( Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} Err(e) => return Err(format!("cannot stat {}: {e}", poi_region.display())), }+ // The boundary hierarchy (`poi_admin.bin`, kind 16) is optional and sorts after the region+ // sidecar it describes. Older apps skip the kind; its digest feeds the build id (below).+ let poi_admin = poi.join("poi_admin.bin");+ let poi_admin = match std::fs::metadata(&poi_admin) {+ Ok(m) if m.len() > 0 => {+ staged.push(Staged::whole(ARCHIVE_KIND_POI_ADMIN, poi_admin.clone(), m.len()));+ Some(poi_admin)+ }+ Ok(_) => None,+ Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,+ Err(e) => return Err(format!("cannot stat {}: {e}", poi_admin.display())),+ }; // Validate every sidecar's magic/version/count BEFORE anything is written: each section's // check is the same one its loader runs, and a mismatch fails closed with a non-zero exit // and no partial output. Only the small files are read whole; the large graph payloads@@ -244,7 +262,7 @@ fn load_sidecars_impl( validate_sidecars(graph, poi, &staged, timer)?; // The tile header's own build-id bytes are read by the caller (it holds the tiles prefix); // placeholder filled in `main` after the tiles prefix is parsed.- Ok(Validated { staged, transit_prefix, osm_id: [0u8; 8], poi_attrs })+ Ok(Validated { staged, transit_prefix, osm_id: [0u8; 8], poi_attrs, poi_admin }) } /// A file's length, with the same "cannot read" wording a whole-file read would give.@@ -479,6 +497,32 @@ fn validate_sidecars( } } }+ validate_poi_admin(&poi.join("poi_admin.bin"))+}++/// `poi_admin.bin`, when present: `PAD1`, version 1, and a length that is exactly the header,+/// `entry_count` 32-byte entries and `names_len` pool bytes. It is keyed by boundary id, not by+/// index ordinal, so there is no record count to cross-check.+fn validate_poi_admin(path: &Path) -> Result<(), String> {+ if !path.exists() {+ return Ok(());+ }+ let b = read_head(path, 16)?;+ if b.len() < 16 {+ return Err("poi_admin.bin ends before its header".to_string());+ }+ if &b[0..4] != b"PAD1" {+ return Err("poi_admin.bin has bad magic".to_string());+ }+ let word = |at: usize| u32::from_le_bytes([b[at], b[at + 1], b[at + 2], b[at + 3]]) as u64;+ if word(4) != 1 {+ return Err(format!("poi_admin.bin is version {}, expected 1", word(4)));+ }+ let want = 16 + 32 * word(8) + word(12);+ let got = file_len(path)?;+ if got != want {+ return Err(format!("poi_admin.bin is {got} bytes, its header declares {want}"));+ } Ok(()) } @@ -1407,6 +1451,52 @@ mod tests { assert_eq!(view.section(&packed, ARCHIVE_KIND_POI_REGION), Some(®ion[..])); let _ = std::fs::remove_dir_all(&dir); }+ /// `poi_admin.bin`: PAD1 + version + one 32-byte entry + a 6-byte name pool.+ fn admin_payload() -> Vec<u8> {+ let mut out = Vec::new();+ out.extend_from_slice(b"PAD1");+ out.extend_from_slice(&1u32.to_le_bytes());+ out.extend_from_slice(&1u32.to_le_bytes());+ out.extend_from_slice(&6u32.to_le_bytes());+ out.extend_from_slice(&((300u64 << 2) | 3).to_le_bytes());+ out.extend_from_slice(&0u64.to_le_bytes());+ out.extend_from_slice(&0u32.to_le_bytes());+ out.extend_from_slice(&u32::MAX.to_le_bytes());+ out.push(8);+ out.extend_from_slice(&[0u8; 7]);+ out.extend_from_slice(b"Paris\0");+ out+ }+ #[test]+ fn an_admin_sidecar_packs_after_the_region_and_moves_the_build_id() {+ let (dir, poi) = overlay_fixture("admin");+ std::fs::write(poi.join("poi_region.bin"), region_payload((300u64 << 2) | 3)).expect("fixture region");+ let before = load_sidecars(&dir, &poi, None).expect("stage without admin").poi_attrs_digest().unwrap();+ let admin = admin_payload();+ std::fs::write(poi.join("poi_admin.bin"), &admin).expect("fixture admin");+ let validated = load_sidecars(&dir, &poi, None).expect("stage fixtures");+ assert_eq!(validated.staged.last().map(|s| s.kind), Some(ARCHIVE_KIND_POI_ADMIN));+ let after = validated.poi_attrs_digest().unwrap();+ assert_ne!(before, after, "adding the hierarchy moves the build-id digest");+ assert!(before.is_empty(), "no attrs, no admin: the digest every old archive had");+ let out = dir.join("packed.mamaps");+ pack_streaming(&dir.join("tiles.mamaps"), &validated, 0xBEEF, &out).expect("pack");+ let packed = std::fs::read(&out).expect("read packed");+ let header = Header::parse(&packed).expect("packed header");+ // Ascending kinds again: 16 after the region's 15.+ let view = ArchiveView::parse(&packed, &header).expect("packed archive opens");+ assert_eq!(view.section(&packed, ARCHIVE_KIND_POI_ADMIN), Some(&admin[..]));+ let _ = std::fs::remove_dir_all(&dir);+ }+ #[test]+ fn a_truncated_admin_sidecar_fails_the_pack() {+ let (dir, poi) = overlay_fixture("admin_short");+ let admin = admin_payload();+ std::fs::write(poi.join("poi_admin.bin"), &admin[..admin.len() - 1]).expect("fixture admin");+ let err = load_sidecars(&dir, &poi, None).expect_err("a short admin table");+ assert!(err.contains("poi_admin.bin"), "{err}");+ let _ = std::fs::remove_dir_all(&dir);+ } #[test] fn a_stale_overlay_fails_the_pack() { let (dir, poi) = overlay_fixture("stale_overlay");
scripts/maps/tile_build/src/bin/mamaps_probe.rs
diff --git a/scripts/maps/tile_build/src/bin/mamaps_probe.rs b/scripts/maps/tile_build/src/bin/mamaps_probe.rsindex e238d62ad0..a608efd504 100644--- a/scripts/maps/tile_build/src/bin/mamaps_probe.rs+++ b/scripts/maps/tile_build/src/bin/mamaps_probe.rs@@ -431,6 +431,7 @@ fn sidecars(path: &str) -> ExitCode { 12 => "poi_words (poi_name_index.bin: PNI1 full-text word index)", 13 => "transit (world.transit: TRIX pack of routes/shapes)", 15 => "poi_region (poi_region.bin: PRG1 region-id sidecar)",+ 16 => "poi_admin (poi_admin.bin: PAD1 boundary names/levels/parents)", _ => "unknown", } }
scripts/maps/tile_build/src/bin/mamaps_sizes.rs
diff --git a/scripts/maps/tile_build/src/bin/mamaps_sizes.rs b/scripts/maps/tile_build/src/bin/mamaps_sizes.rsindex 3fc61cc892..b1f1821418 100644--- a/scripts/maps/tile_build/src/bin/mamaps_sizes.rs+++ b/scripts/maps/tile_build/src/bin/mamaps_sizes.rs@@ -30,11 +30,11 @@ use tile_build::mamaps::dict::Dictionary; use tile_build::mamaps::header::Header; use tile_build::mamaps::index::{decompress_leaf, parse_leaf, parse_root, LEAF_ENTRY_LEN, ROOT_ENTRY_LEN}; -const KIND_NAMES: [(u8, &str); 14] = [+const KIND_NAMES: [(u8, &str); 15] = [ (1, "graph_meta"), (2, "graph_nodes"), (3, "graph_edges"), (4, "graph_intermediate"), (5, "graph_names"), (6, "graph_lanes"), (7, "graph_elevation"), (8, "poi_index"), (9, "poi_names"), (10, "poi_attrs"), (11, "poi_spatial"), (12, "poi_words"),- (13, "transit"), (15, "poi_region"),+ (13, "transit"), (15, "poi_region"), (16, "poi_admin"), ]; fn gb(n: u64) -> f64 {