Skip to content

Final downloader cleanup#18056

Merged
AskAlexSharov merged 8 commits intomainfrom
anacrolix/downlaoder-final
Dec 2, 2025
Merged

Final downloader cleanup#18056
AskAlexSharov merged 8 commits intomainfrom
anacrolix/downlaoder-final

Conversation

@anacrolix
Copy link
Copy Markdown
Contributor

@anacrolix anacrolix commented Nov 25, 2025

Fixes a few things that bothered me that weren't right in 3.1. #16532, #17664, #17310, #16654.

#16698 is not addressed here (not sure if I will, but testing this might make it worthwhile).

List of changes:

  • Downloader.Add is split into Seed and Download. This prevents allowing downloads to occur in parts of code that expect to only Seed (like in the pruning code). It also prevents incomplete/partial torrents being added. Download now blocks and logs synchronously until all requested snapshots are complete. This simplifies the API back and forth with the caller. Snapshot requests now include an appropriate name for the request set.
  • Download.Completed, SetLogPrefix are no longer required. These don't work well since Downloader can be shared, and those concepts don't support sharing.
  • A few logs that weren't clear they weren't related to the downloader/BitTorrent were adjusted.
  • A bunch of metrics in webseed requesting that aren't needed anymore were removed.
  • Download.AddTorrentsFromDisk can be called without breaking existing downloads. It only adds completed snapshots, it's assumed anything else would be a mistake. It's no longer the default anywhere.
  • torrent.TorrentSpec is not used directly anymore. It's been deprecated for a long time.
  • I fixed STOP_BEFORE_STAGE and STOP_AFTER_STAGE.
  • There's no longer snapshot "validation" on completion. We're trusting the torrent client to do the right thing, but also not asking it to download things that should already be complete.
  • Data is always rechecked if an infohash changes.
  • Torrent/metainfo files are retained on disk before initial sync completes. This means significantly faster start-up times if a sync is resumed midway.

@anacrolix anacrolix force-pushed the anacrolix/downlaoder-final branch 3 times, most recently from e5c2935 to dbbcab2 Compare November 25, 2025 23:41
Comment thread db/downloader/downloader.go Outdated
@anacrolix
Copy link
Copy Markdown
Contributor Author

Oops I was trying to figure out how to get linting to work and modified it. I'll restore it.

@anacrolix anacrolix force-pushed the anacrolix/downlaoder-final branch from 4b91260 to 5dbec1b Compare December 1, 2025 07:30
Doesn't actually help yet because nothing uses it further up the stack.
This finishes what is required for snapshot reset to do the right thing.
If data is complete but the infohash for which it is complete is unknown, we can't trust it.
@anacrolix anacrolix force-pushed the anacrolix/downlaoder-final branch from 0984914 to 44e195e Compare December 1, 2025 13:06
@AskAlexSharov AskAlexSharov merged commit cc44877 into main Dec 2, 2025
19 checks passed
@AskAlexSharov AskAlexSharov deleted the anacrolix/downlaoder-final branch December 2, 2025 02:11
AskAlexSharov pushed a commit that referenced this pull request Dec 5, 2025
I think it regenerated stuff because we moved to a newer grpc version.
AskAlexSharov added a commit that referenced this pull request Mar 16, 2026
## Summary

- Moves `AddTorrentsFromDisk` call from `initDownloader` (at startup,
before any sync) to an `afterSnapshotDownload` callback invoked once the
snapshot sync stage completes on the first sync cycle.
- This eliminates false-positive incomplete torrent reports that
occurred because we were registering on-disk snapshots before the sync
stage had a chance to complete them.
- The `afterDownload` callback is threaded through `StageSnapshotsCfg`,
`NewDefaultStages`, and `NewPipelineStages` with a `nil` default so
callers that don't need it are unaffected.
- Incomplete snapshot warnings after this callback are now flagged as
unexpected (sync just finished), with a comment noting the
preverified-set edge case that remains unresolved.

## Background

Issue #19435 first identified this problem: `AddTorrentsFromDisk` was
being called before initial sync status was checked, causing old or
stale `.torrent` files on disk to interfere with the sync stage's
ability to fetch the correct (preverified) versions of snapshots.

PR #19316 by @Giulio2002 addressed a related symptom — converting the
fatal "snapshot already loaded with different infohash" error in
`addPreverifiedSnapshotForDownload` into a warning — but this was
treating a symptom rather than the root cause.

Other related changes to this area:
- PR #18056 — "Final downloader cleanup": Changed `AddTorrentsFromDisk`
to only add completed snapshots (anything incomplete is assumed a
mistake), and removed it as a default at startup.
- PR #18270 — "Quick fix for --downloader.verify assertion": Fixed a
panic in `addCompleteTorrentFromMetainfo` when called from
`AddTorrentsFromDisk` on already-completed files (#18165).
- PR #15043 — "Fix a collection of downloader, snapshot sync and torrent
related issues": Earlier broad fix addressing how disk-loaded torrents
interact with preverified snapshots.
- PR #16655 — "Require torrents added from disk to complete on
`downloader.verify`": Enforced completion check for disk-loaded torrents
during verify.

@mh0lt — please take a look, particularly at the scenario where extra
snapshots land on disk that weren't part of the sync set (e.g. after an
upgrade or downgrade that changes the preverified set).

---------

Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
lupin012 pushed a commit that referenced this pull request Mar 17, 2026
## Summary

- Moves `AddTorrentsFromDisk` call from `initDownloader` (at startup,
before any sync) to an `afterSnapshotDownload` callback invoked once the
snapshot sync stage completes on the first sync cycle.
- This eliminates false-positive incomplete torrent reports that
occurred because we were registering on-disk snapshots before the sync
stage had a chance to complete them.
- The `afterDownload` callback is threaded through `StageSnapshotsCfg`,
`NewDefaultStages`, and `NewPipelineStages` with a `nil` default so
callers that don't need it are unaffected.
- Incomplete snapshot warnings after this callback are now flagged as
unexpected (sync just finished), with a comment noting the
preverified-set edge case that remains unresolved.

## Background

Issue #19435 first identified this problem: `AddTorrentsFromDisk` was
being called before initial sync status was checked, causing old or
stale `.torrent` files on disk to interfere with the sync stage's
ability to fetch the correct (preverified) versions of snapshots.

PR #19316 by @Giulio2002 addressed a related symptom — converting the
fatal "snapshot already loaded with different infohash" error in
`addPreverifiedSnapshotForDownload` into a warning — but this was
treating a symptom rather than the root cause.

Other related changes to this area:
- PR #18056 — "Final downloader cleanup": Changed `AddTorrentsFromDisk`
to only add completed snapshots (anything incomplete is assumed a
mistake), and removed it as a default at startup.
- PR #18270 — "Quick fix for --downloader.verify assertion": Fixed a
panic in `addCompleteTorrentFromMetainfo` when called from
`AddTorrentsFromDisk` on already-completed files (#18165).
- PR #15043 — "Fix a collection of downloader, snapshot sync and torrent
related issues": Earlier broad fix addressing how disk-loaded torrents
interact with preverified snapshots.
- PR #16655 — "Require torrents added from disk to complete on
`downloader.verify`": Enforced completion check for disk-loaded torrents
during verify.

@mh0lt — please take a look, particularly at the scenario where extra
snapshots land on disk that weren't part of the sync set (e.g. after an
upgrade or downgrade that changes the preverified set).

---------

Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants