Porównaj commity

...

11 Commity

Autor SHA1 Wiadomość Data
Michael Barry af1852217c
Merge 48c4f60ad8 into 32f941f1b1 2024-04-04 17:48:52 +02:00
dependabot[bot] 32f941f1b1
Bump org.jacoco:jacoco-maven-plugin from 0.8.11 to 0.8.12 (#863)
Bumps [org.jacoco:jacoco-maven-plugin](https://github.com/jacoco/jacoco) from 0.8.11 to 0.8.12.
- [Release notes](https://github.com/jacoco/jacoco/releases)
- [Commits](https://github.com/jacoco/jacoco/compare/v0.8.11...v0.8.12)

---
updated-dependencies:
- dependency-name: org.jacoco:jacoco-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-04 05:16:39 -04:00
dependabot[bot] ef6fc85691
Bump com.google.cloud.tools:jib-maven-plugin from 3.4.1 to 3.4.2 (#862) 2024-04-03 21:22:21 -04:00
Michael Barry f69882addb
Fix tile size stats memory leak (#861) 2024-04-02 20:34:42 -04:00
dependabot[bot] 6c41c388f4
Bump org.apache.maven.plugins:maven-assembly-plugin from 3.6.0 to 3.7.1 (#860) 2024-04-02 07:49:22 -04:00
dependabot[bot] 689abb5ad7
Bump org.apache.maven.plugins:maven-gpg-plugin from 3.2.1 to 3.2.2 (#858)
Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/apache/maven-gpg-plugin/releases)
- [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.1...maven-gpg-plugin-3.2.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-gpg-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-01 05:49:09 -04:00
dependabot[bot] da9d03c85d
Bump geotools.version from 30.1 to 31.0 (#856) 2024-03-29 05:04:50 -04:00
dependabot[bot] 1871e230ac
Bump org.sonarsource.scanner.maven:sonar-maven-plugin (#855) 2024-03-28 05:16:13 -04:00
Mike Barry 48c4f60ad8 undo 2024-03-04 05:13:29 -05:00
Mike Barry a33f3b8327 smaller ids 2024-03-03 21:15:20 -05:00
Mike Barry b38b8b37a1 encode node/way/relation in vector tile feature id 2024-03-03 20:40:17 -05:00
10 zmienionych plików z 91 dodań i 57 usunięć

Wyświetl plik

@ -30,7 +30,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<version>3.7.1</version>
<!-- for with-deps assembly descriptor -->
<dependencies>
<dependency>

Wyświetl plik

@ -16,7 +16,7 @@
</parent>
<properties>
<geotools.version>30.1</geotools.version>
<geotools.version>31.0</geotools.version>
<log4j.version>2.23.1</log4j.version>
<prometheus.version>0.16.0</prometheus.version>
<protobuf.version>3.25.3</protobuf.version>

Wyświetl plik

@ -6,6 +6,8 @@ import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.geo.GeometryType;
import com.onthegomap.planetiler.reader.SourceFeature;
import com.onthegomap.planetiler.reader.osm.OsmElement;
import com.onthegomap.planetiler.reader.osm.OsmSourceFeature;
import com.onthegomap.planetiler.render.FeatureRenderer;
import com.onthegomap.planetiler.stats.Stats;
import com.onthegomap.planetiler.util.CacheByZoom;
@ -59,7 +61,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
* @return a feature that can be configured further.
*/
public Feature geometry(String layer, Geometry geometry) {
Feature feature = new Feature(layer, geometry, source.id());
Feature feature = new Feature(layer, geometry, source);
output.add(feature);
return feature;
}
@ -81,7 +83,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.worldGeometry());
} catch (GeometryException e) {
e.log(stats, "feature_point", "Error getting point geometry for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id());
return new Feature(layer, EMPTY_GEOM, source);
}
}
@ -101,7 +103,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.line());
} catch (GeometryException e) {
e.log(stats, "feature_line", "Error constructing line for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id());
return new Feature(layer, EMPTY_GEOM, source);
}
}
@ -121,7 +123,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.polygon());
} catch (GeometryException e) {
e.log(stats, "feature_polygon", "Error constructing polygon for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id());
return new Feature(layer, EMPTY_GEOM, source);
}
}
@ -136,7 +138,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.centroid());
} catch (GeometryException e) {
e.log(stats, "feature_centroid", "Error getting centroid for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id());
return new Feature(layer, EMPTY_GEOM, source);
}
}
@ -153,7 +155,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.centroidIfConvex());
} catch (GeometryException e) {
e.log(stats, "feature_centroid_if_convex", "Error constructing centroid if convex for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id());
return new Feature(layer, EMPTY_GEOM, source);
}
}
@ -169,7 +171,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.pointOnSurface());
} catch (GeometryException e) {
e.log(stats, "feature_point_on_surface", "Error constructing point on surface for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id());
return new Feature(layer, EMPTY_GEOM, source);
}
}
@ -191,7 +193,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.innermostPoint(tolerance));
} catch (GeometryException e) {
e.log(stats, "feature_innermost_point", "Error constructing innermost point for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id());
return new Feature(layer, EMPTY_GEOM, source);
}
}
@ -275,11 +277,21 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
private String numPointsAttr = null;
private Feature(String layer, Geometry geom, long id) {
private Feature(String layer, Geometry geom, SourceFeature source) {
this.layer = layer;
this.geom = geom;
this.geometryType = GeometryType.typeOf(geom);
this.id = id;
if (source instanceof OsmSourceFeature osmSourceFeature) {
long osmId = osmSourceFeature.originalElement().id();
this.id = switch (osmSourceFeature.originalElement()) {
case OsmElement.Node node -> node.id() * 3;
case OsmElement.Way way -> way.id() * 3 + 1;
case OsmElement.Relation relation -> relation.id() * 3 + 2;
default -> osmId;
};
} else {
this.id = source.id();
}
if (geometryType == GeometryType.POINT) {
minPixelSizeAtMaxZoom = 0;
defaultMinPixelSize = 0;

Wyświetl plik

@ -266,6 +266,7 @@ public class TileArchiveWriter {
boolean lastIsFill = false;
List<TileSizeStats.LayerStats> lastLayerStats = null;
boolean skipFilled = config.skipFilledTiles();
var layerStatsSerializer = TileSizeStats.newThreadLocalSerializer();
var tileStatsUpdater = tileStats.threadLocalUpdater();
var layerAttrStatsUpdater = layerAttrStats.handlerForThread();
@ -320,7 +321,7 @@ public class TileArchiveWriter {
if ((!skipFilled || !lastIsFill) && bytes != null) {
tileStatsUpdater.recordTile(tileFeatures.tileCoord(), bytes.length, layerStats);
List<String> layerStatsRows = config.outputLayerStats() ?
TileSizeStats.formatOutputRows(tileFeatures.tileCoord(), bytes.length, layerStats) :
layerStatsSerializer.formatOutputRows(tileFeatures.tileCoord(), bytes.length, layerStats) :
List.of();
result.add(
new TileEncodingResult(

Wyświetl plik

@ -38,7 +38,7 @@ import vector_tile.VectorTileProto;
* Utilities for extracting tile and layer size summaries from encoded vector tiles.
* <p>
* {@link #computeTileStats(VectorTileProto.Tile)} extracts statistics about each layer in a tile and
* {@link #formatOutputRows(TileCoord, int, List)} formats them as row of a TSV file to write.
* {@link TsvSerializer} formats them as row of a TSV file to write.
* <p>
* To generate a tsv.gz file with stats for each tile, you can add {@code --output-layerstats} option when generating an
* archive, or run the following an existing archive:
@ -52,13 +52,11 @@ import vector_tile.VectorTileProto;
public class TileSizeStats {
private static final int BATCH_SIZE = 1_000;
private static final CsvMapper MAPPER = new CsvMapper();
private static final CsvSchema SCHEMA = MAPPER
private static final CsvSchema SCHEMA = new CsvMapper()
.schemaFor(OutputRow.class)
.withoutHeader()
.withColumnSeparator('\t')
.withLineSeparator("\n");
private static final ObjectWriter WRITER = MAPPER.writer(SCHEMA);
/** Returns the default path that a layerstats file should go relative to an existing archive. */
public static Path getDefaultLayerstatsPath(Path archive) {
@ -120,6 +118,7 @@ public class TileSizeStats {
List<LayerStats> layerStats = null;
var updater = tileStats.threadLocalUpdater();
var layerStatsSerializer = TileSizeStats.newThreadLocalSerializer();
for (var batch : prev) {
List<String> lines = new ArrayList<>(batch.tiles.size());
for (var tile : batch.tiles) {
@ -130,7 +129,7 @@ public class TileSizeStats {
layerStats = computeTileStats(decoded);
}
updater.recordTile(tile.coord(), zipped.length, layerStats);
lines.addAll(TileSizeStats.formatOutputRows(tile.coord(), zipped.length, layerStats));
lines.addAll(layerStatsSerializer.formatOutputRows(tile.coord(), zipped.length, layerStats));
}
batch.stats.complete(lines);
}
@ -161,28 +160,32 @@ public class TileSizeStats {
stats.printSummary();
}
/** Returns the TSV rows to output for all the layers in a tile. */
public static List<String> formatOutputRows(TileCoord tileCoord, int archivedBytes, List<LayerStats> layerStats)
throws IOException {
int hilbert = tileCoord.hilbertEncoded();
List<String> result = new ArrayList<>(layerStats.size());
for (var layer : layerStats) {
result.add(lineToString(new OutputRow(
tileCoord.z(),
tileCoord.x(),
tileCoord.y(),
hilbert,
archivedBytes,
layer.layer,
layer.layerBytes,
layer.layerFeatures,
layer.layerGeometries,
layer.layerAttrBytes,
layer.layerAttrKeys,
layer.layerAttrValues
)));
}
return result;
/** Returns a {@link TsvSerializer} that can be used by a single thread to convert to CSV rows. */
public static TsvSerializer newThreadLocalSerializer() {
// CsvMapper is not entirely thread safe, and can end up with a BufferRecycler memory leak when writeValueAsString
// is called billions of times from multiple threads, so we generate a new instance per serializing thread
ObjectWriter writer = new CsvMapper().writer(SCHEMA);
return (tileCoord, archivedBytes, layerStats) -> {
int hilbert = tileCoord.hilbertEncoded();
List<String> result = new ArrayList<>(layerStats.size());
for (var layer : layerStats) {
result.add(writer.writeValueAsString(new OutputRow(
tileCoord.z(),
tileCoord.x(),
tileCoord.y(),
hilbert,
archivedBytes,
layer.layer,
layer.layerBytes,
layer.layerFeatures,
layer.layerGeometries,
layer.layerAttrBytes,
layer.layerAttrKeys,
layer.layerAttrValues
)));
}
return result;
};
}
/**
@ -195,11 +198,6 @@ public class TileSizeStats {
StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE))));
}
/** Returns {@code output} encoded as a TSV row string. */
public static String lineToString(OutputRow output) throws IOException {
return WRITER.writeValueAsString(output);
}
/** Returns the header row for the output TSV file. */
public static String headerRow() {
return String.join(
@ -240,6 +238,14 @@ public class TileSizeStats {
return result;
}
@FunctionalInterface
public interface TsvSerializer {
/** Returns the TSV rows to output for all the layers in a tile. */
List<String> formatOutputRows(TileCoord tileCoord, int archivedBytes, List<LayerStats> layerStats)
throws IOException;
}
/** Model for the data contained in each row in the TSV. */
@JsonPropertyOrder({
"z",

Wyświetl plik

@ -875,7 +875,7 @@ class PlanetilerTests {
feature(newPoint(128, 128), Map.of(
"attr", "value",
"name", "name value"
))
)).withId(3)
)
), results.tiles);
}
@ -964,7 +964,7 @@ class PlanetilerTests {
feature(newLineString(128, 128, 192, 192), Map.of(
"attr", "value",
"name", "name value"
))
)).withId(3 * 3 + 1)
)
), results.tiles);
}
@ -1089,7 +1089,7 @@ class PlanetilerTests {
"attr", "value",
"name", "name value",
"relname", "rel name"
))
)).withId(17 * 3 + 2)
)
), results.tiles);
}

Wyświetl plik

@ -279,7 +279,9 @@ public class TestUtils {
case UNKNOWN -> throw new IllegalArgumentException("cannot decompress \"UNKNOWN\"");
};
var decoded = VectorTile.decode(bytes).stream()
.map(feature -> feature(decodeSilently(feature.geometry()), feature.layer(), feature.attrs())).toList();
.map(
feature -> feature(decodeSilently(feature.geometry()), feature.layer(), feature.attrs()).withId(feature.id()))
.toList();
tiles.put(tile.coord(), decoded);
}
return tiles;
@ -467,12 +469,21 @@ public class TestUtils {
public record ComparableFeature(
GeometryComparision geometry,
String layer,
Map<String, Object> attrs
Map<String, Object> attrs,
Long id
) {
ComparableFeature(
GeometryComparision geometry,
String layer,
Map<String, Object> attrs
) {
this(geometry, layer, attrs, null);
}
@Override
public boolean equals(Object o) {
return o == this || (o instanceof ComparableFeature other &&
(id == null || other.id == null || id.equals(other.id)) &&
geometry.equals(other.geometry) &&
attrs.equals(other.attrs) &&
(layer == null || other.layer == null || Objects.equals(layer, other.layer)));
@ -484,6 +495,10 @@ public class TestUtils {
result = 31 * result + attrs.hashCode();
return result;
}
ComparableFeature withId(long id) {
return new ComparableFeature(geometry, layer, attrs, id);
}
}
public static ComparableFeature feature(Geometry geom, String layer, Map<String, Object> attrs) {

Wyświetl plik

@ -37,7 +37,7 @@ class TileSizeStatsTest {
assertEquals(2, entry1.layerAttrKeys());
assertEquals(2, entry1.layerAttrValues());
var formatted = TileSizeStats.formatOutputRows(TileCoord.ofXYZ(1, 2, 3), 999, stats);
var formatted = TileSizeStats.newThreadLocalSerializer().formatOutputRows(TileCoord.ofXYZ(1, 2, 3), 999, stats);
assertEquals(
"""
z x y hilbert archived_tile_bytes layer layer_bytes layer_features layer_geometries layer_attr_bytes layer_attr_keys layer_attr_values
@ -86,7 +86,7 @@ class TileSizeStatsTest {
assertEquals("b", entry2.layer());
assertEquals(1, entry2.layerFeatures());
var formatted = TileSizeStats.formatOutputRows(TileCoord.ofXYZ(1, 2, 3), 999, stats);
var formatted = TileSizeStats.newThreadLocalSerializer().formatOutputRows(TileCoord.ofXYZ(1, 2, 3), 999, stats);
assertEquals(
"""
z x y hilbert archived_tile_bytes layer layer_bytes layer_features layer_geometries layer_attr_bytes layer_attr_keys layer_attr_values

Wyświetl plik

@ -89,7 +89,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<version>3.7.1</version>
<dependencies>
<dependency>
<groupId>com.onthegomap.planetiler</groupId>

Wyświetl plik

@ -284,7 +284,7 @@
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
<configuration>
<skip>true</skip>
</configuration>
@ -328,12 +328,12 @@
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.10.0.2594</version>
<version>3.11.0.3922</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<version>0.8.12</version>
</plugin>
</plugins>
</pluginManagement>
@ -394,7 +394,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
<executions>
<execution>
<id>sign-artifacts</id>