Repository navigation
feat(raster): Mosaic Rasters on a thread of its own, with Cancel (#2907) - #2936
Conversation
…ngeos#2907) raster.mosaic joins workflows::IN_BACKGROUND: the session is read first (the layers shared, the names and the path), and the files are read, checked and copied on the thread, with progress and Cancel. Its GeoTIFF is written beside the destination and put in place as the raster is added. What it answers and says is the same; everything but the app's dispatch still runs it in place. Part 1 of opengeos#2907: the Workflows pane's section comes next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Caution CodeRabbit couldn't post its review summary. Error details
|
| let there = s.finish_raster("raster.mosaic", id, &p).unwrap(); | ||
| assert_eq!(said(&s, mark, &path_there), said_here, "{inputs}"); | ||
| assert_eq!(cells(&s, &there), cells(&s, &here), "{inputs}"); | ||
| assert!((here.get("path").is_some(), there.get("path").is_some()) == (file.is_some(), file.is_some()), "{here} {there}"); |
There was a problem hiding this comment.
Nit: this assert! compares a tuple built from here/there against a tuple that repeats file.is_some(), so a failure message doesn't say which side differs. An assert_eq! with each side's own value reads more clearly and points at the case that broke:
| assert!((here.get("path").is_some(), there.get("path").is_some()) == (file.is_some(), file.is_some()), "{here} {there}"); | |
| assert_eq!((here.get("path").is_some(), there.get("path").is_some()), (file.is_some(), file.is_some()), "{here} {there}"); |
Category: quality
There was a problem hiding this comment.
Agreed, assert_eq! would name the side that differs; the assertion itself is right, so I'm leaving it, and the rows that shadows the total in Tiles::join (imagery.rs:2164, 2168), for a push needed for another reason, or the release quality pass.
On the review's other two points, the description is updated:
- Command Search doesn't reach it.
search_disabled(chrome.rs:1275) greys a command that has a required parameter and no entry insearch_action, and the palette runs only the rows it doesn't grey (chrome.rs:1468).inputsis required andraster.mosaichas no entry, so nothing reacheslib.rs:3399with it yet. The intro now says so, and Reaches says it the same way. - Memory now gives the multiples. They are from the code:
cargo xtask memoryhas table scenarios only (xtask/src/memory.rs,scenarios).
Code reviewI found no bugs, crash paths, security problems or performance regressions in the changed code. I could not build or run the tests (no shell here), so the checks below are by reading only. I checked:
No earlier review threads exist on this PR, so there were no concerns to skip. BugsNone found. SecurityNone found. PerformanceNone found. Quality
AGENTS.md
Earlier concerns left alone: 0 (no prior threads). Change sizeCompared with the base branch (merge base e7f6bcf to PR head 07d9050), as recorded in
|
📖 Docs previewCommit |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| let (dc, dr) = ((pc - c0) as usize, (pr - r0) as usize); | ||
| let (rows, width) = (r.height as usize, r.width as usize); | ||
| let piece = (MOSAIC_PIECE / width.max(1)).max(1); | ||
| for (out, b) in bands.iter_mut().zip(&r.bands) { |
There was a problem hiding this comment.
Performance (not a defect, so it may wait for the release quality pass): the copy runs on one thread, but the bands are independent parts. Each band writes only its own out buffer and reads only its own r.bands[i], so the band loop could run on rustgis_data::threads workers (scoped, with Builder::spawn_scoped, and one thread below a size threshold) with the same output bit for bit. AGENTS.md's "Use the threads" rule asks for this where practical. The PR does not say whether threading was considered, and its timings are not measured, so this is worth a look once the thread is in place.
Category: performance
There was a problem hiding this comment.
Agreed it's worth doing, and left for later, on purpose:
- This PR only moves the run. The band loop in
Tiles::join(crates/engine/src/cmd/imagery.rs, from line 2165) is the one on main (e7f6bcf2, line 2162), with Cancel and progress added. Its cells, answer and file are checked equal to a run in place (a_mosaic_made_on_another_thread_is_the_one_made_here), and threading the copy is a change of another kind, to measure on its own. - Cancel and progress are per thread.
rustgis_data::progresskeeps them in athread_local!(crates/data/src/progress.rs, line 25), so workers would need the run's state handed to them, and the countlong_commandssweeps (crates/engine/src/tests/cancellation.rs) would no longer be in a fixed order. - Nothing is measured yet: a single-band mosaic, the common case, has one part, so a gain would have to be shown on multi-band inputs first.
It fits #2907's part 2 or a follow-up of its own, with timings.
Code reviewI found no bugs or security issues in the changed code. The main risks I checked (cancel and staging, the Bugs: None found.
Security: None found. The Performance:
Quality:
AGENTS.md: No rule breaks found. Checked against the "Never silent", "Never hold the window", "Size for real data", and "Reach every surface" sections, and the cancellation and command-surface lists were updated.
Already raised, not re-posted: 1 (the Change sizeCompared with the base branch: the whole PR against main (merge base e7f6bcf to PR head 07d9050).
|
…a thread (opengeos#2907) (opengeos#3039) * feat(workflows): a Mosaic Rasters section that runs raster.mosaic on a thread (opengeos#2907) The Workflows pane's Mosaic Rasters section lists the rasters to join in order (layers, and on the desktop files not on the map), a name, and on the desktop a GeoTIFF to write or none. It runs through the pane's run, so the desktop app starts raster.mosaic on a thread of its own with its progress and Cancel in the pane (the path from opengeos#2936). It is listed in the Workflows menu, and Command Search now opens it instead of greying raster.mosaic. Closes opengeos#2907 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(workflows): another project opening empties the Mosaic list of its layers (opengeos#2907) The list's layers were dropped by name only, so a raster of the same name in the newly opened project kept its row and Mosaic joined that layer instead. The section now remembers the project its layers are from (Session::opened) and drops them, files kept, when another one opens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(workflows): the Mosaic list offers a name two layers share once, and says so (opengeos#2907) Commands find a raster by its name, case aside (layer_by_name), so with "DEM" listed the section offered "dem", which the mosaic read as "DEM" again. Names are now compared case aside, a name an earlier layer has is offered once, and the section says only the first can be joined. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(workflows): the Mosaic list follows the map shown, and leaves out rasters named as a vector layer (opengeos#2907) The list's layers stayed when another map of the project was shown, so a same-named raster there was joined instead; the list is now tied to the project and its active map. A raster named, case aside, as a vector layer before it was offered and then refused by the command (layer_by_name finds the vector layer); it is now left out with the shared-name notice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(workflows): the Mosaic list knows its map by name, and waits while a listed name is shared (opengeos#2907) Deleting the map shown moved the next one to its index, so the list's layers stayed and a same-named raster there was joined; maps have names of their own, so the list is now tied to the shown map's name. A listed layer whose name another layer comes to have (renamed, or moved before it) would be read as the first one; Mosaic is now off until one is renamed, and the shared-name notice names it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: elpidioassinaturas <elpidiofilho@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Part of #2907 (part 1, the path). Part 2, the Mosaic section in the Workflows pane that calls it, comes after this.
raster.mosaiccan make its raster on a thread of its own in the desktop app, with progress and Cancel, as Polygons to Raster does since #2739. Until part 2 nothing in the app's windows asks for it: it has no pane, and Command Search lists it greyed ("it needs input",search_disabledinchrome.rs), asinputsis required.What changes
mosaic_rasters_work(cmd/imagery.rs) joinsworkflows::IN_BACKGROUND, andraster.mosaicbecomesmade_or_ran. The command line, Python, MCP, scripts, the Assistant and plugins still run it in place, through the same code.Arceach, no copy), which inputs are files, the name and the path. The checks on count and name come first, as now.write_plain_staged,Made::committing). A cancelled or abandoned run leaves the destination as it was and removes the temporary file. Cancel is looked at as it is encoded and every megabyte written.say_lossesis split so its lines can be made off the session (loss_lines)."ran", the internal key the other background raster commands have, is added to its parameters and tocommand-surface.txt.The cells, the answer and the file are the same.
Two differences in a failed run
Permissions
mosaic_reads_filestill decides what is a file, for the command and formosaic_stays_in_project, so #1234 holds: a plugin witheditalone mosaics project layers, and a file or apathneedsfiles. Handing over a run (ran) doesn't get round it: the named inputs are asked about all the same.Memory
As a multiple of the inputs' cells (4 bytes each), for tiles that don't overlap, so the result is the size of the inputs:
The inputs read from files are now let go of once joined, before anything is encoded. Layers stay in the project either way. The encoding is at most the result again (it is compressed), and several bands are also interleaved once. The result then stays in the project with its encoded copy, as before. Where tiles overlap, the inputs are more than the result.
These are from the code, not measured:
cargo xtask memorymeasures table workflows only (load, join, calculate, export, edits, save) and has no raster scenario.One case is new, as in #2739: a raster layer edited while a run reads it is copied (copy-on-write) until the run lets go of it.
Looks at Cancel: the long steps without one
The statistics of the result (
Raster::new), and reading a file in a format whose reader doesn't look. The GeoTIFF reader does look.Reaches
IN_BACKGROUNDcommand, but nothing sends it there yet; part 2 is the caller. The phone app's shell uses the same dispatch.raster.mosaic) on a thread of its own, with Cancel, started from the Workflows pane #2907 says why that is left out.Tests
a_mosaic_made_on_another_thread_is_the_one_made_here: layers, files and both, overlapping (the first wins), with and without a GeoTIFF. Cells, transform, answer, notices and file bytes match those of a run in place. Nothing is said and no file is put in place before it lands, and a run let go of leaves the existing file as it was and no other. Ten refusals give the same words in place and on a thread, and whether the start or the run gives them is checked. A file that can't be put in place (a folder is there) is refused with what the inputs had to say.long_commands: a mosaic of a layer, a file and a layer, written over an existing file. It is cancelled at each of its checks in turn and leaves the project and the files as they were.clip_resample_and_mosaic_run_with_imagery_offnow lands a mosaic as the app does too;plugin_mosaics_of_project_layers_need_no_fileshas the tworancases.cargo test -p rustgis-engine: 2,449 unit tests pass. Of the integration tests, onlyportable_projects::reload::wrong_geometry_missing_file…fails, on this computer, as it compares an operating system message that is in Portuguese here. After the last small edit, only the mosaic and cancellation tests were run again (11 pass).cargo fmt --check, clippy with-D warningson the crate with all targets,cargo xtask layers,test-hygiene,rowsandattribution.🤖 Generated with Claude Code
Summary by CodeRabbit
raster.mosaicnow runs in the background, so you can continue working while a mosaic is created.