-
Notifications
You must be signed in to change notification settings - Fork 44
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
Better ergonomics around updating car root. #245
Comments
There was another thread about this somewhere in this repo. The API I went with in JS is called |
relates to #196 |
I think adding an API to amend the roots in a CAR file after-the-fact should be fine. I guess the only wrinkle is that it might need to shift the entire contents of the CAR file if there isn't enough space for the new header before the start of the inner CARv1. |
https://github.com/ipld/js-car/blob/9fb8dd81e3600501f62848e97fb62b977766aa2d/lib/writer.js#L75 In JS we've just made that not allowed - you need to plan ahead. If you're using a blake2b for your CIDs then you should use a dummy that's of the same length and not a sha2-256 which is going to be a byte shorter. |
If we take the temporary file approach for writing a CARv2 suggested in #249, then I wonder if we can structure data such that deferring the writing of roots is much easier. We could write inner CARv1 data sections separately or write inner CARv1 header at the end, then re-assemble the file in finalisation to conform with CARv2 format. Taking a step further, we could also use the same technique to avoid storing index in memory or re-generate it on resumption. But that's a separate kettle of fish. |
@masih you're right, we could get more clever if we go with #249 for supplying the roots at the very end. That said, I think we need a separate fix that's simpler and more like what JS provides. Given a CAR file, update its roots list. Similar to JS, we could make it so that it just errors if the new header does not fit in the space we have (i.e. in the space up to DataOffset). This could be useful for other use cases aside from OpenReadWrite, too, which is why I think this separate bit of API would be nice. The API signature could be somewhat similar to |
Yup that makes sense 👍 |
Scratch what I said about "fits up to DataOffset" - the roots are in the inner CarV1 header, so I think Rod is right - the roots list must be exactly the same size as before. |
the point of this whole setup is to not re-write the whole car. that said, you could do something tricky by initially putting some extra data offset padding. |
In terms of nice API, maybe we could have a companion to
We could fill the multihash digests with some special sequence of bytes that we can later recognise, to have commands like And, of course, it would let the user provide a list of "preallocating roots" in a single line, without having to work out how to hold go-cid right (e.g. with dummy data to hash). |
Implement an API that allows a caller to replace root CIDs in an existing CAR file, may it be v1 or v2, as long as the resulting serialized header is of identical size to the existing header. Assert that the new API works in a variety of CARv1 and CARv2 files along with failure scenarios. Fixed #245
I like the |
@masih maybe, though then you have to worry about people using |
This is true today about our existing options. Irrelevant options are ignored.
For this my thought was to explicitly document if option is set given roots must be empty or something along those lines. Either approach works. |
Implement an API that allows a caller to replace root CIDs in an existing CAR file, may it be v1 or v2, as long as the resulting serialized header is of identical size to the existing header. Assert that the new API works in a variety of CARv1 and CARv2 files along with failure scenarios. Fixes #245
Implement an API that allows a caller to replace root CIDs in an existing CAR file, may it be v1 or v2, as long as the resulting serialized header is of identical size to the existing header. Assert that the new API works in a variety of CARv1 and CARv2 files along with failure scenarios. Fixes #245
Implement an API that allows a caller to replace root CIDs in an existing CAR file, may it be v1 or v2, as long as the resulting serialized header is of identical size to the existing header. Assert that the new API works in a variety of CARv1 and CARv2 files along with failure scenarios. Fixes #245
The
v2/blockstore
package requires the caller to specify the car root[]cid.Cid
on opening the file.In the common case, the caller will not know their intended root until the end of writing.
This currently seems to require manual file editing by the caller. I've tried finalizing, and the re-opening via
specifying the actual root CID, where on the initial write I instead generate a proxy CID that I know has the same length as the final CID will. This fails, telling me
cannot resume on file with mismatching data header
. Forcing me to manually go in and edit the root unsupported seems like a failing in this library interface.The text was updated successfully, but these errors were encountered: