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

refactor: block on StopPrefetchers() instead of cleanup #1396

Merged
merged 3 commits into from
Nov 25, 2024

Conversation

ARR4N
Copy link
Contributor

@ARR4N ARR4N commented Nov 22, 2024

If you use a shared BoundedWorkers across all tries1 then it's sufficient23 to block on StateDB.StopPrefetcher() or on triePrefetcher.close() when you don't have a full DB.

Footnotes

  1. I think this is what we should be doing as it's the point of BoundedWorkers. It's also what your original implementation had too.

  2. There was a bug in my ordering of the defer statements at the top of subfetcher.loop(). I fixed it here; on my libevm branch I also added a test to prove that StopPrefetcher() blocks until WorkerPool.Wait() returns.

  3. I (wrongly) assumed that BoundedWorkers would allow extra work while Wait()ing.

@ARR4N ARR4N requested review from ceyonur, darioush and a team as code owners November 22, 2024 18:58
core/state/trie_prefetcher.go Show resolved Hide resolved
Comment on lines 75 to 84
// Calling abort() sequentially may result in later fetchers accepting new
// work in the interim.
var wg sync.WaitGroup
for _, f := range p.fetchers {
wg.Add(1)
go func(f *subfetcher) {
f.abort()
wg.Done()
}(f)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is needed, the user of triePrefetcher should not call prefetch after or concurrently with abort.

Also this doesn't guarantee the cancellation.

IMO we can remove this part, rename the fn to releaseWorkerPools() and call it after the sequential abort loop before line 109

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, it was YAGNI thinking on my part.

@darioush darioush merged commit 958808f into trie-prefetcher-alt2 Nov 25, 2024
12 checks passed
@darioush darioush deleted the arr4n/trie-prefetcher-alt2 branch November 25, 2024 15:51
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