Skip to content

fix(cli): merge lower zooms before higher ones with several threads - #280

Open
shimoncohen wants to merge 1 commit into
masterfrom
fix/cli-zoom-order
Open

shimoncohen wants to merge 1 commit into
masterfrom
fix/cli-zoom-order

Conversation

@shimoncohen

Copy link
Copy Markdown
Collaborator

With GENERAL__parallel__numOfThreads above 1, the CLI could start merging a higher-zoom batch while a lower-zoom batch read before it was still being written. Partly covered tiles are filled by upscaling the lower zoom already in the target, so the output depended on thread timing.

  • Each batch now waits until every earlier batch with a lower zoom has finished. Batches of the same zoom still run in parallel.
  • Single-thread runs are unchanged.

Tests: 5 new unit tests for the gate, and all 1,135 MergerLogic and 23 MergerService tests pass. On the z16 + z18 south Lebanon GPKG merge, the current master with 8 threads differed from its own single-thread output on 897 of 34,764 tiles, in all 3 runs. With this change, 3 runs at 8 threads are byte-identical to the single-thread output and take 29–37 s instead of 80 s.

Refs MAPCO-12827. The service has the same race between its per-zoom tasks, and this change does not cover it.

With GENERAL__parallel__numOfThreads above 1, threads take the next batch
and merge it at once, so a batch of a higher zoom could start while a batch
of a lower zoom read before it was still being written. A partly covered
tile is filled by upscaling the lower zoom already in the target, so the
output depended on timing: two 8-thread runs differed on a few tiles and
from the single-thread output on hundreds.

A new ZoomOrderGate in MergerLogic/Batching gives each batch a ticket in
read order. A batch waits until every earlier batch with a lower zoom has
completed. Batches of the same zoom still run in parallel. The ticket is
released in a finally, so a failing batch cannot block the others.

Refs MAPCO-12827 (the service side of the same race is not covered here).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant