From afb86638cdd3026cd7ca1ecbb83111d1aff2f727 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 15 Apr 2016 15:39:20 +0200 Subject: [PATCH] Updates for negative .narinfo caching --- src/hydra-queue-runner/hydra-queue-runner.cc | 1 + .../s3-binary-cache-store.cc | 36 +++++++++++-------- .../s3-binary-cache-store.hh | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 6aec8adc..2dac0dbd 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -639,6 +639,7 @@ void State::dumpStatus(Connection & conn, bool log) auto & stats = store->getStats(); nested.attr("narInfoRead", stats.narInfoRead); nested.attr("narInfoReadAverted", stats.narInfoReadAverted); + nested.attr("narInfoMissing", stats.narInfoMissing); nested.attr("narInfoWrite", stats.narInfoWrite); nested.attr("narInfoCacheSize", stats.narInfoCacheSize); nested.attr("narRead", stats.narRead); diff --git a/src/hydra-queue-runner/s3-binary-cache-store.cc b/src/hydra-queue-runner/s3-binary-cache-store.cc index ca19fe10..05726f4e 100644 --- a/src/hydra-queue-runner/s3-binary-cache-store.cc +++ b/src/hydra-queue-runner/s3-binary-cache-store.cc @@ -87,9 +87,8 @@ bool S3BinaryCacheStore::isValidPath(const Path & storePath) try { readNarInfo(storePath); return true; - } catch (S3Error & e) { - if (e.err == Aws::S3::S3Errors::NO_SUCH_KEY) return false; - throw; + } catch (InvalidPath & e) { + return false; } } @@ -142,7 +141,7 @@ void S3BinaryCacheStore::upsertFile(const std::string & path, const std::string stats.putTimeMs += duration; } -std::string S3BinaryCacheStore::getFile(const std::string & path) +std::shared_ptr S3BinaryCacheStore::getFile(const std::string & path) { printMsg(lvlDebug, format("fetching ‘s3://%1%/%2%’...") % bucketName % path); @@ -157,24 +156,31 @@ std::string S3BinaryCacheStore::getFile(const std::string & path) stats.get++; - auto now1 = std::chrono::steady_clock::now(); + try { - auto result = checkAws(format("AWS error fetching ‘%s’") % path, - client->GetObject(request)); + auto now1 = std::chrono::steady_clock::now(); - auto now2 = std::chrono::steady_clock::now(); + auto result = checkAws(format("AWS error fetching ‘%s’") % path, + client->GetObject(request)); - auto res = dynamic_cast(result.GetBody()).str(); + auto now2 = std::chrono::steady_clock::now(); - auto duration = std::chrono::duration_cast(now2 - now1).count(); + auto res = dynamic_cast(result.GetBody()).str(); - printMsg(lvlTalkative, format("downloaded ‘s3://%1%/%2%’ (%3% bytes) in %4% ms") - % bucketName % path % res.size() % duration); + auto duration = std::chrono::duration_cast(now2 - now1).count(); - stats.getBytes += res.size(); - stats.getTimeMs += duration; + printMsg(lvlTalkative, format("downloaded ‘s3://%1%/%2%’ (%3% bytes) in %4% ms") + % bucketName % path % res.size() % duration); - return res; + stats.getBytes += res.size(); + stats.getTimeMs += duration; + + return std::make_shared(res); + + } catch (S3Error & e) { + if (e.err == Aws::S3::S3Errors::NO_SUCH_KEY) return 0; + throw; + } } } diff --git a/src/hydra-queue-runner/s3-binary-cache-store.hh b/src/hydra-queue-runner/s3-binary-cache-store.hh index d1b9f6dc..b8d7a370 100644 --- a/src/hydra-queue-runner/s3-binary-cache-store.hh +++ b/src/hydra-queue-runner/s3-binary-cache-store.hh @@ -52,7 +52,7 @@ protected: void upsertFile(const std::string & path, const std::string & data) override; - std::string getFile(const std::string & path) override; + std::shared_ptr getFile(const std::string & path) override; };