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(share/eds): Rework accessor cache #2612

Merged
merged 21 commits into from
Sep 18, 2023

Conversation

walldiss
Copy link
Member

@walldiss walldiss commented Aug 25, 2023

Motivation
Previously, all accessors went into cache. They were closed only when they were evicted from it and there was no way to manually close one. Now, when we need to cache accessors only in some cases and in some not to, this approach will not work. Enabling control of accessor close required major cache rework.

New cache features:

  • Old cache didn't allow to close and release of an accessor. Now, Instead of returning just a reader/blockstore, cache returns object that composed of builder and io.Closer (Accessor interface). This allows caller to have an ability to close and release accessor once it is done with reading from it.
  • Items stored in cache also provide io.Closer`, but it is noop. Lifecycle of cached items is controlled by cache itself. For now objects are released right after they are evicted from cache, but it could be changed to smarter release based on current readers count. Will be implemented as separate issue.
  • Lazy blockstore builder. Old cache created blockstore every time accessor was acquired, even when only reader was used and blockstore was not needed. Creating blockstore is costly operation that involves building index, so this was reworked to create blockstore, only when it is requested and store it for subsequent requests.
  • adds cache unit tests.
  • adds metrics for cache methods to track cache hits/miss.
  • general cleanup of unused methods/logic.

It will be easier for reviewer to start from store.go and blockstore.go and then go into new cache pkg

Copy link
Collaborator

@distractedm1nd distractedm1nd left a comment

Choose a reason for hiding this comment

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

First lookthrough, looking good so far

share/eds/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/store.go Outdated Show resolved Hide resolved
- update metrics
- fix tests
# Conflicts:
#	share/eds/blockstore.go
#	share/eds/store.go
- fix merge conflicts
@walldiss
Copy link
Member Author

Needs rework, will update soon.

@walldiss walldiss marked this pull request as draft August 30, 2023 15:09
@walldiss walldiss changed the title feat(share/eds): split accessor cache into recent blocks and ipld requested blocks feat(share/eds): Rework accessor cache, split eds cache into 2 Aug 31, 2023
@walldiss walldiss marked this pull request as ready for review August 31, 2023 11:21
@walldiss walldiss changed the title feat(share/eds): Rework accessor cache, split eds cache into 2 feat(share/eds): Rework accessor cache Sep 5, 2023
# Conflicts:
#	share/eds/accessor_cache.go
#	share/eds/metrics.go
#	share/eds/store.go
@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2023

Codecov Report

Merging #2612 (1d68b60) into main (7c1f8f3) will increase coverage by 0.18%.
The diff coverage is 64.91%.

@@            Coverage Diff             @@
##             main    #2612      +/-   ##
==========================================
+ Coverage   51.37%   51.56%   +0.18%     
==========================================
  Files         159      162       +3     
  Lines       10699    10755      +56     
==========================================
+ Hits         5497     5546      +49     
- Misses       4723     4726       +3     
- Partials      479      483       +4     
Files Changed Coverage Δ
share/eds/cache/noop.go 0.00% <0.00%> (ø)
share/eds/metrics.go 21.05% <0.00%> (-0.31%) ⬇️
share/eds/cache/metrics.go 20.51% <20.51%> (ø)
share/getters/store.go 68.42% <25.00%> (-4.00%) ⬇️
share/p2p/shrexeds/server.go 62.01% <57.14%> (-0.59%) ⬇️
share/eds/blockstore.go 37.50% <74.07%> (+6.46%) ⬆️
share/eds/cache/accessor_cache.go 77.90% <77.90%> (ø)
share/eds/utils.go 78.57% <78.57%> (ø)
share/eds/store.go 68.82% <84.48%> (-0.24%) ⬇️

... and 5 files with indirect coverage changes

Copy link
Collaborator

@distractedm1nd distractedm1nd 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 looking really good, and I noticed a ton of small cleanups that I really appreciate <3

share/eds/cache/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/cache/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/cache/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/cache/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/blockstore.go Outdated Show resolved Hide resolved
share/eds/store.go Outdated Show resolved Hide resolved
share/eds/store.go Outdated Show resolved Hide resolved
share/eds/store.go Outdated Show resolved Hide resolved
share/eds/store.go Show resolved Hide resolved
share/eds/utils.go Show resolved Hide resolved
Copy link
Collaborator

@distractedm1nd distractedm1nd 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 looking really good, and I noticed a ton of small cleanups that I really appreciate <3

Copy link
Contributor

@derrandz derrandz left a comment

Choose a reason for hiding this comment

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

Glanced over this for learning purposes, got only one comment/question.

share/eds/store.go Show resolved Hide resolved
share/p2p/shrexeds/server.go Outdated Show resolved Hide resolved
Copy link
Contributor

@derrandz derrandz left a comment

Choose a reason for hiding this comment

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

a little optimization

share/eds/cache/accessor_cache.go Show resolved Hide resolved
Copy link
Member

@Wondertan Wondertan left a comment

Choose a reason for hiding this comment

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

Trying this review format that app team uses a lot

share/eds/store_test.go Outdated Show resolved Hide resolved
share/eds/cache/cache.go Show resolved Hide resolved
share/eds/cache/cache.go Show resolved Hide resolved
share/eds/cache/cache.go Show resolved Hide resolved
share/eds/store.go Outdated Show resolved Hide resolved
share/eds/blockstore.go Outdated Show resolved Hide resolved
share/eds/cache/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/cache/accessor_cache.go Outdated Show resolved Hide resolved
share/eds/cache/accessor_cache.go Show resolved Hide resolved
share/eds/cache/cache.go Outdated Show resolved Hide resolved
- track close errors in metrics
- move BlockstoreCloser and readCloser to utils
- add comment for sleep in test
go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
share/eds/cache/accessor_cache.go Show resolved Hide resolved
- make errCacheMiss private
- fix go.mod
@walldiss walldiss enabled auto-merge (squash) September 18, 2023 08:19
@walldiss walldiss merged commit 4d98585 into celestiaorg:main Sep 18, 2023
11 of 14 checks passed
vgonkivs pushed a commit to vgonkivs/celestia-node that referenced this pull request Oct 5, 2023
**Motivation** 
Previously, all accessors went into cache. They were closed only when
they were evicted from it and there was no way to manually close one.
Now, when we need to cache accessors only in some cases and in some not
to, this approach will not work. Enabling control of accessor close
required major cache rework.

New cache features:
- Old cache didn't allow to close and release of an accessor. Now,
Instead of returning just a reader/blockstore, cache returns object that
composed of builder and `io.Closer` (Accessor interface). This allows
caller to have an ability to close and release accessor once it is done
with reading from it.
- Items stored in cache also provide io.Closer`, but it is noop.
Lifecycle of cached items is controlled by cache itself. For now objects
are released right after they are evicted from cache, but it could be
changed to smarter release based on current readers count. Will be
implemented as separate issue.
- Lazy blockstore builder. Old cache created blockstore every time
accessor was acquired, even when only reader was used and blockstore was
not needed. Creating blockstore is costly operation that involves
building index, so this was reworked to create blockstore, only when it
is requested and store it for subsequent requests.
- adds cache unit tests.
- adds metrics for cache methods to track cache hits/miss.
- general cleanup of unused methods/logic.

It will be easier for reviewer to start from `store.go` and
`blockstore.go` and then go into new `cache` pkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:storage kind:feat Attached to feature PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants