Introducing a new way to review your PRs.

Read the announcement

maplibre / martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.

View on GitHub

22 documents · Updated Nov 23, 2026

docs / source-catalog-and-lifecycle

Source catalog and lifecycle

Martin turns configured data sources into live tile sources that can be requested by ID. Discovery finds the sources, the tile source manager keeps the live set, and the catalog publishes the metadata that clients need to find and use them.

Source model

The server treats each source as a named producer of tiles. A source ID is the stable link between configuration, discovery results, tile requests, reload events, and catalog entries.

Configuration inputs

Configuration can name a source directly or describe where sources can be found. Local files use paths or watched directories. Remote files use object-store or HTTP locations. Database configuration describes a connection from which Martin can discover publishable sources.

The config file reader loads these settings and resolves environment properties before source discovery. Plain scalar values support $VAR and ${VAR} forms. They also support shell-style defaults such as ${VAR:-fallback} and ${VAR-fallback}. Quoted values and comments keep their literal text, so source locations and connection strings that need substitution must use an unquoted scalar.

The OSM PBF configuration is different: it describes input for martin cp --mode bulk and is not a live tile source in the server manager. See configuration and reload for how serving inputs are set and refreshed.

Martin classifies a source location before discovery selects the matching source kind. A path that is not a recognized remote URL remains a local path, while a valid HTTP or object-store URL follows a remote discovery path. This keeps local file scans separate from remote object checks and listings.

References: crates/…/parse.rs• L10-32 crates/…/parse.rs• L457-517 crates/…/config.rs• L138-232 martin/…/osm.rs• L12-42 martin/…/source_location.rs• L9-41 martin/…/fs.rs• L74-116 martin/…/object_store.rs• L88-132

Source identities

Discovery returns a snapshot of source IDs with a change marker and the information needed to build each source. The marker lets the reload system tell a new source from a removed source and distinguish an unchanged source from one that needs replacement.

The built source also carries its effective serving process settings. These settings control how the source is advertised and served, while source provenance records enough origin data for the running configuration to be saved later.

References: martin/…/discovery_trait.rs• L14-29 martin/…/discovery_trait.rs• L41-78 crates/…/lifecycle.rs• L671-742 martin/…/reload.rs• L45-75

Discovery and registration

Discovery is the boundary between configured locations and the live source set. Each source kind reports what exists now, builds sources on demand, and passes the result to one shared reconciliation path.

Discovery modes

The discovery mode follows the shape of the configured source:

  • Local file discovery scans allowed files in configured directories. Recursive scans turn relative paths into dotted source IDs. File modification time acts as the change marker.
  • Object-store prefix discovery lists matching objects under configured remote prefixes. A configured remote object can instead be checked directly. Remote checks use object metadata such as an ETag or last-modified time as the change marker.
  • PostgreSQL discovery reads the database catalog for spatial tables and tile-serving functions. It merges explicit source settings with database metadata, applies the auto-publish rules, resolves source IDs, and returns source descriptions. Source construction then prepares the tile query and any missing bounds.

PostgreSQL sources can use the connection's default tile grid or a named grid from configuration. The source is served in that grid, while bounds are advertised only when the data can be expressed in the metadata coordinate system.

The result is a consistent source snapshot even though the underlying checks differ. This lets the reload driver use one lifecycle for files, remote objects, and database sources.

References: martin/…/fs.rs• L240-285 martin/…/object_store.rs• L69-75 martin/…/object_store.rs• L174-214 martin/…/postgres.rs• L15-20 martin/…/builder.rs• L166-210 martin/…/builder.rs• L241-298 martin/…/query_tables.rs• L196-258

Startup registration

At startup, configuration resolution validates the enabled source settings, resolves the tile backends, and builds the sources that are already known. It applies effective process settings, handles source warnings according to on_invalid, places the live sources in the tile source manager, and then registers configured aliases.

The manager is therefore the serving authority, not the configuration file. Configuration supplies the initial intent. The manager holds the source objects and the effective process settings that requests use. OSM PBF entries remain inputs for bulk copy mode and do not enter this live tile-source registration path.

The server can start reload drivers for source kinds that need later scans or polls. See configuration and reload for the relationship between the initial resolution and later refreshes.

References: crates/…/lifecycle.rs• L198-280 crates/…/lifecycle.rs• L384-471 crates/…/config.rs• L107-118 martin/…/osm.rs• L1 martin/…/reloaders.rs• L35-165 martin/…/source.rs• L73-119

Live source lifecycle

After startup, each reloader observes its source kind and reconciles its observations with the manager. A change becomes visible only after the replacement source builds and the manager accepts the change.

Discovery reconciliation

The reload driver keeps a baseline of the last applied discovery. On each trigger it discovers again, compares IDs and change markers, builds additions and updates, and sends one change advisory to the manager. A failed discovery keeps the old baseline, so a temporary database or storage error does not turn all sources into removals.

