aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/s3-binary-cache-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-03-27 23:12:31 +0200
committerEelco Dolstra <edolstra@gmail.com>2018-05-30 13:34:57 +0200
commit08ec757726e5ef47e71bf16ed0b252b288bcf0f3 (patch)
tree7a9fc6b077d694620052522ae45cc274b09e0096 /src/libstore/s3-binary-cache-store.cc
parent81ea8bd5ceb3dcae6af0b79c81a39ecbf2ba97a8 (diff)
Make LocalBinaryCacheStore::narFromPath() run in constant memory
This reduces memory consumption of nix copy --from file://... --to ~/my-nix /nix/store/95cwv4q54dc6giaqv6q6p4r02ia2km35-blender-2.79 from 514 MiB to 18 MiB for an uncompressed binary cache, and from 192 MiB to 53 MiB for a bzipped binary cache. It may also be faster because fetching can happen concurrently with decompression/writing. Continuation of 48662d151bdf4a38670897beacea9d1bd750376a. Issue https://github.com/NixOS/nix/issues/1681.
Diffstat (limited to 'src/libstore/s3-binary-cache-store.cc')
-rw-r--r--src/libstore/s3-binary-cache-store.cc24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc
index f2e8efc16..239739bae 100644
--- a/src/libstore/s3-binary-cache-store.cc
+++ b/src/libstore/s3-binary-cache-store.cc
@@ -364,23 +364,23 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
uploadFile(path, data, mimeType, "");
}
- void getFile(const std::string & path,
- Callback<std::shared_ptr<std::string>> callback) override
+ void getFile(const std::string & path, Sink & sink) override
{
- try {
- stats.get++;
+ stats.get++;
- auto res = s3Helper.getObject(bucketName, path);
+ // FIXME: stream output to sink.
+ auto res = s3Helper.getObject(bucketName, path);
- stats.getBytes += res.data ? res.data->size() : 0;
- stats.getTimeMs += res.durationMs;
+ stats.getBytes += res.data ? res.data->size() : 0;
+ stats.getTimeMs += res.durationMs;
- if (res.data)
- printTalkative("downloaded 's3://%s/%s' (%d bytes) in %d ms",
- bucketName, path, res.data->size(), res.durationMs);
+ if (res.data) {
+ printTalkative("downloaded 's3://%s/%s' (%d bytes) in %d ms",
+ bucketName, path, res.data->size(), res.durationMs);
- callback(std::move(res.data));
- } catch (...) { callback.rethrow(); }
+ sink((unsigned char *) res.data->data(), res.data->size());
+ } else
+ throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri());
}
PathSet queryAllValidPaths() override