Design a Reactive Database (Live Queries), stage 6 of 9: decide
Write the commit check
The committer receives a mutation's snapshot timestamp, its read set (index ranges) and its writes. It keeps the writes of recent commits in memory. Write the function that decides whether the mutation may commit.
System so far· 6 parts
Select a component to see what it is responsible for and which state it owns.
- 1Web and mobile apps → Sync servers: Subscribe and mutate
- 2Sync servers → Function runners: Run a function
- 3Function runners → Versioned store: Read at a snapshot
- 4Function runners → Committer: Writes plus read set
- 5Committer → Versioned store: Append in timestamp order
- 6Versioned store → Subscription tracker: Committed writes, in order
- 7Subscription tracker → Sync servers: These subscriptions changed
- 8Sync servers → Web and mobile apps: New results
- Request / response
- Asynchronous
- Server push
What you need to know
0 of 2 checks done
Validation asks one question about a time window: did anything committed between my snapshot and now touch what I read?
A single committer that assigns increasing timestamps in order makes that window well-defined, and lets the check and the append of the new commit happen as one step.
Check
A mutation's snapshot is timestamp 100. Which recent commits must it be checked against?Think first
The committer keeps only the last few seconds of commits in memory. A mutation arrives with a snapshot older than anything it still holds. What should it do?