about summary refs log tree commit diff
path: root/src/libstore/nar-accessor.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-12-06T23·50+0100
committerEelco Dolstra <edolstra@gmail.com>2017-12-07T00·07+0100
commit2df9cbeb47177d6a21606b4b509ebcf6bd0437a6 (patch)
tree14edcd7742a582cdaf5245ae86cb914748b0ebf4 /src/libstore/nar-accessor.hh
parent338f29dbd4ee04f2de4c747eadb8c106a98f885c (diff)
Provide random access to cached NARs
E.g.

  $ time nix cat-store --store https://cache.nixos.org?local-nar-cache=/tmp/nars \
    /nix/store/b0w2hafndl09h64fhb86kw6bmhbmnpm1-blender-2.79/share/icons/hicolor/scalable/apps/blender.svg > /dev/null
  real    0m4.139s

  $ time nix cat-store --store https://cache.nixos.org?local-nar-cache=/tmp/nars \
    /nix/store/b0w2hafndl09h64fhb86kw6bmhbmnpm1-blender-2.79/share/icons/hicolor/scalable/apps/blender.svg > /dev/null
  real    0m0.024s

(Before, the second call took ~0.220s.)

This will use a NAR listing in
/tmp/nars/b0w2hafndl09h64fhb86kw6bmhbmnpm1.ls containing all metadata,
including the offsets of regular files inside the NAR. Thus, we don't
need to read the entire NAR. (We do read the entire listing, but
that's generally pretty small. We could use a SQLite DB by borrowing
some more code from nixos-channel-scripts/file-cache.hh.)

This is primarily useful when Hydra is serving files from an S3 binary
cache, in particular when you have giant NARs. E.g. we had some 12 GiB
NARs, so accessing individuals files was pretty slow.
Diffstat (limited to 'src/libstore/nar-accessor.hh')
-rw-r--r--src/libstore/nar-accessor.hh10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libstore/nar-accessor.hh b/src/libstore/nar-accessor.hh
index ed8fe15cad..1903355a23 100644
--- a/src/libstore/nar-accessor.hh
+++ b/src/libstore/nar-accessor.hh
@@ -8,6 +8,16 @@ namespace nix {
    file. */
 ref<FSAccessor> makeNarAccessor(ref<const std::string> nar);
 
+/* Create a NAR accessor from a NAR listing (in the format produced by
+   listNar()). The callback getNarBytes(offset, length) is used by the
+   readFile() method of the accessor to get the contents of files
+   inside the NAR. */
+typedef std::function<std::string(uint64_t, uint64_t)> GetNarBytes;
+
+ref<FSAccessor> makeLazyNarAccessor(
+    const std::string & listing,
+    GetNarBytes getNarBytes);
+
 class JSONPlaceholder;
 
 /* Write a JSON representation of the contents of a NAR (except file