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: replace CarOffsetWriter with car.NewCarV1StreamReader #693

Closed
wants to merge 1 commit into from

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Aug 10, 2022

WIP:

  • builds on Add a 'skip' parameter to writev1 so that the beginning of a car can … ipld/go-car#291 (plus 326, I'm assuming that'll be merged into that branch)
  • car/ directory still exists, needs to be deleted
  • better test coverage to cover some of the things that the tests in car/ were doing that we're not trusting go-car to do
  • doesn't have the benefit of the BlockInfoCache, so this version will re-load all the blocks during a resumption - it should do it properly, but the existing version keeps a cache of the block's position in the CAR and all of the links in the block so we can take shortcuts with merkledag.Walk; we need to consider if/how we support that. Perhaps it's just a matter of holding onto the reader and reusing it, or holding onto some part of the reader? Since the new TraverseResumer should take care of these concerns for us.

@rvagg rvagg requested a review from willscott August 10, 2022 10:39
@rvagg rvagg force-pushed the rvagg/replace-cow-with-selective-car-with-skip branch from d139989 to 6f65d7a Compare August 10, 2022 10:41
@rvagg
Copy link
Member Author

rvagg commented Aug 10, 2022

I think it should be possible to replicate the BlockInfoCacheManager pattern but associate a PayloadCid with the reader returned from car.NewCarV1StreamReader (and its associated closer that I make in here). Then when we come back to serveContent() for the same payload, we reuse it and the readEmitter that wraps around it will reset it with a Seek() then start passing on new Read()s.

I just don't know about parallel requests for the same PayloadCid, we can only use one reader at a time.

@jacobheun jacobheun added this to the v1.4.0 milestone Aug 10, 2022
@willscott
Copy link
Collaborator

Instead of making the stream readers somehow safe for multiple concurrent users, which will be tough given the semantics of read vs seek, it should be pretty cheap to be able to do a clone() to make a deep copy of metadata for a new user, and then maybe also not too bad to have a merge to be able to push additional learned metadata back into the primary-cached reader at the end of a read.

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

It would be great to get rid of CarOffsetWriter! 👍

Comment on lines +196 to +213
cancelContent := func(parentCtx context.Context) (err error) {
cancelComplete := make(chan struct{}, 1)
go func() {
// calling a Seek() on the SkipWriterReaderSeeker from go-car will cancel
// any existing writer and block until that cancel is complete
if closeErr := closer.Close(); closeErr != nil && !errors.Is(closeErr, context.Canceled) {
// context.Canceled can come up through the http Request from a socket close, ignore it
err = closeErr
}
cancelComplete <- struct{}{}
}()
select {
case <-parentCtx.Done():
return parentCtx.Err()
case <-cancelComplete:
}
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd suggest moving the cancelContent function inside of sendCar as it's not used anywhere else

bic := s.bicm.Get(authVal.PayloadCid)
err = s.serveContent(w, r, authToken, authVal, bic)
s.bicm.Unref(authVal.PayloadCid, err)
_ = s.serveContent(w, r, authToken, authVal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should log this error somewhere?

@jacobheun
Copy link
Contributor

@rvagg what's the current state of this? It sounded like there were some challenges with the go-car updates but following the threads in the related issues wasn't quite clear. I'd like to understand what the blocker on this is so we can sort out next steps.

@jacobheun jacobheun removed this from the v1.4.0 milestone Oct 14, 2022
@dirkmc
Copy link
Contributor

dirkmc commented Sep 14, 2023

Closing as out of date

@dirkmc dirkmc closed this Sep 14, 2023
@masih masih deleted the rvagg/replace-cow-with-selective-car-with-skip branch October 9, 2023 10:35
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.

None yet

4 participants