Skip to content

Commit

Permalink
Revert "[backend] retry 5 times on locking process state file"
Browse files Browse the repository at this point in the history
Fixing the root cause instead...

This reverts commit 3daf16a.
  • Loading branch information
mlschroe committed Feb 3, 2016
1 parent 17ce939 commit a28fe25
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
22 changes: 0 additions & 22 deletions src/backend/BSUtil.pm
Expand Up @@ -726,26 +726,4 @@ sub identical {
return 1;
}

sub lock_daemon_file {
# workaround when systemd starts the new process while the old is still running.
my ($dir, $name) = @_;
mkdir_p($dir);
my $count = 0;
while ($count < 5) {
$count++;
open(RUNLOCK, '>>', "$dir/bs_$name.lock") || die("$dir/bs_$name.lock: $!\n");
if (flock(RUNLOCK, LOCK_EX | LOCK_NB)) {
# success
utime undef, undef, "$dir/bs_$name.lock";
return;
} else {
# failed, sleep and retry
print "lock of $name failed, retrying...\n";
close(RUNLOCK);
sleep(1);
}
}
die("$name is already running!\n");
}

1;
5 changes: 4 additions & 1 deletion src/backend/bs_dispatch
Expand Up @@ -825,7 +825,10 @@ BSUtil::restartexit($ARGV[0], 'dispatcher', "$rundir/bs_dispatch");
printlog("starting build service dispatcher");

# get lock
BSUtil::lock_daemon_file($rundir, "dispatch");
mkdir_p($rundir);
open(RUNLOCK, '>>', "$rundir/bs_dispatch.lock") || die("$rundir/bs_dispatch.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("dispatcher is already running!\n");
utime undef, undef, "$rundir/bs_dispatch.lock";

my $dispatchprios;
my $dispatchprios_project;
Expand Down
5 changes: 4 additions & 1 deletion src/backend/bs_dodup
Expand Up @@ -478,7 +478,10 @@ if (!@ARGV || (@ARGV == 1 && ($ARGV[0] eq '--restart' || $ARGV[0] eq '--exit' ||
$SIG{'PIPE'} = 'IGNORE';
BSUtil::restartexit($ARGV[0], 'dodup', "$rundir/bs_dodup");
printlog("starting build service DoD updater");
BSUtil::lock_daemon_file($rundir, "dodup");
mkdir_p($rundir);
open(RUNLOCK, '>>', "$rundir/bs_dodup.lock") || die("$rundir/bs_dodup.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("dodup is already running!\n");
utime undef, undef, "$rundir/bs_dodup.lock";
daemon();
}

Expand Down
6 changes: 5 additions & 1 deletion src/backend/bs_publish
Expand Up @@ -2175,7 +2175,11 @@ $| = 1;
$SIG{'PIPE'} = 'IGNORE';
BSUtil::restartexit($ARGV[0], 'publisher', "$rundir/bs_publish", "$myeventdir/.ping");
print "starting build service publisher\n";
BSUtil::lock_daemon_file($rundir, "publish");

mkdir_p($rundir);
open(RUNLOCK, '>>', "$rundir/bs_publish.lock") || die("$rundir/bs_publish.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("publisher is already running!\n");
utime undef, undef, "$rundir/bs_publish.lock";

mkdir_p($myeventdir);
if (!-p "$myeventdir/.ping") {
Expand Down
4 changes: 3 additions & 1 deletion src/backend/bs_sched
Expand Up @@ -358,7 +358,9 @@ print "starting build service scheduler\n";
# get lock
mkdir_p($_rundir);
if (!$testprojid) {
BSUtil::lock_daemon_file($_rundir, "sched.$_myarch");
open(RUNLOCK, '>>', "$_rundir/bs_sched.$_myarch.lock") || die("$_rundir/bs_sched.$_myarch.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("scheduler is already running for $_myarch!\n");
utime undef, undef, "$_rundir/bs_sched.$_myarch.lock";
}

for my $d ("$_eventdir/$_myarch", "$_jobsdir/$_myarch", $_infodir) {
Expand Down
5 changes: 4 additions & 1 deletion src/backend/bs_signer
Expand Up @@ -643,7 +643,10 @@ BSUtil::restartexit($ARGV[0], 'signer', "$rundir/bs_signer", "$myeventdir/.ping"
print "starting build service signer\n";

# get lock
BSUtil::lock_daemon_file($rundir, "signer");
mkdir_p($rundir);
open(RUNLOCK, '>>', "$rundir/bs_signer.lock") || die("$rundir/bs_signer.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("signer is already running!\n");
utime undef, undef, "$rundir/bs_signer.lock";

die("sign program is not configured!\n") unless $BSConfig::sign;

Expand Down
5 changes: 4 additions & 1 deletion src/backend/bs_warden
Expand Up @@ -56,7 +56,10 @@ BSUtil::restartexit($ARGV[0], 'warden', "$rundir/bs_warden");
print BSUtil::isotime().": starting build service worker warden\n";

# get lock
BSUtil::lock_daemon_file($rundir, "warden");
mkdir_p($rundir);
open(RUNLOCK, '>>', "$rundir/bs_warden.lock") || die("$rundir/bs_warden.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("worker warden is already running!\n");
utime undef, undef, "$rundir/bs_warden.lock";

my %building;
my $nextorphan = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/backend/bs_worker
Expand Up @@ -2916,7 +2916,9 @@ my $buildcode = codemd5('build');
$| = 1;
print "starting worker $workercode build $buildcode\n";

BSUtil::lock_daemon_file($statedir, "worker");
open(RUNLOCK, '>>', "$statedir/lock") || die("$statedir/lock: $!");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("worker is already running on $statedir!\n");
utime undef, undef, "$statedir/lock";

# we always start idle
lockstate();
Expand Down

0 comments on commit a28fe25

Please sign in to comment.