lekdan commited on
Commit
e94a02c
·
verified ·
1 Parent(s): c59b1ff

Retry failed fetcher rows during updates

Browse files
crates/osu_fetcher/README.md CHANGED
@@ -70,7 +70,7 @@ editing the file.
70
  | `download` | Runs a bounded greedy worker pool. Each idle worker claims the next `pending wanted` row in `set_id` order and cycles mirrors per-set. See **Failure modes** below for the resilience guarantees. |
71
  | `status` | Prints `wanted / pending / in_progress / success / failed / missing` counts. |
72
  | `verify` | Walks `--archives-dir`, validates every `.osz`. With `--fix`, marks corrupt rows back to pending. |
73
- | `retry` | Resets every `failed` and `missing` row back to `pending` so the next download run will retry. |
74
 
75
  ## Global flags
76
 
@@ -174,10 +174,9 @@ State machine (per `set_id`):
174
  (every mirror returned 404)
175
  ```
176
 
177
- `retry` flips `{failed, missing}` back to `pending`. `requeue_in_progress`
178
- fires at the start of every `download` run (and also on `enumerate`'s
179
- startup as a safety net) to recover orphaned claims from a crashed prior
180
- run.
181
 
182
  ## Failure modes
183
 
@@ -234,7 +233,8 @@ touch disk.
234
  `failed` to `missing` (so you can distinguish "transient" from "no mirror
235
  has this anymore").
236
  - 5xx / network: pool advances. The row counts a regular `failed` and gets
237
- `attempts` incremented. Run `retry` later to reset.
 
238
  - 429: same as 5xx for outcome — but the per-mirror rate limiter holds the
239
  next call back automatically, so you don't need to babysit it.
240
  - Final failure logs include the full attempted mirror chain, for example
@@ -382,10 +382,10 @@ Coverage:
382
  - **Long runs**: tail the lockfile path printed by `download begin` to see
383
  the active PID. Ctrl-C is responsive even mid-flight.
384
  - **Disk full**: workers fail individual sets, the run continues. Free
385
- space and run `retry` to drain the failed bucket.
386
  - **Permanently missing maps** (DMCA / mapper deletions on every mirror):
387
- they accumulate in `missing`. Tolerated; not retried by `download` until
388
- you `retry` them explicitly.
389
  - **Rate-limit tuning**: if a mirror op asks you to slow down, lower
390
  `--<name>-rpm`. The update wrapper passes `480` rpm by default for every
391
  fetcher target.
 
70
  | `download` | Runs a bounded greedy worker pool. Each idle worker claims the next `pending wanted` row in `set_id` order and cycles mirrors per-set. See **Failure modes** below for the resilience guarantees. |
71
  | `status` | Prints `wanted / pending / in_progress / success / failed / missing` counts. |
72
  | `verify` | Walks `--archives-dir`, validates every `.osz`. With `--fix`, marks corrupt rows back to pending. |
73
+ | `retry` | Resets `failed` rows back to `pending` so the next download run will retry. Pass `--include-missing` to also retry rows that every mirror reported absent. |
74
 
75
  ## Global flags
76
 
 
174
  (every mirror returned 404)
175
  ```
176
 
177
+ `retry` flips `failed` back to `pending`. `retry --include-missing` also
178
+ resets `missing`. `requeue_in_progress` fires at the start of every
179
+ `download` run to recover orphaned claims from a crashed prior run.
 
180
 
181
  ## Failure modes