The manager applies changes in a stable order: updates first, additions next, and removals last. Updates invalidate cached tiles before the new source is installed. Removals delete the source and its provenance, then invalidate its cached tiles.

This flow shows how an observation becomes a live source change.

flowchart LR
    A[Configured source location] --> B[Discovery snapshot]
    B --> C[Compare with applied baseline]
    C --> D[Build changed sources]
    D --> E[Reload advisory]
    E --> F[Tile source manager]
    F --> G[Live tile requests]
    F --> H[Catalog metadata]

References: martin/…/reconcile.rs• L29-37 martin/…/reconcile.rs• L111-185 martin/…/reload.rs• L86-167 martin/…/tile_source_manager.rs• L159-248

Initial loading

The manager marks sources as loading while reloaders initialize. Tile and metadata requests wait when they name a source that may still be discovered. The load ends after initialization completes, which prevents a request from treating a not-yet-published source as permanently unknown.

Initial loading can publish sources in chunks. This allows early sources to serve before every source has finished building, while the loading signal still protects requests for sources that are later in the load.

References: martin/…/tile_source_manager.rs• L74-99 martin/…/reloaders.rs• L167-176 martin/…/reconcile.rs• L54-77

Request-time refresh

A tile request can find that its source has changed while the request is running. The server then builds and publishes a fresh source, invalidates the old source's cached tiles, and retries the request so the response uses current data.

This is a local freshness safeguard. It complements scheduled discovery and does not replace the normal reload baseline.

References: martin/…/content.rs• L578-645 martin/…/tile_source_manager.rs• L159-248

Invalid source handling

The configured invalid-source policy decides whether a source build error stops the operation or skips only the affected source. In warn mode, a failed addition or update is reported and remains eligible for a later retry. In abort mode, the error returns immediately.

This distinction protects the live catalog from two different risks: abort mode prevents a partial initial state, while warn mode lets healthy sources continue when one source is bad.

References: martin/…/tile_source_manager.rs• L159-170 martin/…/tile_source_manager.rs• L189-227 crates/…/config.rs• L342-389 martin/…/reconcile.rs• L142-158

Tile source manager

The tile source manager is the live registry shared by reloaders and HTTP handlers. It owns source IDs, aliases, process settings, provenance, and optional tile-cache coordination.

Request resolution

Tile requests resolve their source IDs through a read-only view of the manager. A request may name several sources or an alias. The resolver expands aliases, checks that all selected sources use compatible tile formats and grids, and applies the source-specific process settings before tile work begins.

Aliases are named combinations of registered tile sources. They cannot contain another alias or an unknown source, and a request has a fixed maximum number of source IDs. An alias can shadow a source with the same name, so the alias becomes the result for requests using that name.

References: martin/…/tile_source_manager.rs• L102-106 martin/…/source.rs• L159-205 martin/…/source.rs• L207-317 martin/…/content.rs• L102-119

Metadata resolution

Source metadata uses the same resolution path as tile requests. A single-source request returns that source's advertised TileJSON. A composite request combines the member metadata into one TileJSON response, so the URL and advertised details describe the requested source set.

The effective process settings are applied before metadata is returned. This keeps format and encoding claims aligned with the bytes that the tile route serves.

References: martin/…/metadata.rs• L45-113 martin/…/metadata.rs• L116-210 martin/…/source.rs• L269-315

Catalog exposure

The catalog is a metadata view of the sources that are live in the manager. It maps source IDs to content type, optional encoding, human-readable details, tile-grid information, layer count, and source modification time when available.

Tile catalog

The manager builds a fresh tile catalog from the current source set. Each source supplies its metadata, and the effective process settings can change the advertised content type or encoding. Aliases appear as catalog entries when at least one member source is available; their format and encoding come from a member source.

The catalog therefore answers “what is served now,” rather than “what was written in the configuration.” This matters during reloads and when discovery finds sources that were not listed one by one.

References: martin/…/source.rs• L122-150 martin/…/tile_source_manager.rs• L102-106 martin-core/…/catalog.rs• L12-56

Catalog endpoint

The server exposes the tile catalog through GET /catalog. The endpoint waits for initial source loading, then reads the manager's current catalog and combines it with other server resources when those features are enabled.

The catalog endpoint is the broad discovery interface for clients. The per-source metadata route remains the detailed interface for a selected source or source combination. See HTTP APIs and map resources for the public route model and Martin server runtime for how the manager fits into server startup.

References: martin/…/admin.rs• L15-35 martin/…/admin.rs• L68-99 martin/…/metadata.rs• L25-52

OGC tileset metadata

The OGC collection tileset routes expose the same live source view through a standards-based metadata shape. Each route waits for source loading, resolves the collection through the manager, and derives the tile matrix set, bounds, layers, content type, and tile URL template from the source's advertised metadata.

The tileset list describes the available grid. The tileset detail describes its limits and vector layers. An unknown collection or a tile matrix set that does not match the source grid is rejected instead of producing metadata for a different source.

