Skip to content

Comments

Get rid of Hash::dummy from BinaryCacheStore#3935

Merged
edolstra merged 8 commits intoNixOS:masterfrom
obsidiansystems:binary-cache-addToStoreFromDump
Oct 5, 2020
Merged

Get rid of Hash::dummy from BinaryCacheStore#3935
edolstra merged 8 commits intoNixOS:masterfrom
obsidiansystems:binary-cache-addToStoreFromDump

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Aug 15, 2020

CC @roberth. I think between this BinaryCacheStore::addToStoreCommon and your RemoteStore::addCAToStore we are narrowing in on "the one addToStore to rule them all".

@Ericson2314 Ericson2314 force-pushed the binary-cache-addToStoreFromDump branch from 98d3461 to 9fbc31a Compare September 23, 2020 04:56
@Ericson2314 Ericson2314 changed the title WIP: Get rid of Hash::dummy from BinaryCacheStore Get rid of Hash::dummy from BinaryCacheStore Sep 23, 2020
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Implementing addCAToStore might make sense if it's easy to implement, but it will need extra tests because it's not part of "normal" Nix use afaict.

RepairFlag repair, CheckSigsFlag checkSigs)
{
if (!repair && isValidPath(info.path)) {
// FIXME: copyNAR -> null sink
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to parse the NAR to determine the end if we make the caller responsible for ending narSource. That's what addCAToStore is doing.

Suggested change
// FIXME: copyNAR -> null sink
// FIXME: make sure all callers truncate `narSource`

nix-store --import comes to mind. It will have to parse the NAR because the import/export format doesn't have a way to determine the end by simpler means.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think agree it's better to make the caller responsible, but I'm a bit wary on changing the direction of this FIXME as it and this code already existed, I just moved it here.

I'll let @edolstra decide :).

Ericson2314 and others added 5 commits September 23, 2020 10:36
@Ericson2314 Ericson2314 force-pushed the binary-cache-addToStoreFromDump branch from 102063b to 1832436 Compare September 26, 2020 04:58
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

1× fixme
1× store api and binary cache idea. I'll make an issue for that

std::shared_ptr<FSAccessor> narAccessor;
HashSink narHashSink { htSHA256 };
{
FdSink fileSink(fdTemp.get());
Copy link
Member

Choose a reason for hiding this comment

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

This is beyond the scope of this PR, but since we're revisiting these store API methods it's worth noting that we could optimize away the tmpfile if we know a little bit more in advance. Although optimizing away a tmpfile seems unimpressive, it changes the time taken from O(sum(steps)) to O(max(steps)), which is significant when compression and upload take similar amounts of time.

When the file is known to be small (low hanging fruit)

Add a size parameter to addToStoreCommon or use a fancy sink that only writes to file when it crosses a limit. This is similar to what LocalStore::addToStoreFromDump does.

When we know the nar hash in advance

For http binary caches this does require us to change the binary cache filenames to match uncompressed hashes, which seems to be equivalent and can only result in one-time duplication in existing caches when new paths are uploaded.
I don't know yet how IPFS caches fit into this picture, but if those can compress after hashing, this would be beneficial.
Another reason to do this is so we don't need to compress before we can decide to reuse an available nar file.

In this case it does make sense to have both addToStore(const ValidPathInfo & info, .....) and addToStore(....., std::function<ValidPathInfo(HashResult)) where the prior can have a default implementation in terms of the latter.

Copy link
Member

Choose a reason for hiding this comment

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

I decided not to try to optimize away the temporary file for small NARs because the overhead is likely to be insignificant compared to stuff like HTTP requests.

@Ericson2314
Copy link
Member Author

@edolstra OK this is all ready.

@edolstra edolstra merged commit 51c2992 into NixOS:master Oct 5, 2020
@Ericson2314 Ericson2314 deleted the binary-cache-addToStoreFromDump branch October 5, 2020 14:10
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.

3 participants