Skip to content

Commit

Permalink
tests and output max tile sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 16, 2023
1 parent 8f60eb7 commit 87ac5dd
Show file tree
Hide file tree
Showing 4 changed files with 446 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,79 +266,78 @@ private void tileEncoderSink(Iterable<TileBatch> prev) throws IOException {
List<TileStats.LayerStats> lastLayerStats = null;
boolean skipFilled = config.skipFilledTiles();

try (var tileStatsUpdater = tileStats.threadLocalUpdater()) {
for (TileBatch batch : prev) {
List<TileEncodingResult> result = new ArrayList<>(batch.size());
FeatureGroup.TileFeatures last = null;
// each batch contains tile ordered by tile-order ID ascending
for (int i = 0; i < batch.in.size(); i++) {
FeatureGroup.TileFeatures tileFeatures = batch.in.get(i);
featuresProcessed.incBy(tileFeatures.getNumFeaturesProcessed());
byte[] bytes, encoded;
List<TileStats.LayerStats> layerStats;
Long tileDataHash;
if (tileFeatures.hasSameContents(last)) {
bytes = lastBytes;
encoded = lastEncoded;
tileDataHash = lastTileDataHash;
layerStats = lastLayerStats;
memoizedTiles.inc();
var tileStatsUpdater = tileStats.threadLocalUpdater();
for (TileBatch batch : prev) {
List<TileEncodingResult> result = new ArrayList<>(batch.size());
FeatureGroup.TileFeatures last = null;
// each batch contains tile ordered by tile-order ID ascending
for (int i = 0; i < batch.in.size(); i++) {
FeatureGroup.TileFeatures tileFeatures = batch.in.get(i);
featuresProcessed.incBy(tileFeatures.getNumFeaturesProcessed());
byte[] bytes, encoded;
List<TileStats.LayerStats> layerStats;
Long tileDataHash;
if (tileFeatures.hasSameContents(last)) {
bytes = lastBytes;
encoded = lastEncoded;
tileDataHash = lastTileDataHash;
layerStats = lastLayerStats;
memoizedTiles.inc();
} else {
VectorTile en = tileFeatures.getVectorTileEncoder();
if (skipFilled && (lastIsFill = en.containsOnlyFills())) {
encoded = null;
layerStats = null;
bytes = null;
} else {
VectorTile en = tileFeatures.getVectorTileEncoder();
if (skipFilled && (lastIsFill = en.containsOnlyFills())) {
encoded = null;
layerStats = null;
bytes = null;
} else {
var proto = en.toProto();
encoded = proto.toByteArray();
bytes = switch (config.tileCompression()) {
case GZIP -> gzip(encoded);
case NONE -> encoded;
case UNKNWON -> throw new IllegalArgumentException("cannot compress \"UNKNOWN\"");
};
layerStats = TileStats.computeTileStats(proto);
if (encoded.length > config.tileWarningSizeBytes()) {
LOGGER.warn("{} {}kb uncompressed",
tileFeatures.tileCoord(),
encoded.length / 1024);
}
}
lastLayerStats = layerStats;
lastEncoded = encoded;
lastBytes = bytes;
last = tileFeatures;
if (archive.deduplicates() && en.likelyToBeDuplicated() && bytes != null) {
tileDataHash = generateContentHash(bytes);
} else {
tileDataHash = null;
var proto = en.toProto();
encoded = proto.toByteArray();
bytes = switch (config.tileCompression()) {
case GZIP -> gzip(encoded);
case NONE -> encoded;
case UNKNWON -> throw new IllegalArgumentException("cannot compress \"UNKNOWN\"");
};
layerStats = TileStats.computeTileStats(proto);
if (encoded.length > config.tileWarningSizeBytes()) {
LOGGER.warn("{} {}kb uncompressed",
tileFeatures.tileCoord(),
encoded.length / 1024);
}
lastTileDataHash = tileDataHash;
}
if (skipFilled && lastIsFill) {
continue;
lastLayerStats = layerStats;
lastEncoded = encoded;
lastBytes = bytes;
last = tileFeatures;
if (archive.deduplicates() && en.likelyToBeDuplicated() && bytes != null) {
tileDataHash = generateContentHash(bytes);
} else {
tileDataHash = null;
}
int zoom = tileFeatures.tileCoord().z();
int encodedLength = encoded == null ? 0 : encoded.length;
totalTileSizesByZoom[zoom].incBy(encodedLength);
maxTileSizesByZoom[zoom].accumulate(encodedLength);
tileStatsUpdater.recordTile(tileFeatures.tileCoord(), bytes.length, layerStats);
List<String> layerStatsRows = config.outputLayerStats() ?
TileStats.formatOutputRows(tileFeatures.tileCoord(), bytes.length, layerStats) :
List.of();
result.add(
new TileEncodingResult(
tileFeatures.tileCoord(),
bytes,
encoded == null ? 0 : encoded.length,
tileDataHash == null ? OptionalLong.empty() : OptionalLong.of(tileDataHash),
layerStatsRows
)
);
lastTileDataHash = tileDataHash;
}
if (skipFilled && lastIsFill) {
continue;
}
// hand result off to writer
batch.out.complete(result);
int zoom = tileFeatures.tileCoord().z();
int encodedLength = encoded == null ? 0 : encoded.length;
totalTileSizesByZoom[zoom].incBy(encodedLength);
maxTileSizesByZoom[zoom].accumulate(encodedLength);
tileStatsUpdater.recordTile(tileFeatures.tileCoord(), bytes.length, layerStats);

Check warning on line 325 in planetiler-core/src/main/java/com/onthegomap/planetiler/archive/TileArchiveWriter.java

View workflow job for this annotation

GitHub Actions / Analyze with Sonar

MAJOR BUG

A "NullPointerException" could be thrown; "bytes" is nullable here. rule: java:S2259 (https://sonarcloud.io/organizations/onthegomap/rules?open=java%3AS2259&rule_key=java%3AS2259) issue url: https://sonarcloud.io/project/issues?pullRequest=656&open=AYqYcGRt_50aaKHwDaU3&id=onthegomap_planetiler
List<String> layerStatsRows = config.outputLayerStats() ?
TileStats.formatOutputRows(tileFeatures.tileCoord(), bytes.length, layerStats) :
List.of();
result.add(
new TileEncodingResult(
tileFeatures.tileCoord(),
bytes,
encoded == null ? 0 : encoded.length,
tileDataHash == null ? OptionalLong.empty() : OptionalLong.of(tileDataHash),
layerStatsRows
)
);
}
// hand result off to writer
batch.out.complete(result);
}
}

Expand Down
Loading

0 comments on commit 87ac5dd

Please sign in to comment.