Skip to content
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 issue with read_piece() stopping torrent #7359

Merged
merged 1 commit into from
Mar 31, 2023
Merged

fix issue with read_piece() stopping torrent #7359

merged 1 commit into from
Mar 31, 2023

Conversation

arvidn
Copy link
Owner

@arvidn arvidn commented Mar 28, 2023

on pieces not yet downloaded

@SemiAccurate
Copy link

Should you also update the web page reference to indicate the torrent will not be paused on error?

http://libtorrent.org/reference-Alerts.html#read_piece_alert

@arvidn
Copy link
Owner Author

arvidn commented Mar 29, 2023

oh, interesting, stopping the torrent is documented. I think this patch may not be right.
I think a better way to address this is to not issue a read for a piece we know we don't have.

@SemiAccurate
Copy link

oh, interesting, stopping the torrent is documented. I think this patch may not be right. I think a better way to address this is to not issue a read for a piece we know we don't have.

Huh. Well if you're already keeping track of the pieces downloaded (but not yet written to disk) through this internal call to user_have_piece() then why not expose it to user applications so that we don't have to maintain our own data structure duplicating this exact same bookkeeping logic? You already expose the internal data structure for downloaded and saved to disk pieces through the have_piece() call so why not do it also for this structure for merely downloaded pieces? It would save us some headaches.

@arvidn
Copy link
Owner Author

arvidn commented Mar 30, 2023

I think there's some misunderstanding. You can call have_piece() if you'd like to know whether a piece has been downloaded or not. You're probably not going to like it thought, as it's a blocking call.

I don't know what you're asking for be exposed in addition to this.

@SemiAccurate
Copy link

Oh so the internal user_have_piece() call and the have_piece() API call are querying the same data structure?

If so then your change isn't really cancelling the issuing of "a read for a piece we know we don't have" because it's being pessimistic and will also no longer issue a read request for a piece we do have in libtorrent's disk cache (but hasn't yet been saved to disk/OS) as you said in the related thread ("If you read the data via libtorrent, with read_piece() it will be read through the same path data is read when requested by peers. i.e. it can read from libtorrent's disk cache.")

This current change here will make waiting to call read_piece() take longer than necessary (and effectively dependent on the blocking have_piece() call as you said) which would not be a good outcome, as we'd have to wait until the piece is saved to the OS instead of merely waiting until it is downloaded.

In light of this the original change to no longer pause or stop the torrent when the piece isn't there is favorable.

Though probably the best change from the API perspective is as you just suggested in the related thread to add a flag to an overload of the read_piece() API call to notify with read_piece_alert of when the piece is eventually downloaded.

@SemiAccurate
Copy link

What does this latest commit do now?

@arvidn
Copy link
Owner Author

arvidn commented Mar 31, 2023

it checks if the piece has passed hash check, which does not require that it has been written to disk (i.e. handed off to the OS)

@SemiAccurate
Copy link

Ah ok. Yes that is optimal! Otherwise it's a noop (not a failure) right?

I don't know if you checked the msg in the related thread, though what mechanism does read_piece() use to keep track of multiple in-flight read requests to individual pieces?

Could you use this same mechanism as is - or maybe improve it some more - to support the addition of an overloaded call with a flag to keep track of read requests to yet to be downloaded pieces?

@arvidn arvidn merged commit 6d64ac1 into RC_2_0 Mar 31, 2023
@arvidn arvidn deleted the read-piece branch March 31, 2023 17:46
@cas--
Copy link
Contributor

cas-- commented May 26, 2023

Hmm this change has broken how Deluge handles setting an error state for torrents that were seeding but the files were moved on OS therefore should not try to re-download them without user intervention. I will need to revisit this to understand what would work instead, any suggestions @arvidn?

Deluge ticket: https://dev.deluge-torrent.org/ticket/1032

@arvidn
Copy link
Owner Author

arvidn commented May 26, 2023

are calls to read_piece() involved at all?

@cas--
Copy link
Contributor

cas-- commented May 26, 2023

It's been a while since I touched that code but the tests were using read_piece to force the error which seemed to simulate what was occurring with actual torrents correctly.

I think there are two scenarios, one where re-adding a torrent to the session and the files on disk are missing and the other where a running session with seeding torrent have their file on disk moved or removed (e.g. unmounted disk)

I created a ticket with sample code to demo the difference in lt versions: https://dev.deluge-torrent.org/ticket/3603

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.

3 participants