Skip to content

Commit

Permalink
PMTiles cache, refactor file configs, modularize
Browse files Browse the repository at this point in the history
* Implement PMTiles directory cache shared between all pmtiles, with configurable max cache size (in MB), or 0 to disable.
* PMTiles now share web client instance, which optimizes connection reuse in case multiple pmtiles reside on the same host
* Major refactoring to allow modular reuse, enabling the following build features:
    * **postgres** - enable PostgreSQL/PostGIS tile sources
    * **pmtiles** - enable PMTile tile sources
    * **mbtiles** - enable MBTile tile sources
    * **fonts** - enable font sources
    * **sprites** - enable sprite sources
* Use justfile in the CI
  • Loading branch information
nyurik committed Dec 25, 2023
1 parent 14630ae commit 89ef808
Show file tree
Hide file tree
Showing 31 changed files with 585 additions and 401 deletions.
40 changes: 15 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ insta = "1"
itertools = "0.12"
json-patch = "1.2"
log = "0.4"
martin-tile-utils = { path = "./martin-tile-utils", version = "0.3.0" }
mbtiles = { path = "./mbtiles", version = "0.8.0" }
martin-tile-utils = { path = "./martin-tile-utils", version = "0.4.0" }
mbtiles = { path = "./mbtiles", version = "0.9.0" }
moka = { version = "0.12", features = ["future"] }
num_cpus = "1"
pbf_font_tools = { version = "2.5.0", features = ["freetype"] }
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ Martin data is available via the HTTP `GET` endpoints:
| `/font/{font1},…,{fontN}/{start}-{end}` | Composite Font source |
| `/health` | Martin server health check: returns 200 `OK` |

## Re-use Martin as a library

Check failure on line 109 in README.md

View workflow job for this annotation

GitHub Actions / Build Docs

Headings should be surrounded by blank lines

README.md:109 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Re-use Martin as a library"] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md022.md
Martin can be used as a standalone server, or as a library in your own Rust application. When used as a library, you can use the following features:
* **postgres** - enable PostgreSQL/PostGIS tile sources

Check failure on line 111 in README.md

View workflow job for this annotation

GitHub Actions / Build Docs

Lists should be surrounded by blank lines

README.md:111 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "* **postgres** - enable Postgr..."] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md032.md
* **pmtiles** - enable PMTile tile sources
* **mbtiles** - enable MBTile tile sources
* **fonts** - enable font sources
* **sprites** - enable sprite sources

## Documentation

