Reuse build products / metrics stored in the database

[?]
Apr 13, 2016, 1:38 PM
WDGARQ76X6RLSFPJTW52BZYFKBC7DPSTABI7HHIKNYHBYXSUNTHQC

Dependencies

  • [2] ACBS7C6Q hydra-queue-runner: Detect changes to the scheduling shares
  • [3] BAFICF73 Support hydra-build-products on binary cache stores
  • [4] H7SZRHUB Use nix::willBuildLocally()
  • [5] DKJFD6JN Process Nix API changes
  • [6] 73YR46NJ hydra-queue-runner: Write directly to a binary cache
  • [7] ZK76B5ZZ Load the queue in order of global priority
  • [8] VQISTKOP hydra-queue-runner: Use substitutes
  • [9] MHVIT4JY Split hydra-queue-runner.cc more
  • [*] HJOEIMLR Refactor

Change contents

  • edit in src/hydra-queue-runner/queue-monitor.cc at line 4
    [4.77][4.20115:20116](),[4.1279][4.20115:20116](),[4.20115][4.20115:20116]()
  • replacement in src/hydra-queue-runner/queue-monitor.cc at line 161
    [4.24924][3.2070:2160]()
    BuildOutput res = getBuildOutput(destStore, destStore->getFSAccessor(), drv);
    [4.24924]
    [4.24982]
    BuildOutput res = getBuildOutputCached(conn, destStore, drv);
  • edit in src/hydra-queue-runner/queue-monitor.cc at line 531
    [2.1117]
    [2.1117]
    }
    }
    BuildOutput State::getBuildOutputCached(Connection & conn, nix::ref<nix::Store> destStore, const nix::Derivation & drv)
    {
    {
    pqxx::work txn(conn);
    for (auto & output : drv.outputs) {
    auto r = txn.parameterized
    ("select id, buildStatus, releaseName, closureSize, size from Builds b "
    "join BuildOutputs o on b.id = o.build "
    "where finished = 1 and (buildStatus = 0 or buildStatus = 6) and path = $1")
    (output.second.path).exec();
    if (r.empty()) continue;
    BuildID id = r[0][0].as<BuildID>();
    printMsg(lvlInfo, format("re-using products of build %d") % id);
    BuildOutput res;
    res.failed = r[0][1].as<int>() == bsFailedWithOutput;
    res.releaseName = r[0][2].is_null() ? "" : r[0][2].as<std::string>();
    res.closureSize = r[0][3].is_null() ? 0 : r[0][3].as<unsigned long long>();
    res.size = r[0][4].is_null() ? 0 : r[0][4].as<unsigned long long>();
    auto products = txn.parameterized
    ("select type, subtype, fileSize, sha1hash, sha256hash, path, name, defaultPath from BuildProducts where build = $1 order by productnr")
    (id).exec();
    for (auto row : products) {
    BuildProduct product;
    product.type = row[0].as<std::string>();
    product.subtype = row[1].as<std::string>();
    if (row[2].is_null())
    product.isRegular = false;
    else {
    product.isRegular = true;
    product.fileSize = row[2].as<off_t>();
    }
    if (!row[3].is_null())
    product.sha1hash = parseHash(htSHA1, row[3].as<std::string>());
    if (!row[4].is_null())
    product.sha256hash = parseHash(htSHA256, row[4].as<std::string>());
    if (!row[5].is_null())
    product.path = row[5].as<std::string>();
    product.name = row[6].as<std::string>();
    if (!row[7].is_null())
    product.defaultPath = row[7].as<std::string>();
    res.products.emplace_back(product);
    }
    auto metrics = txn.parameterized
    ("select name, unit, value from BuildMetrics where build = $1")
    (id).exec();
    for (auto row : metrics) {
    BuildMetric metric;
    metric.name = row[0].as<std::string>();
    metric.unit = row[1].is_null() ? "" : row[1].as<std::string>();
    metric.value = row[2].as<double>();
    res.metrics.emplace(metric.name, metric);
    }
    return res;
  • edit in src/hydra-queue-runner/queue-monitor.cc at line 597
    [2.1123]
    [2.1123]
    }
    return getBuildOutput(destStore, destStore->getFSAccessor(), drv);
  • edit in src/hydra-queue-runner/state.hh at line 413
    [11.7785]
    [4.1160]
    BuildOutput getBuildOutputCached(Connection & conn, nix::ref<nix::Store> destStore,
    const nix::Derivation & drv);