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

downloader: added downloaded torrents notifier #11850

Merged
merged 21 commits into from
Sep 5, 2024
Merged

downloader: added downloaded torrents notifier #11850

merged 21 commits into from
Sep 5, 2024

Conversation

dvovk
Copy link
Member

@dvovk dvovk commented Sep 3, 2024

Added notifier which notify that torrent downloading completed.

@@ -345,6 +353,7 @@ func New(ctx context.Context, cfg *downloadercfg.Cfg, logger log.Logger, verbosi
downloading: map[string]*downloadInfo{},
webseedsDiscover: discover,
logPrefix: "",
completedTorrents: make(map[string]completedTorrentInfo),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates the info in downloading above and the info held locally in the local maps here:

https://github.com/erigontech/erigon/blob/ba451aac8b75bd851155e95ecfdab6fd5e8ec08b/erigon-lib/downloader/downloader.go#L889C3-L889C12

could you rationalize this so we end up with a single collection which is held by the downloader which keeps the whole download lifecycle.

This is a rationalization which is well overdue - seems like as you are adding another collection it would be a good time to make this change. Note that you may need to protect access to this map with the downloader mutex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not do this as at some point we are deleting from the complete array.

delete(complete, status.name)

This meant that it may not contains completed parts and the complete array may be using for some other stuff so I decided to create own collection.

I think such changes must be done as separate task as it will be to many changes to logic in the same PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is every time we add new collections it makes the code gradually more complex - I don't think the change is that big. You can just add a status with the following states

complete
checking
failed
waiting

to the downloadInfo struct them you only need one map. If you want to add more info you need to do the refactor. I'm ok if you do 2 PR's one with the refactor and the second adding the notifier - but I don't think we should make the code change like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to simplify the change you can just do complete.

At the moment you are setting 2 variable with an external function doing the same thing here:

complete[t.Name()] = struct{}{}
...
d.torrentCompleted(t.Name(), t.InfoHash())

I don't think you should add this code duplication.

startTime time.Time
logPrefix string
startTime time.Time
broadcast func(name string, hash *prototypes.H160)
Copy link
Contributor

@mh0lt mh0lt Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename this to notifyCompleted - you don't need an extra wrapper to call a function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dvovk dvovk requested a review from mh0lt September 3, 2024 13:39
@AskAlexSharov AskAlexSharov merged commit 7a7fbec into main Sep 5, 2024
10 checks passed
@AskAlexSharov AskAlexSharov deleted the pubsub branch September 5, 2024 01:48
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