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

turbo: speed up rebuildSegments #12114

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

stevemilk
Copy link
Contributor

  1. do not reopen segments/indexed if already opened during rebuildSegments
  2. accelerate scanning files by avoiding doubly nested loop

@AskAlexSharov
Copy link
Collaborator

looks good. but seems we have corner-case: we don't know "is download of file finished or not". i think it's possible to open some file (like .idx). i feel - it's possible to open .idx file - which was bad (metadata section was not downloaded) - and still get non-nil object in this case (no error may happen - if validation will not catch it).

In all other cases i think your fix will work.

@stevemilk
Copy link
Contributor Author

find a way to cover the corner case:
if size of downloaded file is equal to the size stored in corresponding torrent file, download is considered as finished.
And only if file is complete(download finished || generate locally) and not opened yet, we reopen the file.

@mh0lt
Copy link
Contributor

mh0lt commented Oct 2, 2024

find a way to cover the corner case: if size of downloaded file is equal to the size stored in corresponding torrent file, download is considered as finished. And only if file is complete(download finished || generate locally) and not opened yet, we reopen the file.

Unfortunately this check won't work. The torrent lib truncates the mmap to its full size on initiation so it can randomly write to the full extent. So this will always be true once the download starts.

We have added a callback from the downloader when download completes - which can be used to know when the file is downloaded:

TorrentCompleted(ctx context.Context, in *TorrentCompletedRequest, opts ...grpc.CallOption) (Downloader_TorrentCompletedClient, error)

Making this call available to the snapshot code is part of a bigger refactor.

@stevemilk
Copy link
Contributor Author

Thx for reminding. Will try implementing the callback and other possible alternatives.

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