- 
                Notifications
    You must be signed in to change notification settings 
- Fork 24
          feat: io.Reader factory for ShardAccessor
          #155
        
          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
base: master
Are you sure you want to change the base?
  
    feat: io.Reader factory for ShardAccessor
  
  #155
              Conversation
        
          
                accessor.go
              
                Outdated
          
        
      | 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 | ||
| } | ||
| } | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
          
        
      | if sa.mmapr != nil { | ||
| return sa.mmapr.ReadAt(p, 0) | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would move this above since we expect it to be the most common path when a shard gets reused.
        
          
                accessor.go
              
                Outdated
          
        
      | if sa.mmapr != nil { | ||
| r = sa.mmapr | ||
| } else if f, ok := sa.data.(*os.File); ok { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now
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.