Periodically clear orphaned build steps
[?]
Apr 13, 2016, 2:18 PM
7LWB2J2ZFB4XJDN5MBL2WDKVBRYQD7Y6RQU7LUYKH7PZTXK2H7KQCDependencies
- [2]
RGCPOSHYhydra-queue-runner: Ensure regular status dumps - [*]
MHVIT4JYSplit hydra-queue-runner.cc more - [*]
BRAESISHWarn if PostgreSQL appears stalled - [*]
24BMQDZAStart of single-process hydra-queue-runner - [*]
IE2PRAQUhydra-queue-runner: Send build notifications - [*]
HJOEIMLRRefactor
Change contents
- edit in src/hydra-queue-runner/builder.cc at line 5
#include "finally.hh" - edit in src/hydra-queue-runner/builder.cc at line 104
bool stepFinished = false;Finally clearStep([&]() {if (stepNr && !stepFinished) {auto orphanedSteps_(orphanedSteps.lock());orphanedSteps_->emplace(build->id, stepNr);}}); - edit in src/hydra-queue-runner/builder.cc at line 182
{ - edit in src/hydra-queue-runner/builder.cc at line 187
}stepFinished = true; - edit in src/hydra-queue-runner/builder.cc at line 248
stepFinished = true; - edit in src/hydra-queue-runner/builder.cc at line 373
stepFinished = true; - edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 828
/* Periodically clean up orphaned busy steps in the database. */std::thread([&]() {while (true) {sleep(180);std::set<std::pair<BuildID, int>> steps;{auto orphanedSteps_(orphanedSteps.lock());if (orphanedSteps_->empty()) continue;steps = *orphanedSteps_;orphanedSteps_->clear();}try {auto conn(dbPool.get());pqxx::work txn(*conn);for (auto & step : steps) {printMsg(lvlError, format("cleaning orphaned step %d of build %d") % step.second % step.first);txn.parameterized("update BuildSteps set busy = 0, status = $1 where build = $2 and stepnr = $3 and busy = 1")((int) bsAborted)(step.first)(step.second).exec();}txn.commit();} catch (std::exception & e) {printMsg(lvlError, format("cleanup thread: %1%") % e.what());auto orphanedSteps_(orphanedSteps.lock());orphanedSteps_->insert(steps.begin(), steps.end());}}}).detach(); - edit in src/hydra-queue-runner/state.hh at line 365[2.357][8.6778]
/* Steps that were busy while we encounted a PostgreSQLerror. These need to be cleared at a later time to prevent themfrom showing up as busy until the queue runner is restarted. */nix::Sync<std::set<std::pair<BuildID, int>>> orphanedSteps;