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

feat: chainstore: sharded mutex for filling chain height index #10896

Merged
merged 2 commits into from
May 24, 2023

Conversation

Kubuxu
Copy link
Contributor

@Kubuxu Kubuxu commented May 19, 2023

This PR introduces as sharded mutex within the ChainIndex#GetTipsetByHeight.
It also replaces a go map with xsync.Map which doesn't require locking.

The lock is taken when it appears that ChainIndex filling work should be
started. After claiming the lock, the status of the cache is rechecked,
if the entry is still missing, the fillCache is started.

Thanks to @snissn and @arajasek for debugging and taking initial stabs at this.

Supersedes #10866 and #10885

This PR introduces as sharded mutex within the ChainIndex#GetTipsetByHeight.
It also replaces a go map with xsync.Map which doesn't require locking.

The lock is taken when it appears that ChainIndex filling work should be
started. After claiming the lock, the status of the cache is rechecked,
if the entry is still missing, the fillCache is started.

Thanks to @snissn and @arajasek for debugging and taking initial stabs at this.

Supersedes #10866 and 10885

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
@Kubuxu Kubuxu requested a review from a team as a code owner May 19, 2023 17:50
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
@snissn
Copy link
Contributor

snissn commented May 19, 2023

// DefaultChainIndexCacheSize no longer sets the maximum size, just the initial size of the map.

are we ok with changing how the cache works? In this new PR we are letting the indexCache grow unbounded. Otherwise the new sharded Mutex + PR looks great!

I don't have an idea for the memory/cpu tradeoff of uncapped indexCache, potentially it could create issues with memory usage

@Kubuxu
Copy link
Contributor Author

Kubuxu commented May 19, 2023

It already became unbounded with the switch from LRU cache to map some time ago. I just documented it.

@Kubuxu
Copy link
Contributor Author

Kubuxu commented May 19, 2023

In this commit 90c8928

@snissn
Copy link
Contributor

snissn commented May 22, 2023

In this commit 90c8928

yes you are right! thank you for clarifying

Copy link
Contributor

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

This is much better than what we have right now

@magik6k magik6k merged commit 8c8e287 into master May 24, 2023
@magik6k magik6k deleted the feat/chainindex-sharded-mutex branch May 24, 2023 10:49
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