Use ref<Store> for localStore/destStore
As suggested by pennae. The stores don't need to be nullable, so we initialize them right in the constructor of `State`. (cherry picked from commit 4b2720816d24c2e9770d1d65b73dbc8974c6dc1d) The lix changes 7bf3d0fa2aac73a838ee91e1170034dfe3722159...949a5615405d24294abab4d3dfb05958d87c32d6 have caused build errors which are addressed with the changes to hydra herein as well as additional changes in lix. Fixes: #36 Flake lock file updates: • Updated input 'lix': 'git+https://git.lix.systems/lix-project/lix?ref=refs/heads/main&rev=b918f1c307b314daa44407bac60046630f13ed48' (2025-03-27) → 'git+https://git.lix.systems/lix-project/lix?ref=refs/heads/main&rev=2ef4b69760af183792a740f425eb371a6aeb0009' (2025-04-06) Co-authored-by: benaryorg <binary@benary.org> Signed-off-by: benaryorg <binary@benary.org>
This commit is contained in:
co-authored by
benaryorg
parent
53557fde75
commit
909542e1cb
Generated
+4
-4
@@ -28,11 +28,11 @@
|
||||
"pre-commit-hooks": "pre-commit-hooks"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1743065774,
|
||||
"narHash": "sha256-aC1lwnqwHbYRsPfx+lRi32fHRcln0xhIzf0Q7/Lg+vQ=",
|
||||
"lastModified": 1743964165,
|
||||
"narHash": "sha256-5vXjK5W+RIveud/Qn4OyVqrZi4pUDefKZsny33dDj+s=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "b918f1c307b314daa44407bac60046630f13ed48",
|
||||
"revCount": 17742,
|
||||
"rev": "2ef4b69760af183792a740f425eb371a6aeb0009",
|
||||
"revCount": 17767,
|
||||
"type": "git",
|
||||
"url": "https://git.lix.systems/lix-project/lix"
|
||||
},
|
||||
|
||||
@@ -654,7 +654,7 @@ void State::buildRemote(AsyncIoRoot & aio,
|
||||
outputs.insert(realisation.outPath);
|
||||
|
||||
/* Copy the output paths. */
|
||||
if (!machine->isLocalhost() || localStore != std::shared_ptr<Store>(destStore)) {
|
||||
if (!machine->isLocalhost() || localStore != destStore) {
|
||||
updateStep(ssReceivingOutputs);
|
||||
|
||||
MaintainCount<counter> mc(nrStepsCopyingFrom);
|
||||
|
||||
@@ -183,7 +183,7 @@ State::StepResult State::doBuildStep(AsyncIoRoot & aio,
|
||||
/* Upload the log file to the binary cache. FIXME: should
|
||||
be done on a worker thread. */
|
||||
try {
|
||||
auto store = destStore.dynamic_pointer_cast<BinaryCacheStore>();
|
||||
auto store = destStore.try_cast_shared<BinaryCacheStore>();
|
||||
if (uploadLogsToBinaryCache && store && pathExists(result.logFile)) {
|
||||
store->upsertFile("log/" + std::string(step->drvPath.to_string()), readFile(result.logFile), "text/plain; charset=utf-8");
|
||||
unlink(result.logFile.c_str());
|
||||
|
||||
@@ -102,11 +102,21 @@ State::PromMetrics::PromMetrics()
|
||||
|
||||
}
|
||||
|
||||
State::State(std::optional<std::string> metricsAddrOpt)
|
||||
State::State(std::optional<std::string> metricsAddrOpt, AsyncIoRoot & aio)
|
||||
: config(std::make_unique<HydraConfig>())
|
||||
, maxUnsupportedTime(config->getIntOption("max_unsupported_time", 0))
|
||||
, dbPool(config->getIntOption("max_db_connections", 128))
|
||||
, localWorkThrottler(static_cast<ptrdiff_t>(config->getIntOption("max_local_worker_threads", std::min(maxSupportedLocalWorkers, std::max(4u, std::thread::hardware_concurrency()) - 2))))
|
||||
, localStore([&]() {
|
||||
StoreConfig::Params localParams;
|
||||
localParams["max-connections"] = "16";
|
||||
localParams["max-connection-age"] = "600";
|
||||
return aio.blockOn(openStore(getEnv("NIX_REMOTE").value_or(""), localParams));
|
||||
}())
|
||||
, _destStore([&](){
|
||||
auto storeUri = config->getStrOption("store_uri");
|
||||
return storeUri == "" ? ref<Store>{*localStore} : aio.blockOn(openStore(storeUri));
|
||||
}())
|
||||
, maxOutputSize(config->getIntOption("max_output_size", 2ULL << 30))
|
||||
, maxLogSize(config->getIntOption("max_log_size", 64ULL << 20))
|
||||
, uploadLogsToBinaryCache(config->getBoolOption("upload_logs_to_binary_cache", false))
|
||||
@@ -145,7 +155,7 @@ nix::MaintainCount<counter> State::startDbUpdate()
|
||||
|
||||
ref<Store> State::getDestStore()
|
||||
{
|
||||
return ref<Store>(_destStore);
|
||||
return ref<Store>{*_destStore};
|
||||
}
|
||||
|
||||
|
||||
@@ -866,14 +876,6 @@ void State::run(AsyncIoRoot & aio, BuildID buildOne)
|
||||
<< metricsAddr << "/metrics (port " << exposerPort << ")"
|
||||
<< std::endl;
|
||||
|
||||
StoreConfig::Params localParams;
|
||||
localParams["max-connections"] = "16";
|
||||
localParams["max-connection-age"] = "600";
|
||||
localStore = aio.blockOn(openStore(getEnv("NIX_REMOTE").value_or(""), localParams));
|
||||
|
||||
auto storeUri = config->getStrOption("store_uri");
|
||||
_destStore = storeUri == "" ? localStore : aio.blockOn(openStore(storeUri));
|
||||
|
||||
useSubstitutes = config->getBoolOption("use-substitutes", false);
|
||||
|
||||
// FIXME: hacky mechanism for configuring determinism checks.
|
||||
@@ -993,7 +995,7 @@ int main(int argc, char * * argv)
|
||||
|
||||
settings.verboseBuild = true;
|
||||
|
||||
State state{metricsAddrOpt};
|
||||
State state{metricsAddrOpt, aio};
|
||||
if (status)
|
||||
state.showStatus(aio);
|
||||
else if (unlock)
|
||||
|
||||
@@ -454,8 +454,8 @@ private:
|
||||
|
||||
std::atomic<time_t> lastDispatcherCheck{0};
|
||||
|
||||
std::shared_ptr<nix::Store> localStore;
|
||||
std::shared_ptr<nix::Store> _destStore;
|
||||
nix::ref<nix::Store> localStore;
|
||||
nix::ref<nix::Store> _destStore;
|
||||
|
||||
size_t maxOutputSize;
|
||||
size_t maxLogSize;
|
||||
@@ -499,7 +499,7 @@ private:
|
||||
PromMetrics prom;
|
||||
|
||||
public:
|
||||
State(std::optional<std::string> metricsAddrOpt);
|
||||
State(std::optional<std::string> metricsAddrOpt, nix::AsyncIoRoot & aio);
|
||||
|
||||
struct BuildOptions {
|
||||
unsigned int maxSilentTime, buildTimeout, repeats;
|
||||
|
||||
@@ -16,6 +16,13 @@ hydra_setup($db);
|
||||
|
||||
my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-send-stats", "--once"));
|
||||
is($stdout, "", "hydra-send-stats stdout should be empty");
|
||||
|
||||
# Remove `unknown setting` warnings. These can happen in the dev shell with a
|
||||
# local `nix.conf` or even in tests since the tests are using a local chroot store,
|
||||
# but hydra-queue-runner sets store config for a remote store.
|
||||
# hydra-queue-runner initializes stores in its ctor now, so these warnings get propagated
|
||||
# in the tests to hydra-send-stats.
|
||||
$stderr = join "\n", grep { 0 != rindex $_, "warning: unknown setting" } split "\n", $stderr;
|
||||
is($stderr, "", "hydra-send-stats stderr should be empty");
|
||||
is($res, 0, "hydra-send-stats --once should exit zero");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user