packages/hercules-ci-agent: apply https://github.com/NixOS/nix/pull/7489 to agent's nix
This commit is contained in:
parent
af019b1079
commit
56a6cfe438
2 changed files with 84 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
perSystem = { filters, inputs', ... }:
|
||||
perSystem = { filters, inputs', lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
tools = import ./lib/tools.nix;
|
||||
|
@ -14,7 +14,19 @@
|
|||
|
||||
agenix = packages.agenix.agenix.override { nix = nix-super; };
|
||||
|
||||
hercules-ci-agent = packages.hercules-ci-agent.hercules-ci-agent;
|
||||
# hci-agent's build code does some funny shenanigans
|
||||
hercules-ci-agent = let
|
||||
original = packages.hercules-ci-agent.hercules-ci-agent;
|
||||
patchedNix = patch-rename-direct original.nix ({ version, ...}: "nix-${version}_hci1") "patches/extra/hercules-ci-agent/nix";
|
||||
in (original.override {
|
||||
# for hercules-ci-cnix-expr, hercules-ci-cnix-store
|
||||
nix = patchedNix;
|
||||
# for cachix
|
||||
pkgs = pkgs // { nix = patchedNix; };
|
||||
}).overrideAttrs (old: {
|
||||
# for hercules-ci-agent
|
||||
buildInputs = (lib.remove original.nix old.buildInputs) ++ [ patchedNix ];
|
||||
});
|
||||
|
||||
hci = packages.hercules-ci-agent.hercules-ci-cli;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc
|
||||
index f4ea739b05d..3e0689534b6 100644
|
||||
--- a/src/libstore/nar-info-disk-cache.cc
|
||||
+++ b/src/libstore/nar-info-disk-cache.cc
|
||||
@@ -166,16 +166,37 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
|
||||
return i->second;
|
||||
}
|
||||
|
||||
+ std::optional<Cache> queryCacheRaw(State & state, const std::string & uri)
|
||||
+ {
|
||||
+ auto i = state.caches.find(uri);
|
||||
+ if (i == state.caches.end()) {
|
||||
+ auto queryCache(state.queryCache.use()(uri)(time(0) - cacheInfoTtl));
|
||||
+ if (!queryCache.next())
|
||||
+ return std::nullopt;
|
||||
+ state.caches.emplace(uri,
|
||||
+ Cache{(int) queryCache.getInt(0), queryCache.getStr(1), queryCache.getInt(2) != 0, (int) queryCache.getInt(3)});
|
||||
+ }
|
||||
+ return getCache(state, uri);
|
||||
+ }
|
||||
+
|
||||
void createCache(const std::string & uri, const Path & storeDir, bool wantMassQuery, int priority) override
|
||||
{
|
||||
retrySQLite<void>([&]() {
|
||||
auto state(_state.lock());
|
||||
+ SQLiteTxn txn(state->db);
|
||||
+
|
||||
+ // To avoid the race, we have to check if maybe someone hasn't yet created
|
||||
+ // the cache for this URI in the meantime.
|
||||
+ auto cache(queryCacheRaw(*state, uri));
|
||||
|
||||
- // FIXME: race
|
||||
+ if (cache)
|
||||
+ return;
|
||||
|
||||
state->insertCache.use()(uri)(time(0))(storeDir)(wantMassQuery)(priority).exec();
|
||||
assert(sqlite3_changes(state->db) == 1);
|
||||
state->caches[uri] = Cache{(int) sqlite3_last_insert_rowid(state->db), storeDir, wantMassQuery, priority};
|
||||
+
|
||||
+ txn.commit();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -183,21 +204,12 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
|
||||
{
|
||||
return retrySQLite<std::optional<CacheInfo>>([&]() -> std::optional<CacheInfo> {
|
||||
auto state(_state.lock());
|
||||
-
|
||||
- auto i = state->caches.find(uri);
|
||||
- if (i == state->caches.end()) {
|
||||
- auto queryCache(state->queryCache.use()(uri)(time(0) - cacheInfoTtl));
|
||||
- if (!queryCache.next())
|
||||
- return std::nullopt;
|
||||
- state->caches.emplace(uri,
|
||||
- Cache{(int) queryCache.getInt(0), queryCache.getStr(1), queryCache.getInt(2) != 0, (int) queryCache.getInt(3)});
|
||||
- }
|
||||
-
|
||||
- auto & cache(getCache(*state, uri));
|
||||
-
|
||||
+ auto cache(queryCacheRaw(*state, uri));
|
||||
+ if (!cache)
|
||||
+ return std::nullopt;
|
||||
return CacheInfo {
|
||||
- .wantMassQuery = cache.wantMassQuery,
|
||||
- .priority = cache.priority
|
||||
+ .wantMassQuery = cache->wantMassQuery,
|
||||
+ .priority = cache->priority
|
||||
};
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue