From 45b138373bf4b5b1ed677d16d3ee172284fe0dc0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Oct 2017 18:55:38 +0200 Subject: [PATCH] hydra-queue-runner: Write GC roots for outputs paths We lost this behaviour somewhere. So build outputs could be GC'ed when running the collector with --option gc-keep-outputs false. --- src/hydra-queue-runner/builder.cc | 3 +++ src/hydra-queue-runner/hydra-queue-runner.cc | 1 + src/hydra-queue-runner/queue-monitor.cc | 3 +++ src/hydra-queue-runner/state.hh | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/src/hydra-queue-runner/builder.cc b/src/hydra-queue-runner/builder.cc index 983ebfec..8a636b17 100644 --- a/src/hydra-queue-runner/builder.cc +++ b/src/hydra-queue-runner/builder.cc @@ -263,6 +263,9 @@ State::StepResult State::doBuildStep(nix::ref destStore, assert(stepNr); + for (auto & path : step->drv.outputPaths()) + writeFile(rootsDir + "/" + baseNameOf(path), ""); + /* Register success in the database for all Build objects that have this step as the top-level step. Since the queue monitor thread may be creating new referring Builds diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 9c56beda..4d0ec169 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -87,6 +87,7 @@ State::State() , 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)) + , rootsDir(config->getStrOption("gc_roots_dir", fmt("%s/gcroots/per-user/%s/hydra-roots", settings.nixStateDir, getEnv("USER")))) { debug("using %d bytes for the NAR buffer", memoryTokens.capacity()); diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index 895363bc..85d8f626 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -221,6 +221,9 @@ bool State::getQueuedBuilds(Connection & conn, Derivation drv = readDerivation(build->drvPath); BuildOutput res = getBuildOutputCached(conn, destStore, drv); + for (auto & path : drv.outputPaths()) + writeFile(rootsDir + "/" + baseNameOf(path), ""); + { auto mc = startDbUpdate(); pqxx::work txn(conn); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index d8dc11f7..f5ba641e 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -436,6 +436,11 @@ private: bool uploadLogsToBinaryCache; + /* Where to store GC roots. Defaults to + /nix/var/nix/gcroots/per-user/$USER/hydra-roots, overridable + via gc_roots_dir. */ + nix::Path rootsDir; + public: State();