forge
Explore
Log in

Don't you dare go Hollow

Drop stale process-lock comments

Browse files at this commit

5ff42c5aa60b45bf3f15e5b371da5bf166c6634aAhmet Kaan GümüşParent: d111b5a
  • docs
    • drop stale process-lock comments
Show full message
📝 docs: drop stale process-lock comments

PRESENCE_LOCK and the other named process locks are gone. Comments and
README still talked as if they serialized writes.
README.mdmodified+14 -15
@@ -3678,14 +3678,12 @@ and pumps it while the delete runs would otherwise leave rows tagged with a
3678 blueprint that no longer exists, and since the grade label *is* the record id,3678 blueprint that no longer exists, and since the grade label *is* the record id,
3679 nothing could ever reach them again. The pump carries the other half of that —3679 nothing could ever reach them again. The pump carries the other half of that —
3680 an attach whose blueprint was deleted mid-run writes nothing and is reported as3680 an attach whose blueprint was deleted mid-run writes nothing and is reported as
3681-`blueprint_deleted`. Those two narrow the window rather than close it — a pump3681+`blueprint_deleted`. The attach's in-transaction claim is a `FOR KEY SHARE`
3682-that read the template alive can still commit its link after the sweep has run,3682+row lock on `class_blueprint` — the one strength a `DELETE` of the row
3683-since a read of one record and a write of another are not serialized against3683+cannot take — so a sourced attach that started first holds the row and the
3684-each other — so the delete and each individual attach are also serialized in3684+delete waits behind it; an attach starting after the delete finds no row
3685-process: the delete holds a write lease across its compare-and-set and its3685+and writes nothing. A pump takes that lock one course at a time, so a
3686-sweep, and a pump takes a read lease one course at a time, so a delete never3686+delete never waits behind a whole grade. The delete is also a
3687-waits behind a whole grade. The backend runs as a single process by decision, which
3688-is what makes an in-process lock the complete answer. The delete is also a
3689 compare-and-set on the list the call read: a `409` means somebody edited the3687 compare-and-set on the list the call read: a `409` means somebody edited the
3690 template in between, and nothing was written — though a template deleted and3688 template in between, and nothing was written — though a template deleted and
3691 recreated at the same grade with the same list satisfies that comparison, which3689 recreated at the same grade with the same list satisfies that comparison, which
@@ -4679,11 +4677,12 @@ database itself decides the winner. Three tiers:
4679 in flight lets that one write through. Damage: one write on a4677 in flight lets that one write through. Damage: one write on a
4680 just-archived term; nothing corrupts, and every later write is refused.4678 just-archived term; nothing corrupts, and every later write is refused.
4681 4679
4682-One in-process lock remains, and it is a *second* line, never the guarantee:4680+No process-wide domain lock remains. Exam-room presence is an in-process
4683-`PRESENCE_LOCK` guards the exam-room presence map (in-process socket state;4681+map (`ExamPresence` in `src/state.rs`; the mutex never spans an await).
4684-there is no row to conditional-write). The other two are gone with the old4682+There is no row to conditional-write for socket counts; the paired
4685-store: `CLAIM_LOCK` tamed a retry loop that `tx_with_retry` now owns, and4683+`left_at` stamp is an idempotent statement on the sitting. `CLAIM_LOCK`
4686-what `APPOINTMENT_LOCK` serialized is three database guarantees — the seat4684+tamed a retry loop that `tx_with_retry` now owns, and what
4685+`APPOINTMENT_LOCK` serialized is three database guarantees — the seat
4687 claim's one-statement write, the publish-overlap exclusion constraint, and4686 claim's one-statement write, the publish-overlap exclusion constraint, and
4688 the serializable approval.4687 the serializable approval.
4689 4688
@@ -4850,8 +4849,8 @@ src/
4850 recurring publish is expanded into rows sharing a series id)4849 recurring publish is expanded into rows sharing a series id)
4851 appointment.rs AppointmentId · AppointmentStatus · AppointmentReason ·4850 appointment.rs AppointmentId · AppointmentStatus · AppointmentReason ·
4852 Appointment (a booking on a slot; occupancy is the slot's4851 Appointment (a booking on a slot; occupancy is the slot's
4853- stored `occupied` cap-1 counter, overlap is derived under4852+ seat claim, publish overlap is the exclusion constraint,
4854- APPOINTMENT_LOCK)4853+ approval overlap is SERIALIZABLE)
4855 pomodoro.rs PomodoroSessionId · PomodoroSession (student focus log)4854 pomodoro.rs PomodoroSessionId · PomodoroSession (student focus log)
4856 pool_question.rs PoolQuestionId · PoolQuestionTitle · PoolQuestionBody ·4855 pool_question.rs PoolQuestionId · PoolQuestionTitle · PoolQuestionBody ·
4857 PoolQuestion (student-asked question; teacher-approved into4856 PoolQuestion (student-asked question; teacher-approved into
src/db/course.rsmodified+2 -2
@@ -261,8 +261,8 @@ pub async fn list_by_ids(db: &Database, ids: &[CourseId]) -> Result<Vec<Course>,
261 }261 }
262 262
263 /// Field-scoped: nothing guards the course row across the handler's read263 /// Field-scoped: nothing guards the course row across the handler's read
264-/// and this write (its `TERM_LOCK` window guards the *term* it links, and264+/// and this write (the term it links is guarded by its own refcount write,
265-/// the assign path takes no lock at all) — so a field the request omitted265+/// and the assign path takes no lock at all) — so a field the request omitted
266 /// (`None`) is not written at all. Sending the snapshot's value back266 /// (`None`) is not written at all. Sending the snapshot's value back
267 /// instead would revert a concurrent edit of that field; scoping the `SET`267 /// instead would revert a concurrent edit of that field; scoping the `SET`
268 /// alone does not stop that, the values have to come from the request.268 /// alone does not stop that, the values have to come from the request.
src/service/settings.rsmodified+5 -5
@@ -557,11 +557,11 @@ mod tests {
557 /// the list the store actually holds.557 /// the list the store actually holds.
558 ///558 ///
559 /// One of the two decides the removal, retires the kind and saves; the559 /// One of the two decides the removal, retires the kind and saves; the
560- /// other cannot even see the old list, because the whole snapshot-retire-560+ /// other cannot even see the old list, because retirement and save share
561- /// save pair is serialized (`SETTINGS_LOCK`). Interleaved, the second561+ /// one transaction. Interleaved, the second attempt would be told "already
562- /// attempt would be told "already retired", record no undo, win the562+ /// retired", record no undo, win the compare-and-set, and leave the first
563- /// compare-and-set, and leave the first attempt un-retiring the kind it had563+ /// attempt un-retiring the kind it had legitimately removed — off the list
564- /// legitimately removed — off the list and gradable.564+ /// and gradable.
565 #[tokio::test]565 #[tokio::test]
566 async fn two_edits_dropping_the_same_kind_leave_it_retired() {566 async fn two_edits_dropping_the_same_kind_leave_it_retired() {
567 let (db, _leases) = init_test_db().await;567 let (db, _leases) = init_test_db().await;
src/state.rsmodified+4 -4
@@ -68,10 +68,10 @@ pub fn scoped_key(slug: &Slug, key: &str) -> String {
68 /// closing one of two tabs never counts as having left the exam.68 /// closing one of two tabs never counts as having left the exam.
69 ///69 ///
70 /// The inner mutex only guards the map (never held across an await — keep it70 /// The inner mutex only guards the map (never held across an await — keep it
71-/// that way). Each count transition and its matching `left_at` DB write are71+/// that way). The matching `left_at` writes are idempotent single statements
72-/// serialized as one critical section by the exam room's `PRESENCE_LOCK`72+/// against the sitting's own row (see `web::exam_ws`): join clears the marker;
73-/// (see `web::exam_ws`), so "clear on join" and "stamp on last-out" stay73+/// last socket out stamps it only while `left_at IS NULL`. Concurrent last-outs
74-/// atomic with the counts they depend on.74+/// are harmless — only the first stamp lands.
75 #[derive(Clone, Default)]75 #[derive(Clone, Default)]
76 pub struct ExamPresence(Arc<Mutex<HashMap<String, usize>>>);76 pub struct ExamPresence(Arc<Mutex<HashMap<String, usize>>>);
77 77
tests/integration.rsmodified+9 -10
@@ -21343,11 +21343,11 @@ async fn refreshing_a_question_recopies_its_template() {
21343 }21343 }
21344 21344
21345 /// A course PATCH is a field-scoped write. The handler reads the course, then21345 /// A course PATCH is a field-scoped write. The handler reads the course, then
21346-/// awaits a term lookup (and its `TERM_LOCK`) before saving, holding nothing21346+/// awaits a term lookup before saving, holding nothing over the course row
21347-/// over the course row itself — so a manager's teacher assignment can land in21347+/// itself — so a manager's teacher assignment can land in that window. A
21348-/// that window. A whole-row save from the stale struct would silently revert21348+/// whole-row save from the stale struct would silently revert the staffing.
21349-/// the staffing. Driven at the domain level: HTTP offers no way to interleave21349+/// Driven at the domain level: HTTP offers no way to interleave inside the
21350-/// inside the handler.21350+/// handler.
21351 #[tokio::test]21351 #[tokio::test]
21352 async fn a_course_patch_does_not_clobber_a_concurrent_teacher_assignment() {21352 async fn a_course_patch_does_not_clobber_a_concurrent_teacher_assignment() {
21353 use hezarfen_backend::db::course;21353 use hezarfen_backend::db::course;
@@ -22235,11 +22235,10 @@ async fn concurrent_duplicate_menu_publishes_conflict_not_500() {
22235 assert_eq!(common::total(&res.body), 1, "and exactly one menu exists");22235 assert_eq!(common::total(&res.body), 1, "and exactly one menu exists");
22236 }22236 }
22237 22237
22238-/// Two appends of one ledger id must both succeed: the id is the idempotence22238+/// Two appends of one ledger id must both succeed: the id is the store's
22239-/// key, so the loser reads back the winner's line instead of surfacing the22239+/// idempotence key, so the loser reads back the winner's line instead of
22240-/// duplicate-key error as a 500. Driven at the domain level on purpose — every22240+/// surfacing the duplicate-key error as a 500. Driven at the domain level
22241-/// HTTP path into the ledger runs under `MENU_LOCK`, which serializes the two22241+/// because that is the collision, not HTTP.
22242-/// writers before they can ever collide.
22243 #[tokio::test]22242 #[tokio::test]
22244 async fn concurrent_ledger_appends_of_one_id_write_one_line_not_a_500() {22243 async fn concurrent_ledger_appends_of_one_id_write_one_line_not_a_500() {
22245 use hezarfen_backend::db::meal_ledger;22244 use hezarfen_backend::db::meal_ledger;
tests/partial_patch_bank_questions.rsmodified+2 -2
@@ -1,8 +1,8 @@
1 //! A bank-template PATCH is a read-modify-write: the kind/choices/correct trio1 //! A bank-template PATCH is a read-modify-write: the kind/choices/correct trio
2 //! has to be re-submitted as a unit (choices carry their ids, and their2 //! has to be re-submitted as a unit (choices carry their ids, and their
3 //! pictures hang off those ids), so the row read, the merge and the write are3 //! pictures hang off those ids), so the row read, the merge and the write are
4-//! held together under the *writer* lease of `BANK_LOCK`. Without that, two4+//! a compare-and-set on the stored snapshot. Without that, two concurrent
5-//! concurrent partial PATCHes revert each other.5+//! partial PATCHes revert each other.
6 6
7 mod common;7 mod common;
8 8
tests/regress_appointments.rsmodified+1 -1
@@ -333,6 +333,6 @@ async fn an_answer_resolves_its_own_prompt_across_an_interleave() {
333 }333 }
334 334
335 // ---------------------------------------------------------------------------335 // ---------------------------------------------------------------------------
336-// The store property behind `APPOINTMENT_LOCK`.336+// The store property that replaced `APPOINTMENT_LOCK`.
337 // ---------------------------------------------------------------------------337 // ---------------------------------------------------------------------------
338 338
tests/regress_bank_images.rsmodified+4 -4
@@ -17,10 +17,10 @@
17 //!17 //!
18 //! These two need no server, so they run in CI by default. The *raced* halves18 //! These two need no server, so they run in CI by default. The *raced* halves
19 //! of the same three holes live beside the code they test, in19 //! of the same three holes live beside the code they test, in
20-//! `bank_question_image`'s own test module, where `init_test_server` and20+//! `bank_question_image`'s own test module, where `init_test_server` is in
21-//! `RACE_LOCK` are in reach: the store's conflict detection is their subject,21+//! reach: the store's conflict detection is their subject, and re-spelling
22-//! and re-spelling the real bootstrap out here would be a hand-kept copy that22+//! the real bootstrap out here would be a hand-kept copy that drifts silently
23-//! drifts silently the first time migration or router construction changes.23+//! the first time migration or router construction changes.
24 24
25 mod common;25 mod common;
26 26
tests/regress_course_delete.rsmodified+9 -17
@@ -1,24 +1,16 @@
1 //! A course delete must take every attempt under it with it — the same hole1 //! A course delete must take every attempt under it with it — the same hole
2-//! `regress_exam_delete` pins one level down, and the same lease.2+//! `regress_exam_delete` pins one level down.
3 //!3 //!
4 //! `delete_course` cascades the course's exams *and their attempts*, and an4 //! `delete_course` cascades the course's exams *and their attempts*, and an
5 //! attempt is still the one exam child whose write cannot collide with that5 //! attempt is still the one exam child whose write cannot collide with that
6-//! sweep: its create rides `cap::claim_and_create` against the *student's* row,6+//! sweep on a key: its create rides `cap::claim_and_create` against the
7-//! which this cascade never touches. So the sweep and a start in flight can7+//! *student's* row, which this cascade never touches. The exam row lock
8-//! both commit, and only `EXAM_LOCK.write()` keeps them apart.8+//! (`FOR UPDATE` on start, `DELETE` waiting behind it) is what keeps the
9+//! sweep and a start from both committing.
9 //!10 //!
10-//! **Its own test binary on purpose.** `EXAM_LOCK` is process-wide, so this11+//! The two cascade tests below fire the delete at [`Course::delete`] rather
11-//! test and `regress_exam_delete`'s share it across two unrelated databases12+//! than at `DELETE /courses/{id}`: the defects they pin live in that
12-//! when they run in one binary: the neighbour holds the writer lease through13+//! transaction's SQL, and neither one needs a race to show.
13-//! its own one-second window, the start here queues behind it, and the timeline
14-//! this test is built on stops holding. It was mutation-proven red alone and
15-//! green — on the *broken* code — beside that neighbour. Anything else added
16-//! here must not take `EXAM_LOCK` either.
17-//!
18-//! Which is why the two cascade tests below fire the delete at
19-//! [`Course::delete`] rather than at `DELETE /courses/{id}`: the handler takes
20-//! the writer lease, the defects they pin live in that transaction's SQL, and
21-//! neither one needs a race to show.
22 14
23 mod common;15 mod common;
24 16
@@ -33,7 +25,7 @@ use hezarfen_backend::domain::course::CourseId;
33 use hezarfen_backend::domain::exam::ExamId;25 use hezarfen_backend::domain::exam::ExamId;
34 use serde_json::json;26 use serde_json::json;
35 27
36-/// Delete `course` the way the handler would, minus its `EXAM_LOCK` lease.28+/// Delete `course` at the store, bypassing HTTP.
37 async fn drop_course(db: &hezarfen_backend::database::Database, course: &str) {29 async fn drop_course(db: &hezarfen_backend::database::Database, course: &str) {
38 let row = course::read(db, &CourseId::from_key(course))30 let row = course::read(db, &CourseId::from_key(course))
39 .await31 .await
tests/regress_exam_delete.rsmodified+7 -6
@@ -6,13 +6,14 @@
6 //! contends on a single key and the store aborts a side. An attempt cannot do6 //! contends on a single key and the store aborts a side. An attempt cannot do
7 //! that: its create rides `cap::claim_and_create` against the *student's* row7 //! that: its create rides `cap::claim_and_create` against the *student's* row
8 //! (`exam_sat_total`), which this delete never touches, so nothing collides and8 //! (`exam_sat_total`), which this delete never touches, so nothing collides and
9-//! the freeze/existence gate is a plain read. `start_attempt` has always held9+//! the freeze/existence gate is a plain read. The start path now takes
10-//! `EXAM_LOCK.write()` from its exam read through the insert; `delete_exam`10+//! `FOR UPDATE` on the exam row from the exam read through the insert, so a
11-//! held nothing at all, and that asymmetry is what let a sitting start inside11+//! delete waits behind an in-flight start and a start after the delete finds
12-//! the delete window and outlive the exam.12+//! no row. The old hole was that `start_attempt` held a process
13+//! `EXAM_LOCK.write()` while `delete_exam` held nothing.
13 //!14 //!
14-//! This suite drives the real handlers, because the lease being tested lives in15+//! This suite drives the real handlers: the gates live on the HTTP path as
15-//! the web layer and no domain call can observe it.16+//! well as the store.
16 17
17 mod common;18 mod common;
18 19
tests/regress_homework_orphans.rsmodified+13 -12
@@ -83,9 +83,9 @@ async fn course_with_student(
83 (course, subject, student, student_id)83 (course, subject, student, student_id)
84 }84 }
85 85
86-/// The upload streams its body *before* it takes `HOMEWORK_LOCK`, and the86+/// The upload used to stream its body *before* it took `HOMEWORK_LOCK`, and
87-/// homework snapshot it acts on was read before that stream — so a delete87+/// the homework snapshot it acted on was read before that stream — so a delete
88-/// (which takes and releases the write lease inside that window) leaves the88+/// (which took and released the write lease inside that window) left the
89 /// handler holding a homework that is gone. It then auto-created a submission89 /// handler holding a homework that is gone. It then auto-created a submission
90 /// under it, credited both badge counters, wrote a blob and a file row, and90 /// under it, credited both badge counters, wrote a blob and a file row, and
91 /// answered `201`. Every route to any of that goes through the vanished91 /// answered `201`. Every route to any of that goes through the vanished
@@ -440,12 +440,12 @@ async fn a_grade_under_a_vanished_homework_is_refused() {
440 assert_eq!(over_http.status, StatusCode::NOT_FOUND);440 assert_eq!(over_http.status, StatusCode::NOT_FOUND);
441 }441 }
442 442
443-/// `delete_course` took `EXAM_LOCK` and nothing else, while its cascade sweeps443+/// `delete_course` used to take `EXAM_LOCK` and nothing else, while its cascade
444-/// the course's homework, submissions, files and results. Grading holds444+/// swept the course's homework, submissions, files and results. Grading used
445-/// `HOMEWORK_LOCK.write()` across a transaction that only *reads* the homework,445+/// to hold `HOMEWORK_LOCK.write()` across a transaction that only *read* the
446-/// and the store conflict-checks write sets rather than read sets — so the446+/// homework, and the store conflict-checked write sets rather than read sets —
447-/// sweep ran on a snapshot without the grade and both committed: an orphan447+/// so the sweep ran on a snapshot without the grade and both committed: an
448-/// `homework_result` under a vanished homework, readable ever after at448+/// orphan `homework_result` under a vanished homework, readable ever after at
449 /// `GET /homework/{id}/result`, which has no existence check of its own.449 /// `GET /homework/{id}/result`, which has no existence check of its own.
450 ///450 ///
451 /// The window is the grade's, not the delete's: a course delete is refused451 /// The window is the grade's, not the delete's: a course delete is refused
@@ -648,9 +648,10 @@ async fn a_student_sees_only_themselves_in_an_assigned_subset() {
648 648
649 /// A file add and a file delete on one submission write the same row — the649 /// A file add and a file delete on one submission write the same row — the
650 /// upload claims its seat on it, the delete re-stamps it — and both handlers650 /// upload claims its seat on it, the delete re-stamps it — and both handlers
651-/// hold only `HOMEWORK_LOCK.read()`, so they contend by design. The delete sent651+/// used to hold only `HOMEWORK_LOCK.read()`, so they contended by design. The
652-/// its cascade through a plain `db.query`, unlike every sibling in the module,652+/// delete sent its cascade through a plain `db.query`, unlike every sibling in
653-/// so a lost round came back as a 500 on a request that had written nothing.653+/// the module, so a lost round came back as a 500 on a request that had written
654+/// nothing.
654 ///655 ///
655 /// The window is the *delete's* own — the retry-less side has to be the one656 /// The window is the *delete's* own — the retry-less side has to be the one
656 /// holding a stale write when the other commits, or nothing it does can be657 /// holding a stale write when the other commits, or nothing it does can be
tests/regress_role_sweep.rsmodified+4 -3
@@ -118,9 +118,10 @@ async fn hold_the_sweep(table: &str, db: &Database) {
118 /// transaction open for seconds against the shared Postgres server, so run in118 /// transaction open for seconds against the shared Postgres server, so run in
119 /// parallel they push each other clean out of their windows: measured, all119 /// parallel they push each other clean out of their windows: measured, all
120 /// three then pass on code with the claim removed, while serialized all three120 /// three then pass on code with the claim removed, while serialized all three
121-/// fail it. Same trap as the process-wide `EXAM_LOCK` note in121+/// fail it. Same trap as two race suites sharing one process-wide lock across
122-/// `regress_course_delete`, and the guard is handed back into a binding that122+/// unrelated databases: the neighbour holds the lease through its window, this
123-/// lives for the whole test the way `init_test_server`'s does.123+/// start queues, and the timeline stops holding. The guard is handed back into
124+/// a binding that lives for the whole test the way `init_test_server`'s does.
124 static ONE_WINDOW_AT_A_TIME: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());125 static ONE_WINDOW_AT_A_TIME: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
125 126
126 /// Start the demotion and wait until it is *inside* the held window, then hand127 /// Start the demotion and wait until it is *inside* the held window, then hand