Skip to content

Commit c8879f9

Browse files
committed
Fix libpqxx 7.10.1 API compatibility
- Replace deprecated exec_params/exec_params0 calls with exec() - Wrap all parameterized queries with pqxx::params{} - Add .no_rows()/.one_row() to exec calls that don't return results
1 parent 2f998c1 commit c8879f9

File tree

4 files changed

+87
-117
lines changed

4 files changed

+87
-117
lines changed

src/hydra-evaluator/hydra-evaluator.cc

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,8 @@ struct Evaluator
180180
{
181181
auto conn(dbPool.get());
182182
pqxx::work txn(*conn);
183-
txn.exec_params0
184-
("update Jobsets set startTime = $1 where id = $2",
185-
now,
186-
jobset.name.id);
183+
txn.exec("update Jobsets set startTime = $1 where id = $2",
184+
pqxx::params{now, jobset.name.id}).no_rows();
187185
txn.commit();
188186
}
189187

@@ -234,7 +232,7 @@ struct Evaluator
234232
pqxx::work txn(*conn);
235233

236234
if (jobset.evaluation_style == EvaluationStyle::ONE_AT_A_TIME) {
237-
auto evaluation_res = txn.exec_params
235+
auto evaluation_res = txn.exec
238236
("select id from JobsetEvals "
239237
"where jobset_id = $1 "
240238
"order by id desc limit 1"
@@ -250,7 +248,7 @@ struct Evaluator
250248

251249
auto evaluation_id = evaluation_res[0][0].as<int>();
252250

253-
auto unfinished_build_res = txn.exec_params
251+
auto unfinished_build_res = txn.exec
254252
("select id from Builds "
255253
"join JobsetEvalMembers "
256254
" on (JobsetEvalMembers.build = Builds.id) "
@@ -420,21 +418,18 @@ struct Evaluator
420418
/* Clear the trigger time to prevent this
421419
jobset from getting stuck in an endless
422420
failing eval loop. */
423-
txn.exec_params0
421+
txn.exec
424422
("update Jobsets set triggerTime = null where id = $1 and startTime is not null and triggerTime <= startTime",
425-
jobset.name.id);
423+
jobset.name.id).no_rows();
426424

427425
/* Clear the start time. */
428-
txn.exec_params0
426+
txn.exec
429427
("update Jobsets set startTime = null where id = $1",
430-
jobset.name.id);
428+
jobset.name.id).no_rows();
431429

432430
if (!WIFEXITED(status) || WEXITSTATUS(status) > 1) {
433-
txn.exec_params0
434-
("update Jobsets set errorMsg = $1, lastCheckedTime = $2, errorTime = $2, fetchErrorMsg = null where id = $3",
435-
fmt("evaluation %s", statusToString(status)),
436-
now,
437-
jobset.name.id);
431+
txn.exec("update Jobsets set errorMsg = $1, lastCheckedTime = $2, errorTime = $2, fetchErrorMsg = null where id = $3",
432+
pqxx::params{fmt("evaluation %s", statusToString(status)), now, jobset.name.id}).no_rows();
438433
}
439434

440435
txn.commit();
@@ -459,7 +454,7 @@ struct Evaluator
459454
{
460455
auto conn(dbPool.get());
461456
pqxx::work txn(*conn);
462-
txn.exec("update Jobsets set startTime = null");
457+
txn.exec("update Jobsets set startTime = null").no_rows();
463458
txn.commit();
464459
}
465460

src/hydra-queue-runner/builder.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,12 @@ void State::failStep(
458458
for (auto & build : indirect) {
459459
if (build->finishedInDB) continue;
460460
printError("marking build %1% as failed", build->id);
461-
txn.exec_params0
462-
("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $4, isCachedBuild = $5, notificationPendingSince = $4 where id = $1 and finished = 0",
463-
build->id,
461+
txn.exec("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $4, isCachedBuild = $5, notificationPendingSince = $4 where id = $1 and finished = 0",
462+
pqxx::params{build->id,
464463
(int) (build->drvPath != step->drvPath && result.buildStatus() == bsFailed ? bsDepFailed : result.buildStatus()),
465464
result.startTime,
466465
result.stopTime,
467-
result.stepStatus == bsCachedFailure ? 1 : 0);
466+
result.stepStatus == bsCachedFailure ? 1 : 0}).no_rows();
468467
nrBuildsDone++;
469468
}
470469

@@ -473,7 +472,7 @@ void State::failStep(
473472
if (result.stepStatus != bsCachedFailure && result.canCache)
474473
for (auto & i : step->drv->outputsAndOptPaths(*localStore))
475474
if (i.second.second)
476-
txn.exec_params0("insert into FailedPaths values ($1)", localStore->printStorePath(*i.second.second));
475+
txn.exec("insert into FailedPaths values ($1)", pqxx::params{localStore->printStorePath(*i.second.second)}).no_rows();
477476

478477
txn.commit();
479478
}

src/hydra-queue-runner/hydra-queue-runner.cc

Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,16 @@ void State::monitorMachinesFile()
276276
void State::clearBusy(Connection & conn, time_t stopTime)
277277
{
278278
pqxx::work txn(conn);
279-
txn.exec_params0
280-
("update BuildSteps set busy = 0, status = $1, stopTime = $2 where busy != 0",
281-
(int) bsAborted,
282-
stopTime != 0 ? std::make_optional(stopTime) : std::nullopt);
279+
txn.exec("update BuildSteps set busy = 0, status = $1, stopTime = $2 where busy != 0",
280+
pqxx::params{(int) bsAborted,
281+
stopTime != 0 ? std::make_optional(stopTime) : std::nullopt}).no_rows();
283282
txn.commit();
284283
}
285284

286285

287286
unsigned int State::allocBuildStep(pqxx::work & txn, BuildID buildId)
288287
{
289-
auto res = txn.exec_params1("select max(stepnr) from BuildSteps where build = $1", buildId);
288+
auto res = txn.exec("select max(stepnr) from BuildSteps where build = $1", buildId).one_row();
290289
return res[0].is_null() ? 1 : res[0].as<int>() + 1;
291290
}
292291

@@ -297,9 +296,8 @@ unsigned int State::createBuildStep(pqxx::work & txn, time_t startTime, BuildID
297296
restart:
298297
auto stepNr = allocBuildStep(txn, buildId);
299298

300-
auto r = txn.exec_params
301-
("insert into BuildSteps (build, stepnr, type, drvPath, busy, startTime, system, status, propagatedFrom, errorMsg, stopTime, machine) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) on conflict do nothing",
302-
buildId,
299+
auto r = txn.exec("insert into BuildSteps (build, stepnr, type, drvPath, busy, startTime, system, status, propagatedFrom, errorMsg, stopTime, machine) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) on conflict do nothing",
300+
pqxx::params{buildId,
303301
stepNr,
304302
0, // == build
305303
localStore->printStorePath(step->drvPath),
@@ -310,17 +308,16 @@ unsigned int State::createBuildStep(pqxx::work & txn, time_t startTime, BuildID
310308
propagatedFrom != 0 ? std::make_optional(propagatedFrom) : std::nullopt, // internal::params
311309
errorMsg != "" ? std::make_optional(errorMsg) : std::nullopt,
312310
startTime != 0 && status != bsBusy ? std::make_optional(startTime) : std::nullopt,
313-
machine);
311+
machine});
314312

315313
if (r.affected_rows() == 0) goto restart;
316314

317315
for (auto & [name, output] : getDestStore()->queryPartialDerivationOutputMap(step->drvPath, &*localStore))
318-
txn.exec_params0
319-
("insert into BuildStepOutputs (build, stepnr, name, path) values ($1, $2, $3, $4)",
320-
buildId, stepNr, name,
316+
txn.exec("insert into BuildStepOutputs (build, stepnr, name, path) values ($1, $2, $3, $4)",
317+
pqxx::params{buildId, stepNr, name,
321318
output
322319
? std::optional { localStore->printStorePath(*output)}
323-
: std::nullopt);
320+
: std::nullopt}).no_rows();
324321

325322
if (status == bsBusy)
326323
txn.exec(fmt("notify step_started, '%d\t%d'", buildId, stepNr));
@@ -331,11 +328,10 @@ unsigned int State::createBuildStep(pqxx::work & txn, time_t startTime, BuildID
331328

332329
void State::updateBuildStep(pqxx::work & txn, BuildID buildId, unsigned int stepNr, StepState stepState)
333330
{
334-
if (txn.exec_params
335-
("update BuildSteps set busy = $1 where build = $2 and stepnr = $3 and busy != 0 and status is null",
336-
(int) stepState,
331+
if (txn.exec("update BuildSteps set busy = $1 where build = $2 and stepnr = $3 and busy != 0 and status is null",
332+
pqxx::params{(int) stepState,
337333
buildId,
338-
stepNr).affected_rows() != 1)
334+
stepNr}).affected_rows() != 1)
339335
throw Error("step %d of build %d is in an unexpected state", stepNr, buildId);
340336
}
341337

@@ -345,29 +341,27 @@ void State::finishBuildStep(pqxx::work & txn, const RemoteResult & result,
345341
{
346342
assert(result.startTime);
347343
assert(result.stopTime);
348-
txn.exec_params0
349-
("update BuildSteps set busy = 0, status = $1, errorMsg = $4, startTime = $5, stopTime = $6, machine = $7, overhead = $8, timesBuilt = $9, isNonDeterministic = $10 where build = $2 and stepnr = $3",
350-
(int) result.stepStatus, buildId, stepNr,
344+
txn.exec("update BuildSteps set busy = 0, status = $1, errorMsg = $4, startTime = $5, stopTime = $6, machine = $7, overhead = $8, timesBuilt = $9, isNonDeterministic = $10 where build = $2 and stepnr = $3",
345+
pqxx::params{(int) result.stepStatus, buildId, stepNr,
351346
result.errorMsg != "" ? std::make_optional(result.errorMsg) : std::nullopt,
352347
result.startTime, result.stopTime,
353348
machine != "" ? std::make_optional(machine) : std::nullopt,
354349
result.overhead != 0 ? std::make_optional(result.overhead) : std::nullopt,
355350
result.timesBuilt > 0 ? std::make_optional(result.timesBuilt) : std::nullopt,
356-
result.timesBuilt > 1 ? std::make_optional(result.isNonDeterministic) : std::nullopt);
351+
result.timesBuilt > 1 ? std::make_optional(result.isNonDeterministic) : std::nullopt}).no_rows();
357352
assert(result.logFile.find('\t') == std::string::npos);
358353
txn.exec(fmt("notify step_finished, '%d\t%d\t%s'",
359354
buildId, stepNr, result.logFile));
360355

361356
if (result.stepStatus == bsSuccess) {
362357
// Update the corresponding `BuildStepOutputs` row to add the output path
363-
auto res = txn.exec_params1("select drvPath from BuildSteps where build = $1 and stepnr = $2", buildId, stepNr);
358+
auto res = txn.exec("select drvPath from BuildSteps where build = $1 and stepnr = $2", pqxx::params{buildId, stepNr}).one_row();
364359
assert(res.size());
365360
StorePath drvPath = localStore->parseStorePath(res[0].as<std::string>());
366361
// If we've finished building, all the paths should be known
367362
for (auto & [name, output] : getDestStore()->queryDerivationOutputMap(drvPath, &*localStore))
368-
txn.exec_params0
369-
("update BuildStepOutputs set path = $4 where build = $1 and stepnr = $2 and name = $3",
370-
buildId, stepNr, name, localStore->printStorePath(output));
363+
txn.exec("update BuildStepOutputs set path = $4 where build = $1 and stepnr = $2 and name = $3",
364+
pqxx::params{buildId, stepNr, name, localStore->printStorePath(output)}).no_rows();
371365
}
372366
}
373367

@@ -378,23 +372,21 @@ int State::createSubstitutionStep(pqxx::work & txn, time_t startTime, time_t sto
378372
restart:
379373
auto stepNr = allocBuildStep(txn, build->id);
380374

381-
auto r = txn.exec_params
382-
("insert into BuildSteps (build, stepnr, type, drvPath, busy, status, startTime, stopTime) values ($1, $2, $3, $4, $5, $6, $7, $8) on conflict do nothing",
383-
build->id,
375+
auto r = txn.exec("insert into BuildSteps (build, stepnr, type, drvPath, busy, status, startTime, stopTime) values ($1, $2, $3, $4, $5, $6, $7, $8) on conflict do nothing",
376+
pqxx::params{build->id,
384377
stepNr,
385378
1, // == substitution
386379
(localStore->printStorePath(drvPath)),
387380
0,
388381
0,
389382
startTime,
390-
stopTime);
383+
stopTime});
391384

392385
if (r.affected_rows() == 0) goto restart;
393386

394-
txn.exec_params0
395-
("insert into BuildStepOutputs (build, stepnr, name, path) values ($1, $2, $3, $4)",
396-
build->id, stepNr, outputName,
397-
localStore->printStorePath(storePath));
387+
txn.exec("insert into BuildStepOutputs (build, stepnr, name, path) values ($1, $2, $3, $4)",
388+
pqxx::params{build->id, stepNr, outputName,
389+
localStore->printStorePath(storePath)}).no_rows();
398390

399391
return stepNr;
400392
}
@@ -461,58 +453,54 @@ void State::markSucceededBuild(pqxx::work & txn, Build::ptr build,
461453
{
462454
if (build->finishedInDB) return;
463455

464-
if (txn.exec_params("select 1 from Builds where id = $1 and finished = 0", build->id).empty()) return;
456+
if (txn.exec("select 1 from Builds where id = $1 and finished = 0", pqxx::params{build->id}).empty()) return;
465457

466-
txn.exec_params0
467-
("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $4, size = $5, closureSize = $6, releaseName = $7, isCachedBuild = $8, notificationPendingSince = $4 where id = $1",
468-
build->id,
458+
txn.exec("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $4, size = $5, closureSize = $6, releaseName = $7, isCachedBuild = $8, notificationPendingSince = $4 where id = $1",
459+
pqxx::params{build->id,
469460
(int) (res.failed ? bsFailedWithOutput : bsSuccess),
470461
startTime,
471462
stopTime,
472463
res.size,
473464
res.closureSize,
474465
res.releaseName != "" ? std::make_optional(res.releaseName) : std::nullopt,
475-
isCachedBuild ? 1 : 0);
466+
isCachedBuild ? 1 : 0}).no_rows();
476467

477468
for (auto & [outputName, outputPath] : res.outputs) {
478-
txn.exec_params0
479-
("update BuildOutputs set path = $3 where build = $1 and name = $2",
480-
build->id,
469+
txn.exec("update BuildOutputs set path = $3 where build = $1 and name = $2",
470+
pqxx::params{build->id,
481471
outputName,
482-
localStore->printStorePath(outputPath)
483-
);
472+
localStore->printStorePath(outputPath)}
473+
).no_rows();
484474
}
485475

486-
txn.exec_params0("delete from BuildProducts where build = $1", build->id);
476+
txn.exec("delete from BuildProducts where build = $1", pqxx::params{build->id}).no_rows();
487477

488478
unsigned int productNr = 1;
489479
for (auto & product : res.products) {
490-
txn.exec_params0
491-
("insert into BuildProducts (build, productnr, type, subtype, fileSize, sha256hash, path, name, defaultPath) values ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
492-
build->id,
480+
txn.exec("insert into BuildProducts (build, productnr, type, subtype, fileSize, sha256hash, path, name, defaultPath) values ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
481+
pqxx::params{build->id,
493482
productNr++,
494483
product.type,
495484
product.subtype,
496485
product.fileSize ? std::make_optional(*product.fileSize) : std::nullopt,
497486
product.sha256hash ? std::make_optional(product.sha256hash->to_string(HashFormat::Base16, false)) : std::nullopt,
498487
product.path,
499488
product.name,
500-
product.defaultPath);
489+
product.defaultPath}).no_rows();
501490
}
502491

503-
txn.exec_params0("delete from BuildMetrics where build = $1", build->id);
492+
txn.exec("delete from BuildMetrics where build = $1", pqxx::params{build->id}).no_rows();
504493

505494
for (auto & metric : res.metrics) {
506-
txn.exec_params0
507-
("insert into BuildMetrics (build, name, unit, value, project, jobset, job, timestamp) values ($1, $2, $3, $4, $5, $6, $7, $8)",
508-
build->id,
495+
txn.exec("insert into BuildMetrics (build, name, unit, value, project, jobset, job, timestamp) values ($1, $2, $3, $4, $5, $6, $7, $8)",
496+
pqxx::params{build->id,
509497
metric.second.name,
510498
metric.second.unit != "" ? std::make_optional(metric.second.unit) : std::nullopt,
511499
metric.second.value,
512500
build->projectName,
513501
build->jobsetName,
514502
build->jobName,
515-
build->timestamp);
503+
build->timestamp}).no_rows();
516504
}
517505

518506
nrBuildsDone++;
@@ -524,7 +512,7 @@ bool State::checkCachedFailure(Step::ptr step, Connection & conn)
524512
pqxx::work txn(conn);
525513
for (auto & i : step->drv->outputsAndOptPaths(*localStore))
526514
if (i.second.second)
527-
if (!txn.exec_params("select 1 from FailedPaths where path = $1", localStore->printStorePath(*i.second.second)).empty())
515+
if (!txn.exec("select 1 from FailedPaths where path = $1", pqxx::params{localStore->printStorePath(*i.second.second)}).empty())
528516
return true;
529517
return false;
530518
}
@@ -736,8 +724,8 @@ void State::dumpStatus(Connection & conn)
736724
auto mc = startDbUpdate();
737725
pqxx::work txn(conn);
738726
// FIXME: use PostgreSQL 9.5 upsert.
739-
txn.exec("delete from SystemStatus where what = 'queue-runner'");
740-
txn.exec_params0("insert into SystemStatus values ('queue-runner', $1)", statusJson.dump());
727+
txn.exec("delete from SystemStatus where what = 'queue-runner'").no_rows();
728+
txn.exec("insert into SystemStatus values ('queue-runner', $1)", pqxx::params{statusJson.dump()}).no_rows();
741729
txn.exec("notify status_dumped");
742730
txn.commit();
743731
}
@@ -802,7 +790,7 @@ void State::unlock()
802790

803791
{
804792
pqxx::work txn(*conn);
805-
txn.exec("delete from SystemStatus where what = 'queue-runner'");
793+
txn.exec("delete from SystemStatus where what = 'queue-runner'").no_rows();
806794
txn.commit();
807795
}
808796
}
@@ -880,11 +868,10 @@ void State::run(BuildID buildOne)
880868
pqxx::work txn(*conn);
881869
for (auto & step : steps) {
882870
printMsg(lvlError, "cleaning orphaned step %d of build %d", step.second, step.first);
883-
txn.exec_params0
884-
("update BuildSteps set busy = 0, status = $1 where build = $2 and stepnr = $3 and busy != 0",
885-
(int) bsAborted,
871+
txn.exec("update BuildSteps set busy = 0, status = $1 where build = $2 and stepnr = $3 and busy != 0",
872+
pqxx::params{(int) bsAborted,
886873
step.first,
887-
step.second);
874+
step.second}).no_rows();
888875
}
889876
txn.commit();
890877
} catch (std::exception & e) {

0 commit comments

Comments
 (0)