libstore: make Worker::waitForAWhile private

Change-Id: I0cdcd436ee71124ca992b4f4fe307624a25f11e9
This commit is contained in:
eldritch horrors 2024-08-02 17:00:57 +02:00
parent b33c969519
commit 3ecb46e3e7
5 changed files with 14 additions and 15 deletions

View file

@ -701,8 +701,7 @@ Goal::WorkResult DerivationGoal::tryToBuild()
if (!actLock) if (!actLock)
actLock = std::make_unique<Activity>(*logger, lvlWarn, actBuildWaiting, actLock = std::make_unique<Activity>(*logger, lvlWarn, actBuildWaiting,
fmt("waiting for lock on %s", Magenta(showPaths(lockFiles)))); fmt("waiting for lock on %s", Magenta(showPaths(lockFiles))));
worker.waitForAWhile(shared_from_this()); return WaitForAWhile{};
return StillAlive{};
} }
actLock.reset(); actLock.reset();
@ -753,9 +752,8 @@ Goal::WorkResult DerivationGoal::tryToBuild()
if (!actLock) if (!actLock)
actLock = std::make_unique<Activity>(*logger, lvlTalkative, actBuildWaiting, actLock = std::make_unique<Activity>(*logger, lvlTalkative, actBuildWaiting,
fmt("waiting for a machine to build '%s'", Magenta(worker.store.printStorePath(drvPath)))); fmt("waiting for a machine to build '%s'", Magenta(worker.store.printStorePath(drvPath))));
worker.waitForAWhile(shared_from_this());
outputLocks.unlock(); outputLocks.unlock();
return StillAlive{}; return WaitForAWhile{};
case rpDecline: case rpDecline:
/* We should do it ourselves. */ /* We should do it ourselves. */
break; break;

View file

@ -107,12 +107,13 @@ public:
struct [[nodiscard]] StillAlive {}; struct [[nodiscard]] StillAlive {};
struct [[nodiscard]] WaitForSlot {}; struct [[nodiscard]] WaitForSlot {};
struct [[nodiscard]] WaitForAWhile {};
struct [[nodiscard]] Finished { struct [[nodiscard]] Finished {
ExitCode result; ExitCode result;
std::unique_ptr<Error> ex; std::unique_ptr<Error> ex;
}; };
struct [[nodiscard]] WorkResult : std::variant<StillAlive, WaitForSlot, Finished> struct [[nodiscard]] WorkResult : std::variant<StillAlive, WaitForSlot, WaitForAWhile, Finished>
{ {
WorkResult() = delete; WorkResult() = delete;
using variant::variant; using variant::variant;

View file

@ -201,8 +201,7 @@ Goal::WorkResult LocalDerivationGoal::tryLocalBuild()
if (!actLock) if (!actLock)
actLock = std::make_unique<Activity>(*logger, lvlWarn, actBuildWaiting, actLock = std::make_unique<Activity>(*logger, lvlWarn, actBuildWaiting,
fmt("waiting for a free build user ID for '%s'", Magenta(worker.store.printStorePath(drvPath)))); fmt("waiting for a free build user ID for '%s'", Magenta(worker.store.printStorePath(drvPath))));
worker.waitForAWhile(shared_from_this()); return WaitForAWhile{};
return StillAlive{};
} }
} }

View file

@ -188,6 +188,7 @@ void Worker::handleWorkResult(GoalPtr goal, Goal::WorkResult how)
overloaded{ overloaded{
[&](Goal::StillAlive) {}, [&](Goal::StillAlive) {},
[&](Goal::WaitForSlot) { waitForBuildSlot(goal); }, [&](Goal::WaitForSlot) { waitForBuildSlot(goal); },
[&](Goal::WaitForAWhile) { waitForAWhile(goal); },
[&](Goal::Finished & f) { goalFinished(goal, f); }, [&](Goal::Finished & f) { goalFinished(goal, f); },
}, },
how how

View file

@ -114,6 +114,14 @@ private:
*/ */
void waitForBuildSlot(GoalPtr goal); void waitForBuildSlot(GoalPtr goal);
/**
* Wait for a few seconds and then retry this goal. Used when
* waiting for a lock held by another process. This kind of
* polling is inefficient, but POSIX doesn't really provide a way
* to wait for multiple locks in the main select() loop.
*/
void waitForAWhile(GoalPtr goal);
public: public:
const Activity act; const Activity act;
@ -239,14 +247,6 @@ public:
*/ */
void childTerminated(Goal * goal); void childTerminated(Goal * goal);
/**
* Wait for a few seconds and then retry this goal. Used when
* waiting for a lock held by another process. This kind of
* polling is inefficient, but POSIX doesn't really provide a way
* to wait for multiple locks in the main select() loop.
*/
void waitForAWhile(GoalPtr goal);
/** /**
* Loop until the specified top-level goals have finished. * Loop until the specified top-level goals have finished.
*/ */