Repository navigation
Charge only changed items against the custom sync budget (#1212, ADR 0072) - #1397
Conversation
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 |
Signed-off-by: Royce Lam <roycelam@umich.edu>
…nce, and a capped round is failed without an alert (deeplethe#1212, ADR 0072) The custom bound used to be derived from the audit history — the last `ok` run's `started_at`. That says when the previous round began, not how far it read: a capped round recorded `ok` too, so the lower bound could step over items that were never read, and the bound could not be cleared without rewriting the rows the same paragraph says to preserve. The bound becomes a value on the source, `sources.sync_checkpoint` — the column migration 0119 already added. NULL means "no bound", which is where every existing source starts, so the upgrade *is* the reset (ADR 0072's Recovery section): the first round re-reads the whole window, and unchanged content dedups into no new version and no new job. Custom's checkpoint advances to the start of the round that read the whole response rather than to now, so changes that arrive during a round stay in the next round's window. A capped round is recorded as failed, but it does not raise a source.sync_failed alert: it did not break, it stopped, and the next round resumes from the same place. `finish_sync` couples the status write to the alert, so the store grows `finish_sync_quiet` for this case. The run error says "changed 200 items" rather than "read", because the budget is charged against changed items. `sync_source` now returns its stats, so a test can assert that the whole response was read instead of only the slice the budget allowed. The 450-item case covers the three rounds it takes to read one window whole, and it reads the alerts table to show that the capped rounds raised no sync-failed alert. Signed-off-by: Royce Lam <roycelam@umich.edu>
…ext one, so 0072's status line can be closed (deeplethe#1212, ADR 0072) Signed-off-by: Royce Lam <roycelam@umich.edu>
3897ad0 to
9b06c4c
Compare
Keeps dev's reads_by_timestamp for the three ticket sources (deeplethe#1508 added gitlab_issues) and the custom checkpoint from this branch beside it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WaylandYang
left a comment
There was a problem hiding this comment.
Thanks — the 11-10 commits cover everything from the 10-24 review and the 10-25 note: a capped round is failed without the sync-failed alert, custom's bound is the source's own checkpoint (so existing sources start from NULL once), the 450-items/three-rounds case and discovered == 201 are asserted, and 0072 reads Implemented. I merged dev into the branch (a4201ee) to resolve the conflict with #1508's reads_by_timestamp; custom sits beside the three ticket sources. Merging.
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.