feat: io.Reader factory for ShardAccessor#155
Open
distractedm1nd wants to merge 2 commits intofilecoin-project:masterfrom
Open
feat: io.Reader factory for ShardAccessor#155distractedm1nd wants to merge 2 commits intofilecoin-project:masterfrom
io.Reader factory for ShardAccessor#155distractedm1nd wants to merge 2 commits intofilecoin-project:masterfrom
Conversation
raulk
reviewed
Apr 3, 2023
accessor.go
Outdated
Comment on lines
+61
to
+69
| if sa.mmapr == nil { | ||
| if f, ok := sa.data.(*os.File); ok { | ||
| if mmapr, err := mmap.Open(f.Name()); err != nil { | ||
| log.Warnf("failed to mmap reader of type %T: %s; using reader as-is", sa.data, err) | ||
| } else { | ||
| sa.mmapr = mmapr | ||
| } | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Let's extract this logic to a tryMmap() method (and document it requires the lock to be held) and refactor the Blockstore() method to use that?
accessor.go
Outdated
Comment on lines
+71
to
+73
| if sa.mmapr != nil { | ||
| return sa.mmapr.ReadAt(p, 0) | ||
| } |
Member
There was a problem hiding this comment.
Would move this above since we expect it to be the most common path when a shard gets reused.
accessor.go
Outdated
Comment on lines
+82
to
+84
| if sa.mmapr != nil { | ||
| r = sa.mmapr | ||
| } else if f, ok := sa.data.(*os.File); ok { |
Member
There was a problem hiding this comment.
Let's extract the mmap logic; then make this method short-circuit for more readable and idiomatic code.
|
Crossposting my review celestiaorg#2 (comment) also cc @raulk |
io.Reader for ShardAccessorio.Reader factory for ShardAccessor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At celestia-node, we don't only use
ShardAccessor's Blockstore to serve individual blocks, but also use the underlying mount to stream the CAR file to other full nodes. We do this by adding aReader() io.Readermethod toShardAccessorthat creates independent mmap-backed (when possible) readers. We would love to upstream it to avoid maintaining a fork.