182
 
 
233
  `failed` to `missing` (so you can distinguish "transient" from "no mirror
234
  has this anymore").
235
  - 5xx / network: pool advances. The row counts a regular `failed` and gets
236
+ `attempts` incremented. The update wrapper runs `retry` before download, so
237
+ the next normal update tries it again.
238
  - 429: same as 5xx for outcome — but the per-mirror rate limiter holds the
239
  next call back automatically, so you don't need to babysit it.
240
  - Final failure logs include the full attempted mirror chain, for example
 
382
  - **Long runs**: tail the lockfile path printed by `download begin` to see
383
  the active PID. Ctrl-C is responsive even mid-flight.
384
  - **Disk full**: workers fail individual sets, the run continues. Free
385
+ space and rerun the update wrapper to drain the failed bucket.
386
  - **Permanently missing maps** (DMCA / mapper deletions on every mirror):
387
+ they accumulate in `missing`. Tolerated; not retried by normal updates
388
+ unless you run `retry --include-missing` or set `RETRY_MISSING=1`.
389
  - **Rate-limit tuning**: if a mirror op asks you to slow down, lower
390
  `--<name>-rpm`. The update wrapper passes `480` rpm by default for every
391
  fetcher target.
crates/osu_fetcher/src/main.rs CHANGED
@@ -158,7 +158,7 @@ enum Cmd {
158
  /// Validate every `.osz` in archives_dir; report corrupt files.
159
  Verify(VerifyArgs),
160
 
161
- /// Reset failed/missing rows back to pending so the next download retries them.
162
  Retry(RetryArgs),
163
 
164
  /// Walk every mirror's search surface and cross-verify candidates.
@@ -262,7 +262,11 @@ struct VerifyArgs {
262
  }
263
 
264
  #[derive(clap::Args, Debug)]
265
- struct RetryArgs {}
 
 
 
 
266
 
267
  #[derive(clap::Args, Debug)]
268
  struct DiscoverArgs {
@@ -342,7 +346,7 @@ async fn main() -> Result<()> {
342
 
343
  match &cli.cmd {
344
  Cmd::Status => cmd_status(state),
345
- Cmd::Retry(_) => cmd_retry(state),
346
  Cmd::Verify(args) => {
347
  cmd_verify(state, &cli.archives_dir, args, progress_enabled(&cli)).await
348
  }
@@ -416,9 +420,13 @@ fn cmd_status(state: Arc<StateDb>) -> Result<()> {
416
  Ok(())
417
  }
418
 
419
- fn cmd_retry(state: Arc<StateDb>) -> Result<()> {
420
- let n = state.reset_failed_to_pending()?;
421
- println!("reset {n} failed/missing rows back to pending");
 
 
 
 
422
  Ok(())
423
  }
424
 
 
158
  /// Validate every `.osz` in archives_dir; report corrupt files.
159
  Verify(VerifyArgs),
160
 
161
+ /// Reset failed rows back to pending so the next download retries them.
162
  Retry(RetryArgs),
163
 
164
  /// Walk every mirror's search surface and cross-verify candidates.
 
262
  }
263
 
264
  #[derive(clap::Args, Debug)]
265
+ struct RetryArgs {
266
+ /// Also retry rows that every mirror reported absent.
267
+ #[arg(long)]
268
+ include_missing: bool,
269
+ }
270
 
271
  #[derive(clap::Args, Debug)]
272
  struct DiscoverArgs {
 
346
 
347
  match &cli.cmd {
348
  Cmd::Status => cmd_status(state),
349
+ Cmd::Retry(args) => cmd_retry(state, args),
350
  Cmd::Verify(args) => {
351
  cmd_verify(state, &cli.archives_dir, args, progress_enabled(&cli)).await
352
  }
 
420
  Ok(())
421
  }
422
 
423
+ fn cmd_retry(state: Arc<StateDb>, args: &RetryArgs) -> Result<()> {
424
+ let n = state.reset_failed_to_pending(args.include_missing)?;
425
+ if args.include_missing {
426
+ println!("reset {n} failed/missing rows back to pending");
427
+ } else {
428
+ println!("reset {n} failed rows back to pending");
429
+ }
430
  Ok(())
431
  }
432
 
crates/osu_fetcher/src/state.rs CHANGED
@@ -43,8 +43,8 @@ pub const SCHEMA_VERSION: i64 = 2;
43
  /// `pending` rows are eligible for download workers. `in_progress` is held
44
  /// only while a worker is actively fetching; on startup, any leftover
45
  /// `in_progress` is reset to `pending` so a crashed worker doesn't strand its
46
- /// claim. Terminal states (`success`, `failed`, `missing`) require explicit
47
- /// user action (e.g. `retry`) to re-enter the queue.
48
  #[derive(Clone, Copy, Debug, Eq, PartialEq)]
49
  pub enum DownloadStatus {
50
  Pending,
@@ -448,15 +448,20 @@ impl StateDb {
448
  Ok(())
449
  }
450
 
451
- /// Reset terminal failed/missing rows back to pending so the next
452
- /// `download` run will retry them. Returns the count moved.
453
- pub fn reset_failed_to_pending(&self) -> Result<u64> {
454
  let conn = self.lock();
455
- let n = conn.execute(
 
 
 
 
 
456
  "UPDATE sets SET download_status = 'pending', last_error = NULL
457
- WHERE download_status IN ('failed', 'missing')",
458
- [],
459
- )?;
460
  Ok(n as u64)
461
  }
462
 
@@ -915,6 +920,73 @@ mod tests {
915
  assert_eq!(counts.pending, 0);
916
  }
917
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
918
  #[test]
919
  fn claim_next_pending_returns_lowest_id() {
920
  let db = StateDb::open_memory().unwrap();
 
43
  /// `pending` rows are eligible for download workers. `in_progress` is held
44
  /// only while a worker is actively fetching; on startup, any leftover
45
  /// `in_progress` is reset to `pending` so a crashed worker doesn't strand its
46
+ /// claim. Failed rows are retried by the update wrapper; missing rows require
47
+ /// explicit user action because every mirror already agreed they were absent.
48
  #[derive(Clone, Copy, Debug, Eq, PartialEq)]
49
  pub enum DownloadStatus {
50
  Pending,
 
448
  Ok(())
449
  }
450
 
451
+ /// Reset failed rows back to pending so the next `download` run retries
452
+ /// them. Returns the count moved.
453
+ pub fn reset_failed_to_pending(&self, include_missing: bool) -> Result<u64> {
454
  let conn = self.lock();
455
+ let predicate = if include_missing {
456
+ "download_status IN ('failed', 'missing')"
457
+ } else {
458
+ "download_status = 'failed'"
459
+ };
460
+ let sql = format!(
461
  "UPDATE sets SET download_status = 'pending', last_error = NULL
462
+ WHERE {predicate}"
463
+ );
464
+ let n = conn.execute(&sql, [])?;
465
  Ok(n as u64)
466
  }
467
 
 
920
  assert_eq!(counts.pending, 0);
921
  }
922
 
923
+ #[test]
924
+ fn retry_resets_failed_without_requeueing_missing_by_default() {
925
+ let db = StateDb::open_memory().unwrap();
926
+ db.upsert_wanted(&WantedRow {
927
+ set_id: 1,
928
+ ranked_status: RankedStatus::Ranked,
929
+ artist: None,
930
+ title: None,
931
+ creator: None,
932
+ api_last_updated: Some("2026-01-01T00:00:00Z"),
933
+ })
934
+ .unwrap();
935
+ db.upsert_wanted(&WantedRow {
936
+ set_id: 2,
937
+ ranked_status: RankedStatus::Ranked,
938
+ artist: None,
939
+ title: None,
940
+ creator: None,
941
+ api_last_updated: Some("2026-01-01T00:00:00Z"),
942
+ })
943
+ .unwrap();
944
+
945
+ db.finish_failed(&DownloadFailure {
946
+ set_id: 1,
947
+ mirror: "m",
948
+ error: "transient",
949
+ })
950
+ .unwrap();
951
+ db.finish_missing(&DownloadFailure {
952
+ set_id: 2,
953
+ mirror: "m",
954
+ error: "absent",
955
+ })
956
+ .unwrap();
957
+
958
+ assert_eq!(db.reset_failed_to_pending(false).unwrap(), 1);
959
+ let counts = db.status_counts().unwrap();
960
+ assert_eq!(counts.pending, 1);
961
+ assert_eq!(counts.failed, 0);
962
+ assert_eq!(counts.missing, 1);
963
+ }
964
+
965
+ #[test]
966
+ fn retry_can_include_missing_when_requested() {
967
+ let db = StateDb::open_memory().unwrap();
968
+ db.upsert_wanted(&WantedRow {
969
+ set_id: 1,
970
+ ranked_status: RankedStatus::Ranked,
971
+ artist: None,
972
+ title: None,
973
+ creator: None,
974
+ api_last_updated: Some("2026-01-01T00:00:00Z"),
975
+ })
976
+ .unwrap();
977
+ db.finish_missing(&DownloadFailure {
978
+ set_id: 1,
979
+ mirror: "m",
980
+ error: "absent",
981
+ })
982
+ .unwrap();
983
+
984
+ assert_eq!(db.reset_failed_to_pending(true).unwrap(), 1);
985
+ let counts = db.status_counts().unwrap();
986
+ assert_eq!(counts.pending, 1);
987
+ assert_eq!(counts.missing, 0);
988
+ }
989
+
990
  #[test]
991
  fn claim_next_pending_returns_lowest_id() {
992
  let db = StateDb::open_memory().unwrap();
docs/PIPELINE_RUNBOOK.md CHANGED
@@ -68,6 +68,8 @@ DISCOVER=1 # run mirror discovery; slower, useful periodically
68
  RANKED_FRONT_PAGES=10 # widen the ranked-desc front scan
69
  CLEAN_INPUT=0 # keep incoming_osz after success
70
  DOWNLOAD_CONCURRENCY=8 # number of greedy download workers
 
 
71
  COMPACT=1 # compact all_revisions after ingest; default is on
72
  COMPACT_TARGET_ROWS=1000000 # target rows per compacted all_revisions file
73
  COMPACT_WORKERS=4 # parallel table compaction workers
@@ -242,6 +244,9 @@ PY
242
 
243
  If fetch/download is interrupted, rerun `scripts/update_maps_v1.sh`. The
244
  fetcher state DB requeues stale `in_progress` rows on the next download run.
 
 
 
245
 
246
  If ingest is interrupted, rerun the same script with a fresh `BATCH_ID`.
247
  Committed archives are skipped by SHA-256. An incomplete chunk has no
 
68
  RANKED_FRONT_PAGES=10 # widen the ranked-desc front scan
69
  CLEAN_INPUT=0 # keep incoming_osz after success
70
  DOWNLOAD_CONCURRENCY=8 # number of greedy download workers
71
+ RETRY_FAILED=1 # retry previously failed acquisitions before download; default is on
72
+ RETRY_MISSING=0 # also retry known-missing rows; default is off
73
  COMPACT=1 # compact all_revisions after ingest; default is on
74
  COMPACT_TARGET_ROWS=1000000 # target rows per compacted all_revisions file
75
  COMPACT_WORKERS=4 # parallel table compaction workers
 
244
 
245
  If fetch/download is interrupted, rerun `scripts/update_maps_v1.sh`. The
246
  fetcher state DB requeues stale `in_progress` rows on the next download run.
247
+ The update wrapper also retries previously failed acquisitions by default.
248
+ Rows that all mirrors reported absent are left alone unless you set
249
+ `RETRY_MISSING=1`.
250
 
251
  If ingest is interrupted, rerun the same script with a fresh `BATCH_ID`.
252
  Committed archives are skipped by SHA-256. An incomplete chunk has no
scripts/update_maps_v1.sh CHANGED
@@ -24,6 +24,8 @@ MODE="${MODE:-0}"
24
  RANKED_FRONT_PAGES="${RANKED_FRONT_PAGES:-5}"
25
  DOWNLOAD_CONCURRENCY="${DOWNLOAD_CONCURRENCY:-16}"
26
  DOWNLOAD_LIMIT="${DOWNLOAD_LIMIT:-}"
 
 
27
  NDJSON_PARSE_WORKERS="${NDJSON_PARSE_WORKERS:-1}"
28
  NDJSON_PARSE_CHUNK_MB="${NDJSON_PARSE_CHUNK_MB:-8}"
29
  COMPACT="${COMPACT:-1}"
@@ -93,6 +95,8 @@ echo "upload=${UPLOAD}"
93
  echo "fetcher_progress=${FETCHER_PROGRESS}"
94
  echo "fetcher_rpm=${FETCHER_RPM}"
95
  echo "discover_search_rpm=${DISCOVER_SEARCH_RPM}"
 
 
96
  echo "compact=${COMPACT}"
97
  echo "compact_target_rows=${COMPACT_TARGET_ROWS}"
98
  echo "compact_batch_size=${COMPACT_BATCH_SIZE}"
@@ -205,8 +209,12 @@ if [ "$FETCH" = "1" ]; then
205
  "$FETCHER" "${fetcher_args[@]}" discover "${discover_args[@]}"
206
  fi
207
 
208
- if [ "${RETRY_FAILED:-0}" = "1" ]; then
209
- "$FETCHER" "${fetcher_args[@]}" retry
 
 
 
 
210
  fi
211
 
212
  "$FETCHER" "${fetcher_args[@]}" status
 
24
  RANKED_FRONT_PAGES="${RANKED_FRONT_PAGES:-5}"
25
  DOWNLOAD_CONCURRENCY="${DOWNLOAD_CONCURRENCY:-16}"
26
  DOWNLOAD_LIMIT="${DOWNLOAD_LIMIT:-}"
27
+ RETRY_FAILED="${RETRY_FAILED:-1}"
28
+ RETRY_MISSING="${RETRY_MISSING:-0}"
29
  NDJSON_PARSE_WORKERS="${NDJSON_PARSE_WORKERS:-1}"
30
  NDJSON_PARSE_CHUNK_MB="${NDJSON_PARSE_CHUNK_MB:-8}"
31
  COMPACT="${COMPACT:-1}"
 
95
  echo "fetcher_progress=${FETCHER_PROGRESS}"
96
  echo "fetcher_rpm=${FETCHER_RPM}"
97
  echo "discover_search_rpm=${DISCOVER_SEARCH_RPM}"
98
+ echo "retry_failed=${RETRY_FAILED}"
99
+ echo "retry_missing=${RETRY_MISSING}"
100
  echo "compact=${COMPACT}"
101
  echo "compact_target_rows=${COMPACT_TARGET_ROWS}"
102
  echo "compact_batch_size=${COMPACT_BATCH_SIZE}"
 
209
  "$FETCHER" "${fetcher_args[@]}" discover "${discover_args[@]}"
210
  fi
211
 
212
+ if [ "$RETRY_FAILED" = "1" ]; then
213
+ retry_args=()
214
+ if [ "$RETRY_MISSING" = "1" ]; then
215
+ retry_args+=(--include-missing)
216
+ fi
217
+ "$FETCHER" "${fetcher_args[@]}" retry "${retry_args[@]}"
218
  fi
219
 
220
  "$FETCHER" "${fetcher_args[@]}" status