S3BinaryCacheStore: Use disk cache

This commit is contained in:
Eelco Dolstra 2016-04-20 15:29:40 +02:00
parent b2b978eda0
commit b50a105ca7
4 changed files with 83 additions and 71 deletions

View file

@ -21,8 +21,8 @@ BuildOutput getBuildOutput(nix::ref<Store> store,
store->computeFSClosure(output, closure);
for (auto & path : closure) {
auto info = store->queryPathInfo(path);
res.closureSize += info.narSize;
if (outputs.find(path) != outputs.end()) res.size += info.narSize;
res.closureSize += info->narSize;
if (outputs.find(path) != outputs.end()) res.size += info->narSize;
}
/* Get build products. */

View file

@ -630,9 +630,8 @@ void State::dumpStatus(Connection & conn, bool log)
}
}
auto store = dynamic_cast<S3BinaryCacheStore *>(&*getDestStore());
auto store = getDestStore();
if (store) {
root.attr("store");
JSONObject nested(out);
@ -641,7 +640,7 @@ void State::dumpStatus(Connection & conn, bool log)
nested.attr("narInfoReadAverted", stats.narInfoReadAverted);
nested.attr("narInfoMissing", stats.narInfoMissing);
nested.attr("narInfoWrite", stats.narInfoWrite);
nested.attr("narInfoCacheSize", stats.narInfoCacheSize);
nested.attr("narInfoCacheSize", stats.pathInfoCacheSize);
nested.attr("narRead", stats.narRead);
nested.attr("narReadBytes", stats.narReadBytes);
nested.attr("narReadCompressedBytes", stats.narReadCompressedBytes);
@ -685,7 +684,6 @@ void State::dumpStatus(Connection & conn, bool log)
+ s3Stats.getBytes / (1024.0 * 1024.0 * 1024.0) * 0.09);
}
}
}
if (log && time(0) >= lastStatusLogged + statusLogInterval) {
printMsg(lvlInfo, format("status: %1%") % out.str());

View file

@ -1,6 +1,7 @@
#include "s3-binary-cache-store.hh"
#include "nar-info.hh"
#include "nar-info-disk-cache.hh"
#include <aws/core/client/ClientConfiguration.h>
#include <aws/s3/S3Client.h>
@ -38,6 +39,12 @@ S3BinaryCacheStore::S3BinaryCacheStore(std::shared_ptr<Store> localStore,
, config(makeConfig())
, client(make_ref<Aws::S3::S3Client>(*config))
{
diskCache = getNarInfoDiskCache();
}
std::string S3BinaryCacheStore::getUri()
{
return "s3://" + bucketName;
}
ref<Aws::Client::ClientConfiguration> S3BinaryCacheStore::makeConfig()
@ -50,6 +57,8 @@ ref<Aws::Client::ClientConfiguration> S3BinaryCacheStore::makeConfig()
void S3BinaryCacheStore::init()
{
if (!diskCache->cacheExists(getUri())) {
/* Create the bucket if it doesn't already exists. */
// FIXME: HeadBucket would be more appropriate, but doesn't return
// an easily parsed 404 message.
@ -70,6 +79,9 @@ void S3BinaryCacheStore::init()
Aws::S3::Model::BucketLocationConstraint::US) */ )));
}
diskCache->createCache(getUri());
}
BinaryCacheStore::init();
}
@ -82,10 +94,10 @@ const S3BinaryCacheStore::Stats & S3BinaryCacheStore::getS3Stats()
fetches the .narinfo file, rather than first checking for its
existence via a HEAD request. Since .narinfos are small, doing a
GET is unlikely to be slower than HEAD. */
bool S3BinaryCacheStore::isValidPath(const Path & storePath)
bool S3BinaryCacheStore::isValidPathUncached(const Path & storePath)
{
try {
readNarInfo(storePath);
queryPathInfo(storePath);
return true;
} catch (InvalidPath & e) {
return false;

View file

@ -25,6 +25,8 @@ public:
void init() override;
std::string getUri();
struct Stats
{
std::atomic<uint64_t> put{0};
@ -38,7 +40,7 @@ public:
const Stats & getS3Stats();
bool isValidPath(const Path & storePath) override;
bool isValidPathUncached(const Path & storePath) override;
private: