From 5668aa5f71aa2862534830e98444921470ef97e5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 20 Feb 2016 10:35:16 +0100 Subject: [PATCH] After uploading a .narinfo, add it to the LRU cache --- src/hydra-queue-runner/binary-cache-store.cc | 32 ++++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/hydra-queue-runner/binary-cache-store.cc b/src/hydra-queue-runner/binary-cache-store.cc index f4e9b652..d5c4d679 100644 --- a/src/hydra-queue-runner/binary-cache-store.cc +++ b/src/hydra-queue-runner/binary-cache-store.cc @@ -50,33 +50,33 @@ void BinaryCacheStore::addToCache(const ValidPathInfo & info, auto narInfoFile = narInfoFileFor(info.path); if (fileExists(narInfoFile)) return; - NarInfo narInfo(info); + auto narInfo = make_ref(info); - narInfo.narSize = nar.size(); - narInfo.narHash = hashString(htSHA256, nar); + narInfo->narSize = nar.size(); + narInfo->narHash = hashString(htSHA256, nar); - if (info.narHash.type != htUnknown && info.narHash != narInfo.narHash) + if (info.narHash.type != htUnknown && info.narHash != narInfo->narHash) throw Error(format("refusing to copy corrupted path ‘%1%’ to binary cache") % info.path); /* Compress the NAR. */ - narInfo.compression = "xz"; + narInfo->compression = "xz"; auto now1 = std::chrono::steady_clock::now(); string narXz = compressXZ(nar); auto now2 = std::chrono::steady_clock::now(); - narInfo.fileHash = hashString(htSHA256, narXz); - narInfo.fileSize = narXz.size(); + narInfo->fileHash = hashString(htSHA256, narXz); + narInfo->fileSize = narXz.size(); auto duration = std::chrono::duration_cast(now2 - now1).count(); printMsg(lvlTalkative, format("copying path ‘%1%’ (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache") - % narInfo.path % narInfo.narSize + % narInfo->path % narInfo->narSize % ((1.0 - (double) narXz.size() / nar.size()) * 100.0) % duration); /* Atomically write the NAR file. */ - narInfo.url = "nar/" + printHash32(narInfo.fileHash) + ".nar.xz"; - if (!fileExists(narInfo.url)) { + narInfo->url = "nar/" + printHash32(narInfo->fileHash) + ".nar.xz"; + if (!fileExists(narInfo->url)) { stats.narWrite++; - upsertFile(narInfo.url, narXz); + upsertFile(narInfo->url, narXz); } else stats.narWriteAverted++; @@ -85,9 +85,15 @@ void BinaryCacheStore::addToCache(const ValidPathInfo & info, stats.narWriteCompressionTimeMs += duration; /* Atomically write the NAR info file.*/ - if (secretKey) narInfo.sign(*secretKey); + if (secretKey) narInfo->sign(*secretKey); - upsertFile(narInfoFile, narInfo.to_string()); + upsertFile(narInfoFile, narInfo->to_string()); + + { + auto state_(state.lock()); + state_->narInfoCache.upsert(narInfo->path, narInfo); + stats.narInfoCacheSize = state_->narInfoCache.size(); + } stats.narInfoWrite++; }