使用渗透快照模式创建 osm-pbf 的 Postgres 数据失败

Postgres data to osm-pbf creation failed using osmosis snapshot schema

我已经使用渗透快照模式将 pbf 导入到 postgres

现在想使用以下命令从该模式创建 pbf

osmosis --read-pgsql host=localhost database=osmosisv1 user=postgres password=postgres postgresSchema=contry_snapshot validateSchemaVersion=no --dataset-dump --write-pbf C:\usr\share\osm.pbf

但出现以下异常

SEVERE: Thread for task 1-read-pgsql failed
java.lang.RuntimeException: java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at org.openstreetmap.osmosis.pgsnapshot.v0_6.PostgreSqlDatasetReader.run(PostgreSqlDatasetReader.java:59)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.base/java.util.TimSort.mergeLo(TimSort.java:781)
        at java.base/java.util.TimSort.mergeAt(TimSort.java:518)
        at java.base/java.util.TimSort.mergeCollapse(TimSort.java:448)
        at java.base/java.util.TimSort.sort(TimSort.java:245)
        at java.base/java.util.Arrays.sort(Arrays.java:1515)
        at java.base/java.util.ArrayList.sort(ArrayList.java:1750)
        at java.base/java.util.Collections.sort(Collections.java:179)
        at org.openstreetmap.osmosis.core.sort.common.FileBasedSort.flushAddBuffer(FileBasedSort.java:89)
        at org.openstreetmap.osmosis.core.sort.common.FileBasedSort.add(FileBasedSort.java:118)
        at org.openstreetmap.osmosis.core.database.SortingStoreRowMapperListener.process(SortingStoreRowMapperListener.java:38)
        at org.openstreetmap.osmosis.core.database.SortingStoreRowMapperListener.process(SortingStoreRowMapperListener.java:17)
        at org.openstreetmap.osmosis.pgsnapshot.common.RowMapperRowCallbackListener.processRow(RowMapperRowCallbackListener.java:46)
        at org.springframework.jdbc.core.JdbcTemplate$RowCallbackHandlerResultSetExtractor.extractData(JdbcTemplate.java:1578)
        at org.springframework.jdbc.core.JdbcTemplateQueryStatementCallback.doInStatement(JdbcTemplate.java:440)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:376)
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:452)
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:457)
        at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.EntityDao.getFeaturelessEntity(EntityDao.java:208)
        at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.EntityDao.iterate(EntityDao.java:253)
        at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.EntityDao.iterate(EntityDao.java:279)
        at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.PostgreSqlDatasetContext.iterate(PostgreSqlDatasetContext.java:214)
        at org.openstreetmap.osmosis.dataset.v0_6.DumpDataset.process(DumpDataset.java:46)
        at org.openstreetmap.osmosis.pgsnapshot.v0_6.PostgreSqlDatasetReader.run(PostgreSqlDatasetReader.java:57)
        ... 1 more

Jun 18, 2021 10:05:17 AM org.openstreetmap.osmosis.core.Osmosis main
SEVERE: Execution aborted.
org.openstreetmap.osmosis.core.OsmosisRuntimeException: One or more tasks failed.
        at org.openstreetmap.osmosis.core.pipeline.common.Pipeline.waitForCompletion(Pipeline.java:146)
        at org.openstreetmap.osmosis.core.Osmosis.run(Osmosis.java:92)
        at org.openstreetmap.osmosis.core.Osmosis.main(Osmosis.java:37)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:330)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:47)

正如您看到的异常,它清楚地提到了以下错误

Comparison method violates its general contract!

这是因为 Comparator 是不可传递的,有 ID Comparator 并且数据库中的 id 是随机生成的,所以随机生成的 id 给这个比较器带来了问题

"Comparison method violates its general contract!"

conclusion : Randomly generated ids have to be in incremented way, should not contain negative values