See [Martin book](https://maplibre.org/martin/) for complete documentation.
Expand Down
5 changes: 4 additions & 1 deletion debian/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ worker_processes: 8
# auto_bounds: skip

# pmtiles:
# dir_cache_size: 100
# dir_cache_size_mb: 100
# paths:
# - /dir-path
# - /path/to/pmtiles.pmtiles
Expand All @@ -33,6 +33,9 @@ worker_processes: 8
# sources:
# mb-src1: /path/to/mbtiles1.mbtiles

# sprites:
# - /path/to/sprites_dir

# fonts:
# - /path/to/font/file.ttf
# - /path/to/font_dir
2 changes: 2 additions & 0 deletions docs/src/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ postgres:

# Publish PMTiles files from local disk or proxy to a web server
pmtiles:
# Memory (in MB) to use for caching PMTiles directories [default: 32, 0 to disable]]
dir_cache_size_mb: 100
paths:
# scan this whole dir, matching all *.pmtiles files
- /dir-path
Expand Down
11 changes: 10 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,16 @@ fmt2:

# Run cargo check
check:
cargo check --workspace --all-targets --bins --tests --lib --benches
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin-tile-utils
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p mbtiles
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p mbtiles --no-default-features
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin --no-default-features
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin --no-default-features --features fonts
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin --no-default-features --features mbtiles
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin --no-default-features --features pmtiles
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin --no-default-features --features postgres
RUSTFLAGS='-D warnings' cargo check --bins --tests --lib --benches --examples -p martin --no-default-features --features sprites

# Verify doc build
check-doc:
Expand Down
2 changes: 1 addition & 1 deletion martin-tile-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lints.workspace = true

[package]
name = "martin-tile-utils"
version = "0.3.1"
version = "0.4.0"
authors = ["Yuri Astrakhan <[email protected]>", "MapLibre contributors"]
description = "Utilites to help with map tile processing, such as type and compression detection. Used by the MapLibre's Martin tile server."
keywords = ["maps", "tiles", "mvt", "tileserver"]
Expand Down
34 changes: 18 additions & 16 deletions martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ lints.workspace = true
[package]
name = "martin"
# Once the release is published with the hash, update https://github.com/maplibre/homebrew-martin
version = "0.11.6"
version = "0.12.0"
authors = ["Stepan Kuzmin <[email protected]>", "Yuri Astrakhan <[email protected]>", "MapLibre contributors"]
description = "Blazing fast and lightweight tile server with PostGIS, MBTiles, and PMTiles support"
keywords = ["maps", "tiles", "mbtiles", "pmtiles", "postgis"]
Expand Down Expand Up @@ -59,10 +59,12 @@ name = "bench"
harness = false

[features]
default = []
#default = ["sprites", "fonts"]
sprites = []
fonts = []
default = ["fonts", "mbtiles", "pmtiles", "postgres", "sprites"]
fonts = ["dep:bit-set","dep:pbf_font_tools"]
mbtiles = []
pmtiles = ["dep:moka"]
postgres = ["dep:deadpool-postgres", "dep:json-patch", "dep:postgis", "dep:postgres", "dep:postgres-protocol", "dep:semver", "dep:tokio-postgres-rustls"]
sprites = ["dep:spreet"]
bless-tests = []

[dependencies]
Expand All @@ -71,41 +73,41 @@ actix-http.workspace = true
actix-rt.workspace = true
actix-web.workspace = true
async-trait.workspace = true
bit-set.workspace = true
bit-set = { workspace = true, optional = true }
brotli.workspace = true
clap.workspace = true
deadpool-postgres.workspace = true
deadpool-postgres = { workspace = true, optional = true }
env_logger.workspace = true
flate2.workspace = true
futures.workspace = true
itertools.workspace = true
json-patch.workspace = true
json-patch = { workspace = true, optional = true }
log.workspace = true
martin-tile-utils.workspace = true
mbtiles.workspace = true
moka.workspace = true
moka = { workspace = true, optional = true }
num_cpus.workspace = true
pbf_font_tools.workspace = true
pbf_font_tools = { workspace = true, optional = true }
pmtiles.workspace = true
postgis.workspace = true
postgres-protocol.workspace = true
postgres.workspace = true
postgis = { workspace = true, optional = true }
postgres-protocol = { workspace = true, optional = true }
postgres = { workspace = true, optional = true }
regex.workspace = true
reqwest.workspace = true
rustls-native-certs.workspace = true
rustls-pemfile.workspace = true
rustls.workspace = true
semver.workspace = true
semver = { workspace = true, optional = true }
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
serde_yaml.workspace = true
spreet.workspace = true
spreet = { workspace = true, optional = true }
subst.workspace = true
thiserror.workspace = true
tilejson.workspace = true
tokio = { workspace = true, features = ["io-std"] }
tokio-postgres-rustls.workspace = true
tokio-postgres-rustls = { workspace = true, optional = true }
url.workspace = true

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions martin/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pub use connections::{Arguments, State};
mod environment;
pub use environment::{Env, OsEnv};

#[cfg(feature = "postgres")]
mod pg;
#[cfg(feature = "postgres")]
pub use pg::{BoundsCalcType, PgArgs, DEFAULT_BOUNDS_TIMEOUT};

mod root;
Expand Down
Loading

0 comments on commit 89ef808

Please sign in to comment.