References: martin/…/tilesets.rs• L95-108 martin/…/tilesets.rs• L139-225 martin/…/tilesets.rs• L249-333

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep discovery change markers aligned with the source data that can change served bytes or metadata. The reload driver uses marker equality to decide whether to rebuild.
  • Keep source provenance aligned with every discoverable source kind. The save-config path uses it to materialize the running catalog back into the matching configuration section.
  • Keep PostgreSQL discovery and instantiation aligned. Discovery must return enough source information for a later build, while instantiation must return updated metadata such as computed bounds for save-config.
  • Keep PostgreSQL tile-grid validation aligned with source metadata and request resolution. A source that discovers successfully must use the same grid when it serves tiles and publishes metadata.
  • Keep alias validation and catalog generation consistent. An alias that resolves for tile requests must also have meaningful catalog metadata.
  • Keep the loading signal around the full initial publication window. Removing it can turn a source that is still loading into a false unknown-source response.
  • Keep cache invalidation coupled to source replacement, request-time refresh, and removal. Otherwise the manager can serve tiles from an older source after a successful reload.
  • Keep OGC tileset metadata tied to the same advertised TileJSON and process settings as tile serving. Otherwise clients can receive a tile URL or format claim that does not match the live source.
  • Keep OSM bulk-copy configuration separate from live server source resolution. Adding it to the tile manager would expose an input that has no server tile source lifecycle.
  • Keep environment substitution rules aligned with source configuration examples. Unquoted source locations and connection strings can resolve properties, while quoted values and comments remain literal.

Important failure modes

TriggerConsequenceGuard
Discovery fails for one reload passThe current source set remains in service and the change is retried on a later trigger.The reload driver retains the last applied baseline on discovery failure.
A source build fails in warn modeThat source is absent or remains unchanged while healthy source changes continue.The manager reports the failed ID and the baseline keeps it pending for retry.
A source build fails in abort modeThe current apply or startup operation stops with an error.The invalid-source policy is checked before the source is published.
A source location or connection string puts an environment token in a quoted scalarDiscovery receives the literal token and can fail to find or open the source.Property substitution applies to plain scalars. Use an unquoted value when configuration needs environment resolution.
A configured PostgreSQL table or function cannot be matched to the database catalogThat source is not published and a source-specific warning is produced.PostgreSQL discovery merges configuration with catalog metadata before it returns a source description.
A PostgreSQL source names an unknown or incompatible tile gridConfiguration fails or the source is skipped instead of serving under a wrong grid.Grid names and CRS support are checked before source construction.
A composite request mixes incompatible formats or tile gridsThe request is rejected instead of merging bytes under the wrong interpretation.Source resolution validates format, encoding, and tile-grid compatibility.
A request arrives before initial discovery publishes its sourceThe request waits while loading instead of failing immediately.The manager releases waiters after source publication or after loading finishes.
A tile source reports that its data is stale during a requestThe old source is refreshed and the request is retried.Tile serving publishes the fresh source before retrying, which also invalidates its cache entries.
An OGC tileset request names a grid that the source does not serveThe request returns an unknown-tileset error.Tileset resolution compares the requested matrix set with the source grid ID.

Key files

FileWhy to read it
martin/…/tile_source_manager.rsShows the live source set, cache coordination, loading gate, and add/update/remove behavior.
martin/…/source.rsShows source ID resolution, aliases, composite compatibility, and tile catalog construction.
crates/…/parse.rsShows how the config file becomes resolved source settings and how environment properties behave in YAML values.
crates/…/config.rsDefines source configuration groups, invalid-source policy, aliases, and the distinction between server tile inputs and OSM bulk-copy inputs.
crates/…/lifecycle.rsShows startup validation, source resolution, manager creation, aliases, provenance, and save-config materialization.
martin/…/mod.rsShows which tile configuration and discovery families participate in the source lifecycle.
martin/…/osm.rsDefines the OSM PBF bulk-copy input that does not become a live server tile source.
martin/…/discovery_trait.rsDefines the common contract for discovery snapshots and source building.
martin/…/reconcile.rsShows how discovery snapshots become reload changes and how failures preserve the baseline.
martin/…/fs.rsExplains local file and directory discovery and the source IDs derived from paths.
martin/…/object_store.rsExplains remote object checks, prefix listings, and retained observations after transient failures.
martin/…/builder.rsExplains PostgreSQL catalog discovery, configured and automatic publication, tile-grid selection, and source construction.
martin/…/query_tables.rsExplains PostgreSQL table metadata, bounds, and grid-aware source queries at a high level.
martin/…/content.rsShows request-time source refresh, tile retry behavior, and cache use after source changes.
martin/…/tilesets.rsShows how live source metadata becomes OGC tileset and tile URL metadata.
martin/…/admin.rsDefines the /catalog response and its initial-load behavior.
martin-core/…/catalog.rsDefines the metadata shape exposed for each tile source.