Skip to main content

Module node_store

Module node_store 

Source
Expand description

Node coordinate store for OSM processing.

Four storage backends are selected based on available RAM and explicit configuration:

  • Dense (mmap): Planetiler’s “ARRAY” strategy — a flat file where node ID is the array index. Each slot stores latitude and longitude as two i32 fixed-point values (1e-7 precision ≈ 1cm), packed into 8 bytes. Used when the store fits in RAM (≤ 105% of physical memory).

  • BufferedFile: A sharded in-memory page cache that buffers writes in 4 KB pages (512 nodes each), flushing to disk via pwrite when a shard exceeds its page budget. After pass 1 completes, NodeStore::prepare_for_reads flushes all remaining pages and switches to a dense mmap for O(1) reads. Used for planet builds where --node-store is explicit and the store exceeds the mmap threshold (e.g. 97 GB on a 96 GB machine).

  • File: Direct random-access I/O via pread/pwrite — same flat file layout as Dense but without mapping the entire address space. Used when --node-store is explicitly provided and the file exceeds the mmap threshold (e.g. planet builds on machines where a 97 GB mmap is rejected by the OS). The kernel’s file buffer cache handles paging transparently.

  • Sparse (HashMap): A HashMap<u64, u64> storing packed coordinates. Used for regional extracts where node IDs span a large range but only a small fraction exist. Avoids allocating a 97 GB file for a 200 MB PBF.

§Node Cache

A sidecar .meta.json file records the PBF file size, modification time, and max node ID used. On subsequent runs, try_open_cached checks the metadata: if the PBF hasn’t changed, the existing node store is reused. This avoids re-scanning billions of nodes on re-runs with the same PBF.

Structs§

ConcurrentNodeWriter
A concurrent writer handle for the node store.
NodeCacheMeta
Sidecar metadata for node cache validation.
NodeStore
A node coordinate store with automatic backend selection.

Functions§

meta_path
Derive the sidecar metadata path from a node store path.
try_open_cached
Try to open a cached node store, validating against the current PBF file.
write_cache_meta
Write cache metadata alongside the node store.