Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
worker.hh
Go to the documentation of this file.
1#pragma once
3
4#include "types.hh"
5#include "store-api.hh"
6#include "goal.hh"
7#include "realisation.hh"
8#include "muxable-pipe.hh"
9
10#include <future>
11#include <thread>
12
13namespace nix {
14
15/* Forward definition. */
16struct DerivationGoal;
19
32GoalPtr upcast_goal(std::shared_ptr<PathSubstitutionGoal> subGoal);
33GoalPtr upcast_goal(std::shared_ptr<DrvOutputSubstitutionGoal> subGoal);
34
35typedef std::chrono::time_point<std::chrono::steady_clock> steady_time_point;
36
42struct Child
43{
44 WeakGoalPtr goal;
45 Goal * goal2; // ugly hackery
46 std::set<MuxablePipePollState::CommChannel> channels;
47 bool respectTimeouts;
48 bool inBuildSlot;
52 steady_time_point lastOutput;
53 steady_time_point timeStarted;
54};
55
56#ifndef _WIN32 // TODO Enable building on Windows
57/* Forward definition. */
58struct HookInstance;
59#endif
60
64class Worker
65{
66private:
67
68 /* Note: the worker should only have strong pointers to the
69 top-level goals. */
70
74 Goals topGoals;
75
79 WeakGoals awake;
80
84 WeakGoals wantingToBuild;
85
89 std::list<Child> children;
90
95 size_t nrLocalBuilds;
96
100 size_t nrSubstitutions;
101
106 std::map<StorePath, std::weak_ptr<DerivationGoal>> derivationGoals;
107 std::map<StorePath, std::weak_ptr<PathSubstitutionGoal>> substitutionGoals;
108 std::map<DrvOutput, std::weak_ptr<DrvOutputSubstitutionGoal>> drvOutputSubstitutionGoals;
109
113 WeakGoals waitingForAnyGoal;
114
118 WeakGoals waitingForAWhile;
119
123 steady_time_point lastWokenUp;
124
128 std::map<StorePath, bool> pathContentsGoodCache;
129
130public:
131
132 const Activity act;
133 const Activity actDerivations;
134 const Activity actSubstitutions;
135
141
146
151
156
157#ifdef _WIN32
158 AutoCloseFD ioport;
159#endif
160
161 Store & store;
162 Store & evalStore;
163
164#ifndef _WIN32 // TODO Enable building on Windows
165 std::unique_ptr<HookInstance> hook;
166#endif
167
168 uint64_t expectedBuilds = 0;
169 uint64_t doneBuilds = 0;
170 uint64_t failedBuilds = 0;
171 uint64_t runningBuilds = 0;
172
173 uint64_t expectedSubstitutions = 0;
174 uint64_t doneSubstitutions = 0;
175 uint64_t failedSubstitutions = 0;
176 uint64_t runningSubstitutions = 0;
177 uint64_t expectedDownloadSize = 0;
178 uint64_t doneDownloadSize = 0;
179 uint64_t expectedNarSize = 0;
180 uint64_t doneNarSize = 0;
181
186 bool tryBuildHook = true;
187
188 Worker(Store & store, Store & evalStore);
189 ~Worker();
190
194
198private:
199 std::shared_ptr<DerivationGoal> makeDerivationGoalCommon(
200 const StorePath & drvPath, const OutputsSpec & wantedOutputs,
201 std::function<std::shared_ptr<DerivationGoal>()> mkDrvGoal);
202public:
203 std::shared_ptr<DerivationGoal> makeDerivationGoal(
204 const StorePath & drvPath,
205 const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal);
206 std::shared_ptr<DerivationGoal> makeBasicDerivationGoal(
207 const StorePath & drvPath, const BasicDerivation & drv,
208 const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal);
209
213 std::shared_ptr<PathSubstitutionGoal> makePathSubstitutionGoal(const StorePath & storePath, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
214 std::shared_ptr<DrvOutputSubstitutionGoal> makeDrvOutputSubstitutionGoal(const DrvOutput & id, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
215
222 GoalPtr makeGoal(const DerivedPath & req, BuildMode buildMode = bmNormal);
223
227 void removeGoal(GoalPtr goal);
228
232 void wakeUp(GoalPtr goal);
233
238 size_t getNrLocalBuilds();
239
243 size_t getNrSubstitutions();
244
249 void childStarted(GoalPtr goal, const std::set<MuxablePipePollState::CommChannel> & channels,
250 bool inBuildSlot, bool respectTimeouts);
251
258 void childTerminated(Goal * goal, bool wakeSleepers = true);
259
264 void waitForBuildSlot(GoalPtr goal);
265
270 void waitForAnyGoal(GoalPtr goal);
271
278 void waitForAWhile(GoalPtr goal);
279
283 void run(const Goals & topGoals);
284
288 void waitForInput();
289
290 /***
291 * The exit status in case of failure.
292 *
293 * In the case of a build failure, returned value follows this
294 * bitmask:
295 *
296 * ```
297 * 0b1100100
298 * ^^^^
299 * |||`- timeout
300 * ||`-- output hash mismatch
301 * |`--- build failure
302 * `---- not deterministic
303 * ```
304 *
305 * In other words, the failure code is at least 100 (0b1100100), but
306 * might also be greater.
307 *
308 * Otherwise (no build failure, but some other sort of failure by
309 * assumption), this returned value is 1.
310 */
311 unsigned int failingExitStatus();
312
317 bool pathContentsGood(const StorePath & path);
318
319 void markContentsGood(const StorePath & path);
320
321 void updateProgress()
322 {
323 actDerivations.progress(doneBuilds, expectedBuilds + doneBuilds, runningBuilds, failedBuilds);
324 actSubstitutions.progress(doneSubstitutions, expectedSubstitutions + doneSubstitutions, runningSubstitutions, failedSubstitutions);
325 act.setExpected(actFileTransfer, expectedDownloadSize + doneDownloadSize);
326 act.setExpected(actCopyPath, expectedNarSize + doneNarSize);
327 }
328};
329
330}
Definition file-descriptor.hh:152
Definition drv-output-substitution-goal.hh:23
Definition path.hh:27
Definition store-api.hh:169
size_t getNrLocalBuilds()
Definition worker.cc:187
bool hashMismatch
Definition worker.hh:150
void childStarted(GoalPtr goal, const std::set< MuxablePipePollState::CommChannel > &channels, bool inBuildSlot, bool respectTimeouts)
Definition worker.cc:199
GoalPtr makeGoal(const DerivedPath &req, BuildMode buildMode=bmNormal)
Definition worker.cc:119
bool timedOut
Definition worker.hh:145
void wakeUp(GoalPtr goal)
Definition worker.cc:180
bool checkMismatch
Definition worker.hh:155
bool pathContentsGood(const StorePath &path)
Definition worker.cc:506
void childTerminated(Goal *goal, bool wakeSleepers=true)
Definition worker.cc:225
bool permanentFailure
Definition worker.hh:140
void run(const Goals &topGoals)
Definition worker.cc:287
void removeGoal(GoalPtr goal)
Definition worker.cc:150
std::shared_ptr< PathSubstitutionGoal > makePathSubstitutionGoal(const StorePath &storePath, RepairFlag repair=NoRepair, std::optional< ContentAddress > ca=std::nullopt)
Definition worker.cc:93
void waitForInput()
Definition worker.cc:361
void waitForAWhile(GoalPtr goal)
Definition worker.cc:280
void waitForAnyGoal(GoalPtr goal)
Definition worker.cc:273
bool tryBuildHook
Definition worker.hh:186
void waitForBuildSlot(GoalPtr goal)
Definition worker.cc:261
size_t getNrSubstitutions()
Definition worker.cc:193
std::shared_ptr< Goal > GoalPtr
Definition goal.hh:20
std::set< GoalPtr, CompareGoalPtrs > Goals
Definition goal.hh:30
RepairFlag repair
Definition lexer.l:7173
Definition logging.hh:137
Definition derivations.hh:285
Definition worker.hh:43
steady_time_point lastOutput
Definition worker.hh:52
Definition derivation-goal.hh:61
Definition derived-path.hh:229
Definition realisation.hh:24
Definition goal.hh:56
Definition outputs-spec.hh:26
Definition substitution-goal.hh:15