📐 name what actually closes the homework freeze
Browse files at this commitcd6bccf0989d45d9f1bfe491ce4e4538ca196df3Parent: c391cb5- docs
- 📐 name what actually closes the homework freeze
2 changed files +27 -14
- src/domain/homework_result.rs +16 -7
- src/web/homework.rs +11 -7
src/domain/homework_result.rsmodified+16 -7
| @@ -128,14 +128,23 @@ impl HomeworkResult { | |||
| 128 | /// concurrent write to slip past. A submission that does not exist yet is | 128 | /// concurrent write to slip past. A submission that does not exist yet is |
| 129 | /// left alone — grading absent work must not conjure a hand-in (the report reads | 129 | /// left alone — grading absent work must not conjure a hand-in (the report reads |
| 130 | /// `submitted`/`missing`/`late` straight off that row). | 130 | /// `submitted`/`missing`/`late` straight off that row). |
| 131 | + /// | ||
| 132 | + /// That one case is where this function stops defending itself: a student's | ||
| 133 | + /// *first* hand-in committing between this grade and nothing-to-stamp would | ||
| 134 | + /// land unstamped, leaving a grade beside an editable submission. Nothing | ||
| 135 | + /// here forbids it — what forbids it is the caller. Grading holds | ||
| 136 | + /// `HOMEWORK_LOCK` (see `crate::web::homework`) for writing across this | ||
| 137 | + /// whole transaction while every student-side write holds it for reading across | ||
| 138 | + /// its own, and the two leases are mutually exclusive in the one process | ||
| 139 | + /// this backend runs as, so the interleaving never gets a window. | ||
| 131 | // | 140 | // |
| 132 | - // ponytail: that one case keeps a residual race — a student's *first* hand-in | 141 | + // ponytail: that makes the freeze depend on lock discipline at the call |
| 133 | - // committing between this grade and nothing-to-stamp lands unstamped, so a | 142 | + // sites, not on this row. Moving a student write's lease to *after* its |
| 134 | - // grade of never-submitted work can end up beside an editable submission. | 143 | + // database write — or sharding HOMEWORK_LOCK per homework — reopens the |
| 135 | - // The web layer's pre-flight read still refuses it whenever the grade landed | 144 | + // window with nothing to catch it. Closing it in the domain layer needs a |
| 136 | - // first, so only a genuine collision slips through. Closing it needs a row to | 145 | + // record both sides own (a per-(homework, user) row the grade can always |
| 137 | - // stamp: either a tombstone submission every read path learns to ignore, or | 146 | + // stamp); a tombstone submission is not it, since every read path would |
| 138 | - // moving the freeze onto a per-(homework, user) record both sides own. | 147 | + // have to learn to ignore it and one missed filter fabricates a hand-in. |
| 139 | pub async fn grade( | 148 | pub async fn grade( |
| 140 | homework: &HomeworkId, | 149 | homework: &HomeworkId, |
| 141 | user: &UserId, | 150 | user: &UserId, |
src/web/homework.rsmodified+11 -7
| @@ -44,13 +44,17 @@ use super::{ | |||
| 44 | 44 | ||
| 45 | /// Serializes the homework subsystem's cross-record check-then-writes, which | 45 | /// Serializes the homework subsystem's cross-record check-then-writes, which |
| 46 | /// `BEGIN…COMMIT` cannot (write skew) — the same reasoning as | 46 | /// `BEGIN…COMMIT` cannot (write skew) — the same reasoning as |
| 47 | -/// [`crate::web::exams::EXAM_LOCK`]. It orders requests but cannot cover a | 47 | +/// [`crate::web::exams::EXAM_LOCK`]. Every lease below is held across the |
| 48 | -/// round trip, so the rule it can no longer be trusted with is the freeze: a | 48 | +/// database write it guards, so within this one process it does order a full |
| 49 | -/// graded submission used to stay unedited because the "no grade yet" read and | 49 | +/// round trip — but the freeze no longer *rests* on that: a graded submission |
| 50 | -/// the write it licensed sat under one lease, with the database consulted in | 50 | +/// used to stay unedited only because the "no grade yet" read and the write it |
| 51 | -/// between. That rule moved into the database — grading stamps | 51 | +/// licensed sat under one lease. That rule now lives in the database too — |
| 52 | -/// [`crate::constant::SUBMISSION_GRADED_FIELD`] on the submission row and every | 52 | +/// grading stamps [`crate::constant::SUBMISSION_GRADED_FIELD`] on the |
| 53 | -/// student-side write carries `graded_by_result = NONE` as its own condition. | 53 | +/// submission row and every student-side write carries `graded_by_result = |
| 54 | +/// NONE` as its own condition. The one case the stamp cannot cover — grading | ||
| 55 | +/// work with no submission row yet — falls back to the lease pair, so a write | ||
| 56 | +/// lease must never stop spanning its own database call (see | ||
| 57 | +/// [`crate::domain::homework_result::HomeworkResult::grade`]). | ||
| 54 | /// | 58 | /// |
| 55 | /// What still leases it, honestly: | 59 | /// What still leases it, honestly: |
| 56 | /// - Write: the homework PATCH's orphan guard ([`update_homework`]), the | 60 | /// - Write: the homework PATCH's orphan guard ([`update_homework`]), the |