Skip to content

Commit

Permalink
Add lz4 compression to planetiler
Browse files Browse the repository at this point in the history
- lz4 compressed files can be generated with libosmium based tools like osmium or python scripts using pyosmium like pyosmium-up-to-date
- lz4 compressed files are bigger (~15-20%) then zlib compressed files but much faster to produce and process
- this patch is in use by us for several month without any problems
  • Loading branch information
Flynn Marquardt committed Nov 16, 2024
1 parent b59c63e commit ce8b2c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions planetiler-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<artifactId>parquet-floor</artifactId>
<version>1.48</version>
</dependency>
<dependency>
<groupId>org.lz4</groupId>
<artifactId>lz4-java</artifactId>
<version>1.8.0</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import java.util.zip.Inflater;
import org.locationtech.jts.geom.Envelope;

import net.jpountz.lz4.LZ4Exception;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor;

/**
* Converts PBF block data into decoded entities. This class was adapted from Osmosis to expose an iterator over blocks
* to give more control over the parallelism.
Expand Down Expand Up @@ -74,6 +78,20 @@ private static byte[] readBlobContent(Fileformat.Blob blob) {
throw new FileFormatException("PBF blob contains incomplete compressed data.");
}
inflater.end();
} else if (blob.hasLz4Data()) {
final int decompressedLength = blob.getRawSize();
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4FastDecompressor decompressor = factory.fastDecompressor();
blobData = new byte[decompressedLength];
try {
int decompressedLength2 = decompressor.decompress(blob.getLz4Data().toByteArray(), 0, blobData, 0, decompressedLength);

Check warning on line 87 in planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java

View workflow job for this annotation

GitHub Actions / Analyze with Sonar

MAJOR CODE_SMELL

Remove this useless assignment to local variable "decompressedLength2". rule: java:S1854 (https://sonarcloud.io/organizations/onthegomap/rules?open=java%3AS1854&rule_key=java%3AS1854) issue url: https://sonarcloud.io/project/issues?pullRequest=1104&open=AZM648ju7mXae_-Xodyf&id=onthegomap_planetiler

Check warning on line 87 in planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java

View workflow job for this annotation

GitHub Actions / Analyze with Sonar

MINOR CODE_SMELL

Remove this unused "decompressedLength2" local variable. rule: java:S1481 (https://sonarcloud.io/organizations/onthegomap/rules?open=java%3AS1481&rule_key=java%3AS1481) issue url: https://sonarcloud.io/project/issues?pullRequest=1104&open=AZM648ju7mXae_-Xodyg&id=onthegomap_planetiler
if (decompressedLength != decompressedLength) {

Check warning on line 88 in planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java

View workflow job for this annotation

GitHub Actions / Analyze with Sonar

MAJOR BUG

Change this condition so that it does not always evaluate to "false" rule: java:S2583 (https://sonarcloud.io/organizations/onthegomap/rules?open=java%3AS2583&rule_key=java%3AS2583) issue url: https://sonarcloud.io/project/issues?pullRequest=1104&open=AZM648ju7mXae_-Xodye&id=onthegomap_planetiler

Check warning on line 88 in planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java

View workflow job for this annotation

GitHub Actions / Analyze with Sonar

MAJOR BUG

Correct one of the identical sub-expressions on both sides of operator "!=" rule: java:S1764 (https://sonarcloud.io/organizations/onthegomap/rules?open=java%3AS1764&rule_key=java%3AS1764) issue url: https://sonarcloud.io/project/issues?pullRequest=1104&open=AZM648ju7mXae_-Xodyh&id=onthegomap_planetiler
// System.out.println("uncompressed size mismatch: "+decompressedLength2+" != "+decompressedLength);
throw new FileFormatException("Unable to decompress PBF blob. uncompressed size mismatch");
}
} catch (LZ4Exception e) {
throw new FileFormatException("Unable to decompress PBF blob.", e);
}
} else {
throw new FileFormatException("PBF blob uses unsupported compression, only raw or zlib may be used.");
}
Expand Down

0 comments on commit ce8b2c1

Please sign in to comment.