chore(dot/state): replace sync.Map with map+mutex#2286
Conversation
Codecov Report
@@ Coverage Diff @@
## development #2286 +/- ##
===============================================
- Coverage 60.08% 57.30% -2.78%
===============================================
Files 211 212 +1
Lines 27759 27768 +9
===============================================
- Hits 16678 15912 -766
- Misses 9357 10223 +866
+ Partials 1724 1633 -91
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
4f04b11 to
960c70f
Compare
960c70f to
b1cd89a
Compare
b1cd89a to
8ef2804
Compare
| t.Parallel() | ||
|
|
||
| var startWg, endWg sync.WaitGroup | ||
| ctx, cancel := context.WithCancel(context.Background()) |
There was a problem hiding this comment.
why do we need this context?
There was a problem hiding this comment.
To cancel all runInLoop goroutines all at once.
for ctx.Err() == nil {
f()
}and the cancel is called by the timer.
To be fair, all this feels like over-engineering but also like the right way to test for data races quickly, since it has to be 'tight' and as event-driven as possible. Probably a topic I should share in go-guild 😉
There was a problem hiding this comment.
I don't really see the need to use a context to handle cancellation. Could you not just close some channel to signify cancellation?
There was a problem hiding this comment.
Yes we can use a struct{} channel that gets closed, it's just that it then becomes:
stop := false
for {
select {
case <-stopGoroutines:
stop = true
default:
}
if stop {
break
}
f()
}Which is longer/more confusing I think. (and no I don't want to use goto 😄)
I am Quentin Mc Gaw, a software engineer working the Go Polkadot host **Gossamer**. I have been working full time on Gossamer since October 2021, mostly on the state trie and storage. I have also made a [few minor pull requests](https://github.com/w3f/polkadot-spec/pulls?q=is%3Apr+is%3Aclosed+author%3Aqdm12) to the Polkadot specification repository. I am requesting to join the Fellowship at rank 1. ## Main contributions ### Gossamer - Fix memory leaks - Trie encoding buffer pools usage fixed [#2009](ChainSafe/gossamer#2009) - Fix state map of tries memory leak [#2286](ChainSafe/gossamer#2286) - Fix sync benchmark [#2234](ChainSafe/gossamer#2234) - Trie proof fixes ([#2604](ChainSafe/gossamer#2604), [#2661](ChainSafe/gossamer#2661)) - Fix end to end tests orchestration ([#2470](ChainSafe/gossamer#2470), [#2452](ChainSafe/gossamer#2452), [#2385](ChainSafe/gossamer#2385), [#2370](ChainSafe/gossamer#2370)) - State trie statistics ([#2378](ChainSafe/gossamer#2378), [#2310](ChainSafe/gossamer#2310), [#2272](ChainSafe/gossamer#2272)) - State trie fixes and improvements - Only deep copy nodes when mutation is certain [#2352](ChainSafe/gossamer#2352) and [#2223](ChainSafe/gossamer#2223) - Only deep copy necessary fields of a node [#2384](ChainSafe/gossamer#2384) - Use Merkle values for database keys instead of always hash [#2725](ChainSafe/gossamer#2725) - Opportunistic parallel Merkle value commputing [#2081](ChainSafe/gossamer#2081) - Grandpa capped number of tracked messages ([#2490](ChainSafe/gossamer#2490), [#2485](ChainSafe/gossamer#2485)) - Add pprof HTTP service for profiling [#1991](ChainSafe/gossamer#1991) Ongoing work: - State trie lazy loading and caching - State trie v1 support ([#2736](ChainSafe/gossamer#2736), [#2747](ChainSafe/gossamer#2747), [#2687](ChainSafe/gossamer#2687), [#2686](ChainSafe/gossamer#2686), [#2685](ChainSafe/gossamer#2685), [#2673](ChainSafe/gossamer#2673), [#2611](ChainSafe/gossamer#2611), [#2530](ChainSafe/gossamer#2530)) ### Polkadot specification ➡️ [Pull requests from qdm12](https://github.com/w3f/polkadot-spec/pulls?q=is%3Apr+is%3Aclosed+author%3Aqdm12)
Changes
Tests
Issues
sync.Map#2281Primary Reviewer