Repository navigation
fix(engine): record per-parent backfill progress as one watermark - #48
Merged
Merged
Conversation
A per-parent backfill (sessions per user, memberships per organization) checkpointed the full list of finished parent ids after every parent. The list grew with the parent stream and was rewritten at each boundary, so the bytes written were quadratic in the number of parents, and a document store's size limit ends the backfill outright: MongoDB's 16 MiB falls at roughly half a million users on the sessions stream, before the final state that would have cleared the list. Parents are now listed in id order and progress is one id, `doneThrough`: every parent sorting at or before it is done. WorkOS ids are time-ordered, so a parent created after a slice sorts past the watermark and the next slice lists it. The engine sorts the parent ids itself rather than trusting a database collation to agree with the comparison. A checkpoint written by an earlier release, with each parent recorded by id, is still honored on resume: its ids are carried until the watermark passes them, then dropped, so an in-flight sliced backfill survives the upgrade.
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryReplaces the growing list of finished parents with one
No actionable issues were found. Tests were not run during this review. Reviews (1) · Last reviewed commit: "fix(engine): record per-parent backfill ..." · Reviewed by Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sessionsper user, memberships per organization, directory users per directory) checkpointed the full list of finished parent ids after every parent. The list grew with the parent stream and was rewritten at each boundary, so the bytes written were quadratic in the number of parents, and a document store's size limit ends the backfill outright: MongoDB's 16 MiB document cap falls at roughly half a million users onsessions, before the final state that would have cleared the list. Surfaced by Greptile on feat(mongodb): add the MongoDB destination package #41.doneThrough: parents are listed in id order and every parent sorting at or before the watermark is done. WorkOS ids are time-ordered, so a parent created after a slice sorts past the watermark and the next slice lists it.order by idunder a non-C collation need not.doneParentsis never written afresh.packages/sync-engine/test/backfill.test.ts) over a stubbed destination: the watermark replaces the list, in-parent checkpoints carry it, the sort is the engine's, a late parent is picked up, and a legacy checkpoint is honored and shrinks. The Postgres and MySQL suites pass unchanged against real servers.