Support multiple machines files

[?]
Aug 25, 2015, 12:11 PM
O3NM62IZE5EMW4KY56TV53BUZZL2NHAC55W7NBPTD7A4CKT4CHUQC

Dependencies

  • [2] YVCZP2ZM Use /etc/nix/machines
  • [3] OG3Z3QGC Namespace cleanup
  • [4] PLOZBRTR Add command ‘hydra-queue-runner --status’ to show current status
  • [5] EYR3EW6J Keep stats for the Hydra auto scaler
  • [6] T2EIYJNG On SIGINT, shut down the builder threads
  • [7] ARATXDQ4 Remove dead code
  • [8] PMNWRTGJ Add multiple output support
  • [9] 5AIYUMTB Basic remote building
  • [10] DBBI2P4N Wake the dispatcher when the machines file has changed
  • [11] SODOV2CM Automatically reload $NIX_REMOTE_SYSTEMS when it changes
  • [12] FQQRJUO4 Mark builds as busy
  • [13] FULDVXE2 Periodically dump/log status
  • [14] CNLNT3T4 Allow only 1 thread to send a closure to a given machine at the same time
  • [15] TTBLPQAJ Keep track of wait time per system type
  • [16] 24BMQDZA Start of single-process hydra-queue-runner
  • [17] HTL6HIBM machine-status: Read /etc/nix.machines instead of using the BuildMachines table
  • [18] YZAI5GQU Implement a database connection pool
  • [19] NJJ7H64S Very basic multi-threaded queue runner
  • [20] 6ZB4CIW6 Security: Improve checking of build products
  • [21] SK6WHODM Support preferLocalBuild
  • [22] HJOEIMLR Refactor
  • [*] 2GK5DOU7 * Downloading closures.

Change contents

  • edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 25
    [4.687][4.687:825](),[4.825][4.244:245]()
    machinesFile = getEnv("NIX_REMOTE_SYSTEMS", "/etc/nix/machines");
    machinesFileStat.st_ino = 0;
    machinesFileStat.st_mtime = 0;
  • replacement in src/hydra-queue-runner/hydra-queue-runner.cc at line 31
    [4.7507][4.826:857]()
    void State::loadMachinesFile()
    [4.7507]
    [4.7922]
    void State::parseMachines(const std::string & contents)
  • edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 33
    [4.7924][4.858:879](),[4.879][4.8027:8063](),[4.8027][4.8027:8063](),[4.8063][4.880:1289](),[4.1289][4.382:454](),[4.454][4.1509:1579](),[4.1509][4.1509:1579](),[4.1579][4.8063:8064](),[4.8063][4.8063:8064]()
    string contents;
    if (pathExists(machinesFile)) {
    struct stat st;
    if (stat(machinesFile.c_str(), &st) != 0)
    throw SysError(format("getting stats about ‘%1%’") % machinesFile);
    if (st.st_ino == machinesFileStat.st_ino && st.st_mtime == machinesFileStat.st_mtime)
    return;
    printMsg(lvlDebug, "reloading machines");
    contents = readFile(machinesFile);
    machinesFileStat = st;
    } else {
    contents = "localhost " + concatStringsSep(",", localPlatforms)
    + " - " + int2String(settings.maxBuildJobs) + " 1";
    }
  • edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 87
    [4.3330]
    [4.3330]
    string defaultMachinesFile = "/etc/nix/machines";
    auto machinesFiles = tokenizeString<std::vector<Path>>(
    getEnv("NIX_REMOTE_SYSTEMS", pathExists(defaultMachinesFile) ? defaultMachinesFile : ""), ":");
    if (machinesFiles.empty()) {
    parseMachines("localhost " + concatStringsSep(",", localPlatforms)
    + " - " + int2String(settings.maxBuildJobs) + " 1");
    return;
    }
    std::vector<struct stat> fileStats;
    fileStats.resize(machinesFiles.size());
    for (unsigned int n = 0; n < machinesFiles.size(); ++n) {
    auto & st(fileStats[n]);
    st.st_ino = st.st_mtime = 0;
    }
    auto readMachinesFiles = [&]() {
    /* Check if any of the machines files changed. */
    bool anyChanged = false;
    for (unsigned int n = 0; n < machinesFiles.size(); ++n) {
    Path machinesFile = machinesFiles[n];
    struct stat st;
    if (stat(machinesFile.c_str(), &st) != 0) {
    if (errno != ENOENT)
    throw SysError(format("getting stats about ‘%1%’") % machinesFile);
    st.st_ino = st.st_mtime = 0;
    }
    auto & old(fileStats[n]);
    if (old.st_ino != st.st_ino || old.st_mtime != st.st_mtime)
    anyChanged = true;
    old = st;
    }
    if (!anyChanged) return;
    debug("reloading machines files");
    string contents;
    for (auto & machinesFile : machinesFiles) {
    try {
    contents += readFile(machinesFile);
    contents += '\n';
    } catch (SysError & e) {
    if (e.errNo != ENOENT) throw;
    }
    }
    parseMachines(contents);
    };
  • edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 141
    [4.3363]
    [4.3363]
    readMachinesFiles();
  • replacement in src/hydra-queue-runner/hydra-queue-runner.cc at line 143
    [4.3398][4.3398:3453]()
    sleep(60);
    loadMachinesFile();
    [4.3398]
    [4.3453]
    sleep(30);
  • edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 622
    [4.810][4.3285:3286](),[4.897][4.3285:3286](),[4.3854][4.3285:3286](),[4.3285][4.3285:3286](),[4.3286][4.5102:5126]()
    loadMachinesFile();
  • edit in src/hydra-queue-runner/state.hh at line 288
    [4.5276][4.5276:5277](),[4.5277][3.585:613](),[3.613][4.5300:5334](),[4.5300][4.5300:5334]()
    nix::Path machinesFile;
    struct stat machinesFileStat;
  • replacement in src/hydra-queue-runner/state.hh at line 352
    [4.6867][4.6867:6934]()
    /* (Re)load /etc/nix/machines. */
    void loadMachinesFile();
    [4.6867]
    [4.6934]
    void parseMachines(const std::string & contents);
  • edit in src/lib/Hydra/Helper/Nix.pm at line 289
    [4.441][2.0:74](),[2.74][4.515:549](),[4.515][4.515:549]()
    my $machinesConf = $ENV{"NIX_REMOTE_SYSTEMS"} || "/etc/nix/machines";
    # Read the list of machines.
  • replacement in src/lib/Hydra/Helper/Nix.pm at line 290
    [4.572][4.572:644]()
    if (-e $machinesConf) {
    open CONF, "<$machinesConf" or die;
    [4.572]
    [4.644]
    my @machinesFiles = split /:/, ($ENV{"NIX_REMOTE_SYSTEMS"} || "/etc/nix/machines");
    for my $machinesFile (@machinesFiles) {
    next unless -e $machinesFile;
    open CONF, "<$machinesFile" or die;
  • edit in src/lib/Hydra/Helper/Nix.pm at line 314
    [4.1376]
    [4.1376]