Skip to content

Commit

Permalink
Optimize log level when couldn't find tile data (#867)
Browse files Browse the repository at this point in the history
Fix #815
  • Loading branch information
sharkAndshark authored Sep 12, 2023
1 parent 7dea916 commit a7ee237
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
6 changes: 3 additions & 3 deletions martin/src/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};

use crate::config::{copy_unrecognized_config, UnrecognizedValues};
use crate::file_config::FileError::{InvalidFilePath, InvalidSourceFilePath, IoError};
use crate::source::{Source, Sources, Xyz};
use crate::source::{Source, Sources};
use crate::utils::{sorted_opt_map, Error, IdResolver, OneOrMany};
use crate::OneOrMany::{Many, One};

Expand All @@ -27,8 +27,8 @@ pub enum FileError {
#[error(r"Unable to parse metadata in file {}: {0}", .1.display())]
InvalidMetadata(String, PathBuf),

#[error(r#"Tile {0:#} not found in {1}"#)]
GetTileError(Xyz, String),
#[error(r#"Unable to aquire connection to file: {0}"#)]
AquireConnError(String),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down
20 changes: 16 additions & 4 deletions martin/src/mbtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use std::path::PathBuf;
use std::sync::Arc;

use async_trait::async_trait;
use log::trace;
use martin_mbtiles::MbtilesPool;
use martin_tile_utils::TileInfo;
use tilejson::TileJSON;

use crate::file_config::FileError;
use crate::file_config::FileError::{GetTileError, InvalidMetadata, IoError};
use crate::file_config::FileError::{AquireConnError, InvalidMetadata, IoError};
use crate::source::{Tile, UrlQuery};
use crate::utils::is_valid_zoom;
use crate::{Error, Source, Xyz};
Expand Down Expand Up @@ -86,11 +87,22 @@ impl Source for MbtSource {
}

async fn get_tile(&self, xyz: &Xyz, _url_query: &Option<UrlQuery>) -> Result<Tile, Error> {
Ok(self
if let Some(tile) = self
.mbtiles
.get_tile(xyz.z, xyz.x, xyz.y)
.await
.map_err(|_| GetTileError(*xyz, self.id.clone()))?
.unwrap_or_default())
.map_err(|_| AquireConnError(self.id.clone()))?
{
Ok(tile)
} else {
trace!(
"Couldn't find tile data in {}/{}/{} of {}",
xyz.z,
xyz.x,
xyz.y,
&self.id
);
Ok(Vec::new())
}
}
}
21 changes: 15 additions & 6 deletions martin/src/pmtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use std::path::PathBuf;
use std::sync::Arc;

use async_trait::async_trait;
use log::warn;
use log::{trace, warn};
use martin_tile_utils::{Encoding, Format, TileInfo};
use pmtiles::async_reader::AsyncPmTilesReader;
use pmtiles::mmap::MmapBackend;
use pmtiles::{Compression, TileType};
use tilejson::TileJSON;

use crate::file_config::FileError;
use crate::file_config::FileError::{GetTileError, InvalidMetadata, IoError};
use crate::file_config::FileError::{InvalidMetadata, IoError};
use crate::source::{Source, Tile, UrlQuery, Xyz};
use crate::utils::is_valid_zoom;
use crate::Error;
Expand Down Expand Up @@ -136,12 +136,21 @@ impl Source for PmtSource {

async fn get_tile(&self, xyz: &Xyz, _url_query: &Option<UrlQuery>) -> Result<Tile, Error> {
// TODO: optimize to return Bytes
Ok(self
if let Some(t) = self
.pmtiles
.get_tile(xyz.z, u64::from(xyz.x), u64::from(xyz.y))
.await
.ok_or_else(|| GetTileError(*xyz, self.id.clone()))?
.data
.to_vec())
{
Ok(t.data.to_vec())
} else {
trace!(
"Couldn't find tile data in {}/{}/{} of {}",
xyz.z,
xyz.x,
xyz.y,
&self.id
);
Ok(Vec::new())
}
}
}

0 comments on commit a7ee237

Please sign in to comment.