-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug: number of downloads for a torrent is reset #1356
Merged
josecelano
merged 7 commits into
torrust:develop
from
josecelano:1264-it-seems-persisted-data-about-torrents-is-not-loaded-from-database
Mar 5, 2025
Merged
Fix bug: number of downloads for a torrent is reset #1356
josecelano
merged 7 commits into
torrust:develop
from
josecelano:1264-it-seems-persisted-data-about-torrents-is-not-loaded-from-database
Mar 5, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… after upserting a peer When you upsert a new peer (announce requests) the swarm stats migth change if the peer announced that has completed the download. If that case we return `true` given the caller the opportunity to know if stats have changed. In the current implementation we get stats before and after upserintg the peer, and we compare them to check if they have changed. However stats migth have change due to a parallel (race condition) announce from another peer. This is the only way to know exactly if this announce request has altered the stats (incremented the number of downloads).
Now the `upsert_peer` fn returns `true`if the stats have changed. IN the other hand, stats migth have changed ebcuase there was a different paralell announce request (race condtions) so it migth not be needed. This removes unnecessary database queries to persits the stats.
…ted downloads for one torrent This will be used to preset the counter from the database when a noew torrent entry is added to the torrent repo after begin removing for a while (peerless torrents are removed). The process is: - A new torrent is announced and added to the torrent repo. - The downloads counter is 0. - One of the peers finishes downloading and the counter increases to 1. - The torrent is removed from the repo becuase none of the peer announce for a while. - A new peer announce the torrent. We have to preset the counter to 1 even if that peer has not completed downloading yet.
… of downloads for a torrent
…sited However, we still have to load the value counter from the database the first time the otrrent is added to the repository.
a054617
to
8f67f12
Compare
This fixed a bug: the number of donwloads for a torrent is not loaded from the database when the torrent is added to the in-memory torrent repository. It should be done when stats are enabled with the configuration option: persistent_torrent_completed_stat = true The patch is applied only to the torrent repository implementation we are using in prodcution (`CrossbeamSkipList<EntryMutexStd>`). The other implementations have this comment: ``` // todo: load persistent torrent data if provided ``` It was not implemented for the others becuase I'm considering taking the counter (for the number of downloads) out of the in-memory repository. And increase it by suing events triggered from the core tracker. I will open a new issue for that. If that's implemented we will need to remove this patch for the repository, meaning reverting cahnges in this commit.
ACK 06ef1d5 |
I've discarded the solution proposed in the PR description. The new solution is described here. I will open a new issue for it. |
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The number of downloads for a torrent is not persisted correctly.
Even when persistence is enabled, it does not work. There are two cases when the counter is reset:
Check the issue to know how to reproduce the bug.
Solution
Every time a new torrent entry is added in the torrent repository we need to load stats (also called persistent torrent, which only includes number of downloads currently) from the database. If persistence for stats is enabled.
Other considerations
1. Unused code
There is a method to load the counters for all torrents but it's not used in production code.
I guess it was added to load the information from the database when the tracker is restarted. However that's not enough because torrents are removed from the repository when they do not have peers (peerless torrents). That would work only if removing peerless torrents is disabled.
2. Better solution
I think there is a better solution than the one this PR applies. This PR is a temporary patch to fix the bug asap.
I would differentiate to different counters:
The counter 1 is what we have before merging this PR. The counter is reset every time the torrent is removed from the swarm. We can keep like it's now before merging this PR. This counter is handled at the in-memory torrent repository.
The new counter (counter 2) would be handled by the announce handler. After processing the announce request if the number of downloads has increased the handler also increases the historical counter. This new value should be the one exposed in the API.
This patches solves the problem but pre-loading the historical data every time the torrent is added to the repository.