Repository navigation
Charge only changed items against the custom sync budget (#1212, ADR 0072) - #1397
rollroyces wants to merge 2 commits into
Conversation
Signed-off-by: Royce Lam <roycelam@umich.edu>
WaylandYang
left a comment
There was a problem hiding this comment.
Thanks, this is the shape 0072 asks for: the whole response is walked, only changed items count, and the second run reaches item 201. Before merge: (1) each capped run currently raises a SOURCE_SYNC_FAILED error alert via finish_sync(Some(err)); please record the run as failed with the message but skip the alert (see #1212). (2) Update 0072's status line and replace the #1246 reference in §Custom with this PR. (3) Add the 450-items/three-runs case from 0072's acceptance list, and assert discovered == 201. (4) Say "changed 200 items" rather than "read" in the run error.
|
Heads-up: #1359 (the GitHub/Jira half of 0072) changes the same |
What changes from the review
Rewritten to implement 0072 §Custom, which replaces what #1246 did. The maintainer's point was correct:
take(MAX_NEW_PER_SYNC)followed by afailedrun replays the same 200 items forever and never reaches item 201 — exactly what 0072 lists under Rejected.crates/utopia-server/src/ingest_sources.rs:SyncStats.incomplete: bool(wastruncated) — set only when processing stops with items still behind.stats.discovered = items.len()— the response size, not the number imported. The previous run logged(0 > 200)becausediscoveredwas never set.sync_customwalks the whole response. A localchangedcounter is charged only byIngestAction::Created/Updated;Unchanged/Moved/Duplicate/Tombstonedcost nothing. The loop breaks whenchangedreachesMAX_NEW_PER_SYNC, settingincomplete.sync_sourcegained a third match arm,Ok(stats) if stats.incomplete, which writes the run asfailed. Sincelast_successful_sync_startonly readsstatus = 'ok', the checkpoint stays at the last complete round and the next run re-sends the samesince. The run still records itscreated/updatedcounts, per 0072's "Keep the committed counts visible for incomplete runs".No store change:
last_successful_sync_startalready filtered onstatus = 'ok', so writingfailedis all that is needed to hold the cursor.Test
a_truncated_custom_batch_resumes_on_the_next_runinsource_checkpoint_tests.rs— serves 201 fresh items and callssync_sourcetwice:failed, error mentions stopping with more behind.Unchangedand cost no budget, so item 201 lands. The source endsok.Two CI issues from the previous review are fixed:
cargo fmt— ran it; the diff is clean.source_sync_runs_source_id_fkey— thesourcesINSERT now runs beforestart_run, so the foreign key resolves. (The old test inserted the source after creating a run row.)Scope
Refs #1212, notCloses— this covers the Custom half only. The GitHub and Jira halves of #1212 need the timestamp-group completion that 0072 specifies and are not in this PR.Verification
CI is green on this branch —
build,lint,test,migrations,backend,weball pass. Thetestjob runs against a real Postgres, soa_truncated_custom_batch_resumes_on_the_next_runactually executed there rather than skipping.Locally:
cargo fmt --all --checkandcargo clippy -p utopia-server --all-targets -- -D warningsboth pass. Clippy caught two problems in the first draft of this change, both fixed here — afield_reassign_with_defaulton thediscoveredassignment and anE0382borrow in the new test.