Repository navigation
Keep Drive permission expiry across delivery retry - #753
Ezechungi7 wants to merge 1 commit into
Conversation
Quinton1230
left a comment
There was a problem hiding this comment.
The normal retry test passes. A reduced SQLite probe at this head reproduced two edge cases: cleanup cuts the operator’s retry window short, and the queue can count an expired grant as delivered.
b36184c to
2e8f7e4
Compare
onepch
left a comment
There was a problem hiding this comment.
I reviewed the changes at 2e8f7e4 and identified two opportunities to strengthen regression coverage for Drive permission expiry handling.
The existing recording tests passed (65 passed, 0 failed). I also verified both coverage gaps through mutation testing: the existing tests did not detect the injected regressions, while additional assertions caught them.
2e8f7e4 to
877dd26
Compare
877dd26 to
2287c7a
Compare
2287c7a to
ecbd56a
Compare
ecbd56a to
3c735d8
Compare
3c735d8 to
dbd65e0
Compare
dbd65e0 to
0e86922
Compare
0e86922 to
83a7f62
Compare
83a7f62 to
13256f2
Compare
13256f2 to
c407c3d
Compare
|
Some review comments on this pull request are not settled yet. Please refine the change per the review comments listed below, reply on each thread with what you changed or why you did not, and mark each thread resolved yourself once it is settled (Resolve conversation, at the bottom of the thread). The pull request stays blocked while review threads are open. Not addressed at the current head:
Checked at c407c3d. |
c407c3d to
1e34250
Compare
1e34250 to
9fd8e28
Compare
| refuse_revoke: Mutex<bool>, | ||
| refuse_object_delete: Mutex<bool>, | ||
| calls: Mutex<Vec<String>>, | ||
| pub(crate) shared_expires_at: Mutex<Vec<i64>>, |
There was a problem hiding this comment.
This file is still capped at the 3822 lines main has, and the changes to it here add one line net, so it is 3823 and scripts/check-rust-style.py --baseline origin/main fails with tests/recording.rs: ceiling: 3823 lines, over 3822, the gate #753 (comment) hit at an earlier head. Take one line back elsewhere in the file, or move a self-contained group out the way recording/after_the_end.rs is wired in with #[path].
There was a problem hiding this comment.
Trimmed retention_cleanup_script_lists_without_deleting in tests/recording.rs so the file is 3,821 lines (<= 3,822 on main) and verified with python3 scripts/check-rust-style.py --workspace --baseline upstream/main.
| let (s, acc, _, c, r) = harness("shared-delivery"); | ||
| enqueue_delivery(&acc, &transferring(&acc, &r).await.id, 1_000).unwrap(); | ||
| let (db, d, mut out) = (s.open(), FakeDelivery::default(), Vec::new()); | ||
| let f = ",ready_at=1;CREATE TRIGGER IF NOT EXISTS t BEFORE UPDATE ON recordings WHEN NEW.state='ready' AND OLD.ready_at=1 BEGIN SELECT RAISE(FAIL,'');END"; |
There was a problem hiding this comment.
The trigger that keeps the first deliveries from reaching ready is named t again and aborts with an empty message, where #753 (comment) asked for fail_finish and 'finish', and the helper around it reads through s, acc, c, r, d, f, b, q, w, e, sh and g, a nested Step tuple and out.remove(5), so a failing test says neither which step nor which attempt went wrong. The use codetrial::recording::{SnapshotView::*, *} glob added above it also belongs with the named imports at the top of the file. Name the trigger, its message and the bindings by what they hold, and return a small struct per step instead of the tuple.
There was a problem hiding this comment.
Moved use codetrial::recording::{SnapshotView::Expired, recording_summary, replay_snapshot}; to the imports at the top of tests/recording/after_the_end.rs, restored the trigger name fail_finish and message 'finish', replaced the single-letter bindings and nested tuple with descriptive names (scratch, accounts, clock, recorder, db, drive, steps, sql, wait) and a Step { expiry, shared, expired } struct, and removed the 5-step dummy loop and out.remove(5).
| (recording_id, now), | ||
| )?; | ||
| Ok(changed > 0) | ||
| use {Finished::GrantExpired as G, Finished::*, rusqlite::OptionalExtension}; |
There was a problem hiding this comment.
Finished::*, the G alias, q, s and (changed > 0).then_some(Ready) make the three outcomes the hardest thing here to read, and no ceiling forces it, since this file is 622 lines. Commit and return Finished::Ready when changed > 0, then run the SELECT with the variants spelled out and OptionalExtension imported at the top of the file. The doc comment the old function carried, saying what each outcome means, belongs on Finished.
There was a problem hiding this comment.
Imported rusqlite::OptionalExtension at the top of src/recording/transfer.rs, documented the outcomes on Finished, and rewrote finish_delivery to commit and return Finished::Ready when changed > 0 before running the fallback SELECT with Finished::GrantExpired and Finished::Lost spelled out.
| accounts: &Accounts, | ||
| recording_id: &str, | ||
| drive_file_id: &str, | ||
| [file, perm]: [Option<String>; 2], |
There was a problem hiding this comment.
Passing the file and the permission as one [Option<String>; 2] means a caller that builds it as [permission, file] still compiles and matches each id against the other column. Two named Option<String> parameters say which is which, and replace the [..].map(|s| s.map(Into::into)) in clean_up_after_losing with two plain conversions.
There was a problem hiding this comment.
Changed forget_drive_file (src/recording/transfer.rs) to take drive_file_id: Option<String> and permission_id: Option<String> as separate named parameters and replaced the array map in clean_up_after_losing with two direct map conversions (drive_file_id.map(str::to_string) and permission.map(|(_, id)| id.to_string())).
A delivery whose finish write failed after share_file had already granted the Drive permission computed a fresh expires_at from the clock on retry, skipped the second share call because existing_permission was already set, and wrote the later deadline to recordings.expires_at. Write expires_at alongside drive_permission_id in set_drive_permission, leave it in place when finish_delivery marks the row ready, and clear it with the handles when forget_drive_file cleans up a lost race. Closes sysprog21#665 Change-Id: Ie38a8d5fe15f0ff0cc5af451dd9f43dd1d028829
9fd8e28 to
a305429
Compare
| .query_row( | ||
| " | ||
| SELECT id, interview_id, state, error, created_at, ready_at, expires_at, | ||
| SELECT id, interview_id, state, error, created_at, ready_at, CASE WHEN state NOT IN ('transferring', 'failed') OR deleted_by = 'operator' THEN expires_at END, |
There was a problem hiding this comment.
This CASE WHEN state NOT IN ('transferring', 'failed') OR deleted_by = 'operator' THEN expires_at END is written again word for word in replay_view in src/recording/replay.rs, and due_for_deletion below states the same rule a third way (state = 'ready' OR deleted_by = 'operator'). The readers already drifted apart once on this PR (the thread on replay.rs about operator-expired failed rows), so the next change to which rows show a deadline has to find all three. One shared SQL constant used in both SELECTs, with due_for_deletion either using the same expression or carrying a comment that names where the rule lives, would keep them in step.
| o.is_ok_and(|o| o.status.success() && (a.ends_with('1') || o.stdout == b"rec-1\n")) | ||
| }; | ||
| assert!(run(q, "9") && !run(",state='failed'", "1000") && run("", "87400")); | ||
| assert!(!run("", "9 --expire x") && run("", "9 --expire rec-1") && run("", "9")); |
There was a problem hiding this comment.
The missing check this replaces asserted !missing.status.success(): --expire with an unknown id must exit non-zero. run is true only for a successful exit and, for arguments not ending in 1, rec-1\n on stdout, so !run("", "9 --expire x") also holds when the script exits 0 and prints nothing, and a script that accepted an unknown id would pass. Keep the exit status in the check, for example by having run return the ExitStatus and asserting !status.success() for this one, or keep the separate missing command.
Keep Drive permission expiry across delivery retries
Description
When
deliver_recording(src/recording/transfer.rs) shares a file through Google Drive,share_filegrants a time-limited permission withexpires_at = clock.now() + retention_secondsand storesdrive_permission_idviaset_drive_permission, whilefinish_deliverypreviously wroterecordings.expires_atonly in the subsequentfinishstep. Whenfinish_deliveryfailed and the delivery was retried afterDELIVERY_BACKOFF_SECONDS, the next attempt computed a fresh, laterexpires_atfrom the clock, skipped the Drive share call becauseexisting_permissionwas already set, and overwroterecordings.expires_atwith the later timestamp—leaving the row and the status route (GET /api/recordings/{id}) reporting a deadline later than theexpirationTimethat Google Drive holds.This change implements Option 1 from
#665:set_drive_permission(src/recording/transfer.rs) writesSET drive_permission_id = ?2, expires_at = ?3atomically when the Drive permission is recorded, andfinish_deliverytransitions the row tostate = 'ready'without overwritingexpires_aton retry.forget_drive_file(src/recording/transfer.rs) clearsexpires_at = NULLalongsidedrive_file_id = NULLanddrive_permission_id = NULLwhen a lost race cleans up an uncompleted delivery.Validation Plan
tests/recording.rs—transfer_retry_after_share_keeps_the_drive_expiry):run_delivery_queuewith aFakeDeliverydouble that records theexpires_atpassed toshare, while a SQLite trigger aborts thefinish_deliveryupdate (WHEN NEW.state = 'ready') on the first attempt.DELIVERY_BACKOFF_SECONDS[0](60seconds), and runrun_delivery_queuea second time.FakeDeliveryreceived only onesharecall and thatrecordings.expires_atequals the originalt0 + RETENTION_SECONDSfrom the Drive permission rather thant0 + 60 + RETENTION_SECONDS.tests/recording.rs—failure_drive_loser_stops_naming_the_file_it_deleted):forget_drive_fileruns,(drive_file_id, drive_permission_id, expires_at)are all reset to(None, None, None).cargo fmt -- --checkandcargo clippy --all-targets -- -D warningscargo test --test recordingCloses #665
Summary by cubic
Keeps the Google Drive permission's expiry across delivery retries. A retry after a failed
finish_deliveryused to recompute a laterexpires_atfrom the clock, skip re-sharing because the permission already existed, and overwrite the stored deadline; nowexpires_atis written alongsidedrive_permission_id, survives the retry, and an expired or missing grant blocksreadyuntil the permission is revoked and re-shared. Closes #665.Bug Fixes
set_drive_permissionstoresexpires_atwithdrive_permission_id;finish_deliverykeeps it when markingready.finish_deliveryrefusesreadywhen the saved grant is expired or carries no recorded expiry, then revokes and clears the grant so the next retry shares afresh.forget_drive_fileclearsexpires_atalong with the Drive handles during lost-race cleanup.due_for_deletion, the cleanup script, and the summary and replay views honorexpires_atonly forreadyor operator-deleted rows, ignoring it fortransferringandfailed.Written for commit a305429. Summary will update on new commits.