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: striped lock to prevent redundant work in index cache #10885

Closed
wants to merge 2 commits into from

Conversation

snissn
Copy link
Contributor

@snissn snissn commented May 18, 2023

Related Issues

see #10866 PR for previous discuss and #10788

Proposed Changes

Feature: Add striped lock for ChainIndex cache access in chain/store/index

This pull request introduces a striped lock for the ChainIndex indexCache. The lock, implemented via the 'github.com/nmvalera/striped-mutex' package, is applied when accessing the indexCache in the GetTipsetByHeight method.

The goal of this change is to prevent redundant computations when the same tipset is accessed concurrently. The lock uses the tipset key as a unique identifier, thereby ensuring mutual exclusion on a per-tipset basis, while allowing different tipsets to still be processed concurrently.

Important Note: The lock is acquired before checking the cache for a tipset and released after the cache is filled with the tipset.

This pull request also introduces a new dependency, 'github.com/nmvalera/striped-mutex', which has been added to go.mod and go.sum.

As a minor change, the fillCache method comment indicating that the caller must hold indexCacheLk has been removed as it's no longer relevant with the current lock usage.

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

arajasek and others added 2 commits May 12, 2023 17:41
This commit introduces a striped lock for the ChainIndex indexCache. The lock, implemented via the 'github.com/nmvalera/striped-mutex' package, is applied when accessing the indexCache in the GetTipsetByHeight method. This change aims to prevent redundant computations when the same tipset is accessed concurrently, as the lock uses the tipset key, ensuring that different tipsets can still be processed concurrently.

Note: The lock is acquired before checking the cache for a tipset and released after the cache is filled with the tipset.

A new dependency, 'github.com/nmvalera/striped-mutex', has been added to go.mod and go.sum.

The fillCache method comment indicating that the caller must hold indexCacheLk has been removed as it's no longer relevant with the current lock usage.
@snissn
Copy link
Contributor Author

snissn commented May 22, 2023

replaced by #10896

@snissn snissn closed this May 22, 2